fix(timer): combine flows to fix a bug with the progress indicator
This commit is contained in:
@@ -33,7 +33,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -59,9 +59,8 @@ class TimerViewModel(
|
||||
|
||||
val time: StateFlow<Long> = _time.asStateFlow()
|
||||
|
||||
val progress = _time.map {
|
||||
val uiState = timerState.value
|
||||
(uiState.totalTime.toFloat() - it) / uiState.totalTime
|
||||
val progress = _time.combine(_timerState) { remainingTime, uiState ->
|
||||
(uiState.totalTime.toFloat() - remainingTime) / uiState.totalTime
|
||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0f)
|
||||
|
||||
private var cycles = 0
|
||||
|
||||
Reference in New Issue
Block a user