From b9fd01315bb692ab964d91d97f2196a1d4c2343d Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 5 Mar 2022 22:38:22 -0500 Subject: [PATCH] Minor cleanup --- .../ui/browse/source/SourceController.kt | 20 ++++--------------- .../ui/browse/source/SourcePresenter.kt | 17 ++-------------- .../tachiyomi/ui/library/LibraryController.kt | 2 +- 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index f5d16adc67..d198e080d8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt @@ -33,8 +33,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.util.preference.minusAssign import eu.kanade.tachiyomi.util.preference.plusAssign import eu.kanade.tachiyomi.util.view.onAnimationsFinished -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get +import uy.kohesive.injekt.injectLazy /** * This controller shows and manages the different catalogues enabled by the user. @@ -48,11 +47,8 @@ class SourceController : FlexibleAdapter.OnItemLongClickListener, SourceAdapter.OnSourceClickListener { - private val preferences: PreferencesHelper = Injekt.get() + private val preferences: PreferencesHelper by injectLazy() - /** - * Adapter containing sources. - */ private var adapter: SourceAdapter? = null init { @@ -128,18 +124,10 @@ class SourceController : val isPinned = item.header?.code?.equals(SourcePresenter.PINNED_KEY) ?: false val items = mutableListOf( - Pair( - activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin), - { toggleSourcePin(item.source) } - ) + activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin) to { toggleSourcePin(item.source) } ) if (item.source !is LocalSource) { - items.add( - Pair( - activity.getString(R.string.action_disable), - { disableSource(item.source) } - ) - ) + items.add(activity.getString(R.string.action_disable) to { disableSource(item.source) }) } SourceOptionsDialog(item.source.toString(), items).showDialog(router) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt index 31ee700320..f08f0134dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt @@ -11,8 +11,6 @@ import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart -import rx.Observable -import rx.Subscription import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.TreeMap @@ -20,9 +18,6 @@ import java.util.TreeMap /** * Presenter of [SourceController] * Function calls should be done from here. UI calls should be done from the controller. - * - * @param sourceManager manages the different sources. - * @param preferences application preferences. */ class SourcePresenter( val sourceManager: SourceManager = Injekt.get(), @@ -31,17 +26,10 @@ class SourcePresenter( var sources = getEnabledSources() - /** - * Subscription for retrieving enabled sources. - */ - private var sourceSubscription: Subscription? = null - /** * Unsubscribe and create a new subscription to fetch enabled sources. */ private fun loadSources() { - sourceSubscription?.unsubscribe() - val pinnedSources = mutableListOf() val pinnedSourceIds = preferences.pinnedSources().get() @@ -53,7 +41,7 @@ class SourcePresenter( else -> d1.compareTo(d2) } } - val byLang = sources.groupByTo(map, { it.lang }) + val byLang = sources.groupByTo(map) { it.lang } var sourceItems = byLang.flatMap { val langItem = LangItem(it.key) it.value.map { source -> @@ -70,8 +58,7 @@ class SourcePresenter( sourceItems = pinnedSources + sourceItems } - sourceSubscription = Observable.just(sourceItems) - .subscribeLatestCache(SourceController::setSources) + view?.setSources(sourceItems) } private fun loadLastUsedSource() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 3085d4d3cb..095c47eb6c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -552,7 +552,7 @@ class LibraryController( val common = presenter.getCommonCategories(mangas) // Get indexes of the mix categories to preselect. val mix = presenter.getMixCategories(mangas) - var preselected = categories.map { + val preselected = categories.map { when (it) { in common -> QuadStateTextView.State.CHECKED.ordinal in mix -> QuadStateTextView.State.INDETERMINATE.ordinal