add "clear chat"

This commit is contained in:
adbenitez
2023-03-13 19:08:06 -04:00
parent 07d681345f
commit ffb788e4b6
6 changed files with 24 additions and 4 deletions
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="@string/menu_clear_chat"
android:id="@+id/menu_clear_chat"/>
</menu>
+1
View File
@@ -192,6 +192,7 @@
<string name="menu_add_attachment">Add Attachment</string>
<string name="menu_leave_group">Leave Group</string>
<string name="menu_delete_chat">Delete Chat</string>
<string name="menu_clear_chat">Clear Chat</string>
<string name="ask_delete_named_chat">Are you sure you want to delete \"%1$s\"?</string>
<string name="menu_delete_messages">Delete Messages</string>
<string name="delete_contact">Delete Contact</string>
@@ -483,6 +483,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
menu.findItem(R.id.menu_archive_chat).setTitle(R.string.menu_unarchive_chat);
}
inflater.inflate(R.menu.conversation_clear, menu);
inflater.inflate(R.menu.conversation_delete, menu);
try {
@@ -533,6 +534,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
case R.id.menu_add_attachment: handleAddAttachment(); return true;
case R.id.menu_leave: handleLeaveGroup(); return true;
case R.id.menu_archive_chat: handleArchiveChat(); return true;
case R.id.menu_clear_chat: fragment.handleClearChat(); return true;
case R.id.menu_delete_chat: handleDeleteChat(); return true;
case R.id.menu_mute_notifications: handleMuteNotifications(); return true;
case R.id.menu_show_map: handleShowMap(); return true;
@@ -331,6 +331,10 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
return Collections.unmodifiableSet(new HashSet<>(batchSelected));
}
public int[] getMessageIds() {
return dcMsgList;
}
public void pulseHighlightItem(int position) {
if (position>=0 && position < getItemCount()) {
positionToPulseHighlight = position;
@@ -357,6 +357,10 @@ public class ConversationFragment extends MessageSelectorFragment
return !dcMsg.isInfo() && dcMsg.getType() != DcMsg.DC_MSG_VIDEOCHAT_INVITATION;
}
public void handleClearChat() {
handleDeleteMessages((int) chatId, getListAdapter().getMessageIds());
}
private ConversationAdapter getListAdapter() {
return (ConversationAdapter) list.getAdapter();
}
@@ -55,19 +55,21 @@ public abstract class MessageSelectorFragment
}
protected void handleDeleteMessages(int chatId, final Set<DcMsg> messageRecords) {
int messagesCount = messageRecords.size();
handleDeleteMessages(chatId, DcMsg.msgSetToIds(messageRecords));
}
protected void handleDeleteMessages(int chatId, final int[] messageIds) {
DcChat dcChat = DcHelper.getContext(getActivity()).getChat(chatId);
String text = getActivity().getResources().getQuantityString(
dcChat.isDeviceTalk()? R.plurals.ask_delete_messages_simple : R.plurals.ask_delete_messages,
messagesCount, messagesCount);
messageIds.length, messageIds.length);
new AlertDialog.Builder(getActivity())
.setMessage(text)
.setCancelable(true)
.setPositiveButton(R.string.delete, (dialog, which) -> {
int[] ids = DcMsg.msgSetToIds(messageRecords);
dcContext.deleteMsgs(ids);
dcContext.deleteMsgs(messageIds);
if (actionMode != null) actionMode.finish();
})
.setNegativeButton(android.R.string.cancel, null)