diff --git a/briar-android/src/main/java/org/briarproject/briar/android/conversation/ConversationActivity.java b/briar-android/src/main/java/org/briarproject/briar/android/conversation/ConversationActivity.java index d983479b2..37457c6a7 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/conversation/ConversationActivity.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/conversation/ConversationActivity.java @@ -389,6 +389,9 @@ public class ConversationActivity extends BriarActivity AliasDialogFragment.newInstance().show( getSupportFragmentManager(), AliasDialogFragment.TAG); return true; + case R.id.action_delete_all_messages: + askToDeleteAllMessages(); + return true; case R.id.action_social_remove_person: askToRemoveContact(); return true; @@ -727,6 +730,52 @@ public class ConversationActivity extends BriarActivity addConversationItem(h.accept(visitor)); } + private void askToDeleteAllMessages() { + AlertDialog.Builder builder = + new AlertDialog.Builder(this, R.style.BriarDialogTheme); + builder.setTitle(getString(R.string.dialog_title_delete_all_messages)); + builder.setMessage( + getString(R.string.dialog_message_delete_all_messages)); + builder.setNegativeButton(R.string.delete, + (dialog, which) -> deleteAllMessages()); + builder.setPositiveButton(R.string.cancel, null); + builder.show(); + } + + private void deleteAllMessages() { + list.showProgressBar(); + runOnDbThread(() -> { + try { + boolean allDeleted = + conversationManager.deleteAllMessages(contactId); + reloadConversationAfterDeletingAllMessages(allDeleted); + } catch (DbException e) { + logException(LOG, WARNING, e); + runOnUiThreadUnlessDestroyed(() -> list.showData()); + } + }); + } + + private void reloadConversationAfterDeletingAllMessages( + boolean allDeleted) { + runOnUiThreadUnlessDestroyed(() -> { + adapter.clear(); + loadMessages(); + if (!allDeleted) showNotAllDeletedDialog(); + }); + } + + private void showNotAllDeletedDialog() { + AlertDialog.Builder builder = + new AlertDialog.Builder(this, R.style.BriarDialogTheme); + builder.setTitle( + getString(R.string.dialog_title_not_all_messages_deleted)); + builder.setMessage( + getString(R.string.dialog_message_not_all_messages_deleted)); + builder.setPositiveButton(R.string.ok, null); + builder.show(); + } + private void askToRemoveContact() { DialogInterface.OnClickListener okListener = (dialog, which) -> removeContact(); diff --git a/briar-android/src/main/res/menu/conversation_actions.xml b/briar-android/src/main/res/menu/conversation_actions.xml index e630f5a33..8447178c7 100644 --- a/briar-android/src/main/res/menu/conversation_actions.xml +++ b/briar-android/src/main/res/menu/conversation_actions.xml @@ -16,6 +16,11 @@ android:enabled="false" app:showAsAction="never"/> + + Change contact name Contact name Change + Delete all messages + Confirm Message Deletion + Are you sure that you want to delete all messages? + Could not delete all messages + Messages related to introductions or invitations cannot be deleted at the moment. Delete contact Confirm Contact Deletion Are you sure that you want to remove this contact and all messages exchanged with this contact?