Skip to content

Commit 2a4fba3

Browse files
Merge pull request #112 from leandroBorgesFerreira/set_progress_error_message
improving error message
2 parents bc9a467 + 01406b3 commit 2a4fba3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

loading-button-android/src/main/java/br/com/simplepass/loadingbutton/customViews/CircularProgressButton.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ open class CircularProgressButton : AppCompatButton, ProgressButton {
167167
}
168168

169169
override fun setProgress(value: Float) {
170-
progressAnimatedDrawable.progress = value
170+
if (presenter.validateSetProgress()) {
171+
progressAnimatedDrawable.progress = value
172+
} else {
173+
throw IllegalStateException("Set progress in being called in the wrong state: ${presenter.state}." +
174+
" Allowed states: ${State.PROGRESS}, ${State.MORPHING}, ${State.WAITING_PROGRESS}")
175+
}
171176
}
172177

173178
data class InitialState(

loading-button-android/src/main/java/br/com/simplepass/loadingbutton/customViews/CircularProgressImageButton.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ open class CircularProgressImageButton : AppCompatImageButton, ProgressButton {
157157
}
158158

159159
override fun setProgress(value: Float) {
160-
progressAnimatedDrawable.progress = value
160+
if (presenter.validateSetProgress()) {
161+
progressAnimatedDrawable.progress = value
162+
} else {
163+
throw IllegalStateException("Set progress in being called in the wrong state: ${presenter.state}." +
164+
" Allowed states: ${State.PROGRESS}, ${State.MORPHING}, ${State.WAITING_PROGRESS}")
165+
}
161166
}
162167

163168
override fun setCompoundDrawables(left: Drawable?, top: Drawable?, right: Drawable?, bottom: Drawable?) {}

loading-button-android/src/main/java/br/com/simplepass/loadingbutton/presentation/ProgressButtonPresenter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,7 @@ internal class ProgressButtonPresenter(private val view: ProgressButton) {
126126
else -> State.DONE
127127
}
128128
}
129+
130+
internal fun validateSetProgress(): Boolean =
131+
state == State.PROGRESS || state == State.MORPHING || state == State.WAITING_PROGRESS
129132
}

0 commit comments

Comments
 (0)