Fix loading local manga (closes #1481, #1474, #1479, #1484, #1439)

This commit is contained in:
Koitharu
2025-07-09 21:21:02 +03:00
parent 088576cc9d
commit d0084e50e7
3 changed files with 23 additions and 14 deletions

View File

@@ -1,6 +1,5 @@
package org.koitharu.kotatsu.core.network
import android.util.Log
import dagger.Lazy
import okhttp3.Headers
import okhttp3.Interceptor
@@ -36,7 +35,8 @@ class CommonHeadersInterceptor @Inject constructor(
mangaRepositoryFactoryLazy.get().create(source) as? ParserMangaRepository
} else {
if (BuildConfig.DEBUG && source == null) {
Log.w("Http", "Request without source tag: ${request.url}")
IllegalArgumentException("Request without source tag: ${request.url}")
.printStackTrace()
}
null
}

View File

@@ -185,7 +185,7 @@ class MangaDataRepository @Inject constructor(
emitInitialState = emitInitialState,
)
private suspend fun Manga.withCachedChaptersIfNeeded(flag: Boolean): Manga = if (flag && chapters.isNullOrEmpty()) {
private suspend fun Manga.withCachedChaptersIfNeeded(flag: Boolean): Manga = if (flag && !isLocal && chapters.isNullOrEmpty()) {
val cachedChapters = db.getChaptersDao().findAll(id)
if (cachedChapters.isEmpty()) {
this

View File

@@ -58,17 +58,26 @@ class DetailsLoadUseCase @Inject constructor(
isLoaded = false,
),
)
val local = if (!manga.isLocal) {
async {
localMangaRepository.findSavedManga(manga)
}
} else {
null
if (manga.isLocal) {
val details = getDetails(manga, force)
send(
MangaDetails(
manga = details,
localManga = null,
override = override,
description = details.description?.parseAsHtml(withImages = false)?.trim(),
isLoaded = true,
),
)
return@channelFlow
}
val local = async {
localMangaRepository.findSavedManga(manga)
}
if (!force && networkState.isOfflineOrRestricted()) {
// try to avoid loading if has saved manga
val localManga = local?.await()
if (manga.isLocal || localManga != null) {
val localManga = local.await()
if (localManga != null) {
send(
MangaDetails(
manga = manga,
@@ -88,7 +97,7 @@ class DetailsLoadUseCase @Inject constructor(
send(
MangaDetails(
manga = details,
localManga = local?.peek(),
localManga = local.peek(),
override = override,
description = details.description?.parseAsHtml(withImages = false)?.trim(),
isLoaded = false,
@@ -97,14 +106,14 @@ class DetailsLoadUseCase @Inject constructor(
send(
MangaDetails(
manga = details,
localManga = local?.await(),
localManga = local.await(),
override = override,
description = details.description?.parseAsHtml(withImages = true)?.trim(),
isLoaded = true,
),
)
} catch (e: IOException) {
local?.await()?.manga?.also { localManga ->
local.await()?.manga?.also { localManga ->
send(
MangaDetails(
manga = localManga,