Migrate FeatureLockedDialog in WidgetBrightDisplayConfigureActivity to compose

This commit is contained in:
Ensar Sarajčić 2023-10-05 13:49:52 +02:00
parent 6893454559
commit d28b51409b

View File

@ -7,12 +7,14 @@ import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle 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.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.dialogs.FeatureLockedAlertDialog
import com.simplemobiletools.commons.extensions.isOrWasThankYouInstalled 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
@ -24,8 +26,6 @@ import com.simplemobiletools.flashlight.screens.WidgetConfigureScreen
class WidgetBrightDisplayConfigureActivity : ComponentActivity() { class WidgetBrightDisplayConfigureActivity : 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)
@ -51,25 +51,33 @@ class WidgetBrightDisplayConfigureActivity : ComponentActivity() {
onColorPressed = ::pickBackgroundColor, onColorPressed = ::pickBackgroundColor,
onSavePressed = ::saveConfig onSavePressed = ::saveConfig
) )
}
}
if (!isCustomizingColors && !isOrWasThankYouInstalled()) {
mFeatureLockedDialog = FeatureLockedDialog(this) { val featureLockedAlertDialogState = rememberAlertDialogState().apply {
DialogMember {
FeatureLockedAlertDialog(
alertDialogState = this,
) {
if (!isOrWasThankYouInstalled()) { if (!isOrWasThankYouInstalled()) {
finish() finish()
} }
} }
} }
} }
LaunchedEffect(isOrWasThankYouInstalled()) {
if (!isCustomizingColors && !isOrWasThankYouInstalled()) {
featureLockedAlertDialogState.show()
} else if (isOrWasThankYouInstalled()) {
featureLockedAlertDialogState.hide()
}
}
}
}
}
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() {