SettingsViewModel.kt
Each line, with the release that last changed it.
| 0.5.0 | 1 | package dev.stave.ui.settings |
| 2 | ||
| 3 | import androidx.lifecycle.ViewModel | |
| 4 | import androidx.lifecycle.viewModelScope | |
| 5 | import dagger.hilt.android.lifecycle.HiltViewModel | |
| 6 | import dev.stave.data.LyricsHighlightColor | |
| 7 | import dev.stave.data.ReplayGainMode | |
| 8 | import dev.stave.data.SettingsStore | |
| 9 | import dev.stave.domain.model.MetadataField | |
| 10 | import kotlinx.coroutines.flow.SharingStarted | |
| 11 | import kotlinx.coroutines.flow.StateFlow | |
| 12 | import kotlinx.coroutines.flow.stateIn | |
| 13 | import kotlinx.coroutines.launch | |
| 14 | import javax.inject.Inject | |
| 15 | ||
| 16 | @HiltViewModel | |
| 17 | class SettingsViewModel @Inject constructor( | |
| 18 | private val store: SettingsStore, | |
| 19 | private val upnpHolder: dev.stave.upnp.UpnpServiceHolder, | |
| 20 | ) : ViewModel() { | |
| 21 | ||
| 22 | val enabled: StateFlow<Set<MetadataField>> = store.enabledFields.stateIn( | |
| 23 | scope = viewModelScope, | |
| 24 | started = SharingStarted.Eagerly, | |
| 25 | initialValue = MetadataField.defaults | |
| 26 | ) | |
| 27 | ||
| 28 | val marqueeEnabled: StateFlow<Boolean> = store.marqueeEnabled.stateIn( | |
| 29 | scope = viewModelScope, | |
| 30 | started = SharingStarted.Eagerly, | |
| 31 | initialValue = false, | |
| 32 | ) | |
| 33 | ||
| 34 | val kioskFlipEnabled: StateFlow<Boolean> = store.kioskFlipEnabled.stateIn( | |
| 35 | scope = viewModelScope, | |
| 36 | started = SharingStarted.Eagerly, | |
| 37 | initialValue = true, | |
| 38 | ) | |
| 39 | ||
| 40 | val domEthaUrl: StateFlow<String?> = store.domEthaUrl.stateIn( | |
| 41 | scope = viewModelScope, | |
| 42 | started = SharingStarted.Eagerly, | |
| 43 | initialValue = null, | |
| 44 | ) | |
| 45 | ||
| 46 | val cornerButtonDomEtha: StateFlow<Boolean> = store.cornerButtonDomEtha.stateIn( | |
| 47 | scope = viewModelScope, | |
| 48 | started = SharingStarted.Eagerly, | |
| 49 | initialValue = false, | |
| 50 | ) | |
| 51 | ||
| 52 | val useFraunces: StateFlow<Boolean> = store.useFraunces.stateIn( | |
| 53 | scope = viewModelScope, | |
| 54 | started = SharingStarted.Eagerly, | |
| 55 | initialValue = true, | |
| 56 | ) | |
| 57 | ||
| 58 | val replayGainMode: StateFlow<ReplayGainMode> = store.replayGainMode.stateIn( | |
| 59 | scope = viewModelScope, | |
| 60 | started = SharingStarted.Eagerly, | |
| 61 | initialValue = ReplayGainMode.OFF, | |
| 62 | ) | |
| 63 | ||
| 64 | val replayGainPreAmpDb: StateFlow<Float> = store.replayGainPreAmpDb.stateIn( | |
| 65 | scope = viewModelScope, | |
| 66 | started = SharingStarted.Eagerly, | |
| 67 | initialValue = 3f, | |
| 68 | ) | |
| 69 | ||
| 70 | val randomExcludedGenres: StateFlow<Set<String>> = store.randomExcludedGenres.stateIn( | |
| 71 | scope = viewModelScope, | |
| 72 | started = SharingStarted.Eagerly, | |
| 73 | initialValue = emptySet(), | |
| 74 | ) | |
| 75 | ||
| 76 | val lyricsHighlightSize: StateFlow<Float> = store.lyricsHighlightSize.stateIn( | |
| 77 | scope = viewModelScope, | |
| 78 | started = SharingStarted.Eagerly, | |
| 79 | initialValue = 1.5f, | |
| 80 | ) | |
| 81 | ||
| 82 | val lyricsHighlightBold: StateFlow<Boolean> = store.lyricsHighlightBold.stateIn( | |
| 83 | scope = viewModelScope, | |
| 84 | started = SharingStarted.Eagerly, | |
| 85 | initialValue = false, | |
| 86 | ) | |
| 87 | ||
| 88 | val lyricsHighlightColor: StateFlow<LyricsHighlightColor> = store.lyricsHighlightColor.stateIn( | |
| 89 | scope = viewModelScope, | |
| 90 | started = SharingStarted.Eagerly, | |
| 91 | initialValue = LyricsHighlightColor.AMBER, | |
| 92 | ) | |
| 93 | ||
| 94 | val allowExternalCalls: StateFlow<Boolean> = store.allowExternalCalls.stateIn( | |
| 95 | scope = viewModelScope, | |
| 96 | started = SharingStarted.Eagerly, | |
| 97 | initialValue = true, | |
| 98 | ) | |
| 99 | ||
| 100 | val lyricsMetadataEnabled: StateFlow<Boolean> = store.lyricsMetadataEnabled.stateIn( | |
| 101 | scope = viewModelScope, | |
| 102 | started = SharingStarted.Eagerly, | |
| 103 | initialValue = true, | |
| 104 | ) | |
| 105 | ||
| 106 | val rendererBroadcastEnabled: StateFlow<Boolean> = store.rendererBroadcastEnabled.stateIn( | |
| 107 | scope = viewModelScope, | |
| 108 | started = SharingStarted.Eagerly, | |
| 109 | initialValue = false, | |
| 110 | ) | |
| 111 | ||
| 112 | val activeRendererUdn: StateFlow<String?> = store.activeRendererUdn.stateIn( | |
| 113 | scope = viewModelScope, | |
| 114 | started = SharingStarted.Eagerly, | |
| 115 | initialValue = null, | |
| 116 | ) | |
| 117 | ||
| 118 | val renderers: StateFlow<List<dev.stave.domain.model.RemoteRenderer>> = | |
| 119 | upnpHolder.renderers | |
| 120 | ||
| 121 | val leftyMode: StateFlow<Boolean> = store.leftyMode.stateIn( | |
| 122 | scope = viewModelScope, | |
| 123 | started = SharingStarted.Eagerly, | |
| 124 | initialValue = false, | |
| 125 | ) | |
| 126 | ||
| 127 | val rendererFriendlyName: StateFlow<String?> = store.rendererFriendlyName.stateIn( | |
| 128 | scope = viewModelScope, | |
| 129 | started = SharingStarted.Eagerly, | |
| 130 | initialValue = null, | |
| 131 | ) | |
| 132 | ||
| 133 | fun toggle(field: MetadataField) { | |
| 134 | viewModelScope.launch { store.toggle(field) } | |
| 135 | } | |
| 136 | ||
| 137 | fun setMarquee(enabled: Boolean) { | |
| 138 | viewModelScope.launch { store.setMarqueeEnabled(enabled) } | |
| 139 | } | |
| 140 | ||
| 141 | fun setKioskFlipEnabled(enabled: Boolean) { | |
| 142 | viewModelScope.launch { store.setKioskFlipEnabled(enabled) } | |
| 143 | } | |
| 144 | ||
| 145 | fun setDomEthaUrl(url: String?) { | |
| 146 | viewModelScope.launch { store.setDomEthaUrl(url) } | |
| 147 | } | |
| 148 | ||
| 149 | fun setCornerButtonDomEtha(enabled: Boolean) { | |
| 150 | viewModelScope.launch { store.setCornerButtonDomEtha(enabled) } | |
| 151 | } | |
| 152 | ||
| 153 | fun setUseFraunces(enabled: Boolean) { | |
| 154 | viewModelScope.launch { store.setUseFraunces(enabled) } | |
| 155 | } | |
| 156 | ||
| 157 | fun setReplayGainMode(mode: ReplayGainMode) { | |
| 158 | viewModelScope.launch { store.setReplayGainMode(mode) } | |
| 159 | } | |
| 160 | ||
| 161 | fun setReplayGainPreAmpDb(db: Float) { | |
| 162 | viewModelScope.launch { store.setReplayGainPreAmpDb(db) } | |
| 163 | } | |
| 164 | ||
| 165 | fun addExcludedGenre(genre: String) { | |
| 166 | viewModelScope.launch { store.addExcludedGenre(genre) } | |
| 167 | } | |
| 168 | ||
| 169 | fun removeExcludedGenre(genre: String) { | |
| 170 | viewModelScope.launch { store.removeExcludedGenre(genre) } | |
| 171 | } | |
| 172 | ||
| 173 | fun setLyricsHighlightSize(multiplier: Float) { | |
| 174 | viewModelScope.launch { store.setLyricsHighlightSize(multiplier) } | |
| 175 | } | |
| 176 | ||
| 177 | fun setLyricsHighlightBold(bold: Boolean) { | |
| 178 | viewModelScope.launch { store.setLyricsHighlightBold(bold) } | |
| 179 | } | |
| 180 | ||
| 181 | fun setLyricsHighlightColor(color: LyricsHighlightColor) { | |
| 182 | viewModelScope.launch { store.setLyricsHighlightColor(color) } | |
| 183 | } | |
| 184 | ||
| 185 | fun setLyricsMetadata(enabled: Boolean) { | |
| 186 | viewModelScope.launch { store.setLyricsMetadataEnabled(enabled) } | |
| 187 | } | |
| 188 | ||
| 189 | fun setAllowExternalCalls(allow: Boolean) { | |
| 190 | viewModelScope.launch { store.setAllowExternalCalls(allow) } | |
| 191 | } | |
| 192 | ||
| 193 | fun setRendererBroadcast(enabled: Boolean) { | |
| 194 | viewModelScope.launch { store.setRendererBroadcastEnabled(enabled) } | |
| 195 | } | |
| 196 | ||
| 197 | fun setActiveRenderer(udn: String?) { | |
| 198 | viewModelScope.launch { store.setActiveRendererUdn(udn) } | |
| 199 | } | |
| 200 | fun setLeftyMode(enabled: Boolean) { | |
| 201 | viewModelScope.launch { store.setLeftyMode(enabled) } | |
| 202 | } | |
| 203 | fun setRendererFriendlyName(name: String?) { | |
| 204 | viewModelScope.launch { store.setRendererFriendlyName(name?.takeIf { it.isNotBlank() }) } | |
| 205 | } | |
| 206 | } |


