From 94b48d5fb934c0b5a55b269720ff277d18008ba4 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 2 Jun 2023 22:36:15 +0930 Subject: [PATCH] Utilise dialog dsl in DeleteMediaPreviewDialog --- .../securesms/DeleteMediaPreviewDialog.kt | 19 ++++++++++++ .../securesms/MediaPreviewActivity.java | 31 +++++++------------ 2 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/DeleteMediaPreviewDialog.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/DeleteMediaPreviewDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/DeleteMediaPreviewDialog.kt new file mode 100644 index 0000000000..0390a3007d --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/DeleteMediaPreviewDialog.kt @@ -0,0 +1,19 @@ +package org.thoughtcrime.securesms + +import android.content.Context +import network.loki.messenger.R + +class DeleteMediaPreviewDialog { + companion object { + @JvmStatic + fun show(context: Context, doDelete: Runnable) { + context.showSessionDialog { + iconAttribute(R.attr.dialog_alert_icon) + title(R.string.MediaPreviewActivity_media_delete_confirmation_title) + text(R.string.MediaPreviewActivity_media_delete_confirmation_message) + button(R.string.delete) { doDelete.run() } + cancelButton() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java index e3cb839bc3..008a45cfd1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java @@ -451,29 +451,20 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im return; } - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setIconAttribute(R.attr.dialog_alert_icon); - builder.setTitle(R.string.MediaPreviewActivity_media_delete_confirmation_title); - builder.setMessage(R.string.MediaPreviewActivity_media_delete_confirmation_message); - builder.setCancelable(true); - - builder.setPositiveButton(R.string.delete, (dialogInterface, which) -> { - new AsyncTask() { - @Override - protected Void doInBackground(Void... voids) { - if (mediaItem.attachment == null) { - return null; - } - AttachmentUtil.deleteAttachment(MediaPreviewActivity.this.getApplicationContext(), - mediaItem.attachment); - return null; - } - }.execute(); + DeleteMediaPreviewDialog.show(this, () -> { + new AsyncTask() { + @Override + protected Void doInBackground(Void... voids) { + DatabaseAttachment attachment = mediaItem.attachment; + if (attachment != null) { + AttachmentUtil.deleteAttachment(getApplicationContext(), attachment); + } + return null; + } + }.execute(); finish(); }); - builder.setNegativeButton(android.R.string.cancel, null); - builder.show(); } @Override