[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.os.Parcelable;
import android.transition.Slide; import android.transition.Slide;
import android.transition.Transition; import android.transition.Transition;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.Menu; 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.os.Build.VERSION.SDK_INT;
import static android.view.Gravity.RIGHT; import static android.view.Gravity.RIGHT;
import static android.widget.Toast.LENGTH_LONG;
import static android.widget.Toast.LENGTH_SHORT; import static android.widget.Toast.LENGTH_SHORT;
import static androidx.core.app.ActivityOptionsCompat.makeSceneTransitionAnimation; import static androidx.core.app.ActivityOptionsCompat.makeSceneTransitionAnimation;
import static androidx.core.view.ViewCompat.setTransitionName; import static androidx.core.view.ViewCompat.setTransitionName;
@@ -442,8 +440,7 @@ public class ConversationActivity extends BriarActivity
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == R.id.action_delete) { if (item.getItemId() == R.id.action_delete) {
Log.e("TEST", "selected: " + getSelection()); deleteSelectedMessages();
Toast.makeText(this, "Not yet implemented", LENGTH_LONG).show();
return true; return true;
} }
return false; return false;
@@ -862,7 +859,7 @@ public class ConversationActivity extends BriarActivity
try { try {
boolean allDeleted = boolean allDeleted =
conversationManager.deleteAllMessages(contactId); conversationManager.deleteAllMessages(contactId);
reloadConversationAfterDeletingAllMessages(allDeleted); reloadConversationAfterDeletingMessages(allDeleted);
} catch (DbException e) { } catch (DbException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
runOnUiThreadUnlessDestroyed(() -> list.showData()); 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) { boolean allDeleted) {
runOnUiThreadUnlessDestroyed(() -> { runOnUiThreadUnlessDestroyed(() -> {
adapter.clear(); adapter.clear();

View File

@@ -139,7 +139,7 @@
<string name="dialog_title_delete_all_messages">Confirm Message Deletion</string> <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_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_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="delete_contact">Delete contact</string>
<string name="dialog_title_delete_contact">Confirm Contact Deletion</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> <string name="dialog_message_delete_contact">Are you sure that you want to remove this contact and all messages exchanged with this contact?</string>