Remove fake chapter deletion state updates

Now that the updates and manga screen listen to download cache changes, it'll reflect the real states once deleted.
pull/8273/head
arkon 2 years ago
parent 152eb5b951
commit d0bff298b7

@ -666,28 +666,13 @@ class MangaPresenter(
*/ */
fun deleteChapters(chapters: List<DomainChapter>) { fun deleteChapters(chapters: List<DomainChapter>) {
presenterScope.launchNonCancellable { presenterScope.launchNonCancellable {
val chapters2 = chapters.map { it.toDbChapter() }
try { try {
updateSuccessState { successState -> successState?.let { state ->
val deletedIds = downloadManager downloadManager.deleteChapters(
.deleteChapters(chapters2, successState.manga, successState.source) chapters.map { it.toDbChapter() },
.map { it.id } state.manga,
val deletedChapters = successState.chapters.filter { deletedIds.contains(it.chapter.id) } state.source,
if (deletedChapters.isEmpty()) return@updateSuccessState successState )
// TODO: Don't do this fake status update
val newChapters = successState.chapters.toMutableList().apply {
deletedChapters.forEach {
val index = indexOf(it)
val toAdd = removeAt(index)
.copy(
downloadState = Download.State.NOT_DOWNLOADED,
downloadProgress = 0,
)
add(index, toAdd)
}
}
successState.copy(chapters = newChapters)
} }
} catch (e: Throwable) { } catch (e: Throwable) {
logcat(LogPriority.ERROR, e) logcat(LogPriority.ERROR, e)

@ -255,30 +255,13 @@ class UpdatesPresenter(
fun deleteChapters(updatesItem: List<UpdatesItem>) { fun deleteChapters(updatesItem: List<UpdatesItem>) {
presenterScope.launchNonCancellable { presenterScope.launchNonCancellable {
val groupedUpdates = updatesItem.groupBy { it.update.mangaId }.values val groupedUpdates = updatesItem.groupBy { it.update.mangaId }.values
val deletedIds = groupedUpdates.flatMap { updates -> groupedUpdates.flatMap { updates ->
val mangaId = updates.first().update.mangaId val mangaId = updates.first().update.mangaId
val manga = getManga.await(mangaId) ?: return@flatMap emptyList() val manga = getManga.await(mangaId) ?: return@flatMap emptyList()
val source = sourceManager.get(manga.source) ?: return@flatMap emptyList() val source = sourceManager.get(manga.source) ?: return@flatMap emptyList()
val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId)?.toDbChapter() } val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId)?.toDbChapter() }
downloadManager.deleteChapters(chapters, manga, source).mapNotNull { it.id } downloadManager.deleteChapters(chapters, manga, source).mapNotNull { it.id }
} }
val deletedUpdates = items.filter {
deletedIds.contains(it.update.chapterId)
}
if (deletedUpdates.isEmpty()) return@launchNonCancellable
// TODO: Don't do this fake status update
state.items = state.items.toMutableList().apply {
deletedUpdates.forEach { deletedUpdate ->
val modifiedIndex = indexOf(deletedUpdate)
val item = removeAt(modifiedIndex).copy(
downloadStateProvider = { Download.State.NOT_DOWNLOADED },
downloadProgressProvider = { 0 },
)
add(modifiedIndex, item)
}
}
} }
} }

Loading…
Cancel
Save