-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathKeyboardViewModel.kt
More file actions
39 lines (36 loc) · 1.4 KB
/
KeyboardViewModel.kt
File metadata and controls
39 lines (36 loc) · 1.4 KB
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
36
37
38
39
package com.rickyhu.hushkeyboard.keyboard
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.rickyhu.hushkeyboard.data.AppSettings
import com.rickyhu.hushkeyboard.data.SettingsRepository
import com.rickyhu.hushkeyboard.data.ThemeOption
import com.rickyhu.hushkeyboard.data.WideNotationOption
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
class KeyboardViewModel(
settingsRepository: SettingsRepository,
) : ViewModel() {
val keyboardState =
settingsRepository.settings
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5000),
AppSettings(),
).map { settings ->
KeyboardState(
themeOption = settings.themeOption,
wideNotationOption = settings.wideNotationOption,
smartDelete = settings.smartDelete,
addSpaceAfterNotation = settings.addSpaceAfterNotation,
vibrateOnTap = settings.vibrateOnTap,
)
}
}
data class KeyboardState(
val themeOption: ThemeOption = ThemeOption.System,
val wideNotationOption: WideNotationOption = WideNotationOption.WideWithW,
val smartDelete: Boolean = true,
val addSpaceAfterNotation: Boolean = true,
val vibrateOnTap: Boolean = true,
)