Skip to content

Commit

Permalink
More explicit delete / purge notification texts
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbWatershed committed Aug 17, 2023
1 parent b986c56 commit 6dfcb4b
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/me/devsaki/hentoid/util/ContentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -777,7 +777,7 @@ public void streamContent(@NonNull final List<Content> 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<ImageFile> imgs = dbContent.getImageFiles();
if (imgs != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -69,6 +70,7 @@ protected BaseDeleteWorker(
queueIds = inputData.getQueueIds();
isDeleteAllQueueRecords = inputData.isDeleteAllQueueRecords();
isDeleteGroupsOnly = inputData.isDeleteGroupsOnly();
isDownloadPrepurge = inputData.isDownloadPrepurge();

dao = new ObjectBoxDAO(context);

Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}
}
1 change: 0 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@
<item quantity="other">%d eliminado con éxito</item>
</plurals>
<string name="notif_delete_fail">Eliminación fallida</string>
<string name="notif_delete_fail_details">Al menos un libro no pudo ser eliminado</string>
<string name="notif_delete_title">Eliminación de contenido</string>
<string name="notif_json_complete">Actualización completa</string>
<string name="notif_json_progress">Actualización de JSON en progreso</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,6 @@
<item quantity="other"><x:g example="1" id="number">%d</x:g> sikeresen törölve</item>
</plurals>
<string name="notif_delete_fail">A törlés sikertelen</string>
<string name="notif_delete_fail_details">Legalább egy könyvet nem sikerült törölni</string>


<string name="title_startup">Indítás</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@
<item quantity="other">%d eliminato correttamente</item>
</plurals>
<string name="notif_delete_fail">Cancellazione fallita</string>
<string name="notif_delete_fail_details">Almeno un libro non ? stato cancellato</string>
<string name="notif_delete_title">Eliminazione del contenuto</string>
<string name="notif_json_complete">Aggiornamento completato</string>
<string name="notif_json_progress">Aggiornamento JSON in corso</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@
<item quantity="other">%dが正常に削除されました</item>
</plurals>
<string name="notif_delete_fail">削除に失敗しました</string>
<string name="notif_delete_fail_details">少なくとも1冊の本を削除できませんでした</string>
<string name="notif_delete_title">コンテンツの削除</string>
<string name="notif_json_complete">更新が完了しました</string>
<string name="notif_json_progress">JSONを更新中</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@
<item quantity="other"><x:g example="1" id="number">%d</x:g>개가 성공적으로 삭제되었습니다</item>
</plurals>
<string name="notif_delete_fail">삭제 실패</string>
<string name="notif_delete_fail_details">하나 이상의 책을 삭제하지 못했습니다</string>
<string name="notif_json_title">JSON 업데이트</string>
<string name="notif_json_progress">JSON 업데이트 중</string>
<string name="notif_json_complete">업데이트 완료</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,6 @@
<item quantity="many">Удалено: <x:g id="number" example="1">%d</x:g></item>
</plurals>
<string name="notif_delete_fail">Удаление не удалось</string>
<string name="notif_delete_fail_details">Не удалось удалить по крайней мере одну книгу</string>

<!-- Startup -->
<string name="title_startup">Запуск</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,6 @@
<item quantity="many">Видалено: <x:g id="number" example="1">%d</x:g></item>
</plurals>
<string name="notif_delete_fail">Видалення не вдалося</string>
<string name="notif_delete_fail_details">Не вдалося видалити принаймні одну книгу</string>

<!-- Startup -->
<string name="title_startup">Запуск</string>
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -957,12 +957,17 @@
<string name="notif_archive_title">Content archival</string>
<string name="notif_delete_title">Content deletion</string>
<string name="notif_delete_complete">Deletion complete</string>
<string name="notif_delete_prepurge_complete">Redownload/Stream pre-purge complete</string>
<plurals name="notif_delete_complete_details">
<item quantity="one"><x:g example="1" id="number">%d</x:g> deleted successfully</item>
<item quantity="other"><x:g example="1" id="number">%d</x:g> deleted successfully</item>
<item quantity="one"><x:g example="1" id="number">%d</x:g> book processed successfully</item>
<item quantity="other"><x:g example="2" id="number">%d</x:g> books processed successfully</item>
</plurals>
<string name="notif_delete_fail">Deletion failed</string>
<string name="notif_delete_fail_details">At least one book failed to be deleted</string>
<string name="notif_delete_prepurge_fail">Redownload/Stream pre-purge failed</string>
<plurals name="notif_delete_fail_details">
<item quantity="one"><x:g example="1" id="number">%d</x:g> book failed</item>
<item quantity="other"><x:g example="2" id="number">%d</x:g> books failed</item>
</plurals>

<!-- Update Json service -->
<string name="notif_json_title">JSON update</string>
Expand Down

0 comments on commit 6dfcb4b

Please sign in to comment.