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 e9de419..bf6ebde 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetBrightDisplayConfigureActivity.kt @@ -19,6 +19,7 @@ import com.simplemobiletools.commons.extensions.isOrWasThankYouInstalled import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS import com.simplemobiletools.flashlight.R import com.simplemobiletools.flashlight.activities.viewmodel.WidgetConfigureViewModel +import com.simplemobiletools.flashlight.extensions.CheckFeatureLocked import com.simplemobiletools.flashlight.extensions.config import com.simplemobiletools.flashlight.helpers.MyWidgetBrightDisplayProvider import com.simplemobiletools.flashlight.screens.WidgetConfigureScreen @@ -53,24 +54,7 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() { ) - val featureLockedAlertDialogState = rememberAlertDialogState().apply { - DialogMember { - FeatureLockedAlertDialog( - alertDialogState = this, - ) { - if (!isOrWasThankYouInstalled()) { - finish() - } - } - } - } - LaunchedEffect(isOrWasThankYouInstalled()) { - if (!isCustomizingColors && !isOrWasThankYouInstalled()) { - featureLockedAlertDialogState.show() - } else if (isOrWasThankYouInstalled()) { - featureLockedAlertDialogState.hide() - } - } + CheckFeatureLocked(skipCheck = isCustomizingColors) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetTorchConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetTorchConfigureActivity.kt index d930501..5b99e6a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetTorchConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetTorchConfigureActivity.kt @@ -12,11 +12,10 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle 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.extensions.isOrWasThankYouInstalled import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS import com.simplemobiletools.flashlight.R import com.simplemobiletools.flashlight.activities.viewmodel.WidgetConfigureViewModel +import com.simplemobiletools.flashlight.extensions.CheckFeatureLocked import com.simplemobiletools.flashlight.extensions.config import com.simplemobiletools.flashlight.extensions.updateBrightDisplayWidget import com.simplemobiletools.flashlight.helpers.MyWidgetTorchProvider @@ -25,8 +24,6 @@ import com.simplemobiletools.flashlight.screens.WidgetConfigureScreen class WidgetTorchConfigureActivity : ComponentActivity() { private val viewModel by viewModels() - private var mFeatureLockedDialog: FeatureLockedDialog? = null - public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setResult(Activity.RESULT_CANCELED) @@ -52,14 +49,8 @@ class WidgetTorchConfigureActivity : ComponentActivity() { onColorPressed = ::pickBackgroundColor, onSavePressed = ::saveConfig ) - } - } - if (!isCustomizingColors && !isOrWasThankYouInstalled()) { - mFeatureLockedDialog = FeatureLockedDialog(this) { - if (!isOrWasThankYouInstalled()) { - finish() - } + CheckFeatureLocked(skipCheck = isCustomizingColors) } } } @@ -67,10 +58,6 @@ class WidgetTorchConfigureActivity : ComponentActivity() { override fun onResume() { super.onResume() window.decorView.setBackgroundColor(0) - - if (mFeatureLockedDialog != null && isOrWasThankYouInstalled()) { - mFeatureLockedDialog?.dismissDialog() - } } private fun saveConfig() { diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/extensions/Activity.kt index 10802da..2c8d65e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/extensions/Activity.kt @@ -7,9 +7,16 @@ import android.net.Uri import android.os.Build import android.provider.Settings import androidx.annotation.RequiresApi +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.platform.LocalContext import com.simplemobiletools.commons.activities.AboutActivity import com.simplemobiletools.commons.activities.CustomizationActivity +import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState +import com.simplemobiletools.commons.compose.extensions.getActivity +import com.simplemobiletools.commons.dialogs.FeatureLockedAlertDialog import com.simplemobiletools.commons.extensions.hideKeyboard +import com.simplemobiletools.commons.extensions.isOrWasThankYouInstalled import com.simplemobiletools.commons.extensions.openDeviceSettings import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FAQItem @@ -79,3 +86,28 @@ private fun getAppIconIDs() = arrayListOf( ) private fun Context.launcherName() = getString(R.string.app_launcher_name) + +@Composable +fun CheckFeatureLocked( + skipCheck: Boolean +) { + val context = LocalContext.current.getActivity() + val featureLockedAlertDialogState = rememberAlertDialogState().apply { + DialogMember { + FeatureLockedAlertDialog( + alertDialogState = this, + ) { + if (!context.isOrWasThankYouInstalled()) { + context.finish() + } + } + } + } + LaunchedEffect(context.isOrWasThankYouInstalled()) { + if (!skipCheck && !context.isOrWasThankYouInstalled()) { + featureLockedAlertDialogState.show() + } else if (context.isOrWasThankYouInstalled()) { + featureLockedAlertDialogState.hide() + } + } +}