• 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.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.dialer.common.Assert;
28 import com.android.dialer.contactsfragment.ContactsFragment.OnContactSelectedListener;
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   private final OnContactSelectedListener onContactSelectedListener;
40 
41   private String headerText;
42   private Uri contactUri;
43   private long contactId;
44 
ContactViewHolder(View itemView, OnContactSelectedListener onContactSelectedListener)45   ContactViewHolder(View itemView, OnContactSelectedListener onContactSelectedListener) {
46     super(itemView);
47     this.onContactSelectedListener = Assert.isNotNull(onContactSelectedListener);
48     context = itemView.getContext();
49     itemView.findViewById(R.id.click_target).setOnClickListener(this);
50     header = itemView.findViewById(R.id.header);
51     name = itemView.findViewById(R.id.contact_name);
52     photo = itemView.findViewById(R.id.photo);
53   }
54 
55   /**
56    * Binds the ViewHolder with relevant data.
57    *
58    * @param headerText populates the header view.
59    * @param displayName populates the name view.
60    * @param contactUri to be shown by the contact card on photo click.
61    * @param showHeader if header view should be shown {@code True}, {@code False} otherwise.
62    */
bind( String headerText, String displayName, Uri contactUri, long contactId, boolean showHeader)63   public void bind(
64       String headerText, String displayName, Uri contactUri, long contactId, boolean showHeader) {
65     Assert.checkArgument(!TextUtils.isEmpty(displayName));
66     this.contactUri = contactUri;
67     this.contactId = contactId;
68     this.headerText = headerText;
69 
70     name.setText(displayName);
71     header.setText(headerText);
72     header.setVisibility(showHeader ? View.VISIBLE : View.INVISIBLE);
73 
74     Logger.get(context)
75         .logQuickContactOnTouch(
76             photo, InteractionEvent.Type.OPEN_QUICK_CONTACT_FROM_CONTACTS_FRAGMENT_BADGE, true);
77   }
78 
getPhoto()79   public QuickContactBadge getPhoto() {
80     return photo;
81   }
82 
getHeader()83   public String getHeader() {
84     return headerText;
85   }
86 
getHeaderView()87   public TextView getHeaderView() {
88     return header;
89   }
90 
91   @Override
onClick(View v)92   public void onClick(View v) {
93     onContactSelectedListener.onContactSelected(photo, contactUri, contactId);
94   }
95 }
96