From 204a784895c9bbd878236a811920f46a7876845e Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 22 Apr 2020 20:33:43 -0400 Subject: [PATCH] Added Last Used header to browse, hides if it is a pinned source --- .../tachiyomi/ui/source/SourceController.kt | 1 + .../eu/kanade/tachiyomi/ui/source/SourceItem.kt | 2 +- .../kanade/tachiyomi/ui/source/SourcePresenter.kt | 15 +++++++++------ .../kanade/tachiyomi/util/system/LocaleHelper.kt | 3 ++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt index a911186cce..b283cf1b92 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt @@ -366,6 +366,7 @@ class SourceController : NucleusController(), adapter?.removeAllScrollableHeaders() if (item != null) { adapter?.addScrollableHeader(item) + adapter?.addScrollableHeader(LangItem(SourcePresenter.LAST_USED_KEY)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceItem.kt index 63f71a44a6..9ec99cfbb1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceItem.kt @@ -26,7 +26,7 @@ class SourceItem(val source: CatalogueSource, header: LangItem? = null, val isPi } override fun isSwipeable(): Boolean { - return source.id != LocalSource.ID + return source.id != LocalSource.ID && header != null } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourcePresenter.kt index 772024e00c..11efa3e0c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourcePresenter.kt @@ -87,14 +87,16 @@ class SourcePresenter( // Emit the first item immediately but delay subsequent emissions by 500ms. lastUsedSubscription = Observable.merge( - sharedObs.take(1), - sharedObs.skip(1).delay(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())) - .distinctUntilChanged() - .map { (sourceManager.get(it) as? CatalogueSource)?.let { source -> + sharedObs.take(1), + sharedObs.skip(1).delay(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread()) + ).distinctUntilChanged().map { + (sourceManager.get(it) as? CatalogueSource)?.let { source -> val pinnedCatalogues = preferences.pinnedCatalogues().getOrDefault() val isPinned = source.id.toString() in pinnedCatalogues - SourceItem(source, null, isPinned) } } - .subscribeLatestCache(SourceController::setLastUsedSource) + if (isPinned) null + else SourceItem(source, null, isPinned) + } + }.subscribeLatestCache(SourceController::setLastUsedSource) } fun updateSources() { @@ -121,5 +123,6 @@ class SourcePresenter( companion object { const val PINNED_KEY = "pinned" + const val LAST_USED_KEY = "last_used" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt index 3c23230186..44d8ac6501 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt @@ -8,8 +8,8 @@ import android.view.ContextThemeWrapper import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.source.SourcePresenter -import java.util.Locale import uy.kohesive.injekt.injectLazy +import java.util.Locale /** * Utility class to change the application's language in runtime. @@ -58,6 +58,7 @@ object LocaleHelper { null -> "" "" -> context.getString(R.string.other) SourcePresenter.PINNED_KEY -> context.getString(R.string.pinned) + SourcePresenter.LAST_USED_KEY -> context.getString(R.string.last_used) "all" -> context.getString(R.string.all) else -> { val locale = getLocale(lang) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 29f237beb6..8b5b6a29dc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -215,6 +215,7 @@ All sources Sources Source hidden + Last Used