feat: fully migrate to compose, main and settings
This commit is contained in:
parent
811808c00f
commit
e6cc16afcd
|
@ -28,12 +28,14 @@
|
|||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:configChanges="orientation"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:configChanges="orientation"
|
||||
android:exported="true"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:label="@string/settings"
|
||||
android:parentActivityName=".activities.MainActivity">
|
||||
|
||||
|
|
|
@ -2,21 +2,23 @@ package com.simplemobiletools.thankyou.activities
|
|||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
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.appLaunched
|
||||
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
||||
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.checkWhatsNew
|
||||
import com.simplemobiletools.thankyou.extensions.startAboutActivity
|
||||
import com.simplemobiletools.thankyou.screens.MainScreen
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdgeSimple()
|
||||
|
@ -34,6 +36,7 @@ class MainActivity : SimpleActivity() {
|
|||
appLaunched(BuildConfig.APPLICATION_ID)
|
||||
checkWhatsNewDialog()
|
||||
}
|
||||
|
||||
private fun launchSettings() {
|
||||
hideKeyboard()
|
||||
startActivity(Intent(this, SettingsActivity::class.java))
|
||||
|
|
|
@ -1,93 +1,75 @@
|
|||
package com.simplemobiletools.thankyou.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.simplemobiletools.commons.compose.extensions.enableEdgeToEdgeSimple
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.NavigationIcon
|
||||
import com.simplemobiletools.commons.extensions.getAppIconColors
|
||||
import com.simplemobiletools.commons.extensions.toggleAppIconColor
|
||||
import com.simplemobiletools.commons.helpers.isTiramisuPlus
|
||||
import com.simplemobiletools.thankyou.BuildConfig
|
||||
import com.simplemobiletools.thankyou.R
|
||||
import com.simplemobiletools.thankyou.databinding.ActivitySettingsBinding
|
||||
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 kotlin.system.exitProcess
|
||||
|
||||
class SettingsActivity : SimpleActivity() {
|
||||
private val binding by lazy(LazyThreadSafetyMode.NONE) { ActivitySettingsBinding.inflate(layoutInflater) }
|
||||
class SettingsActivity : ComponentActivity() {
|
||||
|
||||
private val preferences by lazy { config }
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
isMaterialActivity = true
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(binding.root)
|
||||
|
||||
binding.apply {
|
||||
updateMaterialActivityViews(settingsCoordinator, settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false)
|
||||
setupMaterialScrollListener(settingsNestedScrollview, settingsToolbar)
|
||||
enableEdgeToEdgeSimple()
|
||||
setContent {
|
||||
AppThemeSurface {
|
||||
val wasUseEnglishToggledFlow by preferences.wasUseEnglishToggledFlow.collectAsStateWithLifecycle(preferences.wasUseEnglishToggled)
|
||||
val useEnglishFlow by preferences.useEnglishFlow.collectAsStateWithLifecycle(preferences.useEnglish)
|
||||
val hideLauncherIconFlow by preferences.hideLauncherIconFlow.collectAsStateWithLifecycle(preferences.useEnglish)
|
||||
val displayLanguage = remember { Locale.getDefault().displayLanguage }
|
||||
val isUseEnglishEnabled by remember(wasUseEnglishToggledFlow) {
|
||||
derivedStateOf {
|
||||
(wasUseEnglishToggledFlow || Locale.getDefault().language != "en") && !isTiramisuPlus()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
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
|
||||
SettingsScreen(
|
||||
displayLanguage = displayLanguage,
|
||||
isUseEnglishEnabled = isUseEnglishEnabled,
|
||||
isUseEnglishChecked = useEnglishFlow,
|
||||
onUseEnglishPress = { isChecked ->
|
||||
preferences.useEnglish = isChecked
|
||||
exitProcess(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) {
|
||||
},
|
||||
onSetupLanguagePress = ::launchChangeAppLanguageIntent,
|
||||
isHidingLauncherIcon = hideLauncherIconFlow,
|
||||
hideLauncherIconClick = { isChecked ->
|
||||
preferences.hideLauncherIcon = isChecked
|
||||
if (isChecked) {
|
||||
toggleHideLauncherIcon()
|
||||
} else {
|
||||
ConfirmationDialog(this, "", R.string.hide_launcher_icon_explanation, R.string.ok, R.string.cancel) {
|
||||
toggleHideLauncherIcon()
|
||||
}
|
||||
}
|
||||
},
|
||||
customizeColors = ::startCustomizationActivity,
|
||||
goBack = ::finish
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleHideLauncherIcon() {
|
||||
binding.settingsHideLauncherIcon.toggle()
|
||||
config.hideLauncherIcon = binding.settingsHideLauncherIcon.isChecked
|
||||
|
||||
val appId = BuildConfig.APPLICATION_ID
|
||||
getAppIconColors().forEachIndexed { index, color ->
|
||||
toggleAppIconColor(appId, index, color, false)
|
||||
|
|
|
@ -1,6 +1,118 @@
|
|||
package com.simplemobiletools.thankyou.extensions
|
||||
|
||||
import android.app.Activity
|
||||
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
|
||||
|
||||
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)
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
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 {
|
||||
|
@ -11,4 +14,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
var hideLauncherIcon: Boolean
|
||||
get() = prefs.getBoolean(HIDE_LAUNCHER_ICON, false)
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -2,30 +2,29 @@
|
|||
|
||||
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.Info
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
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.screens.LinkifyText
|
||||
import com.simplemobiletools.commons.compose.screens.stringFromHTML
|
||||
import com.simplemobiletools.commons.compose.settings.scaffold.*
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
@Composable
|
||||
|
@ -35,18 +34,19 @@ internal fun MainScreen(
|
|||
openAbout: () -> Unit,
|
||||
moreAppsFromUs: () -> Unit,
|
||||
) {
|
||||
|
||||
SettingsLazyScaffold(customTopBar = { scrolledColor: Color, _: MutableInteractionSource, scrollBehavior: TopAppBarScrollBehavior, statusBarColor: Int, colorTransitionFraction: Float, contrastColor: Color ->
|
||||
TopAppBar(
|
||||
title = {},
|
||||
actions = {
|
||||
val actionMenus = remember {
|
||||
val list = listOf(
|
||||
ActionItem(R.string.settings, icon = Icons.Outlined.Settings, doAction = openSettings, overflowMode = OverflowMode.NEVER_OVERFLOW),
|
||||
ActionItem(R.string.about, icon = Icons.Outlined.Info, doAction = openAbout, overflowMode = OverflowMode.NEVER_OVERFLOW),
|
||||
)
|
||||
if (showMoreApps) {
|
||||
list + ActionItem(R.string.more_apps_from_us, doAction = moreAppsFromUs, overflowMode = OverflowMode.ALWAYS_OVERFLOW)
|
||||
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()
|
||||
}
|
||||
|
@ -58,11 +58,26 @@ internal fun MainScreen(
|
|||
modifier = Modifier.topAppBarPaddings(),
|
||||
windowInsets = topAppBarInsets()
|
||||
)
|
||||
}) {
|
||||
val source = stringResource(id = com.simplemobiletools.thankyou.R.string.main_text)
|
||||
LinkifyText(modifier = Modifier.padding(40.dp), fontSize = 16.sp) {
|
||||
stringFromHTML(source)
|
||||
}) { 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.setTextColor(textColor)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,21 +92,6 @@ fun topAppBarColors(
|
|||
navigationIconContentColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun ActionMenuMainScreen(
|
||||
) {
|
||||
var isMenuVisible by remember { mutableStateOf(false) }
|
||||
val actionMenus: ImmutableList<ActionItem> = remember {
|
||||
listOf(
|
||||
ActionItem(nameRes = R.string.settings, icon = Icons.Default.Settings, overflowMode = OverflowMode.NEVER_OVERFLOW, doAction = {}),
|
||||
ActionItem(nameRes = R.string.about, icon = Icons.Default.Info, overflowMode = OverflowMode.NEVER_OVERFLOW, doAction = {}),
|
||||
ActionItem(nameRes = R.string.more_apps_from_us, icon = null, overflowMode = OverflowMode.ALWAYS_OVERFLOW, doAction = {}),
|
||||
).toImmutableList()
|
||||
}
|
||||
ActionMenu(items = actionMenus, numIcons = 2, isMenuVisible = isMenuVisible, onMenuToggle = { isMenuVisible = !isMenuVisible })
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
@MyDevices
|
||||
private fun MainScreenPreview() {
|
||||
|
|
|
@ -1,17 +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() {
|
||||
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() }
|
||||
AppThemeSurface {
|
||||
SettingsScreen(
|
||||
displayLanguage = "English",
|
||||
isUseEnglishEnabled = false,
|
||||
isUseEnglishChecked = false,
|
||||
isHidingLauncherIcon = false,
|
||||
onUseEnglishPress = {},
|
||||
onSetupLanguagePress = {},
|
||||
hideLauncherIconClick = {},
|
||||
customizeColors = {},
|
||||
goBack = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
Loading…
Reference in New Issue