Migrate `FeatureLockedDialog` in `WidgetTorchConfigureActivity` to compose

This commit is contained in:
Ensar Sarajčić 2023-10-05 13:59:12 +02:00
parent d28b51409b
commit 6c8b301c9f
3 changed files with 36 additions and 33 deletions

View File

@ -19,6 +19,7 @@ import com.simplemobiletools.commons.extensions.isOrWasThankYouInstalled
import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS
import com.simplemobiletools.flashlight.R import com.simplemobiletools.flashlight.R
import com.simplemobiletools.flashlight.activities.viewmodel.WidgetConfigureViewModel import com.simplemobiletools.flashlight.activities.viewmodel.WidgetConfigureViewModel
import com.simplemobiletools.flashlight.extensions.CheckFeatureLocked
import com.simplemobiletools.flashlight.extensions.config import com.simplemobiletools.flashlight.extensions.config
import com.simplemobiletools.flashlight.helpers.MyWidgetBrightDisplayProvider import com.simplemobiletools.flashlight.helpers.MyWidgetBrightDisplayProvider
import com.simplemobiletools.flashlight.screens.WidgetConfigureScreen import com.simplemobiletools.flashlight.screens.WidgetConfigureScreen
@ -53,24 +54,7 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() {
) )
val featureLockedAlertDialogState = rememberAlertDialogState().apply { CheckFeatureLocked(skipCheck = isCustomizingColors)
DialogMember {
FeatureLockedAlertDialog(
alertDialogState = this,
) {
if (!isOrWasThankYouInstalled()) {
finish()
}
}
}
}
LaunchedEffect(isOrWasThankYouInstalled()) {
if (!isCustomizingColors && !isOrWasThankYouInstalled()) {
featureLockedAlertDialogState.show()
} else if (isOrWasThankYouInstalled()) {
featureLockedAlertDialogState.hide()
}
}
} }
} }
} }

View File

@ -12,11 +12,10 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.dialogs.ColorPickerDialog 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.commons.helpers.IS_CUSTOMIZING_COLORS
import com.simplemobiletools.flashlight.R import com.simplemobiletools.flashlight.R
import com.simplemobiletools.flashlight.activities.viewmodel.WidgetConfigureViewModel import com.simplemobiletools.flashlight.activities.viewmodel.WidgetConfigureViewModel
import com.simplemobiletools.flashlight.extensions.CheckFeatureLocked
import com.simplemobiletools.flashlight.extensions.config import com.simplemobiletools.flashlight.extensions.config
import com.simplemobiletools.flashlight.extensions.updateBrightDisplayWidget import com.simplemobiletools.flashlight.extensions.updateBrightDisplayWidget
import com.simplemobiletools.flashlight.helpers.MyWidgetTorchProvider import com.simplemobiletools.flashlight.helpers.MyWidgetTorchProvider
@ -25,8 +24,6 @@ import com.simplemobiletools.flashlight.screens.WidgetConfigureScreen
class WidgetTorchConfigureActivity : ComponentActivity() { class WidgetTorchConfigureActivity : ComponentActivity() {
private val viewModel by viewModels<WidgetConfigureViewModel>() private val viewModel by viewModels<WidgetConfigureViewModel>()
private var mFeatureLockedDialog: FeatureLockedDialog? = null
public override fun onCreate(savedInstanceState: Bundle?) { public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setResult(Activity.RESULT_CANCELED) setResult(Activity.RESULT_CANCELED)
@ -52,14 +49,8 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
onColorPressed = ::pickBackgroundColor, onColorPressed = ::pickBackgroundColor,
onSavePressed = ::saveConfig onSavePressed = ::saveConfig
) )
}
}
if (!isCustomizingColors && !isOrWasThankYouInstalled()) { CheckFeatureLocked(skipCheck = isCustomizingColors)
mFeatureLockedDialog = FeatureLockedDialog(this) {
if (!isOrWasThankYouInstalled()) {
finish()
}
} }
} }
} }
@ -67,10 +58,6 @@ class WidgetTorchConfigureActivity : ComponentActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
window.decorView.setBackgroundColor(0) window.decorView.setBackgroundColor(0)
if (mFeatureLockedDialog != null && isOrWasThankYouInstalled()) {
mFeatureLockedDialog?.dismissDialog()
}
} }
private fun saveConfig() { private fun saveConfig() {

View File

@ -7,9 +7,16 @@ import android.net.Uri
import android.os.Build import android.os.Build
import android.provider.Settings import android.provider.Settings
import androidx.annotation.RequiresApi 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.AboutActivity
import com.simplemobiletools.commons.activities.CustomizationActivity 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.hideKeyboard
import com.simplemobiletools.commons.extensions.isOrWasThankYouInstalled
import com.simplemobiletools.commons.extensions.openDeviceSettings import com.simplemobiletools.commons.extensions.openDeviceSettings
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.commons.models.FAQItem
@ -79,3 +86,28 @@ private fun getAppIconIDs() = arrayListOf(
) )
private fun Context.launcherName() = getString(R.string.app_launcher_name) 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()
}
}
}