From cdae908f0a3c3754c592996df092722e1a96bde3 Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 22 Mar 2018 14:08:28 -0700 Subject: Allow user to delete previous bubbles. After this change, user will be able to delete text in previous finished bubble. It will also correctly handle deletion from remote. Bug: 67596257 Test: RttChatMessageTest PiperOrigin-RevId: 190122728 Change-Id: Ifebcbe874e5f03857d109b58e758e53f408e7e44 --- .../android/incallui/rtt/impl/RttChatFragment.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'java/com/android/incallui/rtt/impl/RttChatFragment.java') diff --git a/java/com/android/incallui/rtt/impl/RttChatFragment.java b/java/com/android/incallui/rtt/impl/RttChatFragment.java index 90bf199b2..e14ee9b06 100644 --- a/java/com/android/incallui/rtt/impl/RttChatFragment.java +++ b/java/com/android/incallui/rtt/impl/RttChatFragment.java @@ -164,6 +164,26 @@ public class RttChatFragment extends Fragment editText = view.findViewById(R.id.rtt_chat_input); editText.setOnEditorActionListener(this); editText.addTextChangedListener(this); + + editText.setOnKeyListener( + (v, keyCode, event) -> { + // This is only triggered when input method doesn't handle delete key, which means the + // current + // input box is empty. + if (keyCode == KeyEvent.KEYCODE_DEL && event.getAction() == KeyEvent.ACTION_DOWN) { + String lastMessage = adapter.retrieveLastLocalMessage(); + if (lastMessage != null) { + isClearingInput = true; + editText.setText(lastMessage); + editText.setSelection(lastMessage.length()); + isClearingInput = false; + rttCallScreenDelegate.onLocalMessage("\b"); + return true; + } + return false; + } + return false; + }); recyclerView = view.findViewById(R.id.rtt_recycler_view); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); layoutManager.setStackFromEnd(true); @@ -207,7 +227,9 @@ public class RttChatFragment extends Fragment @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { - submitButton.performClick(); + if (!TextUtils.isEmpty(editText.getText())) { + submitButton.performClick(); + } return true; } return false; -- cgit v1.2.3