use of org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask in project Signal-Android by WhisperSystems.
the class ConversationFragment method handleDeleteMessages.
private void handleDeleteMessages(final Set<MessageRecord> messageRecords) {
int messagesCount = messageRecords.size();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setIconAttribute(R.attr.dialog_alert_icon);
builder.setTitle(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messagesCount, messagesCount));
builder.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messagesCount, messagesCount));
builder.setCancelable(true);
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new ProgressDialogAsyncTask<MessageRecord, Void, Void>(getActivity(), R.string.ConversationFragment_deleting, R.string.ConversationFragment_deleting_messages) {
@Override
protected Void doInBackground(MessageRecord... messageRecords) {
for (MessageRecord messageRecord : messageRecords) {
boolean threadDeleted;
if (messageRecord.isMms()) {
threadDeleted = DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
} else {
threadDeleted = DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId());
}
if (threadDeleted) {
threadId = -1;
listener.setThreadId(threadId);
}
}
return null;
}
}.execute(messageRecords.toArray(new MessageRecord[messageRecords.size()]));
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
}
use of org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask in project Signal-Android by WhisperSystems.
the class MediaOverviewActivity method saveToDisk.
private void saveToDisk() {
final Context c = this;
SaveAttachmentTask.showWarningDialog(this, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
new ProgressDialogAsyncTask<Void, Void, List<SaveAttachmentTask.Attachment>>(c, R.string.ConversationFragment_collecting_attahments, R.string.please_wait) {
@Override
protected List<SaveAttachmentTask.Attachment> doInBackground(Void... params) {
Cursor cursor = DatabaseFactory.getMediaDatabase(c).getMediaForThread(threadId);
List<SaveAttachmentTask.Attachment> attachments = new ArrayList<>(cursor.getCount());
while (cursor != null && cursor.moveToNext()) {
MediaRecord record = MediaRecord.from(cursor);
attachments.add(new SaveAttachmentTask.Attachment(record.getAttachment().getDataUri(), record.getContentType(), record.getDate()));
}
return attachments;
}
@Override
protected void onPostExecute(List<SaveAttachmentTask.Attachment> attachments) {
super.onPostExecute(attachments);
SaveAttachmentTask saveTask = new SaveAttachmentTask(c, masterSecret, attachments.size());
saveTask.execute(attachments.toArray(new SaveAttachmentTask.Attachment[attachments.size()]));
}
}.execute();
}
}, gridView.getAdapter().getItemCount());
}
Aggregations