Minor cleanup

(cherry picked from commit b9fd01315bb692ab964d91d97f2196a1d4c2343d)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt
This commit is contained in:
arkon 2022-03-05 22:38:22 -05:00 committed by Jobobby04
parent 3e27e8943b
commit 01b8256daf
3 changed files with 16 additions and 44 deletions

View File

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

View File

@ -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<SourceItem>()
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() {

View File

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