1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/* 2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project 3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License"); 5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License. 6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at 7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * http://www.apache.org/licenses/LICENSE-2.0 9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software 11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS, 12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and 14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License. 15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.ui.conversationlist; 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Intent; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.database.Cursor; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.net.Uri; 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.support.v7.widget.RecyclerView; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.LayoutInflater; 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.ViewGroup; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.R; 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.data.ConversationListItemData; 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.data.ParticipantData; 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.data.PersonItemData; 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.ui.CursorRecyclerAdapter; 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.ui.PersonItemView; 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.ui.PersonItemView.PersonItemViewListener; 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.PhoneUtils; 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/** 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Turn conversation rows into PeopleItemViews 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class ShareIntentAdapter 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd extends CursorRecyclerAdapter<ShareIntentAdapter.ShareIntentViewHolder> { 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public interface HostInterface { 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd void onConversationClicked(final ConversationListItemData conversationListItemData); 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private final HostInterface mHostInterface; 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public ShareIntentAdapter(final Context context, final Cursor cursor, 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final HostInterface hostInterface) { 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super(context, cursor, 0); 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mHostInterface = hostInterface; 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd setHasStableIds(true); 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void bindViewHolder(final ShareIntentViewHolder holder, final Context context, 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final Cursor cursor) { 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd holder.bind(cursor); 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public ShareIntentViewHolder createViewHolder(final Context context, 63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ViewGroup parent, final int viewType) { 64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final PersonItemView itemView = (PersonItemView) LayoutInflater.from(context).inflate( 65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd R.layout.people_list_item_view, null); 66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new ShareIntentViewHolder(itemView); 67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Holds a PersonItemView and keeps it synced with a ConversationListItemData. 71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public class ShareIntentViewHolder extends RecyclerView.ViewHolder implements 73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PersonItemView.PersonItemViewListener { 74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private final ConversationListItemData mData = new ConversationListItemData(); 75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private final PersonItemData mItemData = new PersonItemData() { 76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public Uri getAvatarUri() { 78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mData.getIcon() == null ? null : Uri.parse(mData.getIcon()); 79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getDisplayName() { 83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mData.getName(); 84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getDetails() { 88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String conversationName = mData.getName(); 89d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String conversationPhone = PhoneUtils.getDefault().formatForDisplay( 90d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mData.getOtherParticipantNormalizedDestination()); 91d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (conversationPhone == null || conversationPhone.equals(conversationName)) { 92d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 93d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 94d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return conversationPhone; 95d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 96d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 97d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 98d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public Intent getClickIntent() { 99d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 100d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 101d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 102d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 103d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public long getContactId() { 104d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return ParticipantData.PARTICIPANT_CONTACT_ID_NOT_RESOLVED; 105d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 106d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 107d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 108d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getLookupKey() { 109d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 110d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 111d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 112d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 113d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getNormalizedDestination() { 114d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 115d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 116d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }; 117d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 118d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public ShareIntentViewHolder(final PersonItemView itemView) { 119d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super(itemView); 120d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd itemView.setListener(this); 121d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 122d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 123d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void bind(Cursor cursor) { 124d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mData.bind(cursor); 125d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ((PersonItemView) itemView).bind(mItemData); 126d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 127d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 128d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 129d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onPersonClicked(PersonItemData data) { 130d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mHostInterface.onConversationClicked(mData); 131d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 132d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 133d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 134d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean onPersonLongClicked(PersonItemData data) { 135d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return false; 136d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 137d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 138d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd} 139