Skip to content

Commit

Permalink
don't delete chapters when there is server error
Browse files Browse the repository at this point in the history
  • Loading branch information
nonproto committed Aug 28, 2020
1 parent 774d73a commit b930c85
Showing 1 changed file with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ class MangaDetailsPresenter(

var errorFromNetwork: java.lang.Exception? = null
var errorFromMerged: java.lang.Exception? = null
var error = false
val thumbnailUrl = manga.thumbnail_url

val nPair = async(Dispatchers.IO) {
Expand All @@ -414,6 +415,7 @@ class MangaDetailsPresenter(
Pair(result.first, list.toList())
} catch (e: Exception) {
XLog.e("error with mergedsource", e)
error = true
errorFromMerged = e
result
}
Expand All @@ -422,6 +424,7 @@ class MangaDetailsPresenter(
}
} catch (e: Exception) {
XLog.e("error with mangadex", e)
error = true
errorFromNetwork = e
Pair(null, emptyList<SChapter>())
}
Expand All @@ -445,35 +448,36 @@ class MangaDetailsPresenter(
}
fetchExternalLinks()
val finChapters = networkPair.second

val newChapters = syncChaptersWithSource(db, finChapters, manga)
if (newChapters.first.isNotEmpty()) {
val downloadNew = preferences.downloadNew().getOrDefault()
if (downloadNew && !controller.fromCatalogue && mangaWasInitalized) {
if (!hasMergeChapters && manga.merge_manga_url != null) {
hasMergeChapters = true
} else {
val categoriesToDownload = preferences.downloadNewCategories().getOrDefault().map(String::toInt)
val shouldDownload = categoriesToDownload.isEmpty() || getMangaCategoryIds().any { it in categoriesToDownload }
if (shouldDownload) {
downloadChapters(
newChapters.first.sortedBy { it.chapter_number }
.map { it.toModel() }
)
if (!error) {
val newChapters = syncChaptersWithSource(db, finChapters, manga)
if (newChapters.first.isNotEmpty()) {
val downloadNew = preferences.downloadNew().getOrDefault()
if (downloadNew && !controller.fromCatalogue && mangaWasInitalized) {
if (!hasMergeChapters && manga.merge_manga_url != null) {
hasMergeChapters = true
} else {
val categoriesToDownload = preferences.downloadNewCategories().getOrDefault().map(String::toInt)
val shouldDownload = categoriesToDownload.isEmpty() || getMangaCategoryIds().any { it in categoriesToDownload }
if (shouldDownload) {
downloadChapters(
newChapters.first.sortedBy { it.chapter_number }
.map { it.toModel() }
)
}
}
}
}
}
if (newChapters.second.isNotEmpty()) {
val removedChaptersId = newChapters.second.map { it.id }
val removedChapters = this@MangaDetailsPresenter.chapters.filter {
it.id in removedChaptersId && it.isDownloaded
}
if (removedChapters.isNotEmpty()) {
withContext(Dispatchers.Main) {
controller.showChaptersRemovedPopup(
removedChapters
)
if (newChapters.second.isNotEmpty()) {
val removedChaptersId = newChapters.second.map { it.id }
val removedChapters = this@MangaDetailsPresenter.chapters.filter {
it.id in removedChaptersId && it.isDownloaded
}
if (removedChapters.isNotEmpty()) {
withContext(Dispatchers.Main) {
controller.showChaptersRemovedPopup(
removedChapters
)
}
}
}
}
Expand Down

0 comments on commit b930c85

Please sign in to comment.