diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 8405397bbc..4306d1fa82 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -7,6 +7,10 @@ object PreferenceKeys { const val theme = "pref_theme_key" + const val startingTab = "starting_tab" + + const val backToStart = "back_to_start" + const val rotation = "pref_rotation_type_key" const val enableTransitions = "pref_enable_transitions_key" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index f61ed0c33c..a4c2b698d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -77,7 +77,8 @@ class PreferencesHelper(val context: Context) { fun getStringPref(key: String, default: String?) = rxPrefs.getString(key, default) fun getStringSet(key: String, default: Set) = rxPrefs.getStringSet(key, default) - fun lastTab() = rxPrefs.getInteger("last_tab", 0) + fun startingTab() = flowPrefs.getInt(Keys.startingTab, 0) + fun backReturnsToStart() = flowPrefs.getBoolean(Keys.backToStart, true) fun clear() = prefs.edit().clear().apply() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 87a5179981..25c109282d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -18,6 +18,7 @@ import android.view.ViewGroup import android.view.WindowInsets import android.view.WindowManager import android.webkit.WebView +import androidx.annotation.IdRes import androidx.appcompat.graphics.drawable.DrawerArrowDrawable import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils @@ -188,8 +189,6 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { ) return@setOnNavigationItemSelectedListener false } continueSwitchingTabs = false - if (item.itemId != R.id.nav_browse) - preferences.lastTab().set(item.itemId) val currentRoot = router.backstack.firstOrNull() if (currentRoot?.tag()?.toIntOrNull() != id) { setRoot( @@ -247,8 +246,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { if (!router.hasRootController()) { // Set start screen if (!handleIntentAction(intent)) { - val lastItemId = bottom_nav.menu.findItem(preferences.lastTab().getOrDefault())?.itemId - bottom_nav.selectedItemId = lastItemId ?: R.id.nav_library + goToStartingTab() } } @@ -413,6 +411,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { override fun onPause() { super.onPause() snackBar?.dismiss() + setStartingTab() } private fun getAppUpdates() { @@ -515,11 +514,44 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { if (if (router.backstackSize == 1) !(sheetController?.handleSheetBack() ?: false) else !router.handleBack() ) { - SecureActivityDelegate.locked = true - super.onBackPressed() + if (preferences.backReturnsToStart().get() && + startingTab() != bottom_nav?.selectedItemId) { + goToStartingTab() + } + else { + if (!preferences.backReturnsToStart().get()) { + setStartingTab() + } + SecureActivityDelegate.locked = true + super.onBackPressed() + } } } + private fun setStartingTab() { + if (bottom_nav?.selectedItemId != R.id.nav_browse + && bottom_nav?.selectedItemId != null + && preferences.startingTab().get() >= 0) + preferences.startingTab().set(when (bottom_nav?.selectedItemId) { + R.id.nav_library -> 0 + else -> 1 + }) + } + + @IdRes + private fun startingTab(): Int { + return when (preferences.startingTab().get()) { + 0, -1 -> R.id.nav_library + 1, -2 -> R.id.nav_recents + -3 -> R.id.nav_browse + else -> R.id.nav_library + } + } + + private fun goToStartingTab() { + bottom_nav.selectedItemId = startingTab() + } + private fun setRoot(controller: Controller, id: Int) { router.setRoot(controller.withFadeTransaction().tag(id.toString())) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index bae34258fb..d55e0d623c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -18,45 +18,24 @@ class SettingsGeneralController : SettingsController() { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.general - listPreference(activity) { - key = Keys.lang - titleRes = R.string.language - entryValues = listOf( - "", "ar", "bg", "bn", "ca", "cs", "de", "el", "en-US", "en-GB", - "es", "fr", "hi", "hu", "in", "it", "ja", "ko", "lv", "ms", "nb-rNO", "nl", "pl", "pt", - "pt-BR", "ro", "ru", "sc", "sr", "sv", "th", "tl", "tr", "uk", "vi", "zh-rCN" + intListPreference(activity) { + key = Keys.startingTab + titleRes = R.string.starting_screen + entriesRes = arrayOf( + R.string.last_used_library_recents, + R.string.library, + R.string.recents, + R.string.browse ) - entries = entryValues.map { value -> - val locale = LocaleHelper.getLocaleFromString(value.toString()) - locale?.getDisplayName(locale)?.capitalize() - ?: context.getString(R.string.system_default) - } - defaultValue = "" - summary = "%s" - - onChange { newValue -> - val activity = activity ?: return@onChange false - val app = activity.application - LocaleHelper.changeLocale(newValue.toString()) - LocaleHelper.updateConfiguration(app, app.resources.configuration) - activity.recreate() - true - } + entryValues = (0 downTo -3).toList() + defaultValue = 0 } - listPreference(activity) { - key = Keys.dateFormat - titleRes = R.string.date_format - entryValues = listOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd") - entries = entryValues.map { value -> - if (value == "") { - context.getString(R.string.system_default) - } else { - value - } - } - defaultValue = "" - summary = "%s" + switchPreference { + key = Keys.backToStart + titleRes = R.string.back_to_start + summaryRes = R.string.pressing_back_to_start + defaultValue = true } switchPreference { @@ -80,6 +59,40 @@ class SettingsGeneralController : SettingsController() { } } + preferenceCategory { + titleRes = R.string.display + + intListPreference(activity) { + key = Keys.theme + titleRes = R.string.app_theme + entriesRes = arrayOf( + R.string.white_theme, + R.string.light_blue, + R.string.dark, + R.string.amoled_black, + R.string.dark_blue, + R.string.system_default, + R.string + .system_default_amoled, + R.string.system_default_all_blue + ) + entryValues = listOf(1, 8, 2, 3, 4, 5, 6, 7) + defaultValue = 5 + + onChange { + activity?.recreate() + true + } + } + + switchPreference { + key = Keys.hideBottomNavOnScroll + titleRes = R.string.hide_bottom_nav + summaryRes = R.string.hides_on_scroll + defaultValue = true + } + } + preferenceCategory { titleRes = R.string.security @@ -132,36 +145,47 @@ class SettingsGeneralController : SettingsController() { } preferenceCategory { - titleRes = R.string.display + titleRes = R.string.locale - intListPreference(activity) { - key = Keys.theme - titleRes = R.string.app_theme - entriesRes = arrayOf( - R.string.white_theme, - R.string.light_blue, - R.string.dark, - R.string.amoled_black, - R.string.dark_blue, - R.string.system_default, - R.string - .system_default_amoled, - R.string.system_default_all_blue + listPreference(activity) { + key = Keys.lang + titleRes = R.string.language + entryValues = listOf( + "", "ar", "bg", "bn", "ca", "cs", "de", "el", "en-US", "en-GB", + "es", "fr", "hi", "hu", "in", "it", "ja", "ko", "lv", "ms", "nb-rNO", "nl", "pl", "pt", + "pt-BR", "ro", "ru", "sc", "sr", "sv", "th", "tl", "tr", "uk", "vi", "zh-rCN" ) - entryValues = listOf(1, 8, 2, 3, 4, 5, 6, 7) - defaultValue = 5 + entries = entryValues.map { value -> + val locale = LocaleHelper.getLocaleFromString(value.toString()) + locale?.getDisplayName(locale)?.capitalize() + ?: context.getString(R.string.system_default) + } + defaultValue = "" + summary = "%s" - onChange { - activity?.recreate() + onChange { newValue -> + val activity = activity ?: return@onChange false + val app = activity.application + LocaleHelper.changeLocale(newValue.toString()) + LocaleHelper.updateConfiguration(app, app.resources.configuration) + activity.recreate() true } } - switchPreference { - key = Keys.hideBottomNavOnScroll - titleRes = R.string.hide_bottom_nav - summaryRes = R.string.hides_on_scroll - defaultValue = true + listPreference(activity) { + key = Keys.dateFormat + titleRes = R.string.date_format + entryValues = listOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd") + entries = entryValues.map { value -> + if (value == "") { + context.getString(R.string.system_default) + } else { + value + } + } + defaultValue = "" + summary = "%s" } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2e500d70ef..826002f4fc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -506,6 +506,8 @@ Pure White System default (White + Black) System default (All Blue) + Locale + Last used (Library or Recents) Language System default Date format @@ -516,6 +518,9 @@ Hides when scrolling Hide Tachiyomi from the recents screen Security + Starting screen + Back to start + Pressing back to starting screen Backup