diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 7f9a9933..c5b1756a 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -7,11 +7,11 @@
-
+
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 9f94ed30..8978d23d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,16 +1,9 @@
-
+
-
-
-
\ No newline at end of file
diff --git a/app/src/main/java/com/starry/myne/ui/screens/settings/composables/SettingsItems.kt b/app/src/main/java/com/starry/myne/ui/screens/settings/composables/SettingsItems.kt
index c9ec6331..812a94c5 100644
--- a/app/src/main/java/com/starry/myne/ui/screens/settings/composables/SettingsItems.kt
+++ b/app/src/main/java/com/starry/myne/ui/screens/settings/composables/SettingsItems.kt
@@ -127,7 +127,11 @@ fun SettingItem(icon: Int, mainText: String, subText: String, onClick: () -> Uni
@ExperimentalMaterial3Api
@Composable
fun SettingItemWIthSwitch(
- icon: Int, mainText: String, subText: String, switchState: MutableState
+ icon: Int,
+ mainText: String,
+ subText: String,
+ switchState: MutableState,
+ onCheckChange: (Boolean) -> Unit
) {
Card(
colors = CardDefaults.cardColors(
@@ -186,7 +190,7 @@ fun SettingItemWIthSwitch(
)
}
}
- Switch(checked = switchState.value, onCheckedChange = { switchState.value = it })
+ Switch(checked = switchState.value, onCheckedChange = onCheckChange)
}
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/starry/myne/ui/screens/settings/composables/SettingsScreen.kt b/app/src/main/java/com/starry/myne/ui/screens/settings/composables/SettingsScreen.kt
index f37944b7..c9fba15e 100644
--- a/app/src/main/java/com/starry/myne/ui/screens/settings/composables/SettingsScreen.kt
+++ b/app/src/main/java/com/starry/myne/ui/screens/settings/composables/SettingsScreen.kt
@@ -50,12 +50,13 @@ import coil.annotation.ExperimentalCoilApi
import com.starry.myne.BuildConfig
import com.starry.myne.MainActivity
import com.starry.myne.R
-import com.starry.myne.ui.navigation.Screens
import com.starry.myne.ui.common.CustomTopAppBar
+import com.starry.myne.ui.navigation.Screens
import com.starry.myne.ui.screens.settings.viewmodels.SettingsViewModel
import com.starry.myne.ui.screens.settings.viewmodels.ThemeMode
import com.starry.myne.ui.theme.figeronaFont
import com.starry.myne.utils.getActivity
+import kotlinx.coroutines.launch
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@ExperimentalCoilApi
@@ -274,6 +275,8 @@ fun DisplayOptionsUI(
context: Context,
snackbarHostState: SnackbarHostState,
) {
+ val coroutiScope = rememberCoroutineScope()
+
val displayValue =
when (viewModel.getThemeValue()) {
ThemeMode.Light.ordinal -> "Light"
@@ -312,23 +315,20 @@ fun DisplayOptionsUI(
icon = R.drawable.ic_settings_material_you,
mainText = stringResource(id = R.string.material_you_setting),
subText = materialYouDesc,
- switchState = materialYouSwitch
+ switchState = materialYouSwitch,
+ onCheckChange = { materialYouValue ->
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ viewModel.setMaterialYou(materialYouValue)
+ materialYouSwitch.value = materialYouValue
+ } else {
+ viewModel.setMaterialYou(false)
+ materialYouSwitch.value = false
+ coroutiScope.launch { snackbarHostState.showSnackbar(context.getString(R.string.material_you_error)) }
+ }
+ }
)
}
- if (materialYouSwitch.value) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- viewModel.setMaterialYou(true)
- } else {
- materialYouSwitch.value = false
- LaunchedEffect(
- key1 = true,
- block = { snackbarHostState.showSnackbar(context.getString(R.string.material_you_error)) })
- }
- } else {
- viewModel.setMaterialYou(false)
- }
-
if (displayDialog.value) {
AlertDialog(onDismissRequest = {
displayDialog.value = false