• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.dialer.calldetails;
18 
19 import android.content.Context;
20 import android.net.Uri;
21 import android.support.v7.widget.RecyclerView;
22 import android.text.TextUtils;
23 import android.view.View;
24 import android.view.View.OnClickListener;
25 import android.widget.QuickContactBadge;
26 import android.widget.TextView;
27 import com.android.contacts.common.ContactPhotoManager;
28 import com.android.dialer.callcomposer.CallComposerContact;
29 import com.android.dialer.callintent.CallInitiationType;
30 import com.android.dialer.callintent.CallIntentBuilder;
31 import com.android.dialer.common.Assert;
32 import com.android.dialer.logging.DialerImpression;
33 import com.android.dialer.logging.Logger;
34 import com.android.dialer.util.DialerUtils;
35 
36 /** ViewHolder for Header/Contact in {@link CallDetailsActivity}. */
37 public class CallDetailsHeaderViewHolder extends RecyclerView.ViewHolder
38     implements OnClickListener {
39 
40   private final View callBackButton;
41   private final TextView nameView;
42   private final TextView numberView;
43   private final QuickContactBadge contactPhoto;
44   private final Context context;
45 
46   private CallComposerContact contact;
47 
CallDetailsHeaderViewHolder(View container)48   CallDetailsHeaderViewHolder(View container) {
49     super(container);
50     context = container.getContext();
51     callBackButton = container.findViewById(R.id.call_back_button);
52     nameView = (TextView) container.findViewById(R.id.contact_name);
53     numberView = (TextView) container.findViewById(R.id.phone_number);
54     contactPhoto = (QuickContactBadge) container.findViewById(R.id.quick_contact_photo);
55     callBackButton.setOnClickListener(this);
56   }
57 
58   /** Populates the contact info fields based on the current contact information. */
updateContactInfo(CallComposerContact contact)59   void updateContactInfo(CallComposerContact contact) {
60     this.contact = contact;
61     ContactPhotoManager.getInstance(context)
62         .loadDialerThumbnailOrPhoto(
63             contactPhoto,
64             contact.hasContactUri() ? Uri.parse(contact.getContactUri()) : null,
65             contact.getPhotoId(),
66             contact.hasPhotoUri() ? Uri.parse(contact.getPhotoUri()) : null,
67             contact.getNameOrNumber(),
68             contact.getContactType());
69 
70     contactPhoto.setContentDescription(
71         context.getString(R.string.description_contact_photo_details, contact.getNameOrNumber()));
72     nameView.setText(contact.getNameOrNumber());
73     if (!TextUtils.isEmpty(contact.getDisplayNumber())) {
74       numberView.setVisibility(View.VISIBLE);
75       String secondaryInfo =
76           TextUtils.isEmpty(contact.getNumberLabel())
77               ? contact.getDisplayNumber()
78               : context.getString(
79                   com.android.contacts.common.R.string.call_subject_type_and_number,
80                   contact.getNumberLabel(),
81                   contact.getDisplayNumber());
82       numberView.setText(secondaryInfo);
83     } else {
84       numberView.setVisibility(View.GONE);
85       numberView.setText(null);
86     }
87 
88     if (TextUtils.isEmpty(contact.getNumber())) {
89       callBackButton.setVisibility(View.GONE);
90     }
91   }
92 
93   @Override
onClick(View view)94   public void onClick(View view) {
95     if (view == callBackButton) {
96       Logger.get(view.getContext()).logImpression(DialerImpression.Type.CALL_DETAILS_CALL_BACK);
97       DialerUtils.startActivityWithErrorToast(
98           view.getContext(),
99           new CallIntentBuilder(contact.getNumber(), CallInitiationType.Type.CALL_DETAILS).build());
100     } else {
101       Assert.fail("View OnClickListener not implemented: " + view);
102     }
103   }
104 }
105