From 2c191a696999a2e04a9ca2f3eab9faccd9399115 Mon Sep 17 00:00:00 2001 From: Arne Date: Mon, 1 Jan 2024 19:01:48 +0100 Subject: [PATCH] Continuing emoji picker --- build.gradle | 1 + src/main/AndroidManifest.xml | 2 +- .../ui/ConversationFragment.java | 97 ++++++++++++++++++- src/main/res/layout/fragment_conversation.xml | 43 +++++++- src/main/res/menu/message_context.xml | 4 + src/main/res/values/defaults.xml | 2 +- 6 files changed, 142 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 151df4441f..1844a2d144 100644 --- a/build.gradle +++ b/build.gradle @@ -129,6 +129,7 @@ dependencies { implementation 'com.nineoldandroids:library:2.4.0' implementation "androidx.core:core-ktx:1.12.0" implementation "androidx.compose.material3:material3-android:1.2.0-beta01" + implementation "androidx.emoji2:emoji2-emojipicker:1.4.0" } ext { diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index bd713e957e..6bf0255adb 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -243,7 +243,7 @@ android:launchMode="singleTask" android:minWidth="336dp" android:minHeight="480dp" - android:windowSoftInputMode="stateHidden" /> + android:windowSoftInputMode="adjustResize" /> { + int start = binding.textinput.getSelectionStart(); //this is to get the the cursor position + binding.textinput.getText().insert(start, emojiViewItem.getEmoji()); //this will get the text and insert the emoji into the current position + }); + } + } + }; + + private final OnClickListener mkeyboardButtonListener = new OnClickListener() { + @Override + public void onClick(View v) { + if (binding.keyboardButton.getVisibility() == VISIBLE) { + binding.keyboardButton.setVisibility(GONE); + binding.emojiPicker.setVisibility(GONE); + binding.emojiButton.setVisibility(VISIBLE); + InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + if (inputMethodManager != null) { + binding.textinput.requestFocus(); + inputMethodManager.showSoftInput(binding.textinput, InputMethodManager.SHOW_IMPLICIT); + } + } + } + }; + + private final OnClickListener mRecordVoiceButtonListener = v -> attachFile(ATTACHMENT_CHOICE_RECORD_VOICE); private final OnClickListener mtakePictureButtonListener = v -> attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); @@ -752,6 +791,21 @@ public class ConversationFragment extends XmppFragment } }; + + private final OnBackPressedCallback backPressedLeaveEmojiPicker = new OnBackPressedCallback(false) { + @Override + public void handleOnBackPressed() { + if (binding.emojiPicker.getVisibility()==VISIBLE) { + binding.emojiPicker.setVisibility(GONE); + binding.keyboardButton.setVisibility(GONE); + binding.emojiButton.setVisibility(VISIBLE); + } + this.setEnabled(false); + refresh(); + } + }; + + private int completionIndex = 0; private int lastCompletionLength = 0; private String incomplete; @@ -1430,7 +1484,7 @@ public class ConversationFragment extends XmppFragment super.onCreate(savedInstanceState); setHasOptionsMenu(true); activity.getOnBackPressedDispatcher().addCallback(this, backPressedLeaveSingleThread); - + activity.getOnBackPressedDispatcher().addCallback(this, backPressedLeaveEmojiPicker); } @Override @@ -1551,6 +1605,12 @@ public class ConversationFragment extends XmppFragment //Setting hide thread icon showThreadFeature(); + if (binding.emojiPicker.getVisibility()==VISIBLE) { + backPressedLeaveEmojiPicker.setEnabled(true); + } else { + backPressedLeaveEmojiPicker.setEnabled(false); + } + binding.textinput.addTextChangedListener(new StylingHelper.MessageEditorStyler(binding.textinput)); binding.textinput.setOnEditorActionListener(mEditorActionListener); binding.textinput.setRichContentListener(new String[] {"image/*"}, mEditorContentListener); @@ -1567,6 +1627,8 @@ public class ConversationFragment extends XmppFragment binding.textSendButton.setOnLongClickListener(this.mSendButtonLongListener); binding.scrollToBottomButton.setOnClickListener(this.mScrollButtonListener); binding.recordVoiceButton.setOnClickListener(this.mRecordVoiceButtonListener); + binding.emojiButton.setOnClickListener(this.memojiButtonListener); + binding.keyboardButton.setOnClickListener(this.mkeyboardButtonListener); binding.takePictureButton.setOnClickListener(this.mtakePictureButtonListener); binding.messagesView.setOnScrollListener(mOnScrollListener); binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL); @@ -1879,6 +1941,7 @@ public class ConversationFragment extends XmppFragment MenuItem moderateMessage = menu.findItem(R.id.moderate_message); MenuItem onlyThisThread = menu.findItem(R.id.only_this_thread); MenuItem deleteMessage = menu.findItem(R.id.delete_message); + MenuItem messageReaction = menu.findItem(R.id.message_reaction); //add the most used emoticons MenuItem shareWith = menu.findItem(R.id.share_with); MenuItem sendAgain = menu.findItem(R.id.send_again); MenuItem copyUrl = menu.findItem(R.id.copy_url); @@ -2114,6 +2177,14 @@ public class ConversationFragment extends XmppFragment setThread(selectedMessage.getThread()); } return true; + case R.id.message_reaction: + if (conversation.getMode() == Conversation.MODE_MULTI) { + quoteMessage(selectedMessage, user); + } else { + quoteMessage(selectedMessage, null); + } + chooseReaction(selectedMessage); + return true; default: return onOptionsItemSelected(item); } @@ -2268,6 +2339,10 @@ public class ConversationFragment extends XmppFragment } return true; } + if (binding.emojiPicker.getVisibility()==VISIBLE){ + binding.emojiPicker.setVisibility(GONE); + return true; + } return false; } @@ -3325,6 +3400,26 @@ public class ConversationFragment extends XmppFragment this.binding.textinput.append(message.getBody()); } + private void chooseReaction(Message message) { + while (message.mergeable(message.next())) { + message = message.next(); + } + setThread(message.getThread()); + conversation.setUserSelectedThread(true); + //Open emoji picker + binding.emojiPicker.setVisibility(VISIBLE); + binding.emojiButton.setVisibility(GONE); + binding.keyboardButton.setVisibility(VISIBLE); + hideSoftKeyboard(activity); + EmojiPickerView emojiPickerView = (EmojiPickerView) activity.findViewById(R.id.emoji_picker); + backPressedLeaveEmojiPicker.setEnabled(true); + binding.textinput.requestFocus(); + emojiPickerView.setOnEmojiPickedListener(emojiViewItem -> { + binding.textinput.append(emojiViewItem.getEmoji()); + }); + // TODO: Directly choose emojis from popup menu + } + private void highlightInConference(String nick) { final Editable editable = this.binding.textinput.getText(); String oldString = editable.toString().trim(); diff --git a/src/main/res/layout/fragment_conversation.xml b/src/main/res/layout/fragment_conversation.xml index ff0486942c..7e0f1fe4fd 100644 --- a/src/main/res/layout/fragment_conversation.xml +++ b/src/main/res/layout/fragment_conversation.xml @@ -179,7 +179,7 @@ android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_centerVertical="true" - android:layout_marginEnd="8dp" + android:layout_marginEnd="4dp" android:visibility="visible" android:background="@drawable/thread_hint"> @@ -204,12 +204,38 @@ android:contentDescription="@string/thread_locked" /> - + + + + @@ -299,6 +325,15 @@ android:src="@drawable/ic_send_text_offline" /> + + + false true true - false + true true false false