Search in sources :

Example 1 with ProgressDialogAsyncTask

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask)

Example 2 with ProgressDialogAsyncTask

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());
}
Also used : Context(android.content.Context) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask) MediaRecord(org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DialogInterface (android.content.DialogInterface)2 ProgressDialogAsyncTask (org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 AlertDialog (android.support.v7.app.AlertDialog)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MediaRecord (org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord)1 MediaMmsMessageRecord (org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)1 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)1 SaveAttachmentTask (org.thoughtcrime.securesms.util.SaveAttachmentTask)1