Skip to content

Commit

Permalink
Merge pull request #112 from leandroBorgesFerreira/set_progress_error…
Browse files Browse the repository at this point in the history
…_message

improving error message
  • Loading branch information
leandroBorgesFerreira authored Jan 23, 2019
2 parents bc9a467 + 01406b3 commit 2a4fba3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ open class CircularProgressButton : AppCompatButton, ProgressButton {
}

override fun setProgress(value: Float) {
progressAnimatedDrawable.progress = value
if (presenter.validateSetProgress()) {
progressAnimatedDrawable.progress = value
} else {
throw IllegalStateException("Set progress in being called in the wrong state: ${presenter.state}." +
" Allowed states: ${State.PROGRESS}, ${State.MORPHING}, ${State.WAITING_PROGRESS}")
}
}

data class InitialState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ open class CircularProgressImageButton : AppCompatImageButton, ProgressButton {
}

override fun setProgress(value: Float) {
progressAnimatedDrawable.progress = value
if (presenter.validateSetProgress()) {
progressAnimatedDrawable.progress = value
} else {
throw IllegalStateException("Set progress in being called in the wrong state: ${presenter.state}." +
" Allowed states: ${State.PROGRESS}, ${State.MORPHING}, ${State.WAITING_PROGRESS}")
}
}

override fun setCompoundDrawables(left: Drawable?, top: Drawable?, right: Drawable?, bottom: Drawable?) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@ internal class ProgressButtonPresenter(private val view: ProgressButton) {
else -> State.DONE
}
}

internal fun validateSetProgress(): Boolean =
state == State.PROGRESS || state == State.MORPHING || state == State.WAITING_PROGRESS
}

0 comments on commit 2a4fba3

Please sign in to comment.