1 /* 2 * Copyright (C) 2015 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.messaging.ui.conversationlist; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.database.Cursor; 22 import android.net.Uri; 23 import android.support.v7.widget.RecyclerView; 24 import android.view.LayoutInflater; 25 import android.view.ViewGroup; 26 27 import com.android.messaging.R; 28 import com.android.messaging.datamodel.data.ConversationListItemData; 29 import com.android.messaging.datamodel.data.ParticipantData; 30 import com.android.messaging.datamodel.data.PersonItemData; 31 import com.android.messaging.ui.CursorRecyclerAdapter; 32 import com.android.messaging.ui.PersonItemView; 33 import com.android.messaging.ui.PersonItemView.PersonItemViewListener; 34 import com.android.messaging.util.PhoneUtils; 35 36 /** 37 * Turn conversation rows into PeopleItemViews 38 */ 39 public class ShareIntentAdapter 40 extends CursorRecyclerAdapter<ShareIntentAdapter.ShareIntentViewHolder> { 41 42 public interface HostInterface { 43 void onConversationClicked(final ConversationListItemData conversationListItemData); 44 } 45 46 private final HostInterface mHostInterface; 47 48 public ShareIntentAdapter(final Context context, final Cursor cursor, 49 final HostInterface hostInterface) { 50 super(context, cursor, 0); 51 mHostInterface = hostInterface; 52 setHasStableIds(true); 53 } 54 55 @Override 56 public void bindViewHolder(final ShareIntentViewHolder holder, final Context context, 57 final Cursor cursor) { 58 holder.bind(cursor); 59 } 60 61 @Override 62 public ShareIntentViewHolder createViewHolder(final Context context, 63 final ViewGroup parent, final int viewType) { 64 final PersonItemView itemView = (PersonItemView) LayoutInflater.from(context).inflate( 65 R.layout.people_list_item_view, null); 66 return new ShareIntentViewHolder(itemView); 67 } 68 69 /** 70 * Holds a PersonItemView and keeps it synced with a ConversationListItemData. 71 */ 72 public class ShareIntentViewHolder extends RecyclerView.ViewHolder implements 73 PersonItemView.PersonItemViewListener { 74 private final ConversationListItemData mData = new ConversationListItemData(); 75 private final PersonItemData mItemData = new PersonItemData() { 76 @Override 77 public Uri getAvatarUri() { 78 return mData.getIcon() == null ? null : Uri.parse(mData.getIcon()); 79 } 80 81 @Override 82 public String getDisplayName() { 83 return mData.getName(); 84 } 85 86 @Override 87 public String getDetails() { 88 final String conversationName = mData.getName(); 89 final String conversationPhone = PhoneUtils.getDefault().formatForDisplay( 90 mData.getOtherParticipantNormalizedDestination()); 91 if (conversationPhone == null || conversationPhone.equals(conversationName)) { 92 return null; 93 } 94 return conversationPhone; 95 } 96 97 @Override 98 public Intent getClickIntent() { 99 return null; 100 } 101 102 @Override 103 public long getContactId() { 104 return ParticipantData.PARTICIPANT_CONTACT_ID_NOT_RESOLVED; 105 } 106 107 @Override 108 public String getLookupKey() { 109 return null; 110 } 111 112 @Override 113 public String getNormalizedDestination() { 114 return null; 115 } 116 }; 117 118 public ShareIntentViewHolder(final PersonItemView itemView) { 119 super(itemView); 120 itemView.setListener(this); 121 } 122 123 public void bind(Cursor cursor) { 124 mData.bind(cursor); 125 ((PersonItemView) itemView).bind(mItemData); 126 } 127 128 @Override 129 public void onPersonClicked(PersonItemData data) { 130 mHostInterface.onConversationClicked(mData); 131 } 132 133 @Override 134 public boolean onPersonLongClicked(PersonItemData data) { 135 return false; 136 } 137 } 138 } 139