From d0bff298b7df3524f76434a3636bc196627cb613 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 22 Oct 2022 12:24:59 -0400 Subject: [PATCH] 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. --- .../tachiyomi/ui/manga/MangaPresenter.kt | 27 +++++-------------- .../ui/recent/updates/UpdatesPresenter.kt | 19 +------------ 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 8fca6c1dad..3b090dd7bd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -666,28 +666,13 @@ class MangaPresenter( */ fun deleteChapters(chapters: List) { presenterScope.launchNonCancellable { - val chapters2 = chapters.map { it.toDbChapter() } try { - updateSuccessState { successState -> - val deletedIds = downloadManager - .deleteChapters(chapters2, successState.manga, successState.source) - .map { it.id } - val deletedChapters = successState.chapters.filter { deletedIds.contains(it.chapter.id) } - 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) + successState?.let { state -> + downloadManager.deleteChapters( + chapters.map { it.toDbChapter() }, + state.manga, + state.source, + ) } } catch (e: Throwable) { logcat(LogPriority.ERROR, e) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt index ecbf448f6b..4f58cd3c81 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt @@ -255,30 +255,13 @@ class UpdatesPresenter( fun deleteChapters(updatesItem: List) { presenterScope.launchNonCancellable { val groupedUpdates = updatesItem.groupBy { it.update.mangaId }.values - val deletedIds = groupedUpdates.flatMap { updates -> + groupedUpdates.flatMap { updates -> val mangaId = updates.first().update.mangaId val manga = getManga.await(mangaId) ?: return@flatMap emptyList() val source = sourceManager.get(manga.source) ?: return@flatMap emptyList() val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId)?.toDbChapter() } 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) - } - } } }