Simple loading button for kotlin andorid apps
Simple loading button for kotlin android apps. This button can show results in a nicely designed way to not block the ui while the user is waiting.
SUCCESS | ERROR | PROGRESS |
---|---|---|
test_button.validation = { // call a function for validation }
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.timonknispel:KTLoadingButton:XXXX'
}
Where XXXX need to be replaced by the version showen in the badge above.
<de.timonknispel.ktloadingbutton.KTLoadingButton
android:id="@+id/test_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonName="Test"
/>
Automatically by setting a onClickListener :
test_button.setOnClickListener {}
Simply call :
test_button.startLoading()
This will start the loading animation of the button. By default it should now intermediate.
When loading is done simply call:
test_button.doResult(success: Boolean)
This will stop the loading animation and start the result animation according to the given success. Optional you can add a callback if you want to know when the animation is done. It also returns the LoadingButton itself:
test_button.doResult(success: Boolean) { it: KTLoadingButton ->
// do stuff here
}
Add the progressStyle option to your xml layout:
<de.timonknispel.ktloadingbutton.KTLoadingButton
android:id="@+id/test_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonName="Test"
app:progressStyle="PROGRESS"
/>
All you have to do now is to call:
test_button.setProgress(progress: Float)
to show the progress.
test_button.touchListener = {
// do some stuff
return [true|false]
}
This can be handy if for example want the user to cancel the loading process.
test_button.reset()
test_button.validation = { // call a function for validation }
Attribute | Value/s | Description | Required | Default |
---|---|---|---|---|
buttonName | String | Sets the text for the button | [x] | |
buttonTextSize | Dimension (SP) | Sets the text size for the button | [] | 16sp |
allCaps | Boolean | If set to true all button text will be in caps | [] | true |
buttonColor | Color | Sets the color for the button text and progress | [] | #373737 |
loadingBackgroundColor | Color | Sets the background color for a failed result | [] | buttonColor with transparency of 31% |
succeedColor | Color | Sets the background color for a success result | [] | #4CAF50 |
failedColor | Color | Sets the background color for a failed result | [] | #F44336 |
autoResetButtonAfterResult | Boolean | Decides if the button should reset itself after the result was displayed (after 1,5 seconds) | [] | true |
progressStyle | [INTERMEDIATE or PROGRESS] | Decides if the button should intermediate or display a progress | [] | INTERMEDIATE |
border_thickness | Dimension (DP) | sets the thickness of the outline border and progress circle | [] | 1dp |