Merge pull request #137 from FunkyMuse/feature/migrate_to_compose

Feature/migrate to compose
This commit is contained in:
Tibor Kaputa 2023-09-20 12:47:41 +02:00 committed by GitHub
commit 7584b4366a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 504 additions and 283 deletions

View File

@ -43,6 +43,22 @@ android {
buildFeatures { buildFeatures {
viewBinding = true viewBinding = true
buildConfig = true buildConfig = true
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = project.libs.versions.app.build.kotlinJVMTarget.get()
kotlinOptions.freeCompilerArgs = listOf(
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
"-opt-in=androidx.compose.material.ExperimentalMaterialApi",
"-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
"-Xcontext-receivers"
)
} }
buildTypes { buildTypes {
@ -92,4 +108,7 @@ android {
dependencies { dependencies {
implementation(libs.simple.tools.commons) implementation(libs.simple.tools.commons)
implementation(libs.bundles.lifecycle)
implementation(libs.bundles.compose)
debugImplementation(libs.bundles.compose.preview)
} }

View File

@ -28,12 +28,14 @@
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:configChanges="orientation" android:configChanges="orientation"
android:enableOnBackInvokedCallback="true"
android:exported="false" /> android:exported="false" />
<activity <activity
android:name=".activities.SettingsActivity" android:name=".activities.SettingsActivity"
android:configChanges="orientation" android:configChanges="orientation"
android:exported="true" android:exported="true"
android:enableOnBackInvokedCallback="true"
android:label="@string/settings" android:label="@string/settings"
android:parentActivityName=".activities.MainActivity"> android:parentActivityName=".activities.MainActivity">

View File

@ -2,48 +2,47 @@ package com.simplemobiletools.thankyou.activities
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
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.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.Release import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.thankyou.BuildConfig import com.simplemobiletools.thankyou.BuildConfig
import com.simplemobiletools.thankyou.R import com.simplemobiletools.thankyou.R
import com.simplemobiletools.thankyou.databinding.ActivityMainBinding import com.simplemobiletools.thankyou.extensions.checkWhatsNew
import com.simplemobiletools.thankyou.extensions.startAboutActivity
class MainActivity : SimpleActivity() { import com.simplemobiletools.thankyou.screens.MainScreen
private val binding by lazy(LazyThreadSafetyMode.NONE) { ActivityMainBinding.inflate(layoutInflater) }
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(binding.root) enableEdgeToEdgeSimple()
appLaunched(BuildConfig.APPLICATION_ID) setContent {
refreshMenuItems() AppThemeSurface {
setupOptionsMenu() val linkColor = linkColor()
checkWhatsNewDialog() val showMoreApps = onEventValue { !resources.getBoolean(R.bool.hide_google_relations) }
updateMaterialActivityViews(binding.mainCoordinator, binding.activityMain, useTransparentNavigation = true, useTopSearchMenu = false) MainScreen(
} linkColor = linkColor,
showMoreApps = showMoreApps,
override fun onResume() { openSettings = ::launchSettings,
super.onResume() openAbout = ::launchAbout,
updateTextColors(binding.activityMain) moreAppsFromUs = ::launchMoreAppsFromUsIntent
setupToolbar(binding.mainToolbar, statusBarColor = getProperBackgroundColor()) )
}
private fun refreshMenuItems() {
binding.mainToolbar.menu.apply {
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
}
}
private fun setupOptionsMenu() {
binding.mainToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return@setOnMenuItemClickListener false
} }
return@setOnMenuItemClickListener true }
appLaunched(BuildConfig.APPLICATION_ID)
checkWhatsNewDialog()
}
@Composable
private fun linkColor() = onEventValue {
when {
isWhiteTheme() || isBlackAndWhiteTheme() -> baseConfig.accentColor
else -> getProperPrimaryColor()
} }
} }

View File

@ -1,92 +1,119 @@
package com.simplemobiletools.thankyou.activities package com.simplemobiletools.thankyou.activities
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import androidx.activity.ComponentActivity
import com.simplemobiletools.commons.extensions.* import androidx.activity.compose.setContent
import com.simplemobiletools.commons.helpers.NavigationIcon 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.extensions.getAppIconColors
import com.simplemobiletools.commons.extensions.toggleAppIconColor
import com.simplemobiletools.commons.helpers.isTiramisuPlus import com.simplemobiletools.commons.helpers.isTiramisuPlus
import com.simplemobiletools.thankyou.BuildConfig import com.simplemobiletools.thankyou.BuildConfig
import com.simplemobiletools.thankyou.R import com.simplemobiletools.thankyou.R
import com.simplemobiletools.thankyou.databinding.ActivitySettingsBinding
import com.simplemobiletools.thankyou.extensions.config import com.simplemobiletools.thankyou.extensions.config
import com.simplemobiletools.thankyou.extensions.launchChangeAppLanguageIntent
import com.simplemobiletools.thankyou.extensions.startCustomizationActivity
import com.simplemobiletools.thankyou.screens.SettingsScreen
import java.util.Locale import java.util.Locale
import kotlin.system.exitProcess
class SettingsActivity : SimpleActivity() { class SettingsActivity : ComponentActivity() {
private val binding by lazy(LazyThreadSafetyMode.NONE) { ActivitySettingsBinding.inflate(layoutInflater) }
private val preferences by lazy { config }
@SuppressLint("NewApi")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(binding.root) enableEdgeToEdgeSimple()
setContent {
binding.apply { AppThemeSurface {
updateMaterialActivityViews(settingsCoordinator, settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false) val wasUseEnglishToggledFlow by preferences.wasUseEnglishToggledFlow.collectAsStateWithLifecycle(preferences.wasUseEnglishToggled)
setupMaterialScrollListener(settingsNestedScrollview, settingsToolbar) val useEnglishFlow by preferences.useEnglishFlow.collectAsStateWithLifecycle(preferences.useEnglish)
} val hideLauncherIconFlow by preferences.hideLauncherIconFlow.collectAsStateWithLifecycle(preferences.hideLauncherIcon)
} val displayLanguage = remember { Locale.getDefault().displayLanguage }
val isUseEnglishEnabled by remember(wasUseEnglishToggledFlow) {
override fun onResume() { derivedStateOf {
super.onResume() (wasUseEnglishToggledFlow || Locale.getDefault().language != "en") && !isTiramisuPlus()
setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow) }
setupCustomizeColors()
setupUseEnglish()
setupLanguage()
setupHideLauncherIcon()
updateTextColors(binding.settingsNestedScrollview)
binding.apply {
arrayOf(settingsColorCustomizationSectionLabel, settingsGeneralSettingsLabel).forEach {
it.setTextColor(getProperPrimaryColor())
}
}
}
private fun setupCustomizeColors() {
binding.settingsColorCustomizationHolder.setOnClickListener {
startCustomizationActivity()
}
}
private fun setupUseEnglish() {
binding.apply {
settingsUseEnglishHolder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
settingsUseEnglish.isChecked = config.useEnglish
settingsUseEnglishHolder.setOnClickListener {
settingsUseEnglish.toggle()
config.useEnglish = settingsUseEnglish.isChecked
System.exit(0)
}
}
}
private fun setupLanguage() {
binding.apply {
settingsLanguage.text = Locale.getDefault().displayLanguage
settingsLanguageHolder.beVisibleIf(isTiramisuPlus())
settingsLanguageHolder.setOnClickListener {
launchChangeAppLanguageIntent()
}
}
}
private fun setupHideLauncherIcon() {
binding.settingsHideLauncherIcon.isChecked = config.hideLauncherIcon
binding.settingsHideLauncherIconHolder.setOnClickListener {
if (config.hideLauncherIcon) {
toggleHideLauncherIcon()
} else {
ConfirmationDialog(this, "", R.string.hide_launcher_icon_explanation, R.string.ok, R.string.cancel) {
toggleHideLauncherIcon()
} }
val alertDialogState = rememberAlertDialogState()
ConfirmationHideLauncherDialog(alertDialogState)
SettingsScreen(
displayLanguage = displayLanguage,
isUseEnglishEnabled = isUseEnglishEnabled,
isUseEnglishChecked = useEnglishFlow,
onUseEnglishPress = { isChecked ->
preferences.useEnglish = isChecked
exitProcess(0)
},
onSetupLanguagePress = ::launchChangeAppLanguageIntent,
isHidingLauncherIcon = hideLauncherIconFlow,
hideLauncherIconClick = { isChecked ->
if (isChecked) {
alertDialogState.show()
} else {
toggleHideLauncherIcon()
preferences.hideLauncherIcon = false
}
},
customizeColors = ::startCustomizationActivity,
goBack = ::finish
)
} }
} }
} }
@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
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() { private fun toggleHideLauncherIcon() {
binding.settingsHideLauncherIcon.toggle()
config.hideLauncherIcon = binding.settingsHideLauncherIcon.isChecked
val appId = BuildConfig.APPLICATION_ID val appId = BuildConfig.APPLICATION_ID
getAppIconColors().forEachIndexed { index, color -> getAppIconColors().forEachIndexed { index, color ->
toggleAppIconColor(appId, index, color, false) toggleAppIconColor(appId, index, color, false)

View File

@ -1,6 +1,118 @@
package com.simplemobiletools.thankyou.extensions package com.simplemobiletools.thankyou.extensions
import android.app.Activity
import android.content.Context import android.content.Context
import android.content.Intent
import android.net.Uri
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
import com.simplemobiletools.commons.extensions.hideKeyboard
import com.simplemobiletools.commons.extensions.launchViewIntent
import com.simplemobiletools.commons.extensions.openDeviceSettings
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.thankyou.R
import com.simplemobiletools.thankyou.helpers.Config import com.simplemobiletools.thankyou.helpers.Config
val Context.config: Config get() = Config.newInstance(applicationContext) val Context.config: Config get() = Config.newInstance(applicationContext)
internal fun Activity.startAboutActivity(
appNameId: Int, licenseMask: Long, versionName: String, faqItems: ArrayList<FAQItem>, showFAQBeforeMail: Boolean,
getAppIconIDs: ArrayList<Int> = getAppIconIDs(),
getAppLauncherName : String = launcherName()
) {
hideKeyboard()
Intent(applicationContext, AboutActivity::class.java).apply {
putExtra(APP_ICON_IDS, getAppIconIDs)
putExtra(APP_LAUNCHER_NAME, getAppLauncherName)
putExtra(APP_NAME, getString(appNameId))
putExtra(APP_LICENSES, licenseMask)
putExtra(APP_VERSION_NAME, versionName)
putExtra(APP_FAQ, faqItems)
putExtra(SHOW_FAQ_BEFORE_MAIL, showFAQBeforeMail)
startActivity(this)
}
}
internal fun Activity.startCustomizationActivity(
getAppIconIDs: ArrayList<Int> = getAppIconIDs(),
getAppLauncherName : String = launcherName()
) {
if (!packageName.contains("slootelibomelpmis".reversed(), true)) {
if (baseConfig.appRunCount > 100) {
val label = "You are using a fake version of the app. For your own safety download the original one from www.simplemobiletools.com. Thanks"
ConfirmationDialog(this, label, positive = R.string.ok, negative = 0) {
launchViewIntent("https://play.google.com/store/apps/dev?id=9070296388022589266")
}
return
}
}
Intent(applicationContext, CustomizationActivity::class.java).apply {
putExtra(APP_ICON_IDS, getAppIconIDs)
putExtra(APP_LAUNCHER_NAME, getAppLauncherName)
startActivity(this)
}
}
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
internal fun Activity.launchChangeAppLanguageIntent() {
try {
Intent(Settings.ACTION_APP_LOCALE_SETTINGS).apply {
data = Uri.fromParts("package", packageName, null)
startActivity(this)
}
} catch (e: Exception) {
openDeviceSettings()
}
}
internal fun Activity.checkWhatsNew(releases: List<Release>, currVersion: Int) {
if (baseConfig.lastVersion == 0) {
baseConfig.lastVersion = currVersion
return
}
val newReleases = arrayListOf<Release>()
releases.filterTo(newReleases) { it.id > baseConfig.lastVersion }
if (newReleases.isNotEmpty()) {
WhatsNewDialog(this, newReleases)
}
baseConfig.lastVersion = currVersion
}
private fun getAppIconIDs() = arrayListOf(
R.mipmap.ic_launcher_red,
R.mipmap.ic_launcher_pink,
R.mipmap.ic_launcher_purple,
R.mipmap.ic_launcher_deep_purple,
R.mipmap.ic_launcher_indigo,
R.mipmap.ic_launcher_blue,
R.mipmap.ic_launcher_light_blue,
R.mipmap.ic_launcher_cyan,
R.mipmap.ic_launcher_teal,
R.mipmap.ic_launcher_green,
R.mipmap.ic_launcher_light_green,
R.mipmap.ic_launcher_lime,
R.mipmap.ic_launcher_yellow,
R.mipmap.ic_launcher_amber,
R.mipmap.ic_launcher,
R.mipmap.ic_launcher_deep_orange,
R.mipmap.ic_launcher_brown,
R.mipmap.ic_launcher_blue_grey,
R.mipmap.ic_launcher_grey_black
)
private fun Context.launcherName() = getString(R.string.app_launcher_name)

View File

@ -1,7 +1,10 @@
package com.simplemobiletools.thankyou.helpers package com.simplemobiletools.thankyou.helpers
import android.content.Context import android.content.Context
import com.simplemobiletools.commons.extensions.sharedPreferencesCallback
import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.BaseConfig
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterNotNull
class Config(context: Context) : BaseConfig(context) { class Config(context: Context) : BaseConfig(context) {
companion object { companion object {
@ -11,4 +14,8 @@ class Config(context: Context) : BaseConfig(context) {
var hideLauncherIcon: Boolean var hideLauncherIcon: Boolean
get() = prefs.getBoolean(HIDE_LAUNCHER_ICON, false) get() = prefs.getBoolean(HIDE_LAUNCHER_ICON, false)
set(hideLauncherIcon) = prefs.edit().putBoolean(HIDE_LAUNCHER_ICON, hideLauncherIcon).apply() set(hideLauncherIcon) = prefs.edit().putBoolean(HIDE_LAUNCHER_ICON, hideLauncherIcon).apply()
val hideLauncherIconFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { hideLauncherIcon } }.filterNotNull()
val wasUseEnglishToggledFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { wasUseEnglishToggled } }.filterNotNull()
val useEnglishFlow: Flow<Boolean> = prefs.run { sharedPreferencesCallback { useEnglish } }.filterNotNull()
} }

View File

@ -1,4 +1,4 @@
package com.simplemobiletools.thankyou.helpers package com.simplemobiletools.thankyou.helpers
// Shared Preferences // Shared Preferences
val HIDE_LAUNCHER_ICON = "hide_launcher_icon" const val HIDE_LAUNCHER_ICON = "hide_launcher_icon"

View File

@ -0,0 +1,93 @@
@file:OptIn(ExperimentalMaterial3Api::class)
package com.simplemobiletools.thankyou.screens
import android.text.util.Linkify
import android.view.Gravity
import android.widget.TextView
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.menus.ActionItem
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 kotlinx.collections.immutable.toImmutableList
@Composable
internal fun MainScreen(
showMoreApps: Boolean,
openSettings: () -> Unit,
openAbout: () -> Unit,
moreAppsFromUs: () -> Unit,
linkColor: Int,
) {
SettingsLazyScaffold(customTopBar = { scrolledColor: Color, _: MutableInteractionSource, scrollBehavior: TopAppBarScrollBehavior, statusBarColor: Int, colorTransitionFraction: Float, contrastColor: Color ->
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()
}
var isMenuVisible by remember { mutableStateOf(false) }
ActionMenu(items = actionMenus, numIcons = 2, isMenuVisible = isMenuVisible, onMenuToggle = { isMenuVisible = it }, iconsColor = scrolledColor)
},
scrollBehavior = scrollBehavior,
colors = topAppBarColors(statusBarColor, colorTransitionFraction, contrastColor),
modifier = Modifier.topAppBarPaddings(),
windowInsets = topAppBarInsets()
)
}) { paddingValues ->
val textColor = MaterialTheme.colorScheme.onSurface.toArgb()
AndroidView(
factory = { context ->
TextView(context).apply {
setText(com.simplemobiletools.thankyou.R.string.main_text)
textSize = 16.sp.value
setLineSpacing(3.dp.value, 1f)
gravity = Gravity.CENTER_HORIZONTAL
Linkify.addLinks(this, Linkify.WEB_URLS)
Linkify.addLinks(this, Linkify.EMAIL_ADDRESSES)
}
}, modifier = Modifier
.fillMaxSize()
.padding(bottom = paddingValues.calculateBottomPadding())
.padding(40.dp),
update = { textView ->
textView.setLinkTextColor(linkColor)
textView.setTextColor(textColor)
}
)
}
}
@Composable
@MyDevices
private fun MainScreenPreview() {
AppThemeSurface {
MainScreen(showMoreApps = true, openSettings = {}, openAbout = {}, moreAppsFromUs = {}, linkColor = MaterialTheme.colorScheme.onSurface.toArgb())
}
}

View File

@ -0,0 +1,85 @@
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
import com.simplemobiletools.commons.compose.extensions.MyDevices
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
@Composable
internal fun SettingsScreen(
displayLanguage: String,
isUseEnglishEnabled: Boolean,
isUseEnglishChecked: Boolean,
isHidingLauncherIcon: Boolean,
onUseEnglishPress: (Boolean) -> Unit,
onSetupLanguagePress: () -> Unit,
hideLauncherIconClick: (Boolean) -> Unit,
customizeColors: () -> Unit,
goBack: () -> Unit,
) {
SettingsScaffold(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,
)
}
HorizontalDivider(color = divider_grey)
SettingsGroup(title = {
SettingsTitleTextComponent(text = stringResource(id = R.string.general_settings))
}) {
if (isUseEnglishEnabled) {
SettingsCheckBoxComponent(
title = stringResource(id = R.string.use_english_language),
initialValue = isUseEnglishChecked,
onChange = onUseEnglishPress,
)
}
if (isTiramisuPlus()) {
SettingsPreferenceComponent(
preferenceTitle = stringResource(id = R.string.language),
preferenceSummary = displayLanguage,
doOnPreferenceClick = onSetupLanguagePress,
preferenceSummaryColor = MaterialTheme.colorScheme.onSurface,
)
}
SettingsCheckBoxComponent(
title = stringResource(id = com.simplemobiletools.thankyou.R.string.hide_launcher_icon),
initialValue = isHidingLauncherIcon,
onChange = hideLauncherIconClick,
)
}
}
}
@Composable
@MyDevices
private fun SettingsScreenPreview() {
AppThemeSurface {
SettingsScreen(
displayLanguage = "English",
isUseEnglishEnabled = false,
isUseEnglishChecked = false,
isHidingLauncherIcon = false,
onUseEnglishPress = {},
onSetupLanguagePress = {},
hideLauncherIconClick = {},
customizeColors = {},
goBack = {},
)
}
}

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:menu="@menu/menu_main"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
<RelativeLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="email|web"
android:gravity="center_horizontal"
android:lineSpacingExtra="3dp"
android:padding="40dp"
android:text="@string/main_text"
android:textSize="@dimen/bigger_text_size" />
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,121 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/settings_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/settings_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:title="@string/settings"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
<androidx.core.widget.NestedScrollView
android:id="@+id/settings_nested_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="@+id/settings_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/settings_color_customization_section_label"
style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/color_customization" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/settings_color_customization_holder"
style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_color_customization_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/customize_colors"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<include
android:id="@+id/settings_color_customization_divider"
layout="@layout/divider" />
<TextView
android:id="@+id/settings_general_settings_label"
style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/general_settings" />
<RelativeLayout
android:id="@+id/settings_use_english_holder"
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_use_english"
style="@style/SettingsCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/use_english_language" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_language_holder"
style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_language_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/language" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_language"
style="@style/SettingsTextValueStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_language_label"
tools:text="English" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_hide_launcher_icon_holder"
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_hide_launcher_icon"
style="@style/SettingsCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hide_launcher_icon" />
</RelativeLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/settings"
android:icon="@drawable/ic_settings_cog_vector"
android:title="@string/settings"
app:showAsAction="always" />
<item
android:id="@+id/about"
android:icon="@drawable/ic_info_vector"
android:title="@string/about"
app:showAsAction="always" />
<item
android:id="@+id/more_apps_from_us"
android:title="@string/more_apps_from_us"
app:showAsAction="never" />
</menu>

View File

@ -1,8 +1,17 @@
[versions] [versions]
#jetbrains #jetbrains
kotlin = "1.9.0" kotlin = "1.9.10"
#Simple tools #Simple tools
simple-commons = "de113ad025" simple-commons = "5598de895b"
#Compose
composeActivity = "1.8.0-beta01"
compose = "1.6.0-alpha05"
composeCompiler = "1.5.3"
composeMaterial3 = "1.2.0-alpha07"
#Androidx
androidx-customView = "1.2.0-alpha02"
androidx-customViewPooling = "1.0.0"
androidx-lifecycle = "2.7.0-alpha02"
#Gradle #Gradle
gradlePlugins-agp = "8.1.1" gradlePlugins-agp = "8.1.1"
app-build-compileSDKVersion = "34" app-build-compileSDKVersion = "34"
@ -15,8 +24,51 @@ app-version-appId = "com.simplemobiletools.thankyou"
app-version-versionCode = "31" app-version-versionCode = "31"
app-version-versionName = "5.7.3" app-version-versionName = "5.7.3"
[libraries] [libraries]
#Android X
androidx-customView = { module = "androidx.customview:customview", version.ref = "androidx-customView" }
androidx-customViewPooling = { module = "androidx.customview:customview-poolingcontainer", version.ref = "androidx-customViewPooling" }
#Simple Mobile Tools #Simple Mobile Tools
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" }
#Android X lifecycle
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewModel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewModel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
#Compose
compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "composeCompiler" }
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "composeMaterial3" }
compose-material2 = { module = "androidx.compose.material:material", version.ref = "compose" }
compose-material-icons = { module = "androidx.compose.material:material-icons-extended", version.ref = "compose" }
compose-animation = { module = "androidx.compose.animation:animation", version.ref = "compose" }
compose-activity = { module = "androidx.activity:activity-compose", version.ref = "composeActivity" }
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" }
compose-uiTooling-debug = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-uiTooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
[bundles]
compose = [
"compose-activity",
"compose-animation",
"compose-compiler",
"compose-foundation",
"compose-material-icons",
"compose-material3",
"compose-runtime",
"compose-ui",
"compose-uiTooling-preview",
]
compose-preview = [
"androidx-customView",
"androidx-customViewPooling",
"compose-uiTooling-debug",
]
lifecycle = [
"androidx-lifecycle-compose",
"androidx-lifecycle-runtime",
"androidx-lifecycle-viewModel",
"androidx-lifecycle-viewModel-compose",
]
[plugins] [plugins]
android = { id = "com.android.application", version.ref = "gradlePlugins-agp" } android = { id = "com.android.application", version.ref = "gradlePlugins-agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip