From 34b9c82cd0ca07ded2cd079a9cc18229a02a9a81 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 4 Jun 2023 17:07:29 -0400 Subject: [PATCH] Remove General settings section --- .../settings/screen/SettingsAdvancedScreen.kt | 93 +++++++++------ .../screen/SettingsAppearanceScreen.kt | 52 ++++++++ .../settings/screen/SettingsGeneralScreen.kt | 111 ------------------ .../settings/screen/SettingsLibraryScreen.kt | 4 + .../settings/screen/SettingsMainScreen.kt | 7 -- .../settings/screen/SettingsSearchScreen.kt | 1 - .../settings/screen/SettingsSecurityScreen.kt | 1 - .../tachiyomi/ui/setting/SettingsScreen.kt | 4 +- i18n/src/main/res/values/strings.xml | 1 - 9 files changed, 116 insertions(+), 158 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index f470522f92..cff75a8765 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -3,6 +3,7 @@ package eu.kanade.presentation.more.settings.screen import android.annotation.SuppressLint import android.content.ActivityNotFoundException import android.content.Intent +import android.os.Build import android.provider.Settings import android.webkit.WebStorage import android.webkit.WebView @@ -68,6 +69,7 @@ import uy.kohesive.injekt.api.get import java.io.File object SettingsAdvancedScreen : SearchableSettings { + @ReadOnlyComposable @Composable @StringRes @@ -82,41 +84,62 @@ object SettingsAdvancedScreen : SearchableSettings { val basePreferences = remember { Injekt.get() } val networkPreferences = remember { Injekt.get() } - return listOf( - Preference.PreferenceItem.SwitchPreference( - pref = basePreferences.acraEnabled(), - title = stringResource(R.string.pref_enable_acra), - subtitle = stringResource(R.string.pref_acra_summary), - enabled = isPreviewBuildType || isReleaseBuildType, - ), - Preference.PreferenceItem.TextPreference( - title = stringResource(R.string.pref_dump_crash_logs), - subtitle = stringResource(R.string.pref_dump_crash_logs_summary), - onClick = { - scope.launch { - CrashLogUtil(context).dumpLogs() - } - }, - ), - Preference.PreferenceItem.SwitchPreference( - pref = networkPreferences.verboseLogging(), - title = stringResource(R.string.pref_verbose_logging), - subtitle = stringResource(R.string.pref_verbose_logging_summary), - onValueChanged = { - context.toast(R.string.requires_app_restart) - true - }, - ), - Preference.PreferenceItem.TextPreference( - title = stringResource(R.string.pref_debug_info), - onClick = { navigator.push(DebugInfoScreen) }, - ), - getBackgroundActivityGroup(), - getDataGroup(), - getNetworkGroup(networkPreferences = networkPreferences), - getLibraryGroup(), - getExtensionsGroup(basePreferences = basePreferences), - ) + return buildList { + addAll( + listOf( + Preference.PreferenceItem.SwitchPreference( + pref = basePreferences.acraEnabled(), + title = stringResource(R.string.pref_enable_acra), + subtitle = stringResource(R.string.pref_acra_summary), + enabled = isPreviewBuildType || isReleaseBuildType, + ), + Preference.PreferenceItem.TextPreference( + title = stringResource(R.string.pref_dump_crash_logs), + subtitle = stringResource(R.string.pref_dump_crash_logs_summary), + onClick = { + scope.launch { + CrashLogUtil(context).dumpLogs() + } + }, + ), + Preference.PreferenceItem.SwitchPreference( + pref = networkPreferences.verboseLogging(), + title = stringResource(R.string.pref_verbose_logging), + subtitle = stringResource(R.string.pref_verbose_logging_summary), + onValueChanged = { + context.toast(R.string.requires_app_restart) + true + }, + ), + Preference.PreferenceItem.TextPreference( + title = stringResource(R.string.pref_debug_info), + onClick = { navigator.push(DebugInfoScreen) }, + ), + ), + ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + add( + Preference.PreferenceItem.TextPreference( + title = stringResource(R.string.pref_manage_notifications), + onClick = { + val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply { + putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) + } + context.startActivity(intent) + }, + ), + ) + } + addAll( + listOf( + getBackgroundActivityGroup(), + getDataGroup(), + getNetworkGroup(networkPreferences = networkPreferences), + getLibraryGroup(), + getExtensionsGroup(basePreferences = basePreferences), + ), + ) + } } @Composable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt index 2235daed10..7011bc500c 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt @@ -4,14 +4,18 @@ import android.app.Activity import android.content.Context import android.os.Build import androidx.annotation.StringRes +import androidx.appcompat.app.AppCompatDelegate import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.core.app.ActivityCompat +import androidx.core.os.LocaleListCompat import eu.kanade.domain.ui.UiPreferences import eu.kanade.domain.ui.model.TabletUiMode import eu.kanade.domain.ui.model.ThemeMode @@ -19,10 +23,12 @@ import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.merge +import org.xmlpull.v1.XmlPullParser import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.Date @@ -103,9 +109,30 @@ object SettingsAppearanceScreen : SearchableSettings { context: Context, uiPreferences: UiPreferences, ): Preference.PreferenceGroup { + val langs = remember { getLangs(context) } + var currentLanguage by remember { mutableStateOf(AppCompatDelegate.getApplicationLocales().get(0)?.toLanguageTag() ?: "") } + + LaunchedEffect(currentLanguage) { + val locale = if (currentLanguage.isEmpty()) { + LocaleListCompat.getEmptyLocaleList() + } else { + LocaleListCompat.forLanguageTags(currentLanguage) + } + AppCompatDelegate.setApplicationLocales(locale) + } + return Preference.PreferenceGroup( title = stringResource(R.string.pref_category_display), preferenceItems = listOf( + Preference.PreferenceItem.BasicListPreference( + value = currentLanguage, + title = stringResource(R.string.pref_app_language), + entries = langs, + onValueChanged = { newValue -> + currentLanguage = newValue + true + }, + ), Preference.PreferenceItem.ListPreference( pref = uiPreferences.tabletUiMode(), title = stringResource(R.string.pref_tablet_ui_mode), @@ -146,6 +173,31 @@ object SettingsAppearanceScreen : SearchableSettings { ), ) } + + private fun getLangs(context: Context): Map { + val langs = mutableListOf>() + val parser = context.resources.getXml(R.xml.locales_config) + var eventType = parser.eventType + while (eventType != XmlPullParser.END_DOCUMENT) { + if (eventType == XmlPullParser.START_TAG && parser.name == "locale") { + for (i in 0 until parser.attributeCount) { + if (parser.getAttributeName(i) == "name") { + val langTag = parser.getAttributeValue(i) + val displayName = LocaleHelper.getDisplayName(langTag) + if (displayName.isNotEmpty()) { + langs.add(Pair(langTag, displayName)) + } + } + } + } + eventType = parser.next() + } + + langs.sortBy { it.second } + langs.add(0, Pair("", context.getString(R.string.label_default))) + + return langs.toMap() + } } private val DateFormats = listOf( diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt deleted file mode 100644 index c609b3626f..0000000000 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt +++ /dev/null @@ -1,111 +0,0 @@ -package eu.kanade.presentation.more.settings.screen - -import android.content.Context -import android.content.Intent -import android.os.Build -import android.provider.Settings -import androidx.annotation.StringRes -import androidx.appcompat.app.AppCompatDelegate -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.ReadOnlyComposable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.stringResource -import androidx.core.os.LocaleListCompat -import eu.kanade.presentation.more.settings.Preference -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.util.system.LocaleHelper -import org.xmlpull.v1.XmlPullParser -import tachiyomi.domain.library.service.LibraryPreferences -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get - -object SettingsGeneralScreen : SearchableSettings { - - @Composable - @ReadOnlyComposable - @StringRes - override fun getTitleRes() = R.string.pref_category_general - - @Composable - override fun getPreferences(): List { - val libraryPrefs = remember { Injekt.get() } - val context = LocalContext.current - - val langs = remember { getLangs(context) } - var currentLanguage by remember { mutableStateOf(AppCompatDelegate.getApplicationLocales().get(0)?.toLanguageTag() ?: "") } - - return buildList { - add( - Preference.PreferenceItem.SwitchPreference( - pref = libraryPrefs.newShowUpdatesCount(), - title = stringResource(R.string.pref_library_update_show_tab_badge), - ), - ) - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - add( - Preference.PreferenceItem.TextPreference( - title = stringResource(R.string.pref_manage_notifications), - onClick = { - val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply { - putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) - } - context.startActivity(intent) - }, - ), - ) - } - - add( - Preference.PreferenceItem.BasicListPreference( - value = currentLanguage, - title = stringResource(R.string.pref_app_language), - entries = langs, - onValueChanged = { newValue -> - currentLanguage = newValue - true - }, - ), - ) - - LaunchedEffect(currentLanguage) { - val locale = if (currentLanguage.isEmpty()) { - LocaleListCompat.getEmptyLocaleList() - } else { - LocaleListCompat.forLanguageTags(currentLanguage) - } - AppCompatDelegate.setApplicationLocales(locale) - } - } - } - - private fun getLangs(context: Context): Map { - val langs = mutableListOf>() - val parser = context.resources.getXml(R.xml.locales_config) - var eventType = parser.eventType - while (eventType != XmlPullParser.END_DOCUMENT) { - if (eventType == XmlPullParser.START_TAG && parser.name == "locale") { - for (i in 0 until parser.attributeCount) { - if (parser.getAttributeName(i) == "name") { - val langTag = parser.getAttributeValue(i) - val displayName = LocaleHelper.getDisplayName(langTag) - if (displayName.isNotEmpty()) { - langs.add(Pair(langTag, displayName)) - } - } - } - } - eventType = parser.next() - } - - langs.sortBy { it.second } - langs.add(0, Pair("", context.getString(R.string.label_default))) - - return langs.toMap() - } -} diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt index 7b31e94796..e009675763 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt @@ -265,6 +265,10 @@ object SettingsLibraryScreen : SearchableSettings { Preference.PreferenceItem.InfoPreference( title = stringResource(R.string.pref_update_release_grace_period_info), ).takeIf { MANGA_OUTSIDE_RELEASE_PERIOD in libraryUpdateMangaRestriction && isDevFlavor }, + Preference.PreferenceItem.SwitchPreference( + pref = libraryPreferences.newShowUpdatesCount(), + title = stringResource(R.string.pref_library_update_show_tab_badge), + ), ), ) } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt index 1055a9a6d8..c788640c7f 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt @@ -20,7 +20,6 @@ import androidx.compose.material.icons.outlined.Search import androidx.compose.material.icons.outlined.Security import androidx.compose.material.icons.outlined.SettingsBackupRestore import androidx.compose.material.icons.outlined.Sync -import androidx.compose.material.icons.outlined.Tune import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalContentColor @@ -187,12 +186,6 @@ object SettingsMainScreen : Screen() { ) private val items = listOf( - Item( - titleRes = R.string.pref_category_general, - subtitleRes = R.string.pref_general_summary, - icon = Icons.Outlined.Tune, - screen = SettingsGeneralScreen, - ), Item( titleRes = R.string.pref_category_appearance, subtitleRes = R.string.pref_appearance_summary, diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt index c5fdc1abf7..cad51c0445 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt @@ -284,7 +284,6 @@ private fun getLocalizedBreadcrumb(path: String, node: String?): String { } private val settingScreens = listOf( - SettingsGeneralScreen, SettingsAppearanceScreen, SettingsLibraryScreen, SettingsReaderScreen, diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt index c560dff7f5..d26c080de0 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt @@ -32,7 +32,6 @@ object SettingsSecurityScreen : SearchableSettings { val authSupported = remember { context.isAuthenticationSupported() } val useAuthPref = securityPreferences.useAuthenticator() - val useAuth by useAuthPref.collectAsState() return listOf( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsScreen.kt index e53427a468..8a18219ad4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsScreen.kt @@ -13,8 +13,8 @@ import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.presentation.more.settings.screen.AboutScreen +import eu.kanade.presentation.more.settings.screen.SettingsAppearanceScreen import eu.kanade.presentation.more.settings.screen.SettingsBackupScreen -import eu.kanade.presentation.more.settings.screen.SettingsGeneralScreen import eu.kanade.presentation.more.settings.screen.SettingsMainScreen import eu.kanade.presentation.util.DefaultNavigatorScreenTransition import eu.kanade.presentation.util.LocalBackPress @@ -59,7 +59,7 @@ class SettingsScreen private constructor( } else if (toAbout) { AboutScreen } else { - SettingsGeneralScreen + SettingsAppearanceScreen }, ) { val insets = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal) diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 5bdf165664..7dddc5ca6a 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -171,7 +171,6 @@ Advanced About - App language, notifications Theme, date & time format Categories, global update, chapter swipe Reading mode, display, navigation