Fix page previews only showing previews when the manga first loaded
This commit is contained in:
parent
d3f4f63f52
commit
f06c8ef2cb
@ -98,7 +98,7 @@ class SYDomainModule : InjektModule {
|
|||||||
addFactory { CreateSortTag(get(), get()) }
|
addFactory { CreateSortTag(get(), get()) }
|
||||||
addFactory { DeleteSortTag(get(), get()) }
|
addFactory { DeleteSortTag(get(), get()) }
|
||||||
addFactory { ReorderSortTag(get(), get()) }
|
addFactory { ReorderSortTag(get(), get()) }
|
||||||
addFactory { GetPagePreviews(get()) }
|
addFactory { GetPagePreviews(get(), get()) }
|
||||||
|
|
||||||
// Required for [MetadataSource]
|
// Required for [MetadataSource]
|
||||||
addFactory<MetadataSource.GetMangaId> { GetManga(get()) }
|
addFactory<MetadataSource.GetMangaId> { GetManga(get()) }
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package eu.kanade.domain.manga.interactor
|
package eu.kanade.domain.manga.interactor
|
||||||
|
|
||||||
|
import eu.kanade.domain.history.interactor.GetNextChapters
|
||||||
import eu.kanade.domain.manga.model.Manga
|
import eu.kanade.domain.manga.model.Manga
|
||||||
import eu.kanade.domain.manga.model.PagePreview
|
import eu.kanade.domain.manga.model.PagePreview
|
||||||
import eu.kanade.tachiyomi.data.cache.PagePreviewCache
|
import eu.kanade.tachiyomi.data.cache.PagePreviewCache
|
||||||
@ -9,17 +10,20 @@ import exh.source.getMainSource
|
|||||||
|
|
||||||
class GetPagePreviews(
|
class GetPagePreviews(
|
||||||
private val pagePreviewCache: PagePreviewCache,
|
private val pagePreviewCache: PagePreviewCache,
|
||||||
|
private val getChapters: GetNextChapters,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun await(manga: Manga, source: Source, page: Int): Result {
|
suspend fun await(manga: Manga, source: Source, page: Int): Result {
|
||||||
@Suppress("NAME_SHADOWING")
|
@Suppress("NAME_SHADOWING")
|
||||||
val source = source.getMainSource<PagePreviewSource>() ?: return Result.Unused
|
val source = source.getMainSource<PagePreviewSource>() ?: return Result.Unused
|
||||||
|
val chapters = getChapters.await(manga.id, false)
|
||||||
|
val chapterIds = chapters.map { it.id }
|
||||||
return try {
|
return try {
|
||||||
val pagePreviews = try {
|
val pagePreviews = try {
|
||||||
pagePreviewCache.getPageListFromCache(manga, page)
|
pagePreviewCache.getPageListFromCache(manga, chapterIds, page)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
source.getPagePreviewList(manga.toSManga(), page).also {
|
source.getPagePreviewList(manga.toSManga(), chapters.map { it.toSChapter() }, page).also {
|
||||||
pagePreviewCache.putPageListToCache(manga, it)
|
pagePreviewCache.putPageListToCache(manga, chapterIds, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Result.Success(
|
Result.Success(
|
||||||
|
@ -81,9 +81,9 @@ class PagePreviewCache(private val context: Context) {
|
|||||||
* @param manga the manga.
|
* @param manga the manga.
|
||||||
* @return the list of pages.
|
* @return the list of pages.
|
||||||
*/
|
*/
|
||||||
fun getPageListFromCache(manga: Manga, page: Int): PagePreviewPage {
|
fun getPageListFromCache(manga: Manga, chapterIds: List<Long>, page: Int): PagePreviewPage {
|
||||||
// Get the key for the manga.
|
// Get the key for the manga.
|
||||||
val key = DiskUtil.hashKeyForDisk(getKey(manga, page))
|
val key = DiskUtil.hashKeyForDisk(getKey(manga, chapterIds, page))
|
||||||
|
|
||||||
// Convert JSON string to list of objects. Throws an exception if snapshot is null
|
// Convert JSON string to list of objects. Throws an exception if snapshot is null
|
||||||
return diskCache.get(key).use {
|
return diskCache.get(key).use {
|
||||||
@ -97,7 +97,7 @@ class PagePreviewCache(private val context: Context) {
|
|||||||
* @param manga the manga.
|
* @param manga the manga.
|
||||||
* @param pages list of pages.
|
* @param pages list of pages.
|
||||||
*/
|
*/
|
||||||
fun putPageListToCache(manga: Manga, pages: PagePreviewPage) {
|
fun putPageListToCache(manga: Manga, chapterIds: List<Long>, pages: PagePreviewPage) {
|
||||||
// Convert list of pages to json string.
|
// Convert list of pages to json string.
|
||||||
val cachedValue = json.encodeToString(pages)
|
val cachedValue = json.encodeToString(pages)
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class PagePreviewCache(private val context: Context) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Get editor from md5 key.
|
// Get editor from md5 key.
|
||||||
val key = DiskUtil.hashKeyForDisk(getKey(manga, pages.page))
|
val key = DiskUtil.hashKeyForDisk(getKey(manga, chapterIds, pages.page))
|
||||||
editor = diskCache.edit(key) ?: return
|
editor = diskCache.edit(key) ?: return
|
||||||
|
|
||||||
// Write page preview urls to cache.
|
// Write page preview urls to cache.
|
||||||
@ -211,7 +211,7 @@ class PagePreviewCache(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getKey(manga: Manga, page: Int): String {
|
private fun getKey(manga: Manga, chapterIds: List<Long>, page: Int): String {
|
||||||
return "${manga.id}_$page"
|
return "${manga.id}_${chapterIds.joinToString(separator = "-")}_$page"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1144,11 +1144,12 @@ class EHentai(
|
|||||||
|
|
||||||
override suspend fun getPagePreviewList(
|
override suspend fun getPagePreviewList(
|
||||||
manga: SManga,
|
manga: SManga,
|
||||||
|
chapters: List<SChapter>,
|
||||||
page: Int,
|
page: Int,
|
||||||
): PagePreviewPage {
|
): PagePreviewPage {
|
||||||
val doc = client.newCall(
|
val doc = client.newCall(
|
||||||
exGet(
|
exGet(
|
||||||
(baseUrl + manga.url)
|
(baseUrl + (chapters.lastOrNull()?.url ?: manga.url))
|
||||||
.toHttpUrl()
|
.toHttpUrl()
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
.removeAllQueryParameters("nw")
|
.removeAllQueryParameters("nw")
|
||||||
|
@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.source.PagePreviewInfo
|
|||||||
import eu.kanade.tachiyomi.source.PagePreviewPage
|
import eu.kanade.tachiyomi.source.PagePreviewPage
|
||||||
import eu.kanade.tachiyomi.source.PagePreviewSource
|
import eu.kanade.tachiyomi.source.PagePreviewSource
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.source.online.MetadataSource
|
import eu.kanade.tachiyomi.source.online.MetadataSource
|
||||||
@ -172,7 +173,7 @@ class NHentai(delegate: HttpSource, val context: Context) :
|
|||||||
return "$baseUrl/g/${uri.pathSegments[1]}/"
|
return "$baseUrl/g/${uri.pathSegments[1]}/"
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getPagePreviewList(manga: SManga, page: Int): PagePreviewPage {
|
override suspend fun getPagePreviewList(manga: SManga, chapters: List<SChapter>, page: Int): PagePreviewPage {
|
||||||
val metadata = fetchOrLoadMetadata(manga.id()) {
|
val metadata = fetchOrLoadMetadata(manga.id()) {
|
||||||
client.newCall(mangaDetailsRequest(manga)).await()
|
client.newCall(mangaDetailsRequest(manga)).await()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.source
|
package eu.kanade.tachiyomi.source
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.network.ProgressListener
|
import eu.kanade.tachiyomi.network.ProgressListener
|
||||||
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
@ -11,7 +12,7 @@ import okhttp3.Response
|
|||||||
|
|
||||||
interface PagePreviewSource : Source {
|
interface PagePreviewSource : Source {
|
||||||
|
|
||||||
suspend fun getPagePreviewList(manga: SManga, page: Int): PagePreviewPage
|
suspend fun getPagePreviewList(manga: SManga, chapters: List<SChapter>, page: Int): PagePreviewPage
|
||||||
|
|
||||||
suspend fun fetchPreviewImage(page: PagePreviewInfo, cacheControl: CacheControl? = null): Response
|
suspend fun fetchPreviewImage(page: PagePreviewInfo, cacheControl: CacheControl? = null): Response
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user