Skip to content

Instantly share code, notes, and snippets.

@vegeta2102
Created March 24, 2021 13:16
Show Gist options
  • Save vegeta2102/f4779caf4d49f6a8dbec0e86e0ddb99f to your computer and use it in GitHub Desktop.
Save vegeta2102/f4779caf4d49f6a8dbec0e86e0ddb99f to your computer and use it in GitHub Desktop.
class ProgressBarViewModel @ViewModelInject constructor(
private val progressBarRepository: ProgressBarRepository
) : ViewModel() {
// Display seconds
val countDown: LiveData<String> = progressBarRepository.data.map {
it.time.toString()
}.asLiveData().distinctUntilChanged()
// Progress state of circle bar
val progress: LiveData<Int> = progressBarRepository.data.map {
it.progress
}.asLiveData().distinctUntilChanged()
fun start() {
viewModelScope.launch {
// Count down 10 seconds
progressBarRepository.startCountDown(10)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment