Merge pull request #332 from FunkyMuse/master

fix: customize colors locked
This commit is contained in:
Tibor Kaputa 2023-10-16 10:54:31 +02:00 committed by GitHub
commit 12406eec94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 41 deletions

View file

@ -111,7 +111,6 @@ dependencies {
implementation(libs.exp4j) implementation(libs.exp4j)
implementation(libs.bundles.lifecycle) implementation(libs.bundles.lifecycle)
implementation(libs.bundles.compose) implementation(libs.bundles.compose)
implementation(libs.bundles.accompanist)
debugImplementation(libs.bundles.compose.preview) debugImplementation(libs.bundles.compose.preview)
implementation(libs.bundles.room) implementation(libs.bundles.room)

View file

@ -11,11 +11,13 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.simplemobiletools.calculator.compose.SettingsScreen import com.simplemobiletools.calculator.compose.SettingsScreen
import com.simplemobiletools.calculator.extensions.* import com.simplemobiletools.calculator.extensions.*
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.enableEdgeToEdgeSimple import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
import com.simplemobiletools.commons.compose.extensions.onEventValue import com.simplemobiletools.commons.compose.extensions.onEventValue
import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.getAppIconIds import com.simplemobiletools.commons.compose.theme.getAppIconIds
import com.simplemobiletools.commons.compose.theme.getAppLauncherName import com.simplemobiletools.commons.compose.theme.getAppLauncherName
import com.simplemobiletools.commons.dialogs.FeatureLockedAlertDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import java.util.Locale import java.util.Locale
@ -43,10 +45,8 @@ class SettingsActivity : AppCompatActivity() {
} }
} }
val isOrWasThankYouInstalled = onEventValue { context.isOrWasThankYouInstalled() } val isOrWasThankYouInstalled = onEventValue { context.isOrWasThankYouInstalled() }
val lockedCustomizeColorText by remember(isOrWasThankYouInstalled) {
derivedStateOf { if (isOrWasThankYouInstalled) null else getCustomizeColorsString() }
}
val displayLanguage = remember { Locale.getDefault().displayLanguage } val displayLanguage = remember { Locale.getDefault().displayLanguage }
val featureLockedDialogState = getFeatureLockedDialogState()
SettingsScreen( SettingsScreen(
displayLanguage = displayLanguage, displayLanguage = displayLanguage,
goBack = ::finish, goBack = ::finish,
@ -73,12 +73,21 @@ class SettingsActivity : AppCompatActivity() {
applicationContext.calculatorDB.deleteHistory() applicationContext.calculatorDB.deleteHistory()
} }
}, },
lockedCustomizeColorText = lockedCustomizeColorText lockedCustomizeColorText = getCustomizeColorsString(),
featureLockedDialogState = featureLockedDialogState
) )
} }
} }
} }
@Composable
private fun getFeatureLockedDialogState() =
rememberAlertDialogState().apply {
DialogMember {
FeatureLockedAlertDialog(alertDialogState = this, cancelCallback = {})
}
}
private fun handleCustomizeColorsClick() { private fun handleCustomizeColorsClick() {
Intent(applicationContext, CustomizationActivity::class.java).apply { Intent(applicationContext, CustomizationActivity::class.java).apply {
putExtra(APP_ICON_IDS, getAppIconIds()) putExtra(APP_ICON_IDS, getAppIconIds())

View file

@ -5,12 +5,14 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import com.simplemobiletools.commons.R import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState
import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState
import com.simplemobiletools.commons.compose.extensions.MyDevices import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.lists.SimpleColumnScaffold
import com.simplemobiletools.commons.compose.settings.SettingsCheckBoxComponent import com.simplemobiletools.commons.compose.settings.SettingsCheckBoxComponent
import com.simplemobiletools.commons.compose.settings.SettingsGroup import com.simplemobiletools.commons.compose.settings.SettingsGroup
import com.simplemobiletools.commons.compose.settings.SettingsPreferenceComponent import com.simplemobiletools.commons.compose.settings.SettingsPreferenceComponent
import com.simplemobiletools.commons.compose.settings.SettingsTitleTextComponent import com.simplemobiletools.commons.compose.settings.SettingsTitleTextComponent
import com.simplemobiletools.commons.compose.settings.scaffold.SettingsScaffold
import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.divider_grey import com.simplemobiletools.commons.compose.theme.divider_grey
import com.simplemobiletools.commons.helpers.isTiramisuPlus import com.simplemobiletools.commons.helpers.isTiramisuPlus
@ -32,21 +34,27 @@ internal fun SettingsScreen(
onSetupLanguagePress: () -> Unit, onSetupLanguagePress: () -> Unit,
useCommaAsDecimalMarkFlow: Boolean, useCommaAsDecimalMarkFlow: Boolean,
onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit, onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit,
lockedCustomizeColorText: String?, lockedCustomizeColorText: String,
displayLanguage: String displayLanguage: String,
featureLockedDialogState : AlertDialogState
) { ) {
SettingsScaffold(title = stringResource(id = R.string.settings), goBack = goBack) { SimpleColumnScaffold(title = stringResource(id = R.string.settings), goBack = goBack) {
SettingsGroup(title = { SettingsGroup(title = {
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization)) SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization))
}) { }) {
SettingsPreferenceComponent( SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.customize_colors), label = lockedCustomizeColorText,
doOnPreferenceClick = customizeColors, doOnPreferenceClick = {
isPreferenceEnabled = isOrWasThankYouInstalled, if (isOrWasThankYouInstalled) {
preferenceSummary = lockedCustomizeColorText customizeColors()
} else {
featureLockedDialogState.show()
}
},
preferenceLabelColor = MaterialTheme.colorScheme.onSurface
) )
SettingsPreferenceComponent( SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.customize_widget_colors), label = stringResource(id = R.string.customize_widget_colors),
doOnPreferenceClick = customizeWidgetColors doOnPreferenceClick = customizeWidgetColors
) )
} }
@ -56,37 +64,36 @@ internal fun SettingsScreen(
}) { }) {
if (!isOrWasThankYouInstalled) { if (!isOrWasThankYouInstalled) {
SettingsPreferenceComponent( SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.purchase_simple_thank_you), label = stringResource(id = R.string.purchase_simple_thank_you),
doOnPreferenceClick = onThankYou, doOnPreferenceClick = onThankYou,
) )
} }
if (isUseEnglishEnabled) { if (isUseEnglishEnabled) {
SettingsCheckBoxComponent( SettingsCheckBoxComponent(
title = stringResource(id = R.string.use_english_language), label = stringResource(id = R.string.use_english_language),
initialValue = isUseEnglishChecked, initialValue = isUseEnglishChecked,
onChange = onUseEnglishPress, onChange = onUseEnglishPress,
) )
} }
if (isTiramisuPlus()) { if (isTiramisuPlus()) {
SettingsPreferenceComponent( SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.language), label = stringResource(id = R.string.language),
preferenceSummary = displayLanguage, value = displayLanguage,
doOnPreferenceClick = onSetupLanguagePress, doOnPreferenceClick = onSetupLanguagePress,
preferenceSummaryColor = MaterialTheme.colorScheme.onSurface,
) )
} }
SettingsCheckBoxComponent( SettingsCheckBoxComponent(
title = stringResource(id = R.string.vibrate_on_button_press), label = stringResource(id = R.string.vibrate_on_button_press),
initialValue = vibrateOnButtonPressFlow, initialValue = vibrateOnButtonPressFlow,
onChange = onVibrateOnButtonPressFlow, onChange = onVibrateOnButtonPressFlow,
) )
SettingsCheckBoxComponent( SettingsCheckBoxComponent(
title = stringResource(id = R.string.prevent_phone_from_sleeping), label = stringResource(id = R.string.prevent_phone_from_sleeping),
initialValue = preventPhoneFromSleeping, initialValue = preventPhoneFromSleeping,
onChange = onPreventPhoneFromSleeping, onChange = onPreventPhoneFromSleeping,
) )
SettingsCheckBoxComponent( SettingsCheckBoxComponent(
title = stringResource(id = com.simplemobiletools.calculator.R.string.use_comma_as_decimal_mark), label = stringResource(id = com.simplemobiletools.calculator.R.string.use_comma_as_decimal_mark),
initialValue = useCommaAsDecimalMarkFlow, initialValue = useCommaAsDecimalMarkFlow,
onChange = onUseCommaAsDecimalMarkFlow, onChange = onUseCommaAsDecimalMarkFlow,
) )
@ -106,7 +113,7 @@ private fun SettingsScreenPreview() {
onPreventPhoneFromSleeping = {}, onPreventPhoneFromSleeping = {},
vibrateOnButtonPressFlow = false, vibrateOnButtonPressFlow = false,
onVibrateOnButtonPressFlow = {}, onVibrateOnButtonPressFlow = {},
isOrWasThankYouInstalled = false, isOrWasThankYouInstalled = true,
onThankYou = {}, onThankYou = {},
isUseEnglishEnabled = false, isUseEnglishEnabled = false,
isUseEnglishChecked = false, isUseEnglishChecked = false,
@ -114,8 +121,9 @@ private fun SettingsScreenPreview() {
onSetupLanguagePress = {}, onSetupLanguagePress = {},
useCommaAsDecimalMarkFlow = false, useCommaAsDecimalMarkFlow = false,
onUseCommaAsDecimalMarkFlow = {}, onUseCommaAsDecimalMarkFlow = {},
lockedCustomizeColorText = null, lockedCustomizeColorText = "Customize Colors",
displayLanguage = "English" displayLanguage = "English",
featureLockedDialogState = rememberAlertDialogState()
) )
} }
} }

View file

@ -37,9 +37,7 @@ class Config(context: Context) : BaseConfig(context) {
prefs.edit().putString("$CONVERTER_UNITS_PREFIX.${converter.key}", "${topUnit.key},${bottomUnit.key}").apply() prefs.edit().putString("$CONVERTER_UNITS_PREFIX.${converter.key}", "${topUnit.key},${bottomUnit.key}").apply()
} }
val preventPhoneFromSleepingFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { preventPhoneFromSleeping } }.filterNotNull() val preventPhoneFromSleepingFlow: Flow<Boolean> = ::preventPhoneFromSleeping.asFlowNonNull()
val vibrateOnButtonPressFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { vibrateOnButtonPress } }.filterNotNull() val vibrateOnButtonPressFlow: Flow<Boolean> = ::vibrateOnButtonPress.asFlowNonNull()
val wasUseEnglishToggledFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { wasUseEnglishToggled } }.filterNotNull() val useCommaAsDecimalMarkFlow: Flow<Boolean> = ::useCommaAsDecimalMark.asFlowNonNull()
val useEnglishFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { useEnglish } }.filterNotNull()
val useCommaAsDecimalMarkFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { useCommaAsDecimalMark } }.filterNotNull()
} }

View file

@ -8,11 +8,10 @@ androidx-customView = "1.2.0-alpha02"
androidx-customViewPooling = "1.0.0" androidx-customViewPooling = "1.0.0"
androidx-lifecycle = "2.7.0-alpha02" androidx-lifecycle = "2.7.0-alpha02"
#Compose #Compose
composeActivity = "1.8.0-beta01" composeActivity = "1.8.0"
compose = "1.6.0-alpha05" compose = "1.6.0-alpha07"
composeCompiler = "1.5.3" composeCompiler = "1.5.3"
composeMaterial3 = "1.2.0-alpha07" composeMaterial3 = "1.2.0-alpha09"
accompanist = "0.33.1-alpha"
#AutoFitTextView #AutoFitTextView
autofittextview = "0.2.1" autofittextview = "0.2.1"
#exp4j #exp4j
@ -20,9 +19,9 @@ exp4j = "0.4.8"
#Room #Room
room = "2.5.2" room = "2.5.2"
#Simple tools #Simple tools
simple-commons = "fd7f0ed81f" simple-commons = "fd497d3719"
#Gradle #Gradle
gradlePlugins-agp = "8.1.1" gradlePlugins-agp = "8.1.2"
#build #build
app-build-compileSDKVersion = "34" app-build-compileSDKVersion = "34"
app-build-targetSDK = "34" app-build-targetSDK = "34"
@ -65,8 +64,6 @@ auto-fit-text-view = { module = "me.grantland:autofittextview", version.ref = "a
simple-tools-commons = { module = "com.github.SimpleMobileTools:Simple-Commons", version.ref = "simple-commons" } simple-tools-commons = { module = "com.github.SimpleMobileTools:Simple-Commons", version.ref = "simple-commons" }
#Exp4j #Exp4j
exp4j = { module = "net.objecthunter:exp4j", version.ref = "exp4j" } exp4j = { module = "net.objecthunter:exp4j", version.ref = "exp4j" }
#Accompanist
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
[bundles] [bundles]
compose = [ compose = [
"compose-activity", "compose-activity",
@ -88,9 +85,6 @@ room = [
"androidx-room-ktx", "androidx-room-ktx",
"androidx-room-runtime", "androidx-room-runtime",
] ]
accompanist = [
"accompanist-systemuicontroller",
]
lifecycle = [ lifecycle = [
"androidx-lifecycle-compose", "androidx-lifecycle-compose",
"androidx-lifecycle-runtime", "androidx-lifecycle-runtime",