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

View file

@ -5,12 +5,14 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
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.lists.SimpleColumnScaffold
import com.simplemobiletools.commons.compose.settings.SettingsCheckBoxComponent
import com.simplemobiletools.commons.compose.settings.SettingsGroup
import com.simplemobiletools.commons.compose.settings.SettingsPreferenceComponent
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.divider_grey
import com.simplemobiletools.commons.helpers.isTiramisuPlus
@ -32,21 +34,27 @@ internal fun SettingsScreen(
onSetupLanguagePress: () -> Unit,
useCommaAsDecimalMarkFlow: Boolean,
onUseCommaAsDecimalMarkFlow: (Boolean) -> Unit,
lockedCustomizeColorText: String?,
displayLanguage: String
lockedCustomizeColorText: 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 = {
SettingsTitleTextComponent(text = stringResource(id = R.string.color_customization))
}) {
SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.customize_colors),
doOnPreferenceClick = customizeColors,
isPreferenceEnabled = isOrWasThankYouInstalled,
preferenceSummary = lockedCustomizeColorText
label = lockedCustomizeColorText,
doOnPreferenceClick = {
if (isOrWasThankYouInstalled) {
customizeColors()
} else {
featureLockedDialogState.show()
}
},
preferenceLabelColor = MaterialTheme.colorScheme.onSurface
)
SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.customize_widget_colors),
label = stringResource(id = R.string.customize_widget_colors),
doOnPreferenceClick = customizeWidgetColors
)
}
@ -56,37 +64,36 @@ internal fun SettingsScreen(
}) {
if (!isOrWasThankYouInstalled) {
SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.purchase_simple_thank_you),
label = stringResource(id = R.string.purchase_simple_thank_you),
doOnPreferenceClick = onThankYou,
)
}
if (isUseEnglishEnabled) {
SettingsCheckBoxComponent(
title = stringResource(id = R.string.use_english_language),
label = stringResource(id = R.string.use_english_language),
initialValue = isUseEnglishChecked,
onChange = onUseEnglishPress,
)
}
if (isTiramisuPlus()) {
SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.language),
preferenceSummary = displayLanguage,
label = stringResource(id = R.string.language),
value = displayLanguage,
doOnPreferenceClick = onSetupLanguagePress,
preferenceSummaryColor = MaterialTheme.colorScheme.onSurface,
)
}
SettingsCheckBoxComponent(
title = stringResource(id = R.string.vibrate_on_button_press),
label = stringResource(id = R.string.vibrate_on_button_press),
initialValue = vibrateOnButtonPressFlow,
onChange = onVibrateOnButtonPressFlow,
)
SettingsCheckBoxComponent(
title = stringResource(id = R.string.prevent_phone_from_sleeping),
label = stringResource(id = R.string.prevent_phone_from_sleeping),
initialValue = preventPhoneFromSleeping,
onChange = onPreventPhoneFromSleeping,
)
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,
onChange = onUseCommaAsDecimalMarkFlow,
)
@ -106,7 +113,7 @@ private fun SettingsScreenPreview() {
onPreventPhoneFromSleeping = {},
vibrateOnButtonPressFlow = false,
onVibrateOnButtonPressFlow = {},
isOrWasThankYouInstalled = false,
isOrWasThankYouInstalled = true,
onThankYou = {},
isUseEnglishEnabled = false,
isUseEnglishChecked = false,
@ -114,8 +121,9 @@ private fun SettingsScreenPreview() {
onSetupLanguagePress = {},
useCommaAsDecimalMarkFlow = false,
onUseCommaAsDecimalMarkFlow = {},
lockedCustomizeColorText = null,
displayLanguage = "English"
lockedCustomizeColorText = "Customize Colors",
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()
}
val preventPhoneFromSleepingFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { preventPhoneFromSleeping } }.filterNotNull()
val vibrateOnButtonPressFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { vibrateOnButtonPress } }.filterNotNull()
val wasUseEnglishToggledFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { wasUseEnglishToggled } }.filterNotNull()
val useEnglishFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { useEnglish } }.filterNotNull()
val useCommaAsDecimalMarkFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { useCommaAsDecimalMark } }.filterNotNull()
val preventPhoneFromSleepingFlow: Flow<Boolean> = ::preventPhoneFromSleeping.asFlowNonNull()
val vibrateOnButtonPressFlow: Flow<Boolean> = ::vibrateOnButtonPress.asFlowNonNull()
val useCommaAsDecimalMarkFlow: Flow<Boolean> = ::useCommaAsDecimalMark.asFlowNonNull()
}

View file

@ -8,11 +8,10 @@ androidx-customView = "1.2.0-alpha02"
androidx-customViewPooling = "1.0.0"
androidx-lifecycle = "2.7.0-alpha02"
#Compose
composeActivity = "1.8.0-beta01"
compose = "1.6.0-alpha05"
composeActivity = "1.8.0"
compose = "1.6.0-alpha07"
composeCompiler = "1.5.3"
composeMaterial3 = "1.2.0-alpha07"
accompanist = "0.33.1-alpha"
composeMaterial3 = "1.2.0-alpha09"
#AutoFitTextView
autofittextview = "0.2.1"
#exp4j
@ -20,9 +19,9 @@ exp4j = "0.4.8"
#Room
room = "2.5.2"
#Simple tools
simple-commons = "fd7f0ed81f"
simple-commons = "fd497d3719"
#Gradle
gradlePlugins-agp = "8.1.1"
gradlePlugins-agp = "8.1.2"
#build
app-build-compileSDKVersion = "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" }
#Exp4j
exp4j = { module = "net.objecthunter:exp4j", version.ref = "exp4j" }
#Accompanist
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
[bundles]
compose = [
"compose-activity",
@ -88,9 +85,6 @@ room = [
"androidx-room-ktx",
"androidx-room-runtime",
]
accompanist = [
"accompanist-systemuicontroller",
]
lifecycle = [
"androidx-lifecycle-compose",
"androidx-lifecycle-runtime",