Skip to content

Commit

Permalink
Bugfixes (#7)
Browse files Browse the repository at this point in the history
* Get rid of maxProgressView

* Fix problem with unresponsiveness after all stories finished

* Bump version

* Fix build
  • Loading branch information
teresaholfeld authored Jun 19, 2019
1 parent 82beb18 commit e3fde2f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -116,23 +116,25 @@ 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()
}

/**
* 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()
}

Expand Down Expand Up @@ -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()
Expand All @@ -189,7 +198,9 @@ class StoriesProgressView : LinearLayout {
isComplete = true
storiesListener?.onComplete()
}
isSkipStart = false

wasSkippedForward = false
wasSkippedBackward = false
}
}
}
Expand Down Expand Up @@ -218,8 +229,8 @@ class StoriesProgressView : LinearLayout {
current = -1
storiesListener = null
isComplete = false
isSkipStart = false
isReverseStart = false
wasSkippedForward = false
wasSkippedBackward = false
}

/**
Expand Down

0 comments on commit e3fde2f

Please sign in to comment.