• 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.contactsfragment;
18 
19 import android.content.Context;
20 import android.net.Uri;
21 import android.provider.ContactsContract.QuickContact;
22 import android.support.v7.widget.RecyclerView;
23 import android.text.TextUtils;
24 import android.view.View;
25 import android.view.View.OnClickListener;
26 import android.widget.QuickContactBadge;
27 import android.widget.TextView;
28 import com.android.dialer.common.Assert;
29 import com.android.dialer.logging.InteractionEvent;
30 import com.android.dialer.logging.Logger;
31 
32 /** View holder for a contact. */
33 final class ContactViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
34 
35   private final TextView header;
36   private final TextView name;
37   private final QuickContactBadge photo;
38   private final Context context;
39 
40   private String headerText;
41   private Uri contactUri;
42 
ContactViewHolder(View itemView)43   public ContactViewHolder(View itemView) {
44     super(itemView);
45     context = itemView.getContext();
46     itemView.findViewById(R.id.click_target).setOnClickListener(this);
47     header = (TextView) itemView.findViewById(R.id.header);
48     name = (TextView) itemView.findViewById(R.id.contact_name);
49     photo = (QuickContactBadge) itemView.findViewById(R.id.photo);
50   }
51 
52   /**
53    * Binds the ViewHolder with relevant data.
54    *
55    * @param headerText populates the header view.
56    * @param displayName populates the name view.
57    * @param contactUri to be shown by the contact card on photo click.
58    * @param showHeader if header view should be shown {@code True}, {@code False} otherwise.
59    */
bind(String headerText, String displayName, Uri contactUri, boolean showHeader)60   public void bind(String headerText, String displayName, Uri contactUri, boolean showHeader) {
61     Assert.checkArgument(!TextUtils.isEmpty(displayName));
62     this.contactUri = contactUri;
63     this.headerText = headerText;
64 
65     name.setText(displayName);
66     header.setText(headerText);
67     header.setVisibility(showHeader ? View.VISIBLE : View.INVISIBLE);
68 
69     Logger.get(context)
70         .logQuickContactOnTouch(
71             photo, InteractionEvent.Type.OPEN_QUICK_CONTACT_FROM_CONTACTS_FRAGMENT_BADGE, true);
72   }
73 
getPhoto()74   public QuickContactBadge getPhoto() {
75     return photo;
76   }
77 
getHeader()78   public String getHeader() {
79     return headerText;
80   }
81 
getHeaderView()82   public TextView getHeaderView() {
83     return header;
84   }
85 
86   @Override
onClick(View v)87   public void onClick(View v) {
88     Logger.get(context)
89         .logInteraction(InteractionEvent.Type.OPEN_QUICK_CONTACT_FROM_CONTACTS_FRAGMENT_ITEM);
90     QuickContact.showQuickContact(
91         photo.getContext(), photo, contactUri, QuickContact.MODE_LARGE, null /* excludeMimes */);
92   }
93 }
94