mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 17:31:52 +01:00
Fix loading fallback thumbnails in browse view (closes #4127)
This commit is contained in:
parent
00fe4cdf2d
commit
c5ca739b49
@ -64,8 +64,10 @@ interface Source : tachiyomi.source.Source {
|
|||||||
*/
|
*/
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
|
override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
|
||||||
return fetchMangaDetails(manga.toSManga()).awaitSingle()
|
val sManga = manga.toSManga()
|
||||||
.toMangaInfo()
|
val networkManga = fetchMangaDetails(sManga).awaitSingle()
|
||||||
|
sManga.copyFrom(networkManga)
|
||||||
|
return sManga.toMangaInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -459,7 +459,6 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||||||
val adapter = adapter ?: return
|
val adapter = adapter ?: return
|
||||||
|
|
||||||
preferences.sourceDisplayMode().set(mode)
|
preferences.sourceDisplayMode().set(mode)
|
||||||
presenter.refreshDisplayMode()
|
|
||||||
activity?.invalidateOptionsMenu()
|
activity?.invalidateOptionsMenu()
|
||||||
setupRecycler(view)
|
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.launchIO
|
||||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
import eu.kanade.tachiyomi.util.removeCovers
|
import eu.kanade.tachiyomi.util.removeCovers
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
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.flow.onEach
|
||||||
import kotlinx.coroutines.isActive
|
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
@ -105,11 +108,6 @@ open class BrowseSourcePresenter(
|
|||||||
*/
|
*/
|
||||||
private var pageSubscription: Subscription? = null
|
private var pageSubscription: Subscription? = null
|
||||||
|
|
||||||
/**
|
|
||||||
* Job to initialize manga details.
|
|
||||||
*/
|
|
||||||
private var initializerJob: Job? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedState: Bundle?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
|
|
||||||
@ -139,8 +137,6 @@ open class BrowseSourcePresenter(
|
|||||||
this.query = query
|
this.query = query
|
||||||
this.appliedFilters = filters
|
this.appliedFilters = filters
|
||||||
|
|
||||||
initializeManga()
|
|
||||||
|
|
||||||
// Create a new pager.
|
// Create a new pager.
|
||||||
pager = createPager(query, filters)
|
pager = createPager(query, filters)
|
||||||
|
|
||||||
@ -192,27 +188,6 @@ open class BrowseSourcePresenter(
|
|||||||
return pager.hasNextPage
|
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
|
* 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.
|
* if the manga is not yet in the database.
|
||||||
@ -238,7 +213,19 @@ open class BrowseSourcePresenter(
|
|||||||
* @param mangas the list of manga to initialize.
|
* @param mangas the list of manga to initialize.
|
||||||
*/
|
*/
|
||||||
fun initializeMangas(mangas: List<Manga>) {
|
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
|
* @return the initialized manga
|
||||||
*/
|
*/
|
||||||
private suspend fun getMangaDetails(manga: Manga): Manga {
|
private suspend fun getMangaDetails(manga: Manga): Manga {
|
||||||
return try {
|
try {
|
||||||
source.getMangaDetails(manga.toMangaInfo())
|
val networkManga = source.getMangaDetails(manga.toMangaInfo())
|
||||||
.let { networkManga ->
|
manga.copyFrom(networkManga.toSManga())
|
||||||
manga.copyFrom(networkManga.toSManga())
|
manga.initialized = true
|
||||||
manga.initialized = true
|
db.insertManga(manga).executeAsBlocking()
|
||||||
db.insertManga(manga).executeAsBlocking()
|
|
||||||
manga
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
manga
|
Timber.e(e)
|
||||||
}
|
}
|
||||||
|
return manga
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -282,13 +267,6 @@ open class BrowseSourcePresenter(
|
|||||||
db.insertManga(manga).executeAsBlocking()
|
db.insertManga(manga).executeAsBlocking()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Refreshes the active display mode.
|
|
||||||
*/
|
|
||||||
fun refreshDisplayMode() {
|
|
||||||
initializeManga()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the filter states for the current source.
|
* Set the filter states for the current source.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user