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.calldetails; 18 19 20 import android.content.Context; 21 import android.support.v7.widget.RecyclerView; 22 import android.view.View; 23 import com.android.dialer.calldetails.CallDetailsEntryViewHolder.CallDetailsEntryListener; 24 import com.android.dialer.calldetails.CallDetailsFooterViewHolder.DeleteCallDetailsListener; 25 import com.android.dialer.calldetails.CallDetailsHeaderViewHolder.CallDetailsHeaderListener; 26 import com.android.dialer.dialercontact.DialerContact; 27 import com.android.dialer.glidephotomanager.PhotoInfo; 28 import com.android.dialer.lettertile.LetterTileDrawable; 29 30 /** 31 * A {@link RecyclerView.Adapter} for {@link OldCallDetailsActivity}. 32 * 33 * <p>See {@link CallDetailsAdapterCommon} for logic shared between this adapter and {@link 34 * CallDetailsAdapter}. 35 */ 36 final class OldCallDetailsAdapter extends CallDetailsAdapterCommon { 37 38 /** Contains info to be shown in the header. */ 39 private final DialerContact contact; 40 OldCallDetailsAdapter( Context context, DialerContact contact, CallDetailsEntries callDetailsEntries, CallDetailsEntryListener callDetailsEntryListener, CallDetailsHeaderListener callDetailsHeaderListener, CallDetailsFooterViewHolder.ReportCallIdListener reportCallIdListener, DeleteCallDetailsListener deleteCallDetailsListener)41 OldCallDetailsAdapter( 42 Context context, 43 DialerContact contact, 44 CallDetailsEntries callDetailsEntries, 45 CallDetailsEntryListener callDetailsEntryListener, 46 CallDetailsHeaderListener callDetailsHeaderListener, 47 CallDetailsFooterViewHolder.ReportCallIdListener reportCallIdListener, 48 DeleteCallDetailsListener deleteCallDetailsListener) { 49 super( 50 context, 51 callDetailsEntries, 52 callDetailsEntryListener, 53 callDetailsHeaderListener, 54 reportCallIdListener, 55 deleteCallDetailsListener); 56 this.contact = contact; 57 } 58 59 @Override createCallDetailsHeaderViewHolder( View container, CallDetailsHeaderListener callDetailsHeaderListener)60 protected CallDetailsHeaderViewHolder createCallDetailsHeaderViewHolder( 61 View container, CallDetailsHeaderListener callDetailsHeaderListener) { 62 return new CallDetailsHeaderViewHolder( 63 container, contact.getNumber(), contact.getPostDialDigits(), callDetailsHeaderListener); 64 } 65 66 @Override bindCallDetailsHeaderViewHolder( CallDetailsHeaderViewHolder callDetailsHeaderViewHolder, int position)67 protected void bindCallDetailsHeaderViewHolder( 68 CallDetailsHeaderViewHolder callDetailsHeaderViewHolder, int position) { 69 callDetailsHeaderViewHolder.updateContactInfo(contact, getCallbackAction()); 70 callDetailsHeaderViewHolder.updateAssistedDialingInfo( 71 getCallDetailsEntries().getEntries(position)); 72 } 73 74 @Override getNumber()75 protected String getNumber() { 76 return contact.getNumber(); 77 } 78 79 @Override getPrimaryText()80 protected String getPrimaryText() { 81 return contact.getNameOrNumber(); 82 } 83 84 @Override getPhotoInfo()85 protected PhotoInfo getPhotoInfo() { 86 PhotoInfo.Builder builder = 87 PhotoInfo.newBuilder() 88 .setPhotoUri(contact.getPhotoUri()) 89 .setPhotoId(contact.getPhotoId()) 90 .setName(contact.getNameOrNumber()) 91 .setLookupUri(contact.getContactUri()); 92 switch (contact.getContactType()) { 93 case LetterTileDrawable.TYPE_VOICEMAIL: 94 builder.setIsVoicemail(true); 95 break; 96 case LetterTileDrawable.TYPE_BUSINESS: 97 builder.setIsBusiness(true); 98 break; 99 case LetterTileDrawable.TYPE_SPAM: 100 builder.setIsSpam(true); 101 break; 102 default: // fall out 103 } 104 return builder.build(); 105 } 106 } 107