mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Utilise dialog dsl in DeleteMediaDialog
This commit is contained in:
parent
033eabbc53
commit
975f9fc4d1
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -376,41 +376,26 @@ 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(),
|
||||||
|
R.string.MediaOverviewActivity_Media_delete_progress_title,
|
||||||
builder.setPositiveButton(R.string.delete, (dialogInterface, i) -> {
|
R.string.MediaOverviewActivity_Media_delete_progress_message) {
|
||||||
new ProgressDialogAsyncTask<MediaDatabase.MediaRecord, Void, Void>(getContext(),
|
@Override
|
||||||
R.string.MediaOverviewActivity_Media_delete_progress_title,
|
protected Void doInBackground(MediaDatabase.MediaRecord... records) {
|
||||||
R.string.MediaOverviewActivity_Media_delete_progress_message)
|
if (records == null || records.length == 0) {
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(MediaDatabase.MediaRecord... records) {
|
|
||||||
if (records == null || records.length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MediaDatabase.MediaRecord record : records) {
|
|
||||||
AttachmentUtil.deleteAttachment(getContext(), record.getAttachment());
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}.execute(mediaRecords.toArray(new MediaDatabase.MediaRecord[mediaRecords.size()]));
|
for (MediaDatabase.MediaRecord record : records) {
|
||||||
});
|
AttachmentUtil.deleteAttachment(getContext(), record.getAttachment());
|
||||||
builder.setNegativeButton(android.R.string.cancel, null);
|
}
|
||||||
builder.show();
|
return null;
|
||||||
|
}
|
||||||
|
}.execute(mediaRecords.toArray(new MediaDatabase.MediaRecord[mediaRecords.size()])));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSelectAllMedia() {
|
private void handleSelectAllMedia() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user