From d28b51409b63f04f42fbb71d3a1495c6ed844362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 5 Oct 2023 13:49:52 +0200 Subject: [PATCH] Migrate `FeatureLockedDialog` in `WidgetBrightDisplayConfigureActivity` to compose --- .../WidgetBrightDisplayConfigureActivity.kt | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt index ff70624..e9de419 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt @@ -7,12 +7,14 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.viewModels +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.dialogs.ColorPickerDialog -import com.simplemobiletools.commons.dialogs.FeatureLockedDialog +import com.simplemobiletools.commons.dialogs.FeatureLockedAlertDialog import com.simplemobiletools.commons.extensions.isOrWasThankYouInstalled import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS import com.simplemobiletools.flashlight.R @@ -24,8 +26,6 @@ import com.simplemobiletools.flashlight.screens.WidgetConfigureScreen class WidgetBrightDisplayConfigureActivity : ComponentActivity() { private val viewModel by viewModels() - private var mFeatureLockedDialog: FeatureLockedDialog? = null - public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setResult(Activity.RESULT_CANCELED) @@ -51,13 +51,25 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() { onColorPressed = ::pickBackgroundColor, onSavePressed = ::saveConfig ) - } - } - if (!isCustomizingColors && !isOrWasThankYouInstalled()) { - mFeatureLockedDialog = FeatureLockedDialog(this) { - if (!isOrWasThankYouInstalled()) { - finish() + + val featureLockedAlertDialogState = rememberAlertDialogState().apply { + DialogMember { + FeatureLockedAlertDialog( + alertDialogState = this, + ) { + if (!isOrWasThankYouInstalled()) { + finish() + } + } + } + } + LaunchedEffect(isOrWasThankYouInstalled()) { + if (!isCustomizingColors && !isOrWasThankYouInstalled()) { + featureLockedAlertDialogState.show() + } else if (isOrWasThankYouInstalled()) { + featureLockedAlertDialogState.hide() + } } } } @@ -66,10 +78,6 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() { override fun onResume() { super.onResume() window.decorView.setBackgroundColor(0) - - if (mFeatureLockedDialog != null && isOrWasThankYouInstalled()) { - mFeatureLockedDialog?.dismissDialog() - } } private fun saveConfig() {