Option to set starting screen + back returns to start

By default it's same behavior as before, last used between recents or library
Other setting is self-explanatory, on by default
This commit is contained in:
Jays2Kings 2021-03-23 20:55:50 -04:00
parent 9a220073b9
commit 6654882c1f
5 changed files with 132 additions and 66 deletions

View File

@ -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"

View File

@ -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<String>) = 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()

View File

@ -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,10 +514,43 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
if (if (router.backstackSize == 1) !(sheetController?.handleSheetBack() ?: false)
else !router.handleBack()
) {
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()))

View File

@ -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"
}
}
}

View File

@ -506,6 +506,8 @@
<string name="white_theme">Pure White</string>
<string name="system_default_amoled">System default (White + Black)</string>
<string name="system_default_all_blue">System default (All Blue)</string>
<string name="locale">Locale</string>
<string name="last_used_library_recents">Last used (Library or Recents)</string>
<string name="language">Language</string>
<string name="system_default">System default</string>
<string name="date_format">Date format</string>
@ -516,6 +518,9 @@
<string name="hides_on_scroll">Hides when scrolling</string>
<string name="hide_tachi_from_recents">Hide Tachiyomi from the recents screen</string>
<string name="security">Security</string>
<string name="starting_screen">Starting screen</string>
<string name="back_to_start">Back to start</string>
<string name="pressing_back_to_start">Pressing back to starting screen</string>
<!-- Backup -->
<string name="backup">Backup</string>