diff --git a/README.md b/README.md index 764d44d..20be76d 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Add the dependency in your app `build.gradle`: ``` dependencies { - implementation 'com.github.teresaholfeld:Stories:1.1.2' + implementation 'com.github.teresaholfeld:Stories:1.1.3' } ``` @@ -71,7 +71,7 @@ public class YourActivity extends AppCompatActivity implements StoriesProgressVi @Override public void onPrev() { - // Call when finished revserse animation. + // Called when skipped backwards Toast.makeText(this, "onPrev", Toast.LENGTH_SHORT).show(); } @@ -144,7 +144,7 @@ To do this, you can add the attributes to your layout xml: Modifications: ``` -Copyright (C) 2018 Teresa Holfeld (teresaholfeld), 2017 Shota Saito (shts) +Copyright (C) 2019 Teresa Holfeld (teresaholfeld), 2017 Shota Saito (shts) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/app/build.gradle b/app/build.gradle index 46382c0..4b1b752 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,7 +21,7 @@ android { } dependencies { - implementation 'com.github.teresaholfeld:Stories:1.1.0' + implementation 'com.github.teresaholfeld:Stories:1.1.2' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' diff --git a/library/build.gradle b/library/build.gradle index 9d57c5a..15b5cdd 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -11,7 +11,7 @@ android { minSdkVersion 15 targetSdkVersion 28 versionCode 1 - versionName "1.1.2" + versionName "1.1.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt index ee85892..7921f3a 100644 --- a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt +++ b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt @@ -14,13 +14,12 @@ import android.widget.FrameLayout @SuppressLint("ViewConstructor") internal class PausableProgressBar constructor(context: Context, attrs: AttributeSet? = null, - private val progressColor: Int, - private val progressBackgroundColor: Int) + progressColor: Int, + progressBackgroundColor: Int) : FrameLayout(context, attrs) { private val frontProgressView: View? private val backProgressView: View? - private val maxProgressView: View? private var animation: PausableScaleAnimation? = null private var duration = DEFAULT_PROGRESS_DURATION.toLong() @@ -39,11 +38,9 @@ internal class PausableProgressBar constructor(context: Context, init { LayoutInflater.from(context).inflate(R.layout.pausable_progress, this) frontProgressView = findViewById(R.id.front_progress) - maxProgressView = findViewById(R.id.max_progress) // work around backProgressView = findViewById(R.id.back_progress) - maxProgressView?.setBackgroundColor(progressColor) backProgressView?.setBackgroundColor(progressBackgroundColor) - maxProgressView?.setBackgroundColor(progressColor) + frontProgressView?.setBackgroundColor(progressColor) } fun setDuration(duration: Long) { @@ -55,38 +52,35 @@ internal class PausableProgressBar constructor(context: Context, } fun setMax() { - finishProgress(true) + finishProgress() + frontProgressView?.clearAnimation() + frontProgressView?.visibility = View.VISIBLE } fun setMin() { - finishProgress(false) + finishProgress() } fun setMinWithoutCallback() { - maxProgressView?.setBackgroundColor(progressBackgroundColor) - maxProgressView?.visibility = View.VISIBLE animation?.setAnimationListener(null) animation?.cancel() + frontProgressView?.visibility = View.INVISIBLE } fun setMaxWithoutCallback() { - maxProgressView?.setBackgroundColor(progressColor) - maxProgressView?.visibility = View.VISIBLE animation?.setAnimationListener(null) animation?.cancel() + frontProgressView?.clearAnimation() + frontProgressView?.visibility = View.VISIBLE } - private fun finishProgress(isMax: Boolean) { - if (isMax) maxProgressView?.setBackgroundColor(progressColor) - maxProgressView?.visibility = if (isMax) View.VISIBLE else View.GONE + private fun finishProgress() { animation?.setAnimationListener(null) animation?.cancel() callback?.onFinishProgress() } fun startProgress() { - maxProgressView?.visibility = View.GONE - animation = PausableScaleAnimation(0f, 1f, 1f, 1f, Animation.ABSOLUTE, 0f, Animation.RELATIVE_TO_SELF, 0f) animation?.duration = duration diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index 5c1110d..b22858b 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -31,8 +31,8 @@ class StoriesProgressView : LinearLayout { private var storiesListener: StoriesListener? = null internal var isComplete: Boolean = false - private var isSkipStart: Boolean = false - private var isReverseStart: Boolean = false + private var wasSkippedForward: Boolean = false + private var wasSkippedBackward: Boolean = false interface StoriesListener { fun onNext() @@ -116,11 +116,12 @@ class StoriesProgressView : LinearLayout { * Skip current story */ fun skip() { - if (isSkipStart || isReverseStart) return - if (isComplete) return - if (current < 0) return +// if (wasSkippedForward || wasSkippedBackward) return +// if (isComplete) return + if (current >= progressBars.size) return val p = progressBars[current] - isSkipStart = true + wasSkippedForward = true + wasSkippedBackward = false p.setMax() } @@ -128,11 +129,12 @@ class StoriesProgressView : LinearLayout { * Reverse current story */ fun reverse() { - if (isSkipStart || isReverseStart) return - if (isComplete) return +// if (wasSkippedForward || wasSkippedBackward) return +// if (isComplete) return if (current < 0) return val p = progressBars[current] - isReverseStart = true + wasSkippedBackward = true + wasSkippedForward = false p.setMin() } @@ -164,23 +166,30 @@ class StoriesProgressView : LinearLayout { private fun callback(index: Int): PausableProgressBar.Callback { return object : PausableProgressBar.Callback { + override fun onStartProgress() { current = index } override fun onFinishProgress() { - if (isReverseStart) { + if (wasSkippedBackward) { storiesListener?.onPrev() - if (0 <= current - 1) { + + if (current > 0) { val p = progressBars[current - 1] p.setMinWithoutCallback() + if (current == progressBars.size - 1) { + progressBars[current].setMinWithoutCallback() + } progressBars[--current].startProgress() } else { progressBars[current].startProgress() } - isReverseStart = false + wasSkippedBackward = false + wasSkippedForward = false return } + val next = current + 1 if (next <= progressBars.size - 1) { storiesListener?.onNext() @@ -189,7 +198,9 @@ class StoriesProgressView : LinearLayout { isComplete = true storiesListener?.onComplete() } - isSkipStart = false + + wasSkippedForward = false + wasSkippedBackward = false } } } @@ -218,8 +229,8 @@ class StoriesProgressView : LinearLayout { current = -1 storiesListener = null isComplete = false - isSkipStart = false - isReverseStart = false + wasSkippedForward = false + wasSkippedBackward = false } /**