From 6dfcb4b8abdb8d4ee4c89b67e99b76b3b3d93bdd Mon Sep 17 00:00:00 2001 From: Robb <35880555+robbwatershed@users.noreply.github.com> Date: Thu, 17 Aug 2023 18:45:54 +0200 Subject: [PATCH] More explicit delete / purge notification texts --- .../delete/DeleteCompleteNotification.kt | 21 +++++++++++++++---- .../devsaki/hentoid/util/ContentHelper.java | 7 ++++++- .../hentoid/viewmodels/LibraryViewModel.java | 4 ++-- .../hentoid/viewmodels/QueueViewModel.kt | 1 + .../hentoid/viewmodels/ReaderViewModel.kt | 2 +- .../hentoid/workers/BaseDeleteWorker.java | 4 +++- .../hentoid/workers/data/DeleteData.java | 9 ++++++++ app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-hu/strings.xml | 1 - app/src/main/res/values-it/strings.xml | 1 - app/src/main/res/values-ja/strings.xml | 1 - app/src/main/res/values-ko/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 1 - app/src/main/res/values-uk/strings.xml | 1 - app/src/main/res/values/strings.xml | 11 +++++++--- 15 files changed, 47 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/me/devsaki/hentoid/notification/delete/DeleteCompleteNotification.kt b/app/src/main/java/me/devsaki/hentoid/notification/delete/DeleteCompleteNotification.kt index 44f6475109..fa7edd990c 100644 --- a/app/src/main/java/me/devsaki/hentoid/notification/delete/DeleteCompleteNotification.kt +++ b/app/src/main/java/me/devsaki/hentoid/notification/delete/DeleteCompleteNotification.kt @@ -5,12 +5,25 @@ import androidx.core.app.NotificationCompat import me.devsaki.hentoid.R import me.devsaki.hentoid.util.notification.Notification -class DeleteCompleteNotification(private val books: Int, private val isError: Boolean) : +class DeleteCompleteNotification( + private val books: Int, + private val nbError: Int, + private val isDownloadPrepurge: Boolean +) : Notification { - override fun onCreateNotification(context: Context): android.app.Notification { - val title = if (isError) R.string.notif_delete_fail else R.string.notif_delete_complete - val content = if (isError) context.getString(R.string.notif_delete_fail_details) + val title = if (nbError > 0) { + if (isDownloadPrepurge) R.string.notif_delete_prepurge_fail + else R.string.notif_delete_fail + } else { + if (isDownloadPrepurge) R.string.notif_delete_prepurge_complete + else R.string.notif_delete_complete + } + val content = if (nbError > 0) context.resources.getQuantityString( + R.plurals.notif_delete_fail_details, + nbError, + nbError + ) else context.resources.getQuantityString( R.plurals.notif_delete_complete_details, books, diff --git a/app/src/main/java/me/devsaki/hentoid/util/ContentHelper.java b/app/src/main/java/me/devsaki/hentoid/util/ContentHelper.java index e564868f08..8426fcf808 100644 --- a/app/src/main/java/me/devsaki/hentoid/util/ContentHelper.java +++ b/app/src/main/java/me/devsaki/hentoid/util/ContentHelper.java @@ -1852,10 +1852,15 @@ public static StorageLocation getLocation(Content content) { return StorageLocation.NONE; } - public static void purgeContent(@NonNull final Context context, @NonNull final Content content, boolean keepCover) { + public static void purgeContent( + @NonNull final Context context, + @NonNull final Content content, + boolean keepCover, + boolean isDownloadPrepurge) { DeleteData.Builder builder = new DeleteData.Builder(); builder.setContentPurgeIds(Stream.of(content).map(Content::getId).toList()); builder.setContentPurgeKeepCovers(keepCover); + builder.setDownloadPrepurge(isDownloadPrepurge); WorkManager workManager = WorkManager.getInstance(context); workManager.enqueueUniqueWork( diff --git a/app/src/main/java/me/devsaki/hentoid/viewmodels/LibraryViewModel.java b/app/src/main/java/me/devsaki/hentoid/viewmodels/LibraryViewModel.java index da47559fac..38f76ec59e 100644 --- a/app/src/main/java/me/devsaki/hentoid/viewmodels/LibraryViewModel.java +++ b/app/src/main/java/me/devsaki/hentoid/viewmodels/LibraryViewModel.java @@ -650,7 +650,7 @@ public void redownloadContent( Content content = c.get(); // Non-blocking performance bottleneck; run in a dedicated worker if (reparseImages) - ContentHelper.purgeContent(getApplication(), content, false); + ContentHelper.purgeContent(getApplication(), content, false, true); dao.addContentToQueue( content, targetImageStatus, position, -1, null, ContentQueueManager.INSTANCE.isQueueActive(getApplication())); @@ -777,7 +777,7 @@ public void streamContent(@NonNull final List contentList, Content dbContent = dao.selectContent(c.get().getId()); if (null == dbContent) return; // Non-blocking performance bottleneck; scheduled in a dedicated worker - ContentHelper.purgeContent(getApplication(), c.get(), true); + ContentHelper.purgeContent(getApplication(), c.get(), true, true); dbContent.setDownloadMode(Content.DownloadMode.STREAM); List imgs = dbContent.getImageFiles(); if (imgs != null) { diff --git a/app/src/main/java/me/devsaki/hentoid/viewmodels/QueueViewModel.kt b/app/src/main/java/me/devsaki/hentoid/viewmodels/QueueViewModel.kt index 518eb44870..0503ae74d5 100644 --- a/app/src/main/java/me/devsaki/hentoid/viewmodels/QueueViewModel.kt +++ b/app/src/main/java/me/devsaki/hentoid/viewmodels/QueueViewModel.kt @@ -244,6 +244,7 @@ class QueueViewModel( private fun purgeItem(content: Content) { val builder = DeleteData.Builder() builder.setContentPurgeIds(listOf(content.id)) + builder.setDownloadPrepurge(true) val workManager = WorkManager.getInstance(getApplication()) workManager.enqueueUniqueWork( R.id.delete_service_purge.toString(), diff --git a/app/src/main/java/me/devsaki/hentoid/viewmodels/ReaderViewModel.kt b/app/src/main/java/me/devsaki/hentoid/viewmodels/ReaderViewModel.kt index bdf385fbbc..b8ce9f81f5 100644 --- a/app/src/main/java/me/devsaki/hentoid/viewmodels/ReaderViewModel.kt +++ b/app/src/main/java/me/devsaki/hentoid/viewmodels/ReaderViewModel.kt @@ -1515,7 +1515,7 @@ class ReaderViewModel( withContext(Dispatchers.IO) { contentList.forEach { // Non-blocking performance bottleneck; run in a dedicated worker - ContentHelper.purgeContent(getApplication(), it, false) + ContentHelper.purgeContent(getApplication(), it, false, true) dao.addContentToQueue( it, targetImageStatus, diff --git a/app/src/main/java/me/devsaki/hentoid/workers/BaseDeleteWorker.java b/app/src/main/java/me/devsaki/hentoid/workers/BaseDeleteWorker.java index 7c26f785c8..15bca436ce 100644 --- a/app/src/main/java/me/devsaki/hentoid/workers/BaseDeleteWorker.java +++ b/app/src/main/java/me/devsaki/hentoid/workers/BaseDeleteWorker.java @@ -49,6 +49,7 @@ public abstract class BaseDeleteWorker extends BaseWorker { private final boolean isDeleteAllQueueRecords; private final int deleteMax; private final boolean isDeleteGroupsOnly; + private final boolean isDownloadPrepurge; private int deleteProgress; private int nbError; @@ -69,6 +70,7 @@ protected BaseDeleteWorker( queueIds = inputData.getQueueIds(); isDeleteAllQueueRecords = inputData.isDeleteAllQueueRecords(); isDeleteGroupsOnly = inputData.isDeleteGroupsOnly(); + isDownloadPrepurge = inputData.isDownloadPrepurge(); dao = new ObjectBoxDAO(context); @@ -291,7 +293,7 @@ else if (item instanceof me.devsaki.hentoid.database.domains.Group) } private void progressDone() { - notificationManager.notifyLast(new DeleteCompleteNotification(deleteMax, nbError > 0)); + notificationManager.notifyLast(new DeleteCompleteNotification(deleteMax, nbError, isDownloadPrepurge)); EventBus.getDefault().postSticky(new ProcessEvent(ProcessEvent.EventType.COMPLETE, R.id.generic_progress, 0, deleteProgress, nbError, deleteMax)); } } diff --git a/app/src/main/java/me/devsaki/hentoid/workers/data/DeleteData.java b/app/src/main/java/me/devsaki/hentoid/workers/data/DeleteData.java index da1bfc71b8..e449327dfc 100644 --- a/app/src/main/java/me/devsaki/hentoid/workers/data/DeleteData.java +++ b/app/src/main/java/me/devsaki/hentoid/workers/data/DeleteData.java @@ -24,6 +24,7 @@ public class DeleteData { private static final String KEY_DELETE_GROUPS_ONLY = "deleteGroupsOnly"; private static final String KEY_DELETE_ALL_CONTENT_EXCEPT_FAVS_B = "deleteAllContentExceptFavsB"; private static final String KEY_DELETE_ALL_CONTENT_EXCEPT_FAVS_G = "deleteAllContentExceptFavsG"; + private static final String KEY_DL_PREPURGE = "downloadPrepurge"; private DeleteData() { throw new UnsupportedOperationException(); @@ -69,6 +70,10 @@ public void setDeleteAllContentExceptFavsGroups(boolean value) { builder.putBoolean(KEY_DELETE_ALL_CONTENT_EXCEPT_FAVS_G, value); } + public void setDownloadPrepurge(boolean value) { + builder.putBoolean(KEY_DL_PREPURGE, value); + } + public Data getData() { return builder.build(); } @@ -125,5 +130,9 @@ public boolean isDeleteAllContentExceptFavsBooks() { public boolean isDeleteAllContentExceptFavsGroups() { return data.getBoolean(KEY_DELETE_ALL_CONTENT_EXCEPT_FAVS_G, false); } + + public boolean isDownloadPrepurge() { + return data.getBoolean(KEY_DL_PREPURGE, false); + } } } diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4d3e20fb71..9bef035290 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -543,7 +543,6 @@ %d eliminado con éxito Eliminación fallida - Al menos un libro no pudo ser eliminado Eliminación de contenido Actualización completa Actualización de JSON en progreso diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 2de1895402..1aab2508b5 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -791,7 +791,6 @@ %d sikeresen törölve A törlés sikertelen - Legalább egy könyvet nem sikerült törölni Indítás diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index e2ab3fa961..f198cbc46b 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -543,7 +543,6 @@ %d eliminato correttamente Cancellazione fallita - Almeno un libro non ? stato cancellato Eliminazione del contenuto Aggiornamento completato Aggiornamento JSON in corso diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 53918ba410..0f25ee1a03 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -542,7 +542,6 @@ %dが正常に削除されました 削除に失敗しました - 少なくとも1冊の本を削除できませんでした コンテンツの削除 更新が完了しました JSONを更新中 diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index a8de52614e..176f7313ce 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -813,7 +813,6 @@ %d개가 성공적으로 삭제되었습니다 삭제 실패 - 하나 이상의 책을 삭제하지 못했습니다 JSON 업데이트 JSON 업데이트 중 업데이트 완료 diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index cb09af2869..741dfb3b72 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -867,7 +867,6 @@ Удалено: %d Удаление не удалось - Не удалось удалить по крайней мере одну книгу Запуск diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 0d5a364d3b..0045111204 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -866,7 +866,6 @@ Видалено: %d Видалення не вдалося - Не вдалося видалити принаймні одну книгу Запуск diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38ca9a5120..bfd605329b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -957,12 +957,17 @@ Content archival Content deletion Deletion complete + Redownload/Stream pre-purge complete - %d deleted successfully - %d deleted successfully + %d book processed successfully + %d books processed successfully Deletion failed - At least one book failed to be deleted + Redownload/Stream pre-purge failed + + %d book failed + %d books failed + JSON update