From cc755cb96994d9cd1db4cf876b8c0aef909a949f Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 29 Aug 2018 14:49:02 +0300 Subject: [PATCH] fixes --- .../mthmmy/activities/topic/TopicAdapter.java | 42 +++++++++++++------ .../gr/thmmy/mthmmy/utils/EmojiKeyboard.java | 2 +- .../res/layout/activity_topic_edit_row.xml | 35 ++-------------- app/src/main/res/layout/editor_view.xml | 2 +- 4 files changed, 36 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 3e386994..c7b77901 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -121,9 +121,8 @@ class TopicAdapter extends RecyclerView.Adapter { } else if (viewType == Post.TYPE_EDIT) { View view = LayoutInflater.from(parent.getContext()). inflate(R.layout.activity_topic_edit_row, parent, false); - view.findViewById(R.id.edit_message_submit).setEnabled(true); - final EditText editPostEdittext = view.findViewById(R.id.edit_message_text); + final EditText editPostEdittext = ((EditorView) view.findViewById(R.id.edit_editorview)).getEditText(); editPostEdittext.setFocusableInTouchMode(true); editPostEdittext.setOnFocusChangeListener((v, hasFocus) -> editPostEdittext.post(() -> { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); @@ -463,6 +462,11 @@ class TopicAdapter extends RecyclerView.Adapter { InputConnection ic = holder.replyEditor.getInputConnection(); emojiKeyboardOwner.setEmojiKeyboardInputConnection(ic); holder.replyEditor.updateEmojiKeyboardVisibility(); + holder.replyEditor.getEditText().setOnFocusChangeListener((v, hasFocus) -> { + InputConnection ic12 = holder.replyEditor.getInputConnection(); + emojiKeyboardOwner.setEmojiKeyboardInputConnection(ic12); + holder.replyEditor.updateEmojiKeyboardVisibility(); + }); holder.replyEditor.setText(viewModel.getBuildedQuotes()); holder.replyEditor.setOnSubmitListener(view -> { @@ -475,6 +479,7 @@ class TopicAdapter extends RecyclerView.Adapter { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); holder.itemView.setAlpha(0.5f); holder.itemView.setEnabled(false); + emojiKeyboardOwner.setEmojiKeyboardVisible(false); viewModel.postReply(context, holder.quickReplySubject.getText().toString(), holder.replyEditor.getText().toString()); @@ -501,23 +506,37 @@ class TopicAdapter extends RecyclerView.Adapter { .transform(new CircleTransform()) .into(holder.thumbnail); holder.username.setText(getSessionManager().getUsername()); - holder.editSubject.setText(postsList.get(position).getSubject()); - holder.editMessage.setText(viewModel.getPostBeingEditedText()); - holder.submitButton.setOnClickListener(view -> { + holder.editEditor.setEmojiKeyboardOwner(emojiKeyboardOwner); + InputConnection ic = holder.editEditor.getInputConnection(); + emojiKeyboardOwner.setEmojiKeyboardInputConnection(ic); + holder.editEditor.updateEmojiKeyboardVisibility(); + holder.editEditor.setText(viewModel.getPostBeingEditedText()); + holder.editEditor.getEditText().setOnFocusChangeListener((v, hasFocus) -> { + if (hasFocus) { + InputConnection ic1 = holder.editEditor.getInputConnection(); + emojiKeyboardOwner.setEmojiKeyboardInputConnection(ic1); + holder.editEditor.updateEmojiKeyboardVisibility(); + } + }); + holder.editEditor.setOnSubmitListener(view -> { if (holder.editSubject.getText().toString().isEmpty()) return; - if (holder.editMessage.getText().toString().isEmpty()) return; + if (holder.editEditor.getText().toString().isEmpty()) { + holder.editEditor.setError("Required"); + return; + } InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); holder.itemView.setAlpha(0.5f); holder.itemView.setEnabled(false); + emojiKeyboardOwner.setEmojiKeyboardVisible(false); - viewModel.editPost(position, holder.editSubject.getText().toString(), holder.editMessage.getText().toString()); + viewModel.editPost(position, holder.editSubject.getText().toString(), holder.editEditor.getText().toString()); }); if (backPressHidden) { - holder.editMessage.requestFocus(); + holder.editEditor.requestFocus(); backPressHidden = false; } } @@ -601,17 +620,16 @@ class TopicAdapter extends RecyclerView.Adapter { private static class EditMessageViewHolder extends RecyclerView.ViewHolder { final ImageView thumbnail; final TextView username; - final EditText editMessage, editSubject; - final AppCompatImageButton submitButton; + final EditText editSubject; + final EditorView editEditor; EditMessageViewHolder(View editView) { super(editView); thumbnail = editView.findViewById(R.id.thumbnail); username = editView.findViewById(R.id.username); - editMessage = editView.findViewById(R.id.edit_message_text); editSubject = editView.findViewById(R.id.edit_message_subject); - submitButton = editView.findViewById(R.id.edit_message_submit); + editEditor = editView.findViewById(R.id.edit_editorview); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/EmojiKeyboard.java b/app/src/main/java/gr/thmmy/mthmmy/utils/EmojiKeyboard.java index 9aed027c..b1284b04 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/EmojiKeyboard.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/EmojiKeyboard.java @@ -169,7 +169,7 @@ public class EmojiKeyboard extends LinearLayout { emojiKeyboardAdapter.setOnEmojiClickListener((view, position) -> { if (inputConnection == null) return; String bbcode = emojis[position].getBbcode(); - inputConnection.commitText(bbcode, 1); + inputConnection.commitText(" " + bbcode, 1); }); emojiRecyclerview.setAdapter(emojiKeyboardAdapter); AppCompatImageButton backspaceButton = findViewById(R.id.backspace_button); diff --git a/app/src/main/res/layout/activity_topic_edit_row.xml b/app/src/main/res/layout/activity_topic_edit_row.xml index 0e86a581..183b7560 100644 --- a/app/src/main/res/layout/activity_topic_edit_row.xml +++ b/app/src/main/res/layout/activity_topic_edit_row.xml @@ -80,39 +80,12 @@ android:textSize="10sp" tools:ignore="SmallSp" /> - - - - - - - - - - + android:background="@color/card_background" + card_view:hint="Post message"/> \ No newline at end of file diff --git a/app/src/main/res/layout/editor_view.xml b/app/src/main/res/layout/editor_view.xml index 4d4cfd77..97b8c1b6 100644 --- a/app/src/main/res/layout/editor_view.xml +++ b/app/src/main/res/layout/editor_view.xml @@ -128,7 +128,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" - android:orientation="vertical"> + android:orientation="vertical" >