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 542bdd278..116631335 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 @@ -40,8 +40,7 @@ import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.onAnimationsFinished import exh.ui.smartsearch.SmartSearchController import kotlinx.parcelize.Parcelize -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. @@ -56,11 +55,8 @@ class SourceController(bundle: Bundle? = null) : SourceAdapter.OnSourceClickListener, /*SY -->*/ ChangeSourceCategoriesDialog.Listener /*SY <--*/ { - private val preferences: PreferencesHelper = Injekt.get() + private val preferences: PreferencesHelper by injectLazy() - /** - * Adapter containing sources. - */ private var adapter: SourceAdapter? = null // EXH --> @@ -172,18 +168,10 @@ class SourceController(bundle: Bundle? = null) : 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) }) } // SY --> @@ -191,27 +179,24 @@ class SourceController(bundle: Bundle? = null) : if (item.source.supportsLatest) { items.add( - Pair( - activity.getString(if (isWatched) R.string.unwatch else R.string.watch), - { watchCatalogue(item.source, isWatched) } - ) + activity.getString(if (isWatched) R.string.unwatch else R.string.watch) to { + watchCatalogue(item.source, isWatched) + } ) } items.add( - Pair( - activity.getString(R.string.categories), - { addToCategories(item.source) } - ) + activity.getString(R.string.categories) to { addToCategories(item.source) } ) if (preferences.dataSaver().get()) { val isExcluded = item.source.id.toString() in preferences.dataSaverExcludedSources().get() items.add( - Pair( - activity.getString(if (isExcluded) R.string.data_saver_stop_exclude else R.string.data_saver_exclude), - { excludeFromDataSaver(item.source, isExcluded) } - ) + activity.getString( + if (isExcluded) R.string.data_saver_stop_exclude else R.string.data_saver_exclude + ) to { + excludeFromDataSaver(item.source, isExcluded) + } ) } // SY <-- 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 3ccb50dd3..c28f3f2dd 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(), @@ -34,17 +29,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() @@ -72,7 +60,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 -> @@ -125,8 +113,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 0851a20eb..9f02b6f7a 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 @@ -644,7 +644,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