@@ -1,6 +1,5 @@
|
|||||||
package org.koitharu.kotatsu.core.network
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import dagger.Lazy
|
import dagger.Lazy
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
@@ -36,7 +35,8 @@ class CommonHeadersInterceptor @Inject constructor(
|
|||||||
mangaRepositoryFactoryLazy.get().create(source) as? ParserMangaRepository
|
mangaRepositoryFactoryLazy.get().create(source) as? ParserMangaRepository
|
||||||
} else {
|
} else {
|
||||||
if (BuildConfig.DEBUG && source == null) {
|
if (BuildConfig.DEBUG && source == null) {
|
||||||
Log.w("Http", "Request without source tag: ${request.url}")
|
IllegalArgumentException("Request without source tag: ${request.url}")
|
||||||
|
.printStackTrace()
|
||||||
}
|
}
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ class MangaDataRepository @Inject constructor(
|
|||||||
emitInitialState = emitInitialState,
|
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)
|
val cachedChapters = db.getChaptersDao().findAll(id)
|
||||||
if (cachedChapters.isEmpty()) {
|
if (cachedChapters.isEmpty()) {
|
||||||
this
|
this
|
||||||
|
|||||||
@@ -58,17 +58,26 @@ class DetailsLoadUseCase @Inject constructor(
|
|||||||
isLoaded = false,
|
isLoaded = false,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
val local = if (!manga.isLocal) {
|
if (manga.isLocal) {
|
||||||
async {
|
val details = getDetails(manga, force)
|
||||||
localMangaRepository.findSavedManga(manga)
|
send(
|
||||||
}
|
MangaDetails(
|
||||||
} else {
|
manga = details,
|
||||||
null
|
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()) {
|
if (!force && networkState.isOfflineOrRestricted()) {
|
||||||
// try to avoid loading if has saved manga
|
// try to avoid loading if has saved manga
|
||||||
val localManga = local?.await()
|
val localManga = local.await()
|
||||||
if (manga.isLocal || localManga != null) {
|
if (localManga != null) {
|
||||||
send(
|
send(
|
||||||
MangaDetails(
|
MangaDetails(
|
||||||
manga = manga,
|
manga = manga,
|
||||||
@@ -88,7 +97,7 @@ class DetailsLoadUseCase @Inject constructor(
|
|||||||
send(
|
send(
|
||||||
MangaDetails(
|
MangaDetails(
|
||||||
manga = details,
|
manga = details,
|
||||||
localManga = local?.peek(),
|
localManga = local.peek(),
|
||||||
override = override,
|
override = override,
|
||||||
description = details.description?.parseAsHtml(withImages = false)?.trim(),
|
description = details.description?.parseAsHtml(withImages = false)?.trim(),
|
||||||
isLoaded = false,
|
isLoaded = false,
|
||||||
@@ -97,14 +106,14 @@ class DetailsLoadUseCase @Inject constructor(
|
|||||||
send(
|
send(
|
||||||
MangaDetails(
|
MangaDetails(
|
||||||
manga = details,
|
manga = details,
|
||||||
localManga = local?.await(),
|
localManga = local.await(),
|
||||||
override = override,
|
override = override,
|
||||||
description = details.description?.parseAsHtml(withImages = true)?.trim(),
|
description = details.description?.parseAsHtml(withImages = true)?.trim(),
|
||||||
isLoaded = true,
|
isLoaded = true,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
local?.await()?.manga?.also { localManga ->
|
local.await()?.manga?.also { localManga ->
|
||||||
send(
|
send(
|
||||||
MangaDetails(
|
MangaDetails(
|
||||||
manga = localManga,
|
manga = localManga,
|
||||||
|
|||||||
Reference in New Issue
Block a user