diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-12-25 21:11:20 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-12-25 21:11:20 +0100 |
commit | 1924cfbd53b371c6c0e5f7b5fa719ec62ed9aac6 (patch) | |
tree | ed95ad768802027c48476b141be9080bb295197f /src/main/java/de/pixart/messenger/ui/ConversationFragment.java | |
parent | 37aedc49f36041abc7f35132e13241c26338ba99 (diff) |
support for quoting messages
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 01fc47afe..5363b3db6 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -11,6 +11,7 @@ import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.os.Bundle; import android.os.Handler; +import android.text.Editable; import android.text.InputType; import android.util.Log; import android.util.Pair; @@ -519,6 +520,34 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } }); + messageListAdapter.setOnQuoteListener(new MessageAdapter.OnQuoteListener() { + + @Override + public void onQuote(String text) { + if (mEditMessage.isEnabled()) { + text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", ""); + Editable editable = mEditMessage.getEditableText(); + int position = mEditMessage.getSelectionEnd(); + if (position == -1) position = editable.length(); + if (position > 0 && editable.charAt(position - 1) != '\n') { + editable.insert(position++, "\n"); + } + editable.insert(position, text); + position += text.length(); + editable.insert(position++, "\n"); + if (position < editable.length() && editable.charAt(position) != '\n') { + editable.insert(position, "\n"); + } + mEditMessage.setSelection(position); + mEditMessage.requestFocus(); + InputMethodManager inputMethodManager = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + if (inputMethodManager != null) { + inputMethodManager.showSoftInput(mEditMessage, InputMethodManager.SHOW_IMPLICIT); + } + } + } + }); messagesView.setAdapter(messageListAdapter); registerForContextMenu(messagesView); |