mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-29 11:08:53 +03:00
Fix loading fallback thumbnails in browse view (closes #4127)
This commit is contained in:
parent
00fe4cdf2d
commit
c5ca739b49
3 changed files with 29 additions and 50 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -459,7 +459,6 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||
val adapter = adapter ?: return
|
||||
|
||||
preferences.sourceDisplayMode().set(mode)
|
||||
presenter.refreshDisplayMode()
|
||||
activity?.invalidateOptionsMenu()
|
||||
setupRecycler(view)
|
||||
|
||||
|
|
|
@ -33,10 +33,13 @@ import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper
|
|||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.removeCovers
|
||||
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 rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
|
@ -105,11 +108,6 @@ open class BrowseSourcePresenter(
|
|||
*/
|
||||
private var pageSubscription: Subscription? = null
|
||||
|
||||
/**
|
||||
* Job to initialize manga details.
|
||||
*/
|
||||
private var initializerJob: Job? = null
|
||||
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
|
||||
|
@ -139,8 +137,6 @@ open class BrowseSourcePresenter(
|
|||
this.query = query
|
||||
this.appliedFilters = filters
|
||||
|
||||
initializeManga()
|
||||
|
||||
// Create a new pager.
|
||||
pager = createPager(query, filters)
|
||||
|
||||
|
@ -192,27 +188,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.
|
||||
|
@ -238,7 +213,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()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,17 +235,15 @@ open class BrowseSourcePresenter(
|
|||
* @return the initialized manga
|
||||
*/
|
||||
private suspend fun getMangaDetails(manga: Manga): Manga {
|
||||
return try {
|
||||
source.getMangaDetails(manga.toMangaInfo())
|
||||
.let { networkManga ->
|
||||
manga.copyFrom(networkManga.toSManga())
|
||||
manga.initialized = true
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
manga
|
||||
}
|
||||
try {
|
||||
val networkManga = source.getMangaDetails(manga.toMangaInfo())
|
||||
manga.copyFrom(networkManga.toSManga())
|
||||
manga.initialized = true
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
} catch (e: Exception) {
|
||||
manga
|
||||
Timber.e(e)
|
||||
}
|
||||
return manga
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,13 +267,6 @@ open class BrowseSourcePresenter(
|
|||
db.insertManga(manga).executeAsBlocking()
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the active display mode.
|
||||
*/
|
||||
fun refreshDisplayMode() {
|
||||
initializeManga()
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filter states for the current source.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue