Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-07 19:02:08 +05:00
parent 459db3d0df
commit f43f6299d1
62 changed files with 2 additions and 5914 deletions

View file

@ -1,61 +0,0 @@
package com.tangem.tap.common.toggleWidget
import android.graphics.drawable.Drawable
import android.view.View
import com.google.android.material.button.MaterialButton
import com.tangem.tap.common.entities.ProgressState
import com.tangem.tap.common.extensions.hide
import com.tangem.tap.common.extensions.show
/**
[REDACTED_AUTHOR]
*/
open class IndeterminateProgressButtonWidget(
private val button: MaterialButton,
private val progress: View,
initialState: ProgressState = ProgressState.Done,
) : ViewStateWidget {
private var text: CharSequence = button.text
private var icon: Drawable? = button.icon
private var iconGravity: Int? = button.iconGravity
init {
if (initialState != ProgressState.Done) changeState(initialState)
}
var isEnabled: Boolean
get() = button.isEnabled
set(value) {
button.isEnabled = value
}
override val mainView: View = button
override fun changeState(state: WidgetState) {
val progressState = state as? ProgressState ?: return
when (progressState) {
ProgressState.Done, ProgressState.Error -> switchToNone()
ProgressState.Loading -> switchToProgress()
else -> {}
}
}
protected open fun switchToNone() {
button.isClickable = true
button.text = text
button.icon = icon
iconGravity?.let { button.iconGravity = it }
progress.hide()
}
protected open fun switchToProgress() {
button.isClickable = false
button.text = ""
button.icon = null
progress.show()
}
}