1 /* 2 * Copyright (C) 2020 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.car.dialer.ui.activecall; 18 19 import android.content.Context; 20 import android.graphics.drawable.Drawable; 21 import android.text.TextUtils; 22 import android.view.View; 23 import android.widget.ImageView; 24 import android.widget.TextView; 25 26 import androidx.recyclerview.widget.RecyclerView; 27 28 import com.android.car.apps.common.LetterTileDrawable; 29 import com.android.car.dialer.R; 30 import com.android.car.dialer.ui.view.ContactAvatarOutputlineProvider; 31 import com.android.car.telephony.common.CallDetail; 32 import com.android.car.telephony.common.TelecomUtils; 33 34 import com.bumptech.glide.Glide; 35 import com.bumptech.glide.request.RequestOptions; 36 import com.bumptech.glide.request.target.SimpleTarget; 37 import com.bumptech.glide.request.transition.Transition; 38 39 /** 40 * View holder for a user profile of a conference 41 */ 42 public class ConferenceProfileViewHolder extends RecyclerView.ViewHolder { 43 44 private ImageView mAvatar; 45 private TextView mTitle; 46 private TextView mNumber; 47 private Context mContext; 48 ConferenceProfileViewHolder(View v)49 ConferenceProfileViewHolder(View v) { 50 super(v); 51 52 mAvatar = v.findViewById(R.id.user_profile_avatar); 53 mAvatar.setOutlineProvider(ContactAvatarOutputlineProvider.get()); 54 mTitle = v.findViewById(R.id.user_profile_title); 55 mNumber = v.findViewById(R.id.user_profile_phone_number); 56 mContext = v.getContext(); 57 } 58 59 /** 60 * Binds call details to the profile views 61 */ bind(CallDetail callDetail)62 public void bind(CallDetail callDetail) { 63 String number = callDetail.getNumber(); 64 TelecomUtils.getPhoneNumberInfo(mContext, number) 65 .thenAcceptAsync((info) -> { 66 if (mContext == null) { 67 return; 68 } 69 70 mAvatar.setImageDrawable(TelecomUtils.createLetterTile(mContext, null, null)); 71 mTitle.setText(info.getDisplayName()); 72 73 String phoneNumberLabel = info.getTypeLabel(); 74 if (!phoneNumberLabel.isEmpty()) { 75 phoneNumberLabel += " "; 76 } 77 phoneNumberLabel += TelecomUtils.getFormattedNumber(mContext, number); 78 if (!TextUtils.isEmpty(phoneNumberLabel) 79 && !phoneNumberLabel.equals(info.getDisplayName())) { 80 mNumber.setText(phoneNumberLabel); 81 } else { 82 mNumber.setText(null); 83 } 84 85 LetterTileDrawable letterTile = TelecomUtils.createLetterTile( 86 mContext, info.getInitials(), info.getDisplayName()); 87 88 Glide.with(mContext) 89 .load(info.getAvatarUri()) 90 .apply(new RequestOptions().centerCrop().error(letterTile)) 91 .into(new SimpleTarget<Drawable>() { 92 @Override 93 public void onResourceReady(Drawable resource, 94 Transition<? super Drawable> glideAnimation) { 95 mAvatar.setImageDrawable(resource); 96 } 97 98 @Override 99 public void onLoadFailed(Drawable errorDrawable) { 100 mAvatar.setImageDrawable(letterTile); 101 } 102 }); 103 104 }, mContext.getMainExecutor()); 105 } 106 } 107