-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStopwatchRepositoryImpl.kt
35 lines (30 loc) · 1.11 KB
/
StopwatchRepositoryImpl.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.whakaara.data.stopwatch
import com.whakaara.database.datastore.PreferencesDataStore
import com.whakaara.model.stopwatch.StopwatchReceiverState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import javax.inject.Inject
class StopwatchRepositoryImpl @Inject constructor(
private val preferencesDataStore: PreferencesDataStore
) : StopwatchRepository {
private val _stopwatchState = MutableStateFlow<StopwatchReceiverState>(StopwatchReceiverState.Idle)
override val stopwatchState: StateFlow<StopwatchReceiverState> = _stopwatchState.asStateFlow()
override fun startStopwatch() {
_stopwatchState.update {
StopwatchReceiverState.Started
}
}
override fun pauseStopwatch() {
_stopwatchState.update {
StopwatchReceiverState.Paused
}
}
override suspend fun stopStopwatch() {
_stopwatchState.update {
StopwatchReceiverState.Stopped
}
preferencesDataStore.clearStopwatchState()
}
}