1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.incallui.rtt.impl; 18 19 import android.content.res.Resources; 20 import android.support.v7.widget.RecyclerView.ViewHolder; 21 import android.view.Gravity; 22 import android.view.View; 23 import android.widget.ImageView; 24 import android.widget.LinearLayout; 25 import android.widget.LinearLayout.LayoutParams; 26 import android.widget.TextView; 27 28 /** ViewHolder class for RTT chat message bubble. */ 29 public class RttChatMessageViewHolder extends ViewHolder { 30 31 private final TextView messageTextView; 32 private final Resources resources; 33 private final ImageView avatarImageView; 34 private final View container; 35 RttChatMessageViewHolder(View view)36 RttChatMessageViewHolder(View view) { 37 super(view); 38 container = view.findViewById(R.id.rtt_chat_message_container); 39 messageTextView = view.findViewById(R.id.rtt_chat_message); 40 avatarImageView = view.findViewById(R.id.rtt_chat_avatar); 41 resources = view.getResources(); 42 } 43 setMessage(RttChatMessage message, boolean isSameGroup)44 void setMessage(RttChatMessage message, boolean isSameGroup) { 45 messageTextView.setText(message.getContent()); 46 LinearLayout.LayoutParams params = (LayoutParams) container.getLayoutParams(); 47 params.gravity = message.isRemote ? Gravity.START : Gravity.END; 48 params.topMargin = 49 isSameGroup 50 ? resources.getDimensionPixelSize(R.dimen.rtt_same_group_message_margin_top) 51 : resources.getDimensionPixelSize(R.dimen.rtt_message_margin_top); 52 container.setLayoutParams(params); 53 messageTextView.setEnabled(message.isRemote); 54 if (message.isRemote) { 55 if (isSameGroup) { 56 avatarImageView.setVisibility(View.INVISIBLE); 57 } else { 58 avatarImageView.setVisibility(View.VISIBLE); 59 avatarImageView.setImageResource(R.drawable.product_logo_avatar_anonymous_white_color_120); 60 } 61 } else { 62 avatarImageView.setVisibility(View.GONE); 63 } 64 } 65 } 66