Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setcurrent position #47

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ It is similar to a ViewPager, but you can quickly and painlessly create layout,

![GifSampleShop](https://github.com/yarolegovich/DiscreteScrollView/blob/master/images/cards_shop.gif)

[ ![Download](https://api.bintray.com/packages/jjhesk/maven/discrete-scrollview/images/download.svg) ](https://bintray.com/jjhesk/maven/discrete-scrollview/_latestVersion)

## Gradle
Add this into your dependencies block.
```
compile 'com.yarolegovich:discrete-scrollview:1.3.0'
compile 'com.hkm.ui:discrete-scrollview:1.3.1'
```

## Sample
Expand Down
88 changes: 72 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.novoda:bintray-release:0.4.0'
classpath "com.android.tools.build:gradle:${GRADLE_ANDROID}"
classpath 'com.novoda:bintray-release:0.5.0'
}
}

Expand All @@ -15,21 +15,77 @@ allprojects {
}
}

configure(allprojects) {
/* Android config and dependency versions */
ext {

libden = [

support_v4 : "com.android.support:support-v4:${SUPPORT_LIBRARY}",
percent : "com.android.support:percent:${SUPPORT_LIBRARY}",
annotation : "com.android.support:support-annotations:${SUPPORT_LIBRARY}",
support : "com.android.support:support-v13:${SUPPORT_LIBRARY}",
appCompat : "com.android.support:appcompat-v7:${SUPPORT_LIBRARY}",
recycler : "com.android.support:recyclerview-v7:${SUPPORT_LIBRARY}",
design : "com.android.support:design:${SUPPORT_LIBRARY}",
cardView : "com.android.support:cardview-v7:${SUPPORT_LIBRARY}",
mediarouter : "com.android.support:mediarouter-v7:${SUPPORT_LIBRARY}",
palette : "com.android.support:palette-v7:${SUPPORT_LIBRARY}",


butterknife : "com.jakewharton:butterknife:${BUTTERKNIFE}",
butterknifeapt : "com.jakewharton:butterknife-compiler:${BUTTERKNIFE}",

retrofitAdapter : "com.squareup.retrofit2:retrofit-adapters:${RETROFIT_LIBRARY}",
retrofitCore : "com.squareup.retrofit2:retrofit:${RETROFIT_LIBRARY}",
retrofitRXJava : "com.squareup.retrofit2:adapter-rxjava:${RETROFIT_LIBRARY}",
retrofitConverterGson : "com.squareup.retrofit2:converter-gson:${RETROFIT_LIBRARY}",
retrofitParent : "com.squareup.retrofit2:parent:${RETROFIT_LIBRARY}",

okhttpLogger : "com.squareup.okhttp3:logging-interceptor:${OKHTTP_LIBRARY}",
okhttpWebsocket : "com.squareup.okhttp3:okhttp-ws:${OKHTTP_LIBRARY}",
okhttpCore : "com.squareup.okhttp3:okhttp:${OKHTTP_LIBRARY}",

icepick : "frankiesardo:icepick:${FRANKIES_ICEPICK}",
icepickProcessor : "frankiesardo:icepick-processor:${FRANKIES_ICEPICK}",

smartTabLayoutUtilsV13: "com.ogaclejapan.smarttablayout:utils-v13:${SMARTTABLAYOUT}@aar",
smartTabLayoutUtilsV4 : "com.ogaclejapan.smarttablayout:utils-v4:${SMARTTABLAYOUT}@aar",
smartTabLayoutCore : "com.ogaclejapan.smarttablayout:library:${SMARTTABLAYOUT}@aar",

leakcanary : "com.squareup.leakcanary:leakcanary-android:${LEAKCANARY}",
leakcanarynoop : "com.squareup.leakcanary:leakcanary-android-no-op:${LEAKCANARY}",

gms_anayltics : "com.google.android.gms:play-services-analytics:${GOOGLE_PLAY_SERVICE}",

dagger : "com.google.dagger:dagger:${DAGGER_2}",
daggerapt : "com.google.dagger:dagger-compiler:${DAGGER_2}",


fishglassannotation : "org.glassfish:javax.annotation:10.0-b28",
pretty_time : "org.ocpsoft.prettytime:prettytime:4.0.1.Final",
gson : "com.google.code.gson:gson:2.6.2",
jsoup : "org.jsoup:jsoup:1.9.2",

firebasecore : "com.google.firebase:firebase-core:${FIREBASE}",
database : "com.google.firebase:firebase-database:${FIREBASE}",
storage : "com.google.firebase:firebase-storage:${FIREBASE}",
crash : "com.google.firebase:firebase-crash:${FIREBASE}",
auth : "com.google.firebase:firebase-auth:${FIREBASE}",
messaging : "com.google.firebase:firebase-messaging:${FIREBASE}",
config : "com.google.firebase:firebase-config:${FIREBASE}",
invites : "com.google.firebase:firebase-invites:${FIREBASE}",
ads : "com.google.firebase:firebase-ads:${FIREBASE}",
appindexing : "com.google.firebase:firebase-appindexing:${FIREBASE}",
perf : "com.google.firebase:firebase-perf:${FIREBASE}"


]
}

}

task clean(type: Delete) {
delete rootProject.buildDir
}

ext {
userOrg = 'yarolegovich'
groupId = 'com.yarolegovich'
uploadName = 'DiscreteScrollView'
description = 'Scrollable list of items, where current item is centered and can be changed using swipes.'
publishVersion = '1.3.0'
licences = ['Apache-2.0']

compileSdkVersion = 26
buildToolsVersion = '26.0.1'
targetSdkVersion = 25

supportLibVersion = '26.0.0'
}
56 changes: 56 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,59 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

POM_GROUP_ID=com.hkm.ui
POM_ARTIFACT_ID=discrete-scrollview
POM_VERSION=1.3.1

POM_DESCRIPTION=Scrollable list of items, where current item is centered and can be changed using swipes.
POM_URL=https://github.com/HKMOpen/DiscreteScrollView
POM_SCM_URL=https://github.com/HKMOpen/DiscreteScrollView
POM_SCM_CONNECTION=scm:git@github.com:HKMOpen/DiscreteScrollView.git
POM_SCM_DEV_CONNECTION=scm:git@github.com:HKMOpen/DiscreteScrollView.git
POM_LICENCE_NAME=The MIT License (MIT)
POM_LICENCE_URL=https://github.com/HKMOpen/DiscreteScrollView/LICENSE.MD
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=zawadz88
POM_DEVELOPER_NAME=yarolegovich
POM_EMAIL=yarolegovich@stepstone.com

bintray.user=jjhesk
bintray.apikey=17479d176480ed0232fe101b6555654a2624d7a0

#Needed so that Robolectric is working: https://github.com/robolectric/robolectric/issues/3169
android.enableAapt2=false
#android version build
ANDROID_ESPRESSO=3.0.0
ANDROID_SUPPORT_TEST=1.0.0
ANDROID_BUILD_MIN_SDK_VERSION=21
ANDROID_BUILD_TARGET_SDK_VERSION=26
ANDROID_BUILD_SDK_VERSION=26
ANDROID_BUILD_TOOLS_VERSION=26.0.0
GRADLE_ANDROID=2.3.3
BINTRAY=1.4
MAVEN_GRADLE_PLUGIN=1.4.1
KOTLIN=1.1.4
#testing version
KOTLIN_MOCK=1.4.0
ACCERT_J=1.1.1
ROBOLECTRIC=3.3.1
J_UNIT=4.12
#major supports
SUPPORT_LIBRARY=25.4.0
RETROFIT_LIBRARY=2.3.0
OKHTTP_LIBRARY=3.8.1
LOOKBACK_SDK=1.5.3
FIREBASE=11.2.0
#version check on @link https://github.com/frankiesardo/icepick
FRANKIES_ICEPICK=3.2.0
#version check on @link https://github.com/ogaclejapan/SmartTabLayout
SMARTTABLAYOUT=1.6.1
#version check on @link https://github.com/square/leakcanary
LEAKCANARY=1.5.2
GOOGLE_PLAY_SERVICE=11.3.2
GOOGLE_CLASSPATH=3.1.0
BUTTERKNIFE=8.5.1
DAGGER_2=2.11
REALM=3.5.0
CALLIGRAPHY=2.2.0
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 12 09:24:26 BST 2017
#Thu Sep 14 16:30:06 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
22 changes: 22 additions & 0 deletions library/bintrayrelease.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apply plugin: 'bintray-release'

publish {
groupId = project.POM_GROUP_ID
artifactId = project.POM_ARTIFACT_ID
version = project.ext.POM_VERSION
uploadName = project.POM_ARTIFACT_ID
description = project.POM_DESCRIPTION
website = project.POM_URL
autoPublish = true
dryRun = false
}


if (hasProperty('bintray.user')) {
publish.bintrayUser = property('bintray.user')
}

if (hasProperty('bintray.apikey')) {
publish.bintrayKey = property('bintray.apikey')
}

18 changes: 11 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdkVersion project.ANDROID_BUILD_SDK_VERSION as int
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
minSdkVersion project.ANDROID_BUILD_MIN_SDK_VERSION
targetSdkVersion project.ANDROID_BUILD_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
}
}

dependencies {
compile "com.android.support:appcompat-v7:$supportLibVersion"
compile "com.android.support:recyclerview-v7:$supportLibVersion"
compile libden.appCompat
compile libden.recycler
}

/*

publish {
artifactId = 'discrete-scrollview'
userOrg = rootProject.userOrg
Expand All @@ -26,4 +28,6 @@ publish {
publishVersion = rootProject.publishVersion
description = rootProject.description
licences = rootProject.licences
}
}*/

apply from: 'bintrayrelease.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
private boolean dataSetChangeShiftedPosition;
private boolean isFirstOrEmptyLayout;

private int flingThreshold;
private int flingThreshold = 2100; //Decrease to increase sensitivity.
private boolean shouldSlideOnFling;

@NonNull
Expand Down Expand Up @@ -463,7 +463,7 @@ private void startSmoothPendingScroll() {
startSmoothScroll(scroller);
}

private void startSmoothPendingScroll(int position){
private void startSmoothPendingScroll(int position) {
if (currentPosition == position) return;
pendingScroll = -scrolled;
Direction direction = Direction.fromDelta(position - currentPosition);
Expand Down Expand Up @@ -536,11 +536,11 @@ public void setOrientation(Orientation orientation) {
requestLayout();
}

public void setShouldSlideOnFling(boolean result){
public void setShouldSlideOnFling(boolean result) {
shouldSlideOnFling = result;
}

public void setSlideOnFlingThreshold(int threshold){
public void setSlideOnFlingThreshold(int threshold) {
flingThreshold = threshold;
}

Expand Down Expand Up @@ -599,8 +599,8 @@ public int getExtraLayoutSpace() {

private void notifyScroll() {
float amountToScroll = pendingPosition != NO_POSITION ?
Math.abs(scrolled + pendingScroll) :
scrollToChangeCurrent;
Math.abs(scrolled + pendingScroll) :
scrollToChangeCurrent;
float position = -Math.min(Math.max(-1f, scrolled / amountToScroll), 1f);
scrollStateListener.onScroll(position);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public void setLayoutManager(LayoutManager layout) {
}
}

public final void setCurrentPosition(int position) {
if (getAdapter().getItemCount() > position) {
scrollToPosition(position);
}
}

@Override
public boolean fling(int velocityX, int velocityY) {
Expand Down Expand Up @@ -104,11 +109,11 @@ public void setItemTransitionTimeMillis(@IntRange(from = 10) int millis) {
layoutManager.setTimeForItemSettle(millis);
}

public void setSlideOnFling(boolean result){
public void setSlideOnFling(boolean result) {
layoutManager.setShouldSlideOnFling(result);
}

public void setSlideOnFlingThreshold(int threshold){
public void setSlideOnFlingThreshold(int threshold) {
layoutManager.setSlideOnFlingThreshold(threshold);
}

Expand Down Expand Up @@ -161,8 +166,8 @@ private void notifyScroll(float position,
ViewHolder currentHolder, ViewHolder newHolder) {
for (ScrollStateChangeListener listener : scrollStateChangeListeners) {
listener.onScroll(position, currentIndex, newIndex,
currentHolder,
newHolder);
currentHolder,
newHolder);
}
}

Expand Down Expand Up @@ -221,9 +226,9 @@ public void onScroll(float currentViewPosition) {
int currentIndex = getCurrentItem();
int newIndex = layoutManager.getNextPosition();
notifyScroll(currentViewPosition,
currentIndex, newIndex,
getViewHolder(currentIndex),
getViewHolder(newIndex));
currentIndex, newIndex,
getViewHolder(currentIndex),
getViewHolder(newIndex));
}

@Override
Expand Down
19 changes: 11 additions & 8 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdkVersion project.ANDROID_BUILD_SDK_VERSION as int
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
applicationId "com.yarolegovich.discretescrollview.sample"
minSdkVersion 19
targetSdkVersion rootProject.ext.targetSdkVersion

versionCode 4
versionName "1.0"

minSdkVersion project.ANDROID_BUILD_MIN_SDK_VERSION
targetSdkVersion project.ANDROID_BUILD_TARGET_SDK_VERSION

}

buildTypes {
Expand All @@ -22,12 +26,11 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile "com.android.support:appcompat-v7:$supportLibVersion"
compile "com.android.support:cardview-v7:$supportLibVersion"
compile "com.android.support:design:$supportLibVersion"
compile libden.appCompat
compile libden.cardView
compile libden.design

compile 'com.github.bumptech.glide:glide:3.7.0'

compile 'com.yarolegovich:mp:1.0.5'

compile project(':library')
Expand Down