Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flashing of material you warning message on devices below A12 #88

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean>
icon: Int,
mainText: String,
subText: String,
switchState: MutableState<Boolean>,
onCheckChange: (Boolean) -> Unit
) {
Card(
colors = CardDefaults.cardColors(
Expand Down Expand Up @@ -186,7 +190,7 @@ fun SettingItemWIthSwitch(
)
}
}
Switch(checked = switchState.value, onCheckedChange = { switchState.value = it })
Switch(checked = switchState.value, onCheckedChange = onCheckChange)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -274,6 +275,8 @@ fun DisplayOptionsUI(
context: Context,
snackbarHostState: SnackbarHostState,
) {
val coroutiScope = rememberCoroutineScope()

val displayValue =
when (viewModel.getThemeValue()) {
ThemeMode.Light.ordinal -> "Light"
Expand Down Expand Up @@ -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
Expand Down