1 /* 2 * Copyright (C) 2018 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.calllogutils; 18 19 import android.text.TextUtils; 20 import com.android.dialer.NumberAttributes; 21 import com.android.dialer.glidephotomanager.PhotoInfo; 22 import com.android.dialer.phonelookup.PhoneLookupInfo; 23 import com.android.dialer.phonelookup.consolidator.PhoneLookupInfoConsolidator; 24 25 /** Converts {@link NumberAttributes} to {@link PhotoInfo} */ 26 public final class NumberAttributesConverter { 27 28 /** Converts {@link NumberAttributes} to {@link PhotoInfo.Builder} */ toPhotoInfoBuilder(NumberAttributes numberAttributes)29 public static PhotoInfo.Builder toPhotoInfoBuilder(NumberAttributes numberAttributes) { 30 return PhotoInfo.builder() 31 .setName(numberAttributes.getName()) 32 .setPhotoUri(numberAttributes.getPhotoUri()) 33 .setPhotoId(numberAttributes.getPhotoId()) 34 .setLookupUri(numberAttributes.getLookupUri()) 35 .setIsBusiness(numberAttributes.getIsBusiness()) 36 .setIsSpam(numberAttributes.getIsSpam()) 37 .setIsVoicemail(numberAttributes.getIsVoicemail()) 38 .setIsBlocked(numberAttributes.getIsBlocked()); 39 } 40 41 /** Converts {@link PhoneLookupInfo} to {@link NumberAttributes.Builder} */ fromPhoneLookupInfo(PhoneLookupInfo phoneLookupInfo)42 public static NumberAttributes.Builder fromPhoneLookupInfo(PhoneLookupInfo phoneLookupInfo) { 43 PhoneLookupInfoConsolidator phoneLookupInfoConsolidator = 44 new PhoneLookupInfoConsolidator(phoneLookupInfo); 45 return NumberAttributes.newBuilder() 46 .setName(phoneLookupInfoConsolidator.getName()) 47 .setPhotoUri( 48 !TextUtils.isEmpty(phoneLookupInfoConsolidator.getPhotoThumbnailUri()) 49 ? phoneLookupInfoConsolidator.getPhotoThumbnailUri() 50 : phoneLookupInfoConsolidator.getPhotoUri()) 51 .setPhotoId(phoneLookupInfoConsolidator.getPhotoId()) 52 .setLookupUri(phoneLookupInfoConsolidator.getLookupUri()) 53 .setNumberTypeLabel(phoneLookupInfoConsolidator.getNumberLabel()) 54 .setIsBusiness(phoneLookupInfoConsolidator.isBusiness()) 55 .setIsVoicemail(phoneLookupInfoConsolidator.isVoicemail()) 56 .setIsBlocked(phoneLookupInfoConsolidator.isBlocked()) 57 .setIsSpam(phoneLookupInfoConsolidator.isSpam()) 58 .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber()) 59 .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isDefaultCp2InfoIncomplete()) 60 .setContactSource(phoneLookupInfoConsolidator.getContactSource()); 61 } 62 } 63