implement error status and reset to default style
ClarkXP opened this issue · 5 comments
Hi, I think that the library should implement an error state (when a login has been failed by an user or password error), and a reset method for return to initial style (text and drawable).
Sorry my english is bad.
Good idea, will try to implemented in on weekend.
Haha I also needed to reset the button the it's default state (In my scenario the button triggers a scan, which the user should be able to start again once finished).
So I implemented a "back to normal state" feature, and only then bothered to look if someone else already requested this feature...
If you want I'll submit a pull-request.
In my opinion, the state should be determined by the progress on setProgress:
- If 0 < progress >= maxProgress: State is "Loading".
- if progress == 0: State is "Normal"
- (For error state support) if progress < 0: Error State
Do you agree or do you think that there is a need for an explicit state-selection methods (such like stopProgress)?
I agree to all above.
Because some buttons could also have endless loading, beside setProgress
method we need to add wrapper methods to make API more clear.
setErrorState
= setProgress(-1)
setNormalState
= setProgress(0)
setLoadingState
= setProgress(1)
setCompleteState
= setProgress(100)
Of course replace above with one methods and constants like setState(ProcessButton.STATE_COMPLETE);
New version 0.0.4 is available as a snapshot from maven and pushed to dev
brunch:
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
mavenCentral()
}
compile 'com.github.dmytrodanylyk.android-process-buton:library:0.0.4-SNAPSHOT'
Key changes
Renamed attributes:
- progressText -> textProgress
- completeText -> textComplete
Added attribute to control button corner roundness:
- cornerRadius
ProcessButton
Now state depends on progress:
- normal state [0]
- progress state [1-99]
- success state [100]
- error state [-1] *new
Added abstract drawProgress
method to simplify creation different progress buttons.
General code clean-up.
Thanks to @avrahamshuk I used some code from your pull request. Please check this version, maybe I missed something. Thanks in advance.
Thank you, I will check it now