From 305f7df04262dd01c41aa3d45676d5bcb874b9a1 Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 26 Apr 2018 10:57:09 -0700 Subject: Add advisory text to RTT call about transcript storage. Bug: 78519871 Test: RttChatFragmentTest.java PiperOrigin-RevId: 194421459 Change-Id: I4d04ee3045afdd4d5553032d7434ead280810543 --- .../incallui/rtt/impl/AdvisoryViewHolder.java | 29 ++++++ .../android/incallui/rtt/impl/RttChatAdapter.java | 107 ++++++++++++++++++--- .../android/incallui/rtt/impl/RttChatFragment.java | 1 + .../incallui/rtt/impl/res/layout/frag_rtt_chat.xml | 2 +- .../impl/res/layout/rtt_transcript_advisory.xml | 41 ++++++++ .../incallui/rtt/impl/res/values/strings.xml | 3 + 6 files changed, 167 insertions(+), 16 deletions(-) create mode 100644 java/com/android/incallui/rtt/impl/AdvisoryViewHolder.java create mode 100644 java/com/android/incallui/rtt/impl/res/layout/rtt_transcript_advisory.xml (limited to 'java/com/android/incallui/rtt/impl') diff --git a/java/com/android/incallui/rtt/impl/AdvisoryViewHolder.java b/java/com/android/incallui/rtt/impl/AdvisoryViewHolder.java new file mode 100644 index 000000000..8f081bebf --- /dev/null +++ b/java/com/android/incallui/rtt/impl/AdvisoryViewHolder.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui.rtt.impl; + +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView.ViewHolder; +import android.view.View; + +/** ViewHolder class for RTT advisory text. */ +public class AdvisoryViewHolder extends ViewHolder { + + public AdvisoryViewHolder(@NonNull View itemView) { + super(itemView); + } +} diff --git a/java/com/android/incallui/rtt/impl/RttChatAdapter.java b/java/com/android/incallui/rtt/impl/RttChatAdapter.java index 692266335..f1cde759c 100644 --- a/java/com/android/incallui/rtt/impl/RttChatAdapter.java +++ b/java/com/android/incallui/rtt/impl/RttChatAdapter.java @@ -18,8 +18,10 @@ package com.android.incallui.rtt.impl; import android.content.Context; import android.graphics.drawable.Drawable; +import android.support.annotation.IntDef; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.RecyclerView.ViewHolder; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -27,11 +29,29 @@ import android.view.ViewGroup; import com.android.dialer.common.LogUtil; import com.android.dialer.rtt.RttTranscript; import com.android.dialer.rtt.RttTranscriptMessage; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; /** Adapter class for holding RTT chat data. */ -public class RttChatAdapter extends RecyclerView.Adapter { +public class RttChatAdapter extends RecyclerView.Adapter { + + /** IntDef for the different types of rows that can be shown in the call log. */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ + RowType.ADVISORY, + RowType.MESSAGE, + }) + @interface RowType { + /** The transcript advisory message. */ + int ADVISORY = 1; + + /** RTT chat message. */ + int MESSAGE = 2; + } + + private static final int POSITION_ADVISORY = 0; private Drawable avatarDrawable; @@ -45,6 +65,7 @@ public class RttChatAdapter extends RecyclerView.Adapter rttMessages = new ArrayList<>(); private int lastIndexOfLocalMessage = -1; private final MessageListener messageListener; + private boolean shouldShowAdvisory; RttChatAdapter(Context context, MessageListener listener) { this.context = context; @@ -52,29 +73,54 @@ public class RttChatAdapter extends RecyclerView.Adapter 0) { - isSameGroup = rttMessages.get(i).isRemote == rttMessages.get(i - 1).isRemote; + public void onBindViewHolder(ViewHolder viewHolder, int itemPosition) { + switch (getItemViewType(itemPosition)) { + case RowType.ADVISORY: + return; + case RowType.MESSAGE: + RttChatMessageViewHolder rttChatMessageViewHolder = (RttChatMessageViewHolder) viewHolder; + int messagePosition = toMessagePosition(itemPosition); + boolean isSameGroup = false; + if (messagePosition > 0) { + isSameGroup = + rttMessages.get(messagePosition).isRemote + == rttMessages.get(messagePosition - 1).isRemote; + } + rttChatMessageViewHolder.setMessage( + rttMessages.get(messagePosition), isSameGroup, avatarDrawable); + return; + default: + throw new RuntimeException("Unknown row type."); } - rttChatMessageViewHolder.setMessage(rttMessages.get(i), isSameGroup, avatarDrawable); } @Override public int getItemCount() { - return rttMessages.size(); + return shouldShowAdvisory ? rttMessages.size() + 1 : rttMessages.size(); } private void updateCurrentLocalMessage(String newMessage) { @@ -96,11 +142,31 @@ public class RttChatAdapter extends RecyclerView.Adapter diff --git a/java/com/android/incallui/rtt/impl/res/layout/rtt_transcript_advisory.xml b/java/com/android/incallui/rtt/impl/res/layout/rtt_transcript_advisory.xml new file mode 100644 index 000000000..a2cf3e74f --- /dev/null +++ b/java/com/android/incallui/rtt/impl/res/layout/rtt_transcript_advisory.xml @@ -0,0 +1,41 @@ + + + + + + \ No newline at end of file diff --git a/java/com/android/incallui/rtt/impl/res/values/strings.xml b/java/com/android/incallui/rtt/impl/res/values/strings.xml index 1d09f5446..462eea563 100644 --- a/java/com/android/incallui/rtt/impl/res/values/strings.xml +++ b/java/com/android/incallui/rtt/impl/res/values/strings.xml @@ -30,4 +30,7 @@ Waiting for %s to join RTT call… + + The other party can see you typing. Transcripts stored on your device in the call history. + \ No newline at end of file -- cgit v1.2.3