This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun ProgressBar.handleState(resource: Resource<Any>) { | |
visibility = when (resource) { | |
is Loading -> View.VISIBLE | |
is Error -> View.GONE | |
is Success -> View.GONE | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val defaultDebounce: Long = 500 | |
/** | |
* Prevents that the click events gets called too often by fast clicking user | |
*/ | |
@UiThread | |
fun View.setDebounceOnClickListener(@IntRange(from = 0, to = Integer.MAX_VALUE.toLong()) debounceTime: Long = defaultDebounce, listener: (View) -> Unit) { | |
this.setOnClickListener(object : View.OnClickListener { | |
private var lastClickTime: Long = 0 | |
override fun onClick(v: View) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.Job | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.channelFlow | |
import kotlinx.coroutines.launch | |
import kotlin.time.Duration | |
/** | |
* Debouncing when predicate is [true] |
OlderNewer