Added Last Used header to browse, hides if it is a pinned source

This commit is contained in:
Jay 2020-04-22 20:33:43 -04:00
parent f5cc879a7e
commit 204a784895
5 changed files with 14 additions and 8 deletions

View File

@ -366,6 +366,7 @@ class SourceController : NucleusController<SourcePresenter>(),
adapter?.removeAllScrollableHeaders()
if (item != null) {
adapter?.addScrollableHeader(item)
adapter?.addScrollableHeader(LangItem(SourcePresenter.LAST_USED_KEY))
}
}

View File

@ -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
}
/**

View File

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

View File

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

View File

@ -215,6 +215,7 @@
<string name="all_sources">All sources</string>
<string name="sources">Sources</string>
<string name="source_hidden">Source hidden</string>
<string name="last_used">Last Used</string>
<!-- Other Screens -->