From 51bd8a736cae50d3cd38ce38a9aefef199e0f87b Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Tue, 3 Oct 2023 16:15:20 +0200 Subject: [PATCH 1/3] refactor: migrate dialogs to Compose --- .../thankyou/activities/MainActivity.kt | 106 +++++++++++++++--- .../thankyou/helpers/Constants.kt | 6 + .../thankyou/helpers/Extensions.kt | 86 ++++++++++++++ .../thankyou/screens/MainScreen.kt | 6 +- gradle/libs.versions.toml | 10 +- 5 files changed, 190 insertions(+), 24 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Extensions.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/MainActivity.kt index cd865b6..a414001 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/MainActivity.kt @@ -4,18 +4,29 @@ import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.runtime.Composable +import androidx.compose.runtime.* +import androidx.compose.runtime.snapshots.SnapshotStateList +import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState +import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple +import com.simplemobiletools.commons.compose.extensions.linkColor import com.simplemobiletools.commons.compose.extensions.onEventValue import com.simplemobiletools.commons.compose.theme.AppThemeSurface +import com.simplemobiletools.commons.dialogs.DonateAlertDialog +import com.simplemobiletools.commons.dialogs.RateStarsAlertDialog +import com.simplemobiletools.commons.dialogs.UpgradeToProAlertDialog +import com.simplemobiletools.commons.dialogs.WhatsNewAlertDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.commons.models.Release import com.simplemobiletools.thankyou.BuildConfig import com.simplemobiletools.thankyou.R -import com.simplemobiletools.thankyou.extensions.checkWhatsNew import com.simplemobiletools.thankyou.extensions.startAboutActivity +import com.simplemobiletools.thankyou.helpers.appLaunchedCompose +import com.simplemobiletools.thankyou.helpers.checkWhatsNewCompose +import com.simplemobiletools.thankyou.helpers.upgradeToPro import com.simplemobiletools.thankyou.screens.MainScreen +import kotlinx.collections.immutable.toImmutableList class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -23,6 +34,8 @@ class MainActivity : ComponentActivity() { enableEdgeToEdgeSimple() setContent { AppThemeSurface { + val releasesList = remember { mutableStateListOf() } + val checkWhatsNewAlertDialogState = getCheckWhatsNewAlertDialogState(releasesList) val linkColor = linkColor() val showMoreApps = onEventValue { !resources.getBoolean(R.bool.hide_google_relations) } MainScreen( @@ -32,17 +45,86 @@ class MainActivity : ComponentActivity() { openAbout = ::launchAbout, moreAppsFromUs = ::launchMoreAppsFromUsIntent ) + AppLaunched() + CheckWhatsNew(releasesList, checkWhatsNewAlertDialogState) } } - appLaunched(BuildConfig.APPLICATION_ID) - checkWhatsNewDialog() } @Composable - private fun linkColor() = onEventValue { - when { - isWhiteTheme() || isBlackAndWhiteTheme() -> baseConfig.accentColor - else -> getProperPrimaryColor() + private fun AppLaunched( + donateAlertDialogState: AlertDialogState = getDonateAlertDialogState(), + rateStarsAlertDialogState: AlertDialogState = getRateStarsAlertDialogState(), + upgradeToProAlertDialogState: AlertDialogState = getUpgradeToProAlertDialogState() + ) { + LaunchedEffect(Unit) { + appLaunchedCompose( + appId = BuildConfig.APPLICATION_ID, + showDonateDialog = donateAlertDialogState::show, + showRateUsDialog = rateStarsAlertDialogState::show, + showUpgradeDialog = upgradeToProAlertDialogState::show + ) + } + } + + @Composable + private fun CheckWhatsNew( + releasesList: SnapshotStateList, + checkWhatsNewAlertDialogState: AlertDialogState + ) { + DisposableEffect(Unit) { + checkWhatsNewCompose( + releases = listOf( + Release(14, R.string.release_14), + Release(3, R.string.release_3) + ), + currVersion = BuildConfig.VERSION_CODE, + showWhatsNewDialog = { releases -> + releasesList.addAll(releases) + checkWhatsNewAlertDialogState.show() + } + ) + onDispose { + releasesList.clear() + } + } + } + + @Composable + private fun getUpgradeToProAlertDialogState() = rememberAlertDialogState().apply { + DialogMember { + UpgradeToProAlertDialog( + alertDialogState = this, onMoreInfoClick = ::upgradeToPro, onUpgradeClick = ::launchUpgradeToProIntent + ) + } + } + + + @Composable + private fun getCheckWhatsNewAlertDialogState(releasesList: SnapshotStateList) = rememberAlertDialogState().apply { + DialogMember { + WhatsNewAlertDialog(alertDialogState = this, releases = releasesList.toImmutableList()) + } + } + + @Composable + private fun getDonateAlertDialogState() = + rememberAlertDialogState().apply { + DialogMember { + DonateAlertDialog(alertDialogState = this) + } + } + + @Composable + private fun getRateStarsAlertDialogState() = rememberAlertDialogState().apply { + DialogMember { + RateStarsAlertDialog(alertDialogState = this) { stars -> + if (stars == 5) { + redirectToRateUs() + } + toast(com.simplemobiletools.commons.R.string.thank_you) + baseConfig.wasAppRated = true + } } } @@ -61,12 +143,4 @@ class MainActivity : ComponentActivity() { startAboutActivity(R.string.app_name, 0, BuildConfig.VERSION_NAME, faqItems, false) } - - private fun checkWhatsNewDialog() { - arrayListOf().apply { - add(Release(14, R.string.release_14)) - add(Release(3, R.string.release_3)) - checkWhatsNew(this, BuildConfig.VERSION_CODE) - } - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Constants.kt index 872bc73..bdda420 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Constants.kt @@ -1,4 +1,10 @@ package com.simplemobiletools.thankyou.helpers +import androidx.compose.material3.Typography + // Shared Preferences const val HIDE_LAUNCHER_ICON = "hide_launcher_icon" + +val typography = Typography( + +) diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Extensions.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Extensions.kt new file mode 100644 index 0000000..98249e6 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Extensions.kt @@ -0,0 +1,86 @@ +package com.simplemobiletools.thankyou.helpers + +import android.content.ComponentName +import android.content.Context +import android.content.pm.PackageManager +import androidx.activity.ComponentActivity +import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.models.Release +import com.simplemobiletools.thankyou.R + +fun ComponentActivity.appLaunchedCompose( + appId: String, + showUpgradeDialog: () -> Unit, + showDonateDialog: () -> Unit, + showRateUsDialog: () -> Unit +) { + baseConfig.internalStoragePath = getInternalStoragePath() + updateSDCardPath() + baseConfig.appId = appId + if (baseConfig.appRunCount == 0) { + baseConfig.wasOrangeIconChecked = true + checkAppIconColor() + } else if (!baseConfig.wasOrangeIconChecked) { + baseConfig.wasOrangeIconChecked = true + val primaryColor = resources.getColor(R.color.color_primary) + if (baseConfig.appIconColor != primaryColor) { + getAppIconColors().forEachIndexed { index, color -> + toggleAppIconColor(appId, index, color, false) + } + + val defaultClassName = "${baseConfig.appId.removeSuffix(".debug")}.activities.SplashActivity" + packageManager.setComponentEnabledSetting( + ComponentName(baseConfig.appId, defaultClassName), + PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, + PackageManager.DONT_KILL_APP + ) + + val orangeClassName = "${baseConfig.appId.removeSuffix(".debug")}.activities.SplashActivity.Orange" + packageManager.setComponentEnabledSetting( + ComponentName(baseConfig.appId, orangeClassName), + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP + ) + + baseConfig.appIconColor = primaryColor + baseConfig.lastIconColor = primaryColor + } + } + + baseConfig.appRunCount++ + if (baseConfig.appRunCount % 30 == 0 && !isAProApp()) { + if (!resources.getBoolean(R.bool.hide_google_relations)) { + if (getCanAppBeUpgraded()) { + showUpgradeDialog() + } else if (!isOrWasThankYouInstalled()) { + showDonateDialog() + } + } + } + + if (baseConfig.appRunCount % 40 == 0 && !baseConfig.wasAppRated) { + if (!resources.getBoolean(R.bool.hide_google_relations)) { + showRateUsDialog() + } + } +} + +fun ComponentActivity.checkWhatsNewCompose(releases: List, currVersion: Int, showWhatsNewDialog: (List) -> Unit) { + if (baseConfig.lastVersion == 0) { + baseConfig.lastVersion = currVersion + return + } + + val newReleases = arrayListOf() + releases.filterTo(newReleases) { it.id > baseConfig.lastVersion } + + if (newReleases.isNotEmpty()) { + showWhatsNewDialog(newReleases) + } + + baseConfig.lastVersion = currVersion +} + +fun ComponentActivity.upgradeToPro() { + launchViewIntent("https://simplemobiletools.com/upgrade_to_pro") +} diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/MainScreen.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/MainScreen.kt index b348e82..a2daad6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/MainScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/MainScreen.kt @@ -33,7 +33,7 @@ internal fun MainScreen( openSettings: () -> Unit, openAbout: () -> Unit, moreAppsFromUs: () -> Unit, - linkColor: Int, + linkColor: Color, ) { SettingsLazyScaffold(customTopBar = { scrolledColor: Color, _: MutableInteractionSource, scrollBehavior: TopAppBarScrollBehavior, statusBarColor: Int, colorTransitionFraction: Float, contrastColor: Color -> TopAppBar( @@ -77,7 +77,7 @@ internal fun MainScreen( .padding(bottom = paddingValues.calculateBottomPadding()) .padding(40.dp), update = { textView -> - textView.setLinkTextColor(linkColor) + textView.setLinkTextColor(linkColor.toArgb()) textView.setTextColor(textColor) } ) @@ -88,6 +88,6 @@ internal fun MainScreen( @MyDevices private fun MainScreenPreview() { AppThemeSurface { - MainScreen(showMoreApps = true, openSettings = {}, openAbout = {}, moreAppsFromUs = {}, linkColor = MaterialTheme.colorScheme.onSurface.toArgb()) + MainScreen(showMoreApps = true, openSettings = {}, openAbout = {}, moreAppsFromUs = {}, linkColor = MaterialTheme.colorScheme.onSurface) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 747c3e4..a07b2a1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,18 +2,18 @@ #jetbrains kotlin = "1.9.10" #Simple tools -simple-commons = "b7dd6ad428" +simple-commons = "a32b3b41a5" #Compose -composeActivity = "1.8.0-beta01" -compose = "1.6.0-alpha05" +composeActivity = "1.8.0-rc01" +compose = "1.6.0-alpha06" composeCompiler = "1.5.3" -composeMaterial3 = "1.2.0-alpha07" +composeMaterial3 = "1.2.0-alpha08" #Androidx androidx-customView = "1.2.0-alpha02" androidx-customViewPooling = "1.0.0" androidx-lifecycle = "2.7.0-alpha02" #Gradle -gradlePlugins-agp = "8.1.1" +gradlePlugins-agp = "8.1.2" app-build-compileSDKVersion = "34" app-build-targetSDK = "34" app-build-minimumSDK = "23" From 1a7070c278aebcd5f17624b5d95c58f9f1d302c8 Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Wed, 4 Oct 2023 17:28:57 +0200 Subject: [PATCH 2/3] refactor: migrate to latest commons and compose --- .../thankyou/activities/MainActivity.kt | 32 ++----- .../thankyou/activities/SettingsActivity.kt | 59 ++++--------- .../thankyou/extensions/Context.kt | 2 - .../thankyou/helpers/Config.kt | 9 +- .../thankyou/helpers/Constants.kt | 10 --- .../thankyou/helpers/Extensions.kt | 86 ------------------- .../thankyou/screens/MainScreen.kt | 37 +++++--- .../thankyou/screens/SettingsScreen.kt | 4 +- gradle/libs.versions.toml | 2 +- 9 files changed, 51 insertions(+), 190 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Constants.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Extensions.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/MainActivity.kt index a414001..8592e27 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/MainActivity.kt @@ -8,23 +8,18 @@ import androidx.compose.runtime.* import androidx.compose.runtime.snapshots.SnapshotStateList import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState -import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple -import com.simplemobiletools.commons.compose.extensions.linkColor -import com.simplemobiletools.commons.compose.extensions.onEventValue +import com.simplemobiletools.commons.compose.extensions.* import com.simplemobiletools.commons.compose.theme.AppThemeSurface import com.simplemobiletools.commons.dialogs.DonateAlertDialog import com.simplemobiletools.commons.dialogs.RateStarsAlertDialog -import com.simplemobiletools.commons.dialogs.UpgradeToProAlertDialog import com.simplemobiletools.commons.dialogs.WhatsNewAlertDialog -import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.extensions.hideKeyboard +import com.simplemobiletools.commons.extensions.launchMoreAppsFromUsIntent import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.commons.models.Release import com.simplemobiletools.thankyou.BuildConfig import com.simplemobiletools.thankyou.R import com.simplemobiletools.thankyou.extensions.startAboutActivity -import com.simplemobiletools.thankyou.helpers.appLaunchedCompose -import com.simplemobiletools.thankyou.helpers.checkWhatsNewCompose -import com.simplemobiletools.thankyou.helpers.upgradeToPro import com.simplemobiletools.thankyou.screens.MainScreen import kotlinx.collections.immutable.toImmutableList @@ -55,14 +50,13 @@ class MainActivity : ComponentActivity() { private fun AppLaunched( donateAlertDialogState: AlertDialogState = getDonateAlertDialogState(), rateStarsAlertDialogState: AlertDialogState = getRateStarsAlertDialogState(), - upgradeToProAlertDialogState: AlertDialogState = getUpgradeToProAlertDialogState() ) { LaunchedEffect(Unit) { appLaunchedCompose( appId = BuildConfig.APPLICATION_ID, showDonateDialog = donateAlertDialogState::show, showRateUsDialog = rateStarsAlertDialogState::show, - showUpgradeDialog = upgradeToProAlertDialogState::show + showUpgradeDialog = {} ) } } @@ -90,16 +84,6 @@ class MainActivity : ComponentActivity() { } } - @Composable - private fun getUpgradeToProAlertDialogState() = rememberAlertDialogState().apply { - DialogMember { - UpgradeToProAlertDialog( - alertDialogState = this, onMoreInfoClick = ::upgradeToPro, onUpgradeClick = ::launchUpgradeToProIntent - ) - } - } - - @Composable private fun getCheckWhatsNewAlertDialogState(releasesList: SnapshotStateList) = rememberAlertDialogState().apply { DialogMember { @@ -118,13 +102,7 @@ class MainActivity : ComponentActivity() { @Composable private fun getRateStarsAlertDialogState() = rememberAlertDialogState().apply { DialogMember { - RateStarsAlertDialog(alertDialogState = this) { stars -> - if (stars == 5) { - redirectToRateUs() - } - toast(com.simplemobiletools.commons.R.string.thank_you) - baseConfig.wasAppRated = true - } + RateStarsAlertDialog(alertDialogState = this, onRating = ::rateStarsRedirectAndThankYou) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/SettingsActivity.kt index 0d94509..fd95566 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/activities/SettingsActivity.kt @@ -4,21 +4,12 @@ import android.annotation.SuppressLint import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.material3.TextButton import androidx.compose.runtime.* -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.window.DialogProperties import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.simplemobiletools.commons.compose.alert_dialog.AlertDialogState import com.simplemobiletools.commons.compose.alert_dialog.rememberAlertDialogState import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple import com.simplemobiletools.commons.compose.theme.AppThemeSurface -import com.simplemobiletools.commons.compose.theme.Shapes +import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedAlertDialog import com.simplemobiletools.commons.extensions.getAppIconColors import com.simplemobiletools.commons.extensions.toggleAppIconColor import com.simplemobiletools.commons.helpers.isTiramisuPlus @@ -50,8 +41,7 @@ class SettingsActivity : ComponentActivity() { (wasUseEnglishToggledFlow || Locale.getDefault().language != "en") && !isTiramisuPlus() } } - val alertDialogState = rememberAlertDialogState() - ConfirmationHideLauncherDialog(alertDialogState) + val confirmHideIconAlertDialogState = getConfirmHideIconAlertDialogState() SettingsScreen( displayLanguage = displayLanguage, @@ -65,7 +55,7 @@ class SettingsActivity : ComponentActivity() { isHidingLauncherIcon = hideLauncherIconFlow, hideLauncherIconClick = { isChecked -> if (isChecked) { - alertDialogState.show() + confirmHideIconAlertDialogState.show() } else { toggleHideLauncherIcon() preferences.hideLauncherIcon = false @@ -79,39 +69,22 @@ class SettingsActivity : ComponentActivity() { } @Composable - private fun ConfirmationHideLauncherDialog(alertDialogState: AlertDialogState) { - alertDialogState.DialogMember { - AlertDialog( - modifier = Modifier.fillMaxWidth(0.9f), - properties = DialogProperties(usePlatformDefaultWidth = false), - onDismissRequest = alertDialogState::hide, - confirmButton = { - TextButton(onClick = { - alertDialogState.hide() - preferences.hideLauncherIcon = true + private fun getConfirmHideIconAlertDialogState() = + rememberAlertDialogState().apply { + DialogMember { + ConfirmationAdvancedAlertDialog( + alertDialogState = this, + messageId = R.string.hide_launcher_icon_explanation, + positive = R.string.ok, + negative = R.string.cancel + ) { hideIcon -> + preferences.hideLauncherIcon = hideIcon + if (hideIcon) { toggleHideLauncherIcon() - }) { - Text(text = stringResource(id = R.string.ok)) } - }, - dismissButton = { - TextButton(onClick = { - alertDialogState.hide() - preferences.hideLauncherIcon = false - }) { - Text(text = stringResource(id = R.string.cancel)) - } - }, - shape = Shapes.large, - text = { - Text( - text = stringResource(id = R.string.hide_launcher_icon_explanation), - color = MaterialTheme.colorScheme.onSurface - ) - }, - ) + } + } } - } private fun toggleHideLauncherIcon() { val appId = BuildConfig.APPLICATION_ID diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/extensions/Context.kt index 32fb6ed..a931ad3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/extensions/Context.kt @@ -8,9 +8,7 @@ import android.os.Build import android.provider.Settings import androidx.annotation.RequiresApi import com.simplemobiletools.commons.activities.AboutActivity -import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.CustomizationActivity -import com.simplemobiletools.commons.compose.theme.getAppLauncherName import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.WhatsNewDialog import com.simplemobiletools.commons.extensions.baseConfig diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Config.kt index 4b3d6b9..b69e077 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Config.kt @@ -1,13 +1,12 @@ package com.simplemobiletools.thankyou.helpers import android.content.Context -import com.simplemobiletools.commons.extensions.sharedPreferencesCallback import com.simplemobiletools.commons.helpers.BaseConfig import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.filterNotNull class Config(context: Context) : BaseConfig(context) { companion object { + const val HIDE_LAUNCHER_ICON = "hide_launcher_icon" fun newInstance(context: Context) = Config(context) } @@ -15,7 +14,7 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(HIDE_LAUNCHER_ICON, false) set(hideLauncherIcon) = prefs.edit().putBoolean(HIDE_LAUNCHER_ICON, hideLauncherIcon).apply() - val hideLauncherIconFlow: Flow = prefs.run { sharedPreferencesCallback { hideLauncherIcon } }.filterNotNull() - val wasUseEnglishToggledFlow: Flow = prefs.run { sharedPreferencesCallback { wasUseEnglishToggled } }.filterNotNull() - val useEnglishFlow: Flow = prefs.run { sharedPreferencesCallback { useEnglish } }.filterNotNull() + val hideLauncherIconFlow: Flow = ::hideLauncherIcon.asFlowNonNull() + val wasUseEnglishToggledFlow: Flow = ::wasUseEnglishToggled.asFlowNonNull() + val useEnglishFlow: Flow = ::useEnglish.asFlowNonNull() } diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Constants.kt deleted file mode 100644 index bdda420..0000000 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Constants.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.simplemobiletools.thankyou.helpers - -import androidx.compose.material3.Typography - -// Shared Preferences -const val HIDE_LAUNCHER_ICON = "hide_launcher_icon" - -val typography = Typography( - -) diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Extensions.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Extensions.kt deleted file mode 100644 index 98249e6..0000000 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/helpers/Extensions.kt +++ /dev/null @@ -1,86 +0,0 @@ -package com.simplemobiletools.thankyou.helpers - -import android.content.ComponentName -import android.content.Context -import android.content.pm.PackageManager -import androidx.activity.ComponentActivity -import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.models.Release -import com.simplemobiletools.thankyou.R - -fun ComponentActivity.appLaunchedCompose( - appId: String, - showUpgradeDialog: () -> Unit, - showDonateDialog: () -> Unit, - showRateUsDialog: () -> Unit -) { - baseConfig.internalStoragePath = getInternalStoragePath() - updateSDCardPath() - baseConfig.appId = appId - if (baseConfig.appRunCount == 0) { - baseConfig.wasOrangeIconChecked = true - checkAppIconColor() - } else if (!baseConfig.wasOrangeIconChecked) { - baseConfig.wasOrangeIconChecked = true - val primaryColor = resources.getColor(R.color.color_primary) - if (baseConfig.appIconColor != primaryColor) { - getAppIconColors().forEachIndexed { index, color -> - toggleAppIconColor(appId, index, color, false) - } - - val defaultClassName = "${baseConfig.appId.removeSuffix(".debug")}.activities.SplashActivity" - packageManager.setComponentEnabledSetting( - ComponentName(baseConfig.appId, defaultClassName), - PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP - ) - - val orangeClassName = "${baseConfig.appId.removeSuffix(".debug")}.activities.SplashActivity.Orange" - packageManager.setComponentEnabledSetting( - ComponentName(baseConfig.appId, orangeClassName), - PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP - ) - - baseConfig.appIconColor = primaryColor - baseConfig.lastIconColor = primaryColor - } - } - - baseConfig.appRunCount++ - if (baseConfig.appRunCount % 30 == 0 && !isAProApp()) { - if (!resources.getBoolean(R.bool.hide_google_relations)) { - if (getCanAppBeUpgraded()) { - showUpgradeDialog() - } else if (!isOrWasThankYouInstalled()) { - showDonateDialog() - } - } - } - - if (baseConfig.appRunCount % 40 == 0 && !baseConfig.wasAppRated) { - if (!resources.getBoolean(R.bool.hide_google_relations)) { - showRateUsDialog() - } - } -} - -fun ComponentActivity.checkWhatsNewCompose(releases: List, currVersion: Int, showWhatsNewDialog: (List) -> Unit) { - if (baseConfig.lastVersion == 0) { - baseConfig.lastVersion = currVersion - return - } - - val newReleases = arrayListOf() - releases.filterTo(newReleases) { it.id > baseConfig.lastVersion } - - if (newReleases.isNotEmpty()) { - showWhatsNewDialog(newReleases) - } - - baseConfig.lastVersion = currVersion -} - -fun ComponentActivity.upgradeToPro() { - launchViewIntent("https://simplemobiletools.com/upgrade_to_pro") -} diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/MainScreen.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/MainScreen.kt index a2daad6..d13f79c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/MainScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/MainScreen.kt @@ -25,6 +25,7 @@ import com.simplemobiletools.commons.compose.menus.ActionMenu import com.simplemobiletools.commons.compose.menus.OverflowMode import com.simplemobiletools.commons.compose.settings.scaffold.* import com.simplemobiletools.commons.compose.theme.AppThemeSurface +import com.simplemobiletools.commons.compose.theme.SimpleTheme import kotlinx.collections.immutable.toImmutableList @Composable @@ -39,18 +40,7 @@ internal fun MainScreen( TopAppBar( title = {}, actions = { - val actionMenus = remember { - val settings = - ActionItem(R.string.settings, icon = Icons.Filled.Settings, doAction = openSettings, overflowMode = OverflowMode.NEVER_OVERFLOW) - val about = ActionItem(R.string.about, icon = Icons.Outlined.Info, doAction = openAbout, overflowMode = OverflowMode.NEVER_OVERFLOW) - - val list = if (showMoreApps) { - listOf(settings, about, ActionItem(R.string.more_apps_from_us, doAction = moreAppsFromUs, overflowMode = OverflowMode.ALWAYS_OVERFLOW)) - } else { - listOf(settings, about) - } - list.toImmutableList() - } + val actionMenus = rememberActionItems(openSettings, openAbout, showMoreApps, moreAppsFromUs) var isMenuVisible by remember { mutableStateOf(false) } ActionMenu(items = actionMenus, numIcons = 2, isMenuVisible = isMenuVisible, onMenuToggle = { isMenuVisible = it }, iconsColor = scrolledColor) }, @@ -60,7 +50,7 @@ internal fun MainScreen( windowInsets = topAppBarInsets() ) }) { paddingValues -> - val textColor = MaterialTheme.colorScheme.onSurface.toArgb() + val textColor = SimpleTheme.colorScheme.onSurface.toArgb() AndroidView( factory = { context -> @@ -84,10 +74,29 @@ internal fun MainScreen( } } +@Composable +private fun rememberActionItems( + openSettings: () -> Unit, + openAbout: () -> Unit, + showMoreApps: Boolean, + moreAppsFromUs: () -> Unit +) = remember { + val settings = + ActionItem(R.string.settings, icon = Icons.Filled.Settings, doAction = openSettings, overflowMode = OverflowMode.NEVER_OVERFLOW) + val about = ActionItem(R.string.about, icon = Icons.Outlined.Info, doAction = openAbout, overflowMode = OverflowMode.NEVER_OVERFLOW) + + val list = if (showMoreApps) { + listOf(settings, about, ActionItem(R.string.more_apps_from_us, doAction = moreAppsFromUs, overflowMode = OverflowMode.ALWAYS_OVERFLOW)) + } else { + listOf(settings, about) + } + list.toImmutableList() +} + @Composable @MyDevices private fun MainScreenPreview() { AppThemeSurface { - MainScreen(showMoreApps = true, openSettings = {}, openAbout = {}, moreAppsFromUs = {}, linkColor = MaterialTheme.colorScheme.onSurface) + MainScreen(showMoreApps = true, openSettings = {}, openAbout = {}, moreAppsFromUs = {}, linkColor = SimpleTheme.colorScheme.onSurface) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/SettingsScreen.kt b/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/SettingsScreen.kt index 96ab67a..049b5cf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/SettingsScreen.kt +++ b/app/src/main/kotlin/com/simplemobiletools/thankyou/screens/SettingsScreen.kt @@ -1,7 +1,6 @@ package com.simplemobiletools.thankyou.screens import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import com.simplemobiletools.commons.R @@ -12,6 +11,7 @@ import com.simplemobiletools.commons.compose.settings.SettingsPreferenceComponen 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.SimpleTheme import com.simplemobiletools.commons.compose.theme.divider_grey import com.simplemobiletools.commons.helpers.isTiramisuPlus @@ -53,7 +53,7 @@ internal fun SettingsScreen( label = stringResource(id = R.string.language), value = displayLanguage, doOnPreferenceClick = onSetupLanguagePress, - preferenceLabelColor = MaterialTheme.colorScheme.onSurface, + preferenceLabelColor = SimpleTheme.colorScheme.onSurface, ) } SettingsCheckBoxComponent( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a07b2a1..5f659c0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ #jetbrains kotlin = "1.9.10" #Simple tools -simple-commons = "a32b3b41a5" +simple-commons = "dfe8acfbf9" #Compose composeActivity = "1.8.0-rc01" compose = "1.6.0-alpha06" From 553cc163137499bbbb08ac28b751787a2471daca Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Thu, 5 Oct 2023 11:53:19 +0200 Subject: [PATCH 3/3] build: latest commons --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5f659c0..433d434 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ #jetbrains kotlin = "1.9.10" #Simple tools -simple-commons = "dfe8acfbf9" +simple-commons = "b72ded2a75" #Compose composeActivity = "1.8.0-rc01" compose = "1.6.0-alpha06"