• 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.net.Uri;
20 import android.provider.ContactsContract.QuickContact;
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 
29 /** View holder for a contact. */
30 final class ContactViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
31 
32   private final TextView header;
33   private final TextView name;
34   private final QuickContactBadge photo;
35 
36   private String headerText;
37   private Uri contactUri;
38 
ContactViewHolder(View itemView)39   public ContactViewHolder(View itemView) {
40     super(itemView);
41     itemView.findViewById(R.id.click_target).setOnClickListener(this);
42     header = (TextView) itemView.findViewById(R.id.header);
43     name = (TextView) itemView.findViewById(R.id.contact_name);
44     photo = (QuickContactBadge) itemView.findViewById(R.id.photo);
45   }
46 
47   /**
48    * Binds the ViewHolder with relevant data.
49    *
50    * @param headerText populates the header view.
51    * @param displayName populates the name view.
52    * @param contactUri to be shown by the contact card on photo click.
53    * @param showHeader if header view should be shown {@code True}, {@code False} otherwise.
54    */
bind(String headerText, String displayName, Uri contactUri, boolean showHeader)55   public void bind(String headerText, String displayName, Uri contactUri, boolean showHeader) {
56     Assert.checkArgument(!TextUtils.isEmpty(displayName));
57     this.contactUri = contactUri;
58     this.headerText = headerText;
59 
60     name.setText(displayName);
61     header.setText(headerText);
62     header.setVisibility(showHeader ? View.VISIBLE : View.INVISIBLE);
63   }
64 
getPhoto()65   public QuickContactBadge getPhoto() {
66     return photo;
67   }
68 
getHeader()69   public String getHeader() {
70     return headerText;
71   }
72 
getHeaderView()73   public TextView getHeaderView() {
74     return header;
75   }
76 
77   @Override
onClick(View v)78   public void onClick(View v) {
79     QuickContact.showQuickContact(
80         photo.getContext(), photo, contactUri, QuickContact.MODE_LARGE, null /* excludeMimes */);
81   }
82 }
83