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 eu.kanade.tachiyomi.util.view.onAnimationsFinished
import exh.ui.smartsearch.SmartSearchController import exh.ui.smartsearch.SmartSearchController
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
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.
@ -56,11 +55,8 @@ class SourceController(bundle: Bundle? = null) :
SourceAdapter.OnSourceClickListener, SourceAdapter.OnSourceClickListener,
/*SY -->*/ ChangeSourceCategoriesDialog.Listener /*SY <--*/ { /*SY -->*/ ChangeSourceCategoriesDialog.Listener /*SY <--*/ {
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
// EXH --> // EXH -->
@ -172,18 +168,10 @@ class SourceController(bundle: Bundle? = null) :
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) }
)
)
} }
// SY --> // SY -->
@ -191,27 +179,24 @@ class SourceController(bundle: Bundle? = null) :
if (item.source.supportsLatest) { if (item.source.supportsLatest) {
items.add( items.add(
Pair( activity.getString(if (isWatched) R.string.unwatch else R.string.watch) to {
activity.getString(if (isWatched) R.string.unwatch else R.string.watch), watchCatalogue(item.source, isWatched)
{ watchCatalogue(item.source, isWatched) } }
)
) )
} }
items.add( items.add(
Pair( activity.getString(R.string.categories) to { addToCategories(item.source) }
activity.getString(R.string.categories),
{ addToCategories(item.source) }
)
) )
if (preferences.dataSaver().get()) { if (preferences.dataSaver().get()) {
val isExcluded = item.source.id.toString() in preferences.dataSaverExcludedSources().get() val isExcluded = item.source.id.toString() in preferences.dataSaverExcludedSources().get()
items.add( items.add(
Pair( activity.getString(
activity.getString(if (isExcluded) R.string.data_saver_stop_exclude else R.string.data_saver_exclude), if (isExcluded) R.string.data_saver_stop_exclude else R.string.data_saver_exclude
{ excludeFromDataSaver(item.source, isExcluded) } ) to {
) excludeFromDataSaver(item.source, isExcluded)
}
) )
} }
// SY <-- // SY <--

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(),
@ -34,17 +29,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()
@ -72,7 +60,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 ->
@ -125,8 +113,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

@ -644,7 +644,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