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.phonelookup.PhoneLookupInfo;
22 import com.android.dialer.phonelookup.consolidator.PhoneLookupInfoConsolidator;
23 
24 /** Builds {@link NumberAttributes} from other data types. */
25 public final class NumberAttributesBuilder {
26 
27   /** Returns a {@link NumberAttributes.Builder} with info from {@link PhoneLookupInfo}. */
fromPhoneLookupInfo(PhoneLookupInfo phoneLookupInfo)28   public static NumberAttributes.Builder fromPhoneLookupInfo(PhoneLookupInfo phoneLookupInfo) {
29     PhoneLookupInfoConsolidator phoneLookupInfoConsolidator =
30         new PhoneLookupInfoConsolidator(phoneLookupInfo);
31     return NumberAttributes.newBuilder()
32         .setName(phoneLookupInfoConsolidator.getName())
33         .setPhotoUri(
34             !TextUtils.isEmpty(phoneLookupInfoConsolidator.getPhotoThumbnailUri())
35                 ? phoneLookupInfoConsolidator.getPhotoThumbnailUri()
36                 : phoneLookupInfoConsolidator.getPhotoUri())
37         .setPhotoId(phoneLookupInfoConsolidator.getPhotoId())
38         .setLookupUri(phoneLookupInfoConsolidator.getLookupUri())
39         .setNumberTypeLabel(phoneLookupInfoConsolidator.getNumberLabel())
40         .setIsBusiness(phoneLookupInfoConsolidator.isBusiness())
41         .setIsBlocked(phoneLookupInfoConsolidator.isBlocked())
42         .setIsSpam(phoneLookupInfoConsolidator.isSpam())
43         .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber())
44         .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isDefaultCp2InfoIncomplete())
45         .setContactSource(phoneLookupInfoConsolidator.getContactSource())
46         .setCanSupportCarrierVideoCall(phoneLookupInfoConsolidator.canSupportCarrierVideoCall())
47         .setGeolocation(phoneLookupInfoConsolidator.getGeolocation())
48         .setIsEmergencyNumber(phoneLookupInfoConsolidator.isEmergencyNumber());
49   }
50 }
51