[android] hook up UI to ConversationManager to actually delete messages

This commit is contained in:
Torsten Grote
2019-10-22 11:38:10 -03:00
parent 9ce327a40c
commit 97dd9b901d
2 changed files with 21 additions and 7 deletions

View File

@@ -7,7 +7,6 @@ import android.os.Bundle;
import android.os.Parcelable;
import android.transition.Slide;
import android.transition.Transition;
import android.util.Log;
import android.util.SparseArray;
import android.view.ActionMode;
import android.view.Menu;
@@ -113,7 +112,6 @@ import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
import static android.os.Build.VERSION.SDK_INT;
import static android.view.Gravity.RIGHT;
import static android.widget.Toast.LENGTH_LONG;
import static android.widget.Toast.LENGTH_SHORT;
import static androidx.core.app.ActivityOptionsCompat.makeSceneTransitionAnimation;
import static androidx.core.view.ViewCompat.setTransitionName;
@@ -442,8 +440,7 @@ public class ConversationActivity extends BriarActivity
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == R.id.action_delete) {
Log.e("TEST", "selected: " + getSelection());
Toast.makeText(this, "Not yet implemented", LENGTH_LONG).show();
deleteSelectedMessages();
return true;
}
return false;
@@ -862,7 +859,7 @@ public class ConversationActivity extends BriarActivity
try {
boolean allDeleted =
conversationManager.deleteAllMessages(contactId);
reloadConversationAfterDeletingAllMessages(allDeleted);
reloadConversationAfterDeletingMessages(allDeleted);
} catch (DbException e) {
logException(LOG, WARNING, e);
runOnUiThreadUnlessDestroyed(() -> list.showData());
@@ -870,7 +867,24 @@ public class ConversationActivity extends BriarActivity
});
}
private void reloadConversationAfterDeletingAllMessages(
private void deleteSelectedMessages() {
list.showProgressBar();
Collection<MessageId> selected = getSelection();
// close action mode only after getting the selection
if (actionMode != null) actionMode.finish();
runOnDbThread(() -> {
try {
boolean allDeleted =
conversationManager.deleteMessages(contactId, selected);
reloadConversationAfterDeletingMessages(allDeleted);
} catch (DbException e) {
logException(LOG, WARNING, e);
runOnUiThreadUnlessDestroyed(() -> list.showData());
}
});
}
private void reloadConversationAfterDeletingMessages(
boolean allDeleted) {
runOnUiThreadUnlessDestroyed(() -> {
adapter.clear();

View File

@@ -139,7 +139,7 @@
<string name="dialog_title_delete_all_messages">Confirm Message Deletion</string>
<string name="dialog_message_delete_all_messages">Are you sure that you want to delete all messages?</string>
<string name="dialog_title_not_all_messages_deleted">Could not delete all messages</string>
<string name="dialog_message_not_all_messages_deleted">Messages related to ongoing introductions or invitations cannot be deleted until they conclude.</string>
<string name="dialog_message_not_all_messages_deleted">Messages related to\n\n• ongoing introductions\n• ongoing (blog/forum/group) invitations\n• partly downloaded messages\n\ncannot be deleted until they conclude.</string>
<string name="delete_contact">Delete contact</string>
<string name="dialog_title_delete_contact">Confirm Contact Deletion</string>
<string name="dialog_message_delete_contact">Are you sure that you want to remove this contact and all messages exchanged with this contact?</string>