summaryrefslogtreecommitdiff
path: root/java/com/android/incallui/rtt/impl/RttChatFragment.java
diff options
context:
space:
mode:
authorwangqi <wangqi@google.com>2018-03-29 16:13:00 -0700
committerCopybara-Service <copybara-piper@google.com>2018-03-29 17:21:15 -0700
commit2789d6a0014209f7bafa8a8cc15f88b1edfa3f61 (patch)
tree91e691c7d40231dff2223be410624da8755a4f06 /java/com/android/incallui/rtt/impl/RttChatFragment.java
parentd6a2f81c52918e1d988979c83dcb779087c2ed13 (diff)
UI adjustment to RTT screen.
1. Don't close overflow menu after menu item is clicked. 2. Add correct shadow and animation to overflow menu. 3. Only scroll when remote message is updated if input box is empty. 4. Only hide keyboard if scrolling up is triggered by user. 5. Add paddingTop to recyclerView so that first message won't be covered by toolbar. Bug: 70177426 Test: manual PiperOrigin-RevId: 191002774 Change-Id: Ic69f80323e3d31d7853d4e8d0c6e4c100fe4a776
Diffstat (limited to 'java/com/android/incallui/rtt/impl/RttChatFragment.java')
-rw-r--r--java/com/android/incallui/rtt/impl/RttChatFragment.java53
1 files changed, 41 insertions, 12 deletions
diff --git a/java/com/android/incallui/rtt/impl/RttChatFragment.java b/java/com/android/incallui/rtt/impl/RttChatFragment.java
index 56ac2429c..a181f88f0 100644
--- a/java/com/android/incallui/rtt/impl/RttChatFragment.java
+++ b/java/com/android/incallui/rtt/impl/RttChatFragment.java
@@ -85,15 +85,6 @@ public class RttChatFragment extends Fragment
private ImageButton submitButton;
private boolean isClearingInput;
- private final OnScrollListener onScrollListener =
- new OnScrollListener() {
- @Override
- public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
- if (dy < 0) {
- UiUtil.hideKeyboardFrom(getContext(), editText);
- }
- }
- };
private InCallScreenDelegate inCallScreenDelegate;
private RttCallScreenDelegate rttCallScreenDelegate;
private InCallButtonUiDelegate inCallButtonUiDelegate;
@@ -105,6 +96,8 @@ public class RttChatFragment extends Fragment
private SecondaryInfo savedSecondaryInfo;
private TextView statusBanner;
private PrimaryInfo primaryInfo;
+ private boolean isUserScrolling;
+ private boolean shouldAutoScrolling;
/**
* Create a new instance of RttChatFragment.
@@ -193,7 +186,27 @@ public class RttChatFragment extends Fragment
recyclerView.setHasFixedSize(false);
adapter = new RttChatAdapter(getContext(), this, savedInstanceState);
recyclerView.setAdapter(adapter);
- recyclerView.addOnScrollListener(onScrollListener);
+ recyclerView.addOnScrollListener(
+ new OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(RecyclerView recyclerView, int i) {
+ if (i == RecyclerView.SCROLL_STATE_DRAGGING) {
+ isUserScrolling = true;
+ } else if (i == RecyclerView.SCROLL_STATE_IDLE) {
+ isUserScrolling = false;
+ // Auto scrolling for new messages should be resumed if it's scrolled to bottom.
+ shouldAutoScrolling = !recyclerView.canScrollVertically(1);
+ }
+ }
+
+ @Override
+ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
+ if (dy < 0 && isUserScrolling) {
+ UiUtil.hideKeyboardFrom(getContext(), editText);
+ }
+ }
+ });
+
submitButton = view.findViewById(R.id.rtt_chat_submit_button);
submitButton.setOnClickListener(
v -> {
@@ -202,6 +215,9 @@ public class RttChatFragment extends Fragment
editText.setText("");
isClearingInput = false;
rttCallScreenDelegate.onLocalMessage(Constants.BUBBLE_BREAKER);
+ // Auto scrolling for new messages should be resumed since user has submit current
+ // message.
+ shouldAutoScrolling = true;
});
submitButton.setEnabled(false);
endCallButton = view.findViewById(R.id.rtt_end_call_button);
@@ -276,8 +292,21 @@ public class RttChatFragment extends Fragment
}
@Override
- public void newMessageAdded() {
- recyclerView.smoothScrollToPosition(adapter.getItemCount());
+ public void onUpdateLocalMessage(int position) {
+ if (position < 0) {
+ return;
+ }
+ recyclerView.smoothScrollToPosition(position);
+ }
+
+ @Override
+ public void onUpdateRemoteMessage(int position) {
+ if (position < 0) {
+ return;
+ }
+ if (shouldAutoScrolling) {
+ recyclerView.smoothScrollToPosition(position);
+ }
}
@Override