Utilise dialog dsl in DeleteMediaDialog

This commit is contained in:
andrew 2023-06-02 22:05:34 +09:30
parent 033eabbc53
commit 975f9fc4d1
2 changed files with 44 additions and 31 deletions

View File

@ -0,0 +1,28 @@
package org.thoughtcrime.securesms
import android.content.Context
import network.loki.messenger.R
class DeleteMediaDialog {
companion object {
@JvmStatic
fun show(context: Context, recordCount: Int, doDelete: Runnable) = context.showSessionDialog {
iconAttribute(R.attr.dialog_alert_icon)
title(
context.resources.getQuantityString(
R.plurals.MediaOverviewActivity_Media_delete_confirm_title,
recordCount,
recordCount
)
)
text(
context.resources.getQuantityString(R.plurals.MediaOverviewActivity_Media_delete_confirm_message,
recordCount,
recordCount
)
)
button(R.string.delete) { doDelete.run() }
cancelButton()
}
}
}

View File

@ -376,25 +376,14 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity {
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private void handleDeleteMedia(@NonNull Collection<MediaDatabase.MediaRecord> mediaRecords) { private void handleDeleteMedia(@NonNull Collection<MediaDatabase.MediaRecord> mediaRecords) {
int recordCount = mediaRecords.size(); int recordCount = mediaRecords.size();
Resources res = getContext().getResources();
String confirmTitle = res.getQuantityString(R.plurals.MediaOverviewActivity_Media_delete_confirm_title,
recordCount,
recordCount);
String confirmMessage = res.getQuantityString(R.plurals.MediaOverviewActivity_Media_delete_confirm_message,
recordCount,
recordCount);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); DeleteMediaDialog.show(
builder.setIconAttribute(R.attr.dialog_alert_icon); requireContext(),
builder.setTitle(confirmTitle); recordCount,
builder.setMessage(confirmMessage); () -> new ProgressDialogAsyncTask<MediaDatabase.MediaRecord, Void, Void>(
builder.setCancelable(true); requireContext(),
builder.setPositiveButton(R.string.delete, (dialogInterface, i) -> {
new ProgressDialogAsyncTask<MediaDatabase.MediaRecord, Void, Void>(getContext(),
R.string.MediaOverviewActivity_Media_delete_progress_title, R.string.MediaOverviewActivity_Media_delete_progress_title,
R.string.MediaOverviewActivity_Media_delete_progress_message) R.string.MediaOverviewActivity_Media_delete_progress_message) {
{
@Override @Override
protected Void doInBackground(MediaDatabase.MediaRecord... records) { protected Void doInBackground(MediaDatabase.MediaRecord... records) {
if (records == null || records.length == 0) { if (records == null || records.length == 0) {
@ -406,11 +395,7 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity {
} }
return null; return null;
} }
}.execute(mediaRecords.toArray(new MediaDatabase.MediaRecord[mediaRecords.size()])));
}.execute(mediaRecords.toArray(new MediaDatabase.MediaRecord[mediaRecords.size()]));
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
} }
private void handleSelectAllMedia() { private void handleSelectAllMedia() {