From 00cdd7b552b3fde4c9cbc1c4e4d0edc1b54df365 Mon Sep 17 00:00:00 2001 From: linyuh Date: Fri, 18 May 2018 13:32:36 -0700 Subject: Remove duplicate code when constructing PhotoInfo proto. Bug: 79770053 Test: Existing tests PiperOrigin-RevId: 197192087 Change-Id: I44c60d13c83b3e23dc141fd9e9b88e108687bf96 --- .../calllogutils/NumberAttributesBuilder.java | 50 +++++++++++++++++ .../calllogutils/NumberAttributesConverter.java | 63 ---------------------- .../dialer/calllogutils/PhotoInfoBuilder.java | 57 ++++++++++++++++++++ 3 files changed, 107 insertions(+), 63 deletions(-) create mode 100644 java/com/android/dialer/calllogutils/NumberAttributesBuilder.java delete mode 100644 java/com/android/dialer/calllogutils/NumberAttributesConverter.java create mode 100644 java/com/android/dialer/calllogutils/PhotoInfoBuilder.java (limited to 'java/com/android/dialer/calllogutils') diff --git a/java/com/android/dialer/calllogutils/NumberAttributesBuilder.java b/java/com/android/dialer/calllogutils/NumberAttributesBuilder.java new file mode 100644 index 000000000..015d59fd8 --- /dev/null +++ b/java/com/android/dialer/calllogutils/NumberAttributesBuilder.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.calllogutils; + +import android.text.TextUtils; +import com.android.dialer.NumberAttributes; +import com.android.dialer.phonelookup.PhoneLookupInfo; +import com.android.dialer.phonelookup.consolidator.PhoneLookupInfoConsolidator; + +/** Builds {@link NumberAttributes} from other data types. */ +public final class NumberAttributesBuilder { + + /** Returns a {@link NumberAttributes.Builder} with info from {@link PhoneLookupInfo}. */ + public static NumberAttributes.Builder fromPhoneLookupInfo(PhoneLookupInfo phoneLookupInfo) { + PhoneLookupInfoConsolidator phoneLookupInfoConsolidator = + new PhoneLookupInfoConsolidator(phoneLookupInfo); + return NumberAttributes.newBuilder() + .setName(phoneLookupInfoConsolidator.getName()) + .setPhotoUri( + !TextUtils.isEmpty(phoneLookupInfoConsolidator.getPhotoThumbnailUri()) + ? phoneLookupInfoConsolidator.getPhotoThumbnailUri() + : phoneLookupInfoConsolidator.getPhotoUri()) + .setPhotoId(phoneLookupInfoConsolidator.getPhotoId()) + .setLookupUri(phoneLookupInfoConsolidator.getLookupUri()) + .setNumberTypeLabel(phoneLookupInfoConsolidator.getNumberLabel()) + .setIsBusiness(phoneLookupInfoConsolidator.isBusiness()) + .setIsBlocked(phoneLookupInfoConsolidator.isBlocked()) + .setIsSpam(phoneLookupInfoConsolidator.isSpam()) + .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber()) + .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isDefaultCp2InfoIncomplete()) + .setContactSource(phoneLookupInfoConsolidator.getContactSource()) + .setCanSupportCarrierVideoCall(phoneLookupInfoConsolidator.canSupportCarrierVideoCall()) + .setGeolocation(phoneLookupInfoConsolidator.getGeolocation()) + .setIsEmergencyNumber(phoneLookupInfoConsolidator.isEmergencyNumber()); + } +} diff --git a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java deleted file mode 100644 index 8081c4b3f..000000000 --- a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.calllogutils; - -import android.text.TextUtils; -import com.android.dialer.NumberAttributes; -import com.android.dialer.glidephotomanager.PhotoInfo; -import com.android.dialer.phonelookup.PhoneLookupInfo; -import com.android.dialer.phonelookup.consolidator.PhoneLookupInfoConsolidator; - -/** Converts {@link NumberAttributes} to {@link PhotoInfo} */ -public final class NumberAttributesConverter { - - /** Converts {@link NumberAttributes} to {@link PhotoInfo.Builder} */ - public static PhotoInfo.Builder toPhotoInfoBuilder(NumberAttributes numberAttributes) { - return PhotoInfo.newBuilder() - .setName(numberAttributes.getName()) - .setPhotoUri(numberAttributes.getPhotoUri()) - .setPhotoId(numberAttributes.getPhotoId()) - .setLookupUri(numberAttributes.getLookupUri()) - .setIsBusiness(numberAttributes.getIsBusiness()) - .setIsSpam(numberAttributes.getIsSpam()) - .setIsBlocked(numberAttributes.getIsBlocked()); - } - - /** Converts {@link PhoneLookupInfo} to {@link NumberAttributes.Builder} */ - public static NumberAttributes.Builder fromPhoneLookupInfo(PhoneLookupInfo phoneLookupInfo) { - PhoneLookupInfoConsolidator phoneLookupInfoConsolidator = - new PhoneLookupInfoConsolidator(phoneLookupInfo); - return NumberAttributes.newBuilder() - .setName(phoneLookupInfoConsolidator.getName()) - .setPhotoUri( - !TextUtils.isEmpty(phoneLookupInfoConsolidator.getPhotoThumbnailUri()) - ? phoneLookupInfoConsolidator.getPhotoThumbnailUri() - : phoneLookupInfoConsolidator.getPhotoUri()) - .setPhotoId(phoneLookupInfoConsolidator.getPhotoId()) - .setLookupUri(phoneLookupInfoConsolidator.getLookupUri()) - .setNumberTypeLabel(phoneLookupInfoConsolidator.getNumberLabel()) - .setIsBusiness(phoneLookupInfoConsolidator.isBusiness()) - .setIsBlocked(phoneLookupInfoConsolidator.isBlocked()) - .setIsSpam(phoneLookupInfoConsolidator.isSpam()) - .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber()) - .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isDefaultCp2InfoIncomplete()) - .setContactSource(phoneLookupInfoConsolidator.getContactSource()) - .setCanSupportCarrierVideoCall(phoneLookupInfoConsolidator.canSupportCarrierVideoCall()) - .setGeolocation(phoneLookupInfoConsolidator.getGeolocation()) - .setIsEmergencyNumber(phoneLookupInfoConsolidator.isEmergencyNumber()); - } -} diff --git a/java/com/android/dialer/calllogutils/PhotoInfoBuilder.java b/java/com/android/dialer/calllogutils/PhotoInfoBuilder.java new file mode 100644 index 000000000..8d193bfd3 --- /dev/null +++ b/java/com/android/dialer/calllogutils/PhotoInfoBuilder.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.calllogutils; + +import android.provider.CallLog.Calls; +import android.support.v4.os.BuildCompat; +import com.android.dialer.NumberAttributes; +import com.android.dialer.calllog.model.CoalescedRow; +import com.android.dialer.glidephotomanager.PhotoInfo; +import com.android.dialer.voicemail.model.VoicemailEntry; + +/** Builds {@link PhotoInfo} from other data types. */ +public final class PhotoInfoBuilder { + + /** Returns a {@link PhotoInfo.Builder} with info from {@link CoalescedRow}. */ + public static PhotoInfo.Builder fromCoalescedRow(CoalescedRow coalescedRow) { + return fromNumberAttributes(coalescedRow.getNumberAttributes()) + .setFormattedNumber(coalescedRow.getFormattedNumber()) + .setIsVoicemail(coalescedRow.getIsVoicemailCall()) + .setIsVideo((coalescedRow.getFeatures() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO) + .setIsRtt( + BuildCompat.isAtLeastP() + && (coalescedRow.getFeatures() & Calls.FEATURES_RTT) == Calls.FEATURES_RTT); + } + + /** Returns a {@link PhotoInfo.Builder} with info from {@link VoicemailEntry}. */ + public static PhotoInfo.Builder fromVoicemailEntry(VoicemailEntry voicemailEntry) { + return fromNumberAttributes(voicemailEntry.getNumberAttributes()) + .setFormattedNumber(voicemailEntry.getFormattedNumber()); + } + + /** Returns a {@link PhotoInfo.Builder} with info from {@link NumberAttributes}. */ + private static PhotoInfo.Builder fromNumberAttributes(NumberAttributes numberAttributes) { + return PhotoInfo.newBuilder() + .setName(numberAttributes.getName()) + .setPhotoUri(numberAttributes.getPhotoUri()) + .setPhotoId(numberAttributes.getPhotoId()) + .setLookupUri(numberAttributes.getLookupUri()) + .setIsBusiness(numberAttributes.getIsBusiness()) + .setIsBlocked(numberAttributes.getIsBlocked()) + .setIsSpam(numberAttributes.getIsSpam()); + } +} -- cgit v1.2.3