[briar-android] Add conversation menu action to delete all messages

This commit is contained in:
Torsten Grote
2019-10-03 15:24:36 -03:00
parent c46fdce277
commit 3ac5646355
3 changed files with 59 additions and 0 deletions

View File

@@ -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();