From 7ca99f749be0bae9cf3c0118af36c268d9ca0ced Mon Sep 17 00:00:00 2001 From: len Date: Sun, 8 May 2016 18:11:09 +0200 Subject: [PATCH] Remember last active category. Closes #261 --- .../kanade/tachiyomi/data/preference/PreferenceKeys.kt | 3 ++- .../tachiyomi/data/preference/PreferencesHelper.kt | 2 ++ .../eu/kanade/tachiyomi/ui/library/LibraryFragment.kt | 9 +++++++++ app/src/main/res/values/keys.xml | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) 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 f17b15d26..3d09756ff 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 @@ -52,6 +52,8 @@ class PreferenceKeys(context: Context) { val lastUsedCatalogueSource = context.getString(R.string.pref_last_catalogue_source_key) + val lastUsedCategory = context.getString(R.string.pref_last_used_category_key) + val seamlessMode = context.getString(R.string.pref_seamless_mode_key) val catalogueAsList = context.getString(R.string.pref_display_catalogue_as_list) @@ -80,7 +82,6 @@ class PreferenceKeys(context: Context) { fun sourceUsername(sourceId: Int) = "pref_source_username_$sourceId" - fun sourcePassword(sourceId: Int) = "pref_source_password_$sourceId" fun syncUsername(syncId: Int) = "pref_mangasync_username_$syncId" 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 335302de9..fd47d8323 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 @@ -97,6 +97,8 @@ class PreferencesHelper(private val context: Context) { fun lastUsedCatalogueSource() = rxPrefs.getInteger(keys.lastUsedCatalogueSource, -1) + fun lastUsedCategory() = rxPrefs.getInteger(keys.lastUsedCategory, 0) + fun seamlessMode() = prefs.getBoolean(keys.seamlessMode, true) fun catalogueAsList() = rxPrefs.getBoolean(keys.catalogueAsList, false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt index 9a4699926..b68b4bacd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Intent import android.os.Bundle import android.support.design.widget.TabLayout +import android.support.v4.view.ViewPager import android.support.v7.view.ActionMode import android.support.v7.widget.SearchView import android.view.* @@ -13,6 +14,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.library.LibraryUpdateService +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.event.LibraryMangaEvent import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment import eu.kanade.tachiyomi.ui.category.CategoryActivity @@ -116,12 +118,19 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback adapter = LibraryAdapter(childFragmentManager) view_pager.adapter = adapter + view_pager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { + override fun onPageSelected(position: Int) { + presenter.preferences.lastUsedCategory().set(position) + } + }) tabs.setupWithViewPager(view_pager) if (savedState != null) { activeCategory = savedState.getInt(CATEGORY_KEY) query = savedState.getString(QUERY_KEY) presenter.searchSubject.onNext(query) + } else { + activeCategory = presenter.preferences.lastUsedCategory().getOrDefault() } } diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index c0f8b2ecc..e66fe62d3 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -46,13 +46,13 @@ pref_remove_after_read_key pref_remove_after_read_previous_key + last_used_category pref_source_languages pref_clear_chapter_cache_key pref_clear_database_key - pref_version pref_build_time pref_enable_automatic_updates_key