From 78410291b71534ef03cb756754005af675278389 Mon Sep 17 00:00:00 2001 From: kosyak Date: Wed, 27 Dec 2023 01:11:01 +0100 Subject: [PATCH] better self contact handling --- .../conversations/entities/Conversation.java | 1 + .../ui/ConversationsOverviewFragment.java | 15 +++++++++++++++ .../ui/adapter/ConversationAdapter.java | 4 ++++ .../res/menu/fragment_conversations_overview.xml | 7 +++++++ src/main/res/values/strings.xml | 1 + 5 files changed, 28 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 890bd4e51..874dff415 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -720,6 +720,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl @Override public int compareTo(@NonNull Conversation another) { return ComparisonChain.start() + .compareFalseFirst(another.getBooleanAttribute(ATTRIBUTE_PINNED_ON_TOP, false) && another.withSelf(), getBooleanAttribute(ATTRIBUTE_PINNED_ON_TOP, false) && withSelf()) .compareFalseFirst(another.getBooleanAttribute(ATTRIBUTE_PINNED_ON_TOP, false), getBooleanAttribute(ATTRIBUTE_PINNED_ON_TOP, false)) .compare(another.getSortableTime(), getSortableTime()) .result(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java index 48b9709f8..80df3c3dc 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java @@ -64,6 +64,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.FragmentConversationsOverviewBinding; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.services.XmppConnectionService; @@ -74,6 +75,7 @@ import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.PendingActionHelper; import eu.siacs.conversations.ui.util.PendingItem; import eu.siacs.conversations.ui.util.ScrollState; +import eu.siacs.conversations.ui.util.SoftKeyboardUtils; import eu.siacs.conversations.ui.util.StyledAttributes; import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.EasyOnboardingInvite; @@ -315,7 +317,12 @@ public class ConversationsOverviewFragment extends XmppFragment { menuInflater.inflate(R.menu.fragment_conversations_overview, menu); AccountUtils.showHideMenuItems(menu); final MenuItem easyOnboardInvite = menu.findItem(R.id.action_easy_invite); + MenuItem noteToSelf = menu.findItem(R.id.action_note_to_self); easyOnboardInvite.setVisible(EasyOnboardingInvite.anyHasSupport(activity == null ? null : activity.xmppConnectionService)); + + if (activity == null || activity.xmppConnectionService == null || activity.xmppConnectionService.getAccounts().size() != 1) { + noteToSelf.setVisible(false); + } } @Override @@ -430,6 +437,14 @@ public class ConversationsOverviewFragment extends XmppFragment { case R.id.action_easy_invite: selectAccountToStartEasyInvite(); return true; + case R.id.action_note_to_self: + final List accounts = activity.xmppConnectionService.getAccounts(); + if (accounts.size() == 1) { + final Contact self = new Contact(accounts.get(0).getSelfContact()); + Conversation conversation = activity.xmppConnectionService.findOrCreateConversation(self.getAccount(), self.getJid(), null, false, false, true, null); + SoftKeyboardUtils.hideSoftKeyboard(activity); + activity.switchToConversation(conversation); + } } return super.onOptionsItemSelected(item); } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index 2c4e868aa..a874dc035 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -72,6 +72,10 @@ public class ConversationAdapter name = viewHolder.binding.getRoot().getResources().getString(R.string.muc_private_conversation_title, conversation.getNextCounterpart().getResource(), conversation.getName()); } + if (conversation.withSelf()) { + name = viewHolder.binding.getRoot().getResources().getString(R.string.note_to_self_conversation_title, name); + } + if (name instanceof Jid) { viewHolder.binding.conversationName.setText( IrregularUnicodeDetector.style(activity, (Jid) name)); diff --git a/src/main/res/menu/fragment_conversations_overview.xml b/src/main/res/menu/fragment_conversations_overview.xml index 38c83df8f..8e206efde 100644 --- a/src/main/res/menu/fragment_conversations_overview.xml +++ b/src/main/res/menu/fragment_conversations_overview.xml @@ -35,6 +35,13 @@ android:title="@string/search_messages" android:visible="@bool/show_individual_search_options" app:showAsAction="never" /> + + + filter could_not_create_file %1$s (%2$s) + Note to self (%1$s) Private conversation with: %1$d selected General