Minor cleanup

This commit is contained in:
arkon 2022-03-05 22:38:22 -05:00
parent a72098b862
commit b9fd01315b
3 changed files with 7 additions and 32 deletions

View File

@ -33,8 +33,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.util.preference.minusAssign import eu.kanade.tachiyomi.util.preference.minusAssign
import eu.kanade.tachiyomi.util.preference.plusAssign import eu.kanade.tachiyomi.util.preference.plusAssign
import eu.kanade.tachiyomi.util.view.onAnimationsFinished import eu.kanade.tachiyomi.util.view.onAnimationsFinished
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.injectLazy
import uy.kohesive.injekt.api.get
/** /**
* This controller shows and manages the different catalogues enabled by the user. * This controller shows and manages the different catalogues enabled by the user.
@ -48,11 +47,8 @@ class SourceController :
FlexibleAdapter.OnItemLongClickListener, FlexibleAdapter.OnItemLongClickListener,
SourceAdapter.OnSourceClickListener { SourceAdapter.OnSourceClickListener {
private val preferences: PreferencesHelper = Injekt.get() private val preferences: PreferencesHelper by injectLazy()
/**
* Adapter containing sources.
*/
private var adapter: SourceAdapter? = null private var adapter: SourceAdapter? = null
init { init {
@ -128,18 +124,10 @@ class SourceController :
val isPinned = item.header?.code?.equals(SourcePresenter.PINNED_KEY) ?: false val isPinned = item.header?.code?.equals(SourcePresenter.PINNED_KEY) ?: false
val items = mutableListOf( val items = mutableListOf(
Pair( activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin) to { toggleSourcePin(item.source) }
activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin),
{ toggleSourcePin(item.source) }
)
) )
if (item.source !is LocalSource) { if (item.source !is LocalSource) {
items.add( items.add(activity.getString(R.string.action_disable) to { disableSource(item.source) })
Pair(
activity.getString(R.string.action_disable),
{ disableSource(item.source) }
)
)
} }
SourceOptionsDialog(item.source.toString(), items).showDialog(router) SourceOptionsDialog(item.source.toString(), items).showDialog(router)

View File

@ -11,8 +11,6 @@ import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.onStart
import rx.Observable
import rx.Subscription
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.TreeMap import java.util.TreeMap
@ -20,9 +18,6 @@ import java.util.TreeMap
/** /**
* Presenter of [SourceController] * Presenter of [SourceController]
* Function calls should be done from here. UI calls should be done from the controller. * 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( class SourcePresenter(
val sourceManager: SourceManager = Injekt.get(), val sourceManager: SourceManager = Injekt.get(),
@ -31,17 +26,10 @@ class SourcePresenter(
var sources = getEnabledSources() var sources = getEnabledSources()
/**
* Subscription for retrieving enabled sources.
*/
private var sourceSubscription: Subscription? = null
/** /**
* Unsubscribe and create a new subscription to fetch enabled sources. * Unsubscribe and create a new subscription to fetch enabled sources.
*/ */
private fun loadSources() { private fun loadSources() {
sourceSubscription?.unsubscribe()
val pinnedSources = mutableListOf<SourceItem>() val pinnedSources = mutableListOf<SourceItem>()
val pinnedSourceIds = preferences.pinnedSources().get() val pinnedSourceIds = preferences.pinnedSources().get()
@ -53,7 +41,7 @@ class SourcePresenter(
else -> d1.compareTo(d2) else -> d1.compareTo(d2)
} }
} }
val byLang = sources.groupByTo(map, { it.lang }) val byLang = sources.groupByTo(map) { it.lang }
var sourceItems = byLang.flatMap { var sourceItems = byLang.flatMap {
val langItem = LangItem(it.key) val langItem = LangItem(it.key)
it.value.map { source -> it.value.map { source ->
@ -70,8 +58,7 @@ class SourcePresenter(
sourceItems = pinnedSources + sourceItems sourceItems = pinnedSources + sourceItems
} }
sourceSubscription = Observable.just(sourceItems) view?.setSources(sourceItems)
.subscribeLatestCache(SourceController::setSources)
} }
private fun loadLastUsedSource() { private fun loadLastUsedSource() {

View File

@ -552,7 +552,7 @@ class LibraryController(
val common = presenter.getCommonCategories(mangas) val common = presenter.getCommonCategories(mangas)
// Get indexes of the mix categories to preselect. // Get indexes of the mix categories to preselect.
val mix = presenter.getMixCategories(mangas) val mix = presenter.getMixCategories(mangas)
var preselected = categories.map { val preselected = categories.map {
when (it) { when (it) {
in common -> QuadStateTextView.State.CHECKED.ordinal in common -> QuadStateTextView.State.CHECKED.ordinal
in mix -> QuadStateTextView.State.INDETERMINATE.ordinal in mix -> QuadStateTextView.State.INDETERMINATE.ordinal