Resume on last used tab

This commit is contained in:
Jay 2020-03-28 14:11:19 -04:00
parent 5e45c29f58
commit d82b6fbe04
2 changed files with 8 additions and 6 deletions

View File

@ -53,6 +53,8 @@ class PreferencesHelper(val context: Context) {
fun getStringPref(key: String, default: String?) = rxPrefs.getString(key, default) fun getStringPref(key: String, default: String?) = rxPrefs.getString(key, default)
fun getStringSet(key: String, default: Set<String>) = rxPrefs.getStringSet(key, default) fun getStringSet(key: String, default: Set<String>) = rxPrefs.getStringSet(key, default)
fun lastTab() = rxPrefs.getInteger("last_tab", 0)
fun clear() = prefs.edit().clear().apply() fun clear() = prefs.edit().clear().apply()
fun theme() = prefs.getInt(Keys.theme, 5) fun theme() = prefs.getInt(Keys.theme, 5)

View File

@ -61,9 +61,6 @@ import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePadding import eu.kanade.tachiyomi.util.view.updatePadding
import java.util.Date
import java.util.concurrent.TimeUnit
import kotlin.math.abs
import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.main_activity.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
@ -71,6 +68,9 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.util.Date
import java.util.concurrent.TimeUnit
import kotlin.math.abs
open class MainActivity : BaseActivity(), DownloadServiceListener { open class MainActivity : BaseActivity(), DownloadServiceListener {
@ -141,6 +141,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
}) return@setOnNavigationItemSelectedListener false }) return@setOnNavigationItemSelectedListener false
} }
continueSwitchingTabs = false continueSwitchingTabs = false
preferences.lastTab().set(item.itemId)
val currentRoot = router.backstack.firstOrNull() val currentRoot = router.backstack.firstOrNull()
if (currentRoot?.tag()?.toIntOrNull() != id) { if (currentRoot?.tag()?.toIntOrNull() != id) {
when (id) { when (id) {
@ -223,7 +224,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
if (!router.hasRootController()) { if (!router.hasRootController()) {
// Set start screen // Set start screen
if (!handleIntentAction(intent)) { if (!handleIntentAction(intent)) {
bottom_nav.selectedItemId = R.id.nav_library val lastItemId = bottom_nav.menu.findItem(preferences.lastTab().getOrDefault())?.itemId
bottom_nav.selectedItemId = lastItemId ?: R.id.nav_library
} }
} }
@ -387,14 +389,12 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
when (intent.action) { when (intent.action) {
SHORTCUT_LIBRARY -> bottom_nav.selectedItemId = R.id.nav_library SHORTCUT_LIBRARY -> bottom_nav.selectedItemId = R.id.nav_library
SHORTCUT_RECENTLY_UPDATED, SHORTCUT_RECENTLY_READ -> { SHORTCUT_RECENTLY_UPDATED, SHORTCUT_RECENTLY_READ -> {
// preferences.showRecentUpdates().set(intent.action == SHORTCUT_RECENTLY_UPDATED)
bottom_nav.selectedItemId = R.id.nav_recents bottom_nav.selectedItemId = R.id.nav_recents
val controller: Controller = when (intent.action) { val controller: Controller = when (intent.action) {
SHORTCUT_RECENTLY_UPDATED -> RecentChaptersController() SHORTCUT_RECENTLY_UPDATED -> RecentChaptersController()
else -> RecentlyReadController() else -> RecentlyReadController()
} }
router.pushController(controller.withFadeTransaction()) router.pushController(controller.withFadeTransaction())
// updateRecentsIcon()
} }
SHORTCUT_CATALOGUES -> bottom_nav.selectedItemId = R.id.nav_catalogues SHORTCUT_CATALOGUES -> bottom_nav.selectedItemId = R.id.nav_catalogues
SHORTCUT_EXTENSIONS -> { SHORTCUT_EXTENSIONS -> {