Fix loading fallback thumbnails in browse view (closes #4127)

(cherry picked from commit c5ca739b4926362967d02323ceda56072d992134)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt
This commit is contained in:
arkon 2020-12-13 20:47:48 -05:00 committed by Jobobby04
parent 962344f5fc
commit 1d55a1bec4
3 changed files with 29 additions and 50 deletions

View File

@ -64,8 +64,10 @@ interface Source : tachiyomi.source.Source {
*/
@Suppress("DEPRECATION")
override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
return fetchMangaDetails(manga.toSManga()).awaitSingle()
.toMangaInfo()
val sManga = manga.toSManga()
val networkManga = fetchMangaDetails(sManga).awaitSingle()
sManga.copyFrom(networkManga)
return sManga.toMangaInfo()
}
/**

View File

@ -635,7 +635,6 @@ open class BrowseSourceController(bundle: Bundle) :
val adapter = adapter ?: return
preferences.sourceDisplayMode().set(mode)
presenter.refreshDisplayMode()
activity?.invalidateOptionsMenu()
setupRecycler(view)

View File

@ -37,10 +37,13 @@ import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.removeCovers
import exh.savedsearches.EXHSavedSearch
import exh.savedsearches.JsonSavedSearch
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.isActive
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
@ -126,11 +129,6 @@ open class BrowseSourcePresenter(
private val filterSerializer = FilterSerializer()
// SY <--
/**
* Job to initialize manga details.
*/
private var initializerJob: Job? = null
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
@ -168,8 +166,6 @@ open class BrowseSourcePresenter(
this.query = query
this.appliedFilters = filters
initializeManga()
// Create a new pager.
pager = createPager(query, filters)
@ -225,27 +221,6 @@ open class BrowseSourcePresenter(
return pager.hasNextPage
}
/**
* Subscribes to the initializer of manga details and updates the view if needed.
*/
private fun initializeManga() {
initializerJob?.cancel()
initializerJob = launchIO {
mangaDetailsFlow
.onEach { mangas ->
if (!isActive) return@onEach
try {
mangas.filter { it.thumbnail_url == null && !it.initialized }
.map { getMangaDetails(it) }
.forEach { launchUI { view?.onMangaInitialized(it) } }
} catch (error: Exception) {
launchUI { Timber.e(error) }
}
}
}
}
/**
* Returns a manga from the database for the given manga from network. It creates a new entry
* if the manga is not yet in the database.
@ -271,7 +246,19 @@ open class BrowseSourcePresenter(
* @param mangas the list of manga to initialize.
*/
fun initializeMangas(mangas: List<Manga>) {
launchIO { mangaDetailsFlow.emit(mangas) }
launchIO {
mangas.asFlow()
.filter { it.thumbnail_url == null && !it.initialized }
.map { getMangaDetails(it) }
.onEach {
launchUI {
@Suppress("DEPRECATION")
view?.onMangaInitialized(it)
}
}
.catch { e -> Timber.e(e) }
.collect()
}
}
/**
@ -281,17 +268,15 @@ open class BrowseSourcePresenter(
* @return the initialized manga
*/
private suspend fun getMangaDetails(manga: Manga): Manga {
return try {
source.getMangaDetails(manga.toMangaInfo())
.let { networkManga ->
try {
val networkManga = source.getMangaDetails(manga.toMangaInfo())
manga.copyFrom(networkManga.toSManga())
manga.initialized = true
db.insertManga(manga).executeAsBlocking()
manga
}
} catch (e: Exception) {
manga
Timber.e(e)
}
return manga
}
/**
@ -315,13 +300,6 @@ open class BrowseSourcePresenter(
db.insertManga(manga).executeAsBlocking()
}
/**
* Refreshes the active display mode.
*/
fun refreshDisplayMode() {
initializeManga()
}
/**
* Set the filter states for the current source.
*