Skip to content

fixing startAnimation on create bug #137

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

Merged
merged 1 commit into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion loading-button-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'org.jmailen.kotlinter'

// Bintray depends on this global variable to set the library version!
version = "2.1.1"
version = "2.1.3"
group = 'br.com.simplepass'

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ open class CircularProgressButton : AppCompatButton, ProgressButton {

override lateinit var drawableBackground: Drawable

private var savedAnimationEndListener: () -> Unit = {}

private val presenter = ProgressButtonPresenter(this)

private val morphAnimator by lazy {
Expand Down Expand Up @@ -124,10 +126,12 @@ open class CircularProgressButton : AppCompatButton, ProgressButton {
}

override fun startMorphAnimation() {
applyAnimationEndListener(morphAnimator, savedAnimationEndListener)
morphAnimator.start()
}

override fun startMorphRevertAnimation() {
applyAnimationEndListener(morphAnimator, savedAnimationEndListener)
morphRevertAnimator.start()
}

Expand All @@ -140,14 +144,12 @@ open class CircularProgressButton : AppCompatButton, ProgressButton {
}

override fun startAnimation(onAnimationEndListener: () -> Unit) {
applyAnimationEndListener(morphAnimator, onAnimationEndListener)

savedAnimationEndListener = onAnimationEndListener
presenter.startAnimation()
}

override fun revertAnimation(onAnimationEndListener: () -> Unit) {
applyAnimationEndListener(morphRevertAnimator, onAnimationEndListener)

savedAnimationEndListener = onAnimationEndListener
presenter.revertAnimation()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ open class CircularProgressImageButton : AppCompatImageButton, ProgressButton {

override lateinit var drawableBackground: Drawable

private var savedAnimationEndListener: () -> Unit = {}

private val presenter = ProgressButtonPresenter(this)

private val morphAnimator by lazy {
Expand Down Expand Up @@ -113,10 +115,12 @@ open class CircularProgressImageButton : AppCompatImageButton, ProgressButton {
}

override fun startMorphAnimation() {
applyAnimationEndListener(morphAnimator, savedAnimationEndListener)
morphAnimator.start()
}

override fun startMorphRevertAnimation() {
applyAnimationEndListener(morphAnimator, savedAnimationEndListener)
morphRevertAnimator.start()
}

Expand All @@ -129,14 +133,12 @@ open class CircularProgressImageButton : AppCompatImageButton, ProgressButton {
}

override fun startAnimation(onAnimationEndListener: () -> Unit) {
applyAnimationEndListener(morphAnimator, onAnimationEndListener)

savedAnimationEndListener = onAnimationEndListener
presenter.startAnimation()
}

override fun revertAnimation(onAnimationEndListener: () -> Unit) {
applyAnimationEndListener(morphRevertAnimator, onAnimationEndListener)

savedAnimationEndListener = onAnimationEndListener
presenter.revertAnimation()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ internal class ProgressButtonPresenter(private val view: ProgressButton) {
}

fun onDraw(canvas: Canvas) {
if (state == State.BEFORE_DRAW) {
state = State.IDLE
view.saveInitialState()
}

when (state) {
State.WAITING_PROGRESS -> view.startMorphAnimation()
State.BEFORE_DRAW -> {
state = State.IDLE
view.saveInitialState()
}
State.WAITING_PROGRESS -> {
view.saveInitialState()
view.startMorphAnimation()
}
State.PROGRESS -> view.drawProgress(canvas)
State.DONE -> view.drawDoneAnimation(canvas)
else -> return
Expand Down