1
1
/*
2
- * Copyright 2024 Angel Studio
3
2
*
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
3
+ * * Copyright (c) 2024 Angel Studio
4
+ * *
5
+ * * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * * you may not use this file except in compliance with the License.
7
+ * * You may obtain a copy of the License at
8
+ * *
9
+ * * http://www.apache.org/licenses/LICENSE-2.0
10
+ * *
11
+ * * Unless required by applicable law or agreed to in writing, software
12
+ * * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * * See the License for the specific language governing permissions and
15
+ * * limitations under the License.
7
16
*
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
17
*/
16
18
package fr.angel.soundtap
17
19
@@ -23,12 +25,14 @@ import androidx.compose.material3.SheetState
23
25
import androidx.datastore.core.DataStore
24
26
import androidx.lifecycle.ViewModel
25
27
import androidx.lifecycle.viewModelScope
28
+ import androidx.navigation.NavHostController
26
29
import dagger.hilt.android.lifecycle.HiltViewModel
27
30
import dagger.hilt.android.qualifiers.ApplicationContext
28
31
import fr.angel.soundtap.data.enums.AutoPlayMode
29
32
import fr.angel.soundtap.data.enums.HapticFeedbackLevel
30
33
import fr.angel.soundtap.data.enums.WorkingMode
31
34
import fr.angel.soundtap.data.models.BottomSheetState
35
+ import fr.angel.soundtap.data.settings.customization.ControlMediaAction
32
36
import fr.angel.soundtap.data.settings.customization.CustomizationSettings
33
37
import fr.angel.soundtap.data.settings.settings.AppSettings
34
38
import fr.angel.soundtap.data.settings.stats.StatsSettings
@@ -52,7 +56,11 @@ data class MainUiState(
52
56
val customizationSettings : CustomizationSettings = CustomizationSettings (),
53
57
val appSettings : AppSettings = AppSettings (),
54
58
val statsSettings : StatsSettings = StatsSettings (),
59
+ val defaultNavController : NavHostController ? = null ,
60
+ val focusedNavController : NavHostController ? = null ,
55
61
) {
62
+ val currentNavController: NavHostController
63
+ get() = focusedNavController ? : defaultNavController!!
56
64
val defaultScreen: Screens
57
65
get() = if (appSettings.onboardingPageCompleted) Screens .App else Screens .Onboarding
58
66
}
@@ -208,4 +216,51 @@ class MainViewModel
208
216
fun setBottomSheetState (sheetState : SheetState ) {
209
217
this .sheetState = sheetState
210
218
}
219
+
220
+ fun setDefaultNavController (navController : NavHostController ) {
221
+ _uiState .value = _uiState .value.copy(defaultNavController = navController)
222
+ }
223
+
224
+ fun setFocusedNavController (navController : NavHostController ) {
225
+ _uiState .value = _uiState .value.copy(focusedNavController = navController)
226
+ }
227
+
228
+ fun resetFocusedNavController () {
229
+ _uiState .value = _uiState .value.copy(focusedNavController = null )
230
+ }
231
+
232
+ fun toggleControlMediaAction (action : ControlMediaAction ) {
233
+ viewModelScope.launch {
234
+ customizationSettingsDataStore.updateData { settings ->
235
+ val newAction = action.copy(enabled = ! action.enabled)
236
+ when (action.id) {
237
+ 0 -> settings.copy(longVolumeUpPressControlMediaAction = newAction)
238
+ 1 -> settings.copy(longVolumeDownPressControlMediaAction = newAction)
239
+ 2 -> settings.copy(doubleVolumeLongPressControlMediaAction = newAction)
240
+ else -> settings
241
+ }
242
+ }
243
+ }
244
+ }
245
+
246
+ fun changeControlMediaAction (controlMediaAction : ControlMediaAction ) {
247
+ showBottomSheet(
248
+ BottomSheetState .EditControlMediaAction (
249
+ displayName = " Edit ${controlMediaAction.title} action" ,
250
+ onSetAction = { newAction ->
251
+ viewModelScope.launch {
252
+ customizationSettingsDataStore.updateData { settings ->
253
+ val newControlMediaAction = controlMediaAction.copy(action = newAction)
254
+ when (controlMediaAction.id) {
255
+ 0 -> settings.copy(longVolumeUpPressControlMediaAction = newControlMediaAction)
256
+ 1 -> settings.copy(longVolumeDownPressControlMediaAction = newControlMediaAction)
257
+ 2 -> settings.copy(doubleVolumeLongPressControlMediaAction = newControlMediaAction)
258
+ else -> settings
259
+ }
260
+ }
261
+ }
262
+ },
263
+ ),
264
+ )
265
+ }
211
266
}
0 commit comments