Remember last active category. Closes #261

This commit is contained in:
len 2016-05-08 18:11:09 +02:00
parent 7cc4405c09
commit 7ca99f749b
4 changed files with 14 additions and 2 deletions

View File

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

View File

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

View File

@ -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<LibraryPresenter>(), 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()
}
}

View File

@ -46,13 +46,13 @@
<string name="pref_remove_after_read_key">pref_remove_after_read_key</string>
<string name="pref_remove_after_read_previous_key">pref_remove_after_read_previous_key</string>
<string name="pref_last_used_category_key">last_used_category</string>
<string name="pref_source_languages">pref_source_languages</string>
<string name="pref_clear_chapter_cache_key">pref_clear_chapter_cache_key</string>
<string name="pref_clear_database_key">pref_clear_database_key</string>
<string name="pref_version">pref_version</string>
<string name="pref_build_time">pref_build_time</string>
<string name="pref_enable_automatic_updates_key">pref_enable_automatic_updates_key</string>