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.calllog.ui.menu; 18 19 import android.content.Context; 20 import android.text.TextUtils; 21 import com.android.dialer.calldetails.CallDetailsActivity; 22 import com.android.dialer.calldetails.CallDetailsHeaderInfo; 23 import com.android.dialer.calllog.model.CoalescedRow; 24 import com.android.dialer.calllogutils.CallLogEntryText; 25 import com.android.dialer.calllogutils.PhotoInfoBuilder; 26 import com.android.dialer.historyitemactions.HistoryItemActionModule; 27 import com.android.dialer.historyitemactions.HistoryItemActionModuleInfo; 28 import com.android.dialer.historyitemactions.HistoryItemActionModulesBuilder; 29 import com.android.dialer.historyitemactions.IntentModule; 30 import com.android.dialer.phonenumberutil.PhoneNumberHelper; 31 import java.util.List; 32 33 /** 34 * Configures the modules for the bottom sheet; these are the rows below the top row (contact info) 35 * in the bottom sheet. 36 */ 37 final class Modules { 38 39 /** 40 * Returns a list of {@link HistoryItemActionModule HistoryItemActionModules}, which are items in 41 * the bottom sheet. 42 */ fromRow(Context context, CoalescedRow row)43 static List<HistoryItemActionModule> fromRow(Context context, CoalescedRow row) { 44 HistoryItemActionModulesBuilder modulesBuilder = 45 new HistoryItemActionModulesBuilder(context, buildModuleInfo(row)); 46 47 48 // TODO(zachh): Module for CallComposer. 49 50 if (PhoneNumberHelper.canPlaceCallsTo( 51 row.getNumber().getNormalizedNumber(), row.getNumberPresentation())) { 52 modulesBuilder 53 .addModuleForVoiceCall() 54 .addModuleForVideoCall() 55 .addModuleForSendingTextMessage() 56 .addModuleForDivider() 57 .addModuleForAddingToContacts() 58 .addModuleForBlockedOrSpamNumber() 59 .addModuleForCopyingNumber(); 60 } 61 62 List<HistoryItemActionModule> modules = modulesBuilder.build(); 63 64 // Add modules only available in the call log. 65 modules.add(createModuleForAccessingCallDetails(context, row)); 66 modules.add(new DeleteCallLogItemModule(context, row.getCoalescedIds())); 67 return modules; 68 } 69 createModuleForAccessingCallDetails( Context context, CoalescedRow row)70 private static HistoryItemActionModule createModuleForAccessingCallDetails( 71 Context context, CoalescedRow row) { 72 boolean canReportAsInvalidNumber = 73 !row.getIsVoicemailCall() && row.getNumberAttributes().getCanReportAsInvalidNumber(); 74 75 return new IntentModule( 76 context, 77 CallDetailsActivity.newInstance( 78 context, 79 row.getCoalescedIds(), 80 createCallDetailsHeaderInfoFromRow(context, row), 81 canReportAsInvalidNumber, 82 canSupportAssistedDialing(row)), 83 R.string.call_details_menu_label, 84 R.drawable.quantum_ic_info_outline_vd_theme_24); 85 } 86 createCallDetailsHeaderInfoFromRow( Context context, CoalescedRow row)87 private static CallDetailsHeaderInfo createCallDetailsHeaderInfoFromRow( 88 Context context, CoalescedRow row) { 89 return CallDetailsHeaderInfo.newBuilder() 90 .setDialerPhoneNumber(row.getNumber()) 91 .setPhotoInfo(PhotoInfoBuilder.fromCoalescedRow(context, row)) 92 .setPrimaryText(CallLogEntryText.buildPrimaryText(context, row).toString()) 93 .setSecondaryText( 94 CallLogEntryText.buildSecondaryTextForBottomSheet(context, row).toString()) 95 .build(); 96 } 97 canSupportAssistedDialing(CoalescedRow row)98 private static boolean canSupportAssistedDialing(CoalescedRow row) { 99 return !TextUtils.isEmpty(row.getNumberAttributes().getLookupUri()); 100 } 101 buildModuleInfo(CoalescedRow row)102 private static HistoryItemActionModuleInfo buildModuleInfo(CoalescedRow row) { 103 return HistoryItemActionModuleInfo.newBuilder() 104 .setNormalizedNumber(row.getNumber().getNormalizedNumber()) 105 .setCountryIso(row.getNumber().getCountryIso()) 106 .setName(row.getNumberAttributes().getName()) 107 .setCallType(row.getCallType()) 108 .setFeatures(row.getFeatures()) 109 .setLookupUri(row.getNumberAttributes().getLookupUri()) 110 .setPhoneAccountComponentName(row.getPhoneAccountComponentName()) 111 .setCanReportAsInvalidNumber(row.getNumberAttributes().getCanReportAsInvalidNumber()) 112 .setCanSupportAssistedDialing(canSupportAssistedDialing(row)) 113 .setCanSupportCarrierVideoCall(row.getNumberAttributes().getCanSupportCarrierVideoCall()) 114 .setIsBlocked(row.getNumberAttributes().getIsBlocked()) 115 .setIsEmergencyNumber(row.getNumberAttributes().getIsEmergencyNumber()) 116 .setIsSpam(row.getNumberAttributes().getIsSpam()) 117 .setIsVoicemailCall(row.getIsVoicemailCall()) 118 .setContactSource(row.getNumberAttributes().getContactSource()) 119 .setHost(HistoryItemActionModuleInfo.Host.CALL_LOG) 120 .build(); 121 } 122 } 123