revert: Revert "refactor(library): Use flow to update libraryManga"

This reverts commit 8e32b6b74e.
This commit is contained in:
Ahmad Ansori Palembani 2024-06-18 11:17:54 +07:00
parent 8e32b6b74e
commit 18953f901c
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
4 changed files with 29 additions and 37 deletions

View file

@ -544,7 +544,7 @@ open class LibraryController(
}
presenter.groupType = item
shouldScrollToTop = true
presenter.updateLibrary()
presenter.getLibrary()
true
}.show()
}
@ -1033,7 +1033,7 @@ open class LibraryController(
if (type.isEnter) {
binding.filterBottomSheet.filterBottomSheet.isVisible = true
if (type == ControllerChangeType.POP_ENTER) {
presenter.updateLibrary()
presenter.getLibrary()
isPoppingIn = true
}
DownloadJob.callListeners()
@ -1073,7 +1073,7 @@ open class LibraryController(
if (!isBindingInitialized) return
updateFilterSheetY()
if (observeLater) {
presenter.updateLibrary()
presenter.getLibrary()
}
}
@ -1384,7 +1384,7 @@ open class LibraryController(
private fun onRefresh() {
showCategories(false)
presenter.updateLibrary()
presenter.getLibrary()
destroyActionModeIfNeeded()
}
@ -1408,14 +1408,14 @@ open class LibraryController(
val isShowAllCategoriesSet = preferences.showAllCategories().get()
if (!query.isNullOrBlank() && this.query.isBlank() && !isShowAllCategoriesSet) {
presenter.forceShowAllCategories = preferences.showAllCategoriesWhenSearchingSingleCategory().get()
presenter.updateLibrary()
presenter.getLibrary()
} else if (query.isNullOrBlank() && this.query.isNotBlank() && !isShowAllCategoriesSet) {
if (!isSubClass) {
preferences.showAllCategoriesWhenSearchingSingleCategory()
.set(presenter.forceShowAllCategories)
}
presenter.forceShowAllCategories = false
presenter.updateLibrary()
presenter.getLibrary()
}
if (query != this.query && !query.isNullOrBlank()) {
@ -1796,7 +1796,7 @@ open class LibraryController(
val category = (adapter.getItem(position) as? LibraryHeaderItem)?.category ?: return
if (!category.isDynamic) {
ManageCategoryDialog(category) {
presenter.updateLibrary()
presenter.getLibrary()
}.showDialog(router)
}
}
@ -1889,7 +1889,7 @@ open class LibraryController(
isGone = true
setOnClickListener {
presenter.forceShowAllCategories = !presenter.forceShowAllCategories
presenter.updateLibrary()
presenter.getLibrary()
isSelected = presenter.forceShowAllCategories
}
val pad = 12.dpToPx
@ -2168,7 +2168,7 @@ open class LibraryController(
private fun showChangeMangaCategoriesSheet() {
val activity = activity ?: return
selectedMangas.toList().moveCategories(presenter.db, activity) {
presenter.updateLibrary()
presenter.getLibrary()
destroyActionModeIfNeeded()
}
}

View file

@ -49,7 +49,6 @@ import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.system.withIOContext
import eu.kanade.tachiyomi.util.system.withUIContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
@ -79,7 +78,7 @@ class LibraryPresenter(
private val getLibraryManga: GetLibraryManga by injectLazy()
private val getChapters: GetChapters by injectLazy()
private var libraryManga: List<LibraryManga> = emptyList()
private val libraryManga: List<LibraryManga> = emptyList()
private val context = preferences.context
private val viewContext
@ -165,19 +164,7 @@ class LibraryPresenter(
lastLibraryItems = null
lastAllLibraryItems = null
}
presenterScope.launch {
getLibraryManga.subscribe().collectLatest { lib ->
libraryManga = lib.apply {
if (groupType > BY_DEFAULT) {
distinctBy { it.id }
}
}
updateLibrary()
}
}
getLibrary()
if (!preferences.showLibrarySearchSuggestions().isSet()) {
DelayedLibrarySuggestionsJob.setupTask(context, true)
} else if (preferences.showLibrarySearchSuggestions().get() &&
@ -200,8 +187,8 @@ class LibraryPresenter(
}
}
/** Update library state and sort and filter it */
fun updateLibrary() {
/** Get favorited manga for library and sort and filter it */
fun getLibrary() {
if (categories.isEmpty()) {
val dbCategories = db.getCategories().executeAsBlocking()
if ((dbCategories + Category.createDefault(context)).distinctBy { it.order }.size != dbCategories.size + 1) {
@ -721,7 +708,11 @@ class LibraryPresenter(
private suspend fun getLibraryFromDB(): Pair<List<LibraryItem>, List<LibraryItem>> {
removeArticles = preferences.removeArticles().get()
val categories = db.getCategories().executeAsBlocking().toMutableList()
var libraryManga = getLibraryManga.await()
val showAll = showAllCategories
if (groupType > BY_DEFAULT) {
libraryManga = libraryManga.distinctBy { it.id }
}
val hiddenItems = mutableListOf<LibraryItem>()
val items = if (groupType <= BY_DEFAULT || !libraryIsGrouped) {
@ -1085,7 +1076,7 @@ class LibraryPresenter(
mangaToDelete.forEach { it.favorite = false }
db.insertMangas(mangaToDelete).executeOnIO()
updateLibrary()
getLibrary()
}
}
@ -1111,7 +1102,7 @@ class LibraryPresenter(
/** Called when Library Service updates a manga, update the item as well */
fun updateManga() {
presenterScope.launch {
updateLibrary()
getLibrary()
}
}
@ -1122,7 +1113,7 @@ class LibraryPresenter(
mangaToAdd.forEach { it.favorite = true }
db.insertMangas(mangaToAdd).executeOnIO()
(view as? FilteredLibraryController)?.updateStatsPage()
updateLibrary()
getLibrary()
mangaToAdd.forEach { db.insertManga(it).executeAsBlocking() }
}
}
@ -1210,7 +1201,7 @@ class LibraryPresenter(
db.insertCategory(category).executeAsBlocking()
}
}
updateLibrary()
getLibrary()
}
}
@ -1244,7 +1235,7 @@ class LibraryPresenter(
}
preferences.collapsedDynamicCategories().set(categoriesHidden)
}
updateLibrary()
getLibrary()
}
private fun getDynamicCategoryName(category: Category): String =
@ -1275,7 +1266,7 @@ class LibraryPresenter(
}
}
}
updateLibrary()
getLibrary()
}
fun allCategoriesExpanded(): Boolean {
@ -1318,7 +1309,7 @@ class LibraryPresenter(
mapMangaChapters[manga] = oldChapters
}
updateLibrary()
getLibrary()
}
return mapMangaChapters
}
@ -1330,7 +1321,7 @@ class LibraryPresenter(
mangaList.forEach { (_, chapters) ->
db.updateChaptersProgress(chapters).executeAsBlocking()
}
updateLibrary()
getLibrary()
}
}

View file

@ -17,7 +17,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
override fun initGeneralPreferences() {
with(binding) {
showAll.bindToPreference(preferences.showAllCategories()) {
controller?.presenter?.updateLibrary()
controller?.presenter?.getLibrary()
binding.categoryShow.isEnabled = it
}
categoryShow.isEnabled = showAll.isChecked
@ -27,7 +27,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
dynamicToBottom.text = context.getString(R.string.move_dynamic_to_bottom)
.withSubtitle(context, R.string.when_grouping_by_sources_tags)
dynamicToBottom.bindToPreference(preferences.collapsedDynamicAtBottom()) {
controller?.presenter?.updateLibrary()
controller?.presenter?.getLibrary()
}
showEmptyCatsFiltering.bindToPreference(preferences.showEmptyCategoriesWhileFiltering()) {
controller?.presenter?.requestFilterUpdate()

View file

@ -25,12 +25,13 @@ import coil3.size.Precision
import coil3.size.Scale
import coil3.transform.RoundedCornersTransformation
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.ui.recents.RecentsPresenter
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.launchIO
import kotlinx.coroutines.MainScope
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import yokai.domain.manga.models.Manga
import yokai.presentation.widget.components.CoverHeight
import yokai.presentation.widget.components.CoverWidth
import yokai.presentation.widget.components.LockedWidget