Fix restoring bookmarks

This commit is contained in:
Koitharu
2024-05-04 17:20:42 +03:00
parent 17828ae755
commit 5ef1b4ac9c
2 changed files with 15 additions and 2 deletions

View File

@@ -54,7 +54,7 @@ class DetailsLoadUseCase @Inject constructor(
send(MangaDetails(manga, null, null, false))
try {
val details = getDetails(manga)
launch { updateTracker(manga) }
launch { updateTracker(details) }
send(MangaDetails(details, local?.peek(), details.description?.parseAsHtml(withImages = false), false))
send(MangaDetails(details, local?.await(), details.description?.parseAsHtml(withImages = true), true))
} catch (e: IOException) {

View File

@@ -5,6 +5,7 @@ import coil.intercept.Interceptor
import coil.network.HttpException
import coil.request.ErrorResult
import coil.request.ImageResult
import okio.FileNotFoundException
import org.jsoup.HttpStatusException
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
@@ -13,11 +14,14 @@ import org.koitharu.kotatsu.core.parser.MangaDataRepository
import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
import org.koitharu.kotatsu.parsers.exception.ParseException
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
import java.net.UnknownHostException
import java.util.Collections
import javax.inject.Inject
import javax.net.ssl.SSLException
class CoverRestoreInterceptor @Inject constructor(
private val dataRepository: MangaDataRepository,
@@ -56,6 +60,8 @@ class CoverRestoreInterceptor @Inject constructor(
}
val restored = runCatchingCancellable {
restoreMangaImpl(manga)
}.onFailure { e ->
e.printStackTraceDebug()
}.getOrDefault(false)
if (restored) {
blacklist.remove(key)
@@ -84,6 +90,8 @@ class CoverRestoreInterceptor @Inject constructor(
}
val restored = runCatchingCancellable {
restoreBookmarkImpl(bookmark)
}.onFailure { e ->
e.printStackTraceDebug()
}.getOrDefault(false)
if (restored) {
blacklist.remove(key)
@@ -105,6 +113,11 @@ class CoverRestoreInterceptor @Inject constructor(
}
private fun Throwable.shouldRestore(): Boolean {
return this is HttpException || this is HttpStatusException || this is ParseException
return this is HttpException
|| this is HttpStatusException
|| this is SSLException
|| this is ParseException
|| this is UnknownHostException
|| this is FileNotFoundException
}
}