Delay computing of PhoneNumber as much as possible.
Computing PhoneNumber is an expensive operation. We want to make that
asynchronous and it is currently only used together with the offline
geocoder, which also needs to be asynchronous.
Therefore, delay the call to generate a PhoneNumer until it is actually
needed, i.e., at the same time as computing the geocode. This means we
only need to make one call asynchronous instead of many.
Change-Id: Iebebf098be713281b2976c72506e480466fb65d4
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index d2c193e..3189b2d 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -419,8 +419,7 @@
numberText = candidateNumberText;
}
}
- return new PhoneCallDetails(number, numberText,
- mPhoneNumberHelper.parsePhoneNumber(number, countryIso),
+ return new PhoneCallDetails(number, numberText, countryIso,
new int[]{ callType }, date, duration,
nameText, numberType, numberLabel, personId, photoUri);
} finally {
diff --git a/src/com/android/contacts/PhoneCallDetails.java b/src/com/android/contacts/PhoneCallDetails.java
index 0672673..347a303 100644
--- a/src/com/android/contacts/PhoneCallDetails.java
+++ b/src/com/android/contacts/PhoneCallDetails.java
@@ -16,8 +16,6 @@
package com.android.contacts;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
-
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -30,8 +28,8 @@
public final CharSequence number;
/** The formatted version of {@link #number}. */
public final CharSequence formattedNumber;
- /** The structured phone number corresponding to {@link #number}. */
- public final PhoneNumber structuredPhoneNumber;
+ /** The country corresponding with the phone number. */
+ public final String countryIso;
/**
* The type of calls, as defined in the call log table, e.g., {@link Calls#INCOMING_TYPE}.
* <p>
@@ -58,19 +56,18 @@
/** Create the details for a call with a number not associated with a contact. */
public PhoneCallDetails(CharSequence number, CharSequence formattedNumber,
- PhoneNumber structuredPhoneNumber, int[] callTypes, long date, long duration) {
- this(number, formattedNumber, structuredPhoneNumber, callTypes, date, duration,
- "", 0, "", -1L, null);
+ String countryIso, int[] callTypes, long date, long duration) {
+ this(number, formattedNumber, countryIso, callTypes, date, duration, "", 0, "", -1L, null);
}
/** Create the details for a call with a number associated with a contact. */
public PhoneCallDetails(CharSequence number, CharSequence formattedNumber,
- PhoneNumber structuredPhoneNumber, int[] callTypes, long date, long duration,
+ String countryIso, int[] callTypes, long date, long duration,
CharSequence name, int numberType, CharSequence numberLabel, long personId,
Uri photoUri) {
this.number = number;
this.formattedNumber = formattedNumber;
- this.structuredPhoneNumber = structuredPhoneNumber;
+ this.countryIso = countryIso;
this.callTypes = callTypes;
this.date = date;
this.duration = duration;
diff --git a/src/com/android/contacts/PhoneCallDetailsHelper.java b/src/com/android/contacts/PhoneCallDetailsHelper.java
index db3928e..2c36cec 100644
--- a/src/com/android/contacts/PhoneCallDetailsHelper.java
+++ b/src/com/android/contacts/PhoneCallDetailsHelper.java
@@ -118,7 +118,9 @@
mPhoneNumberHelper.getDisplayNumber(details.number, details.formattedNumber);
if (TextUtils.isEmpty(details.name)) {
nameText = displayNumber;
- numberText = mPhoneNumberHelper.getGeocodeForNumber(details.structuredPhoneNumber);
+ numberText = mPhoneNumberHelper.getGeocodeForNumber(
+ mPhoneNumberHelper.parsePhoneNumber(
+ details.number.toString(), details.countryIso));
} else {
nameText = details.name;
if (numberFormattedLabel != null) {
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index e2e44a8..c04e62b 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -29,7 +29,6 @@
import com.android.contacts.util.ExpirableCache;
import com.android.internal.telephony.CallerInfo;
import com.google.common.annotations.VisibleForTesting;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import android.app.ListFragment;
import android.content.ContentUris;
@@ -663,13 +662,11 @@
final String lookupKey = info.lookupKey;
final int[] callTypes = getCallTypes(c, count);
final PhoneCallDetails details;
- PhoneNumber structuredPhoneNumber =
- mPhoneNumberHelper.parsePhoneNumber(number, countryIso);
if (TextUtils.isEmpty(name)) {
- details = new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber,
+ details = new PhoneCallDetails(number, formattedNumber, countryIso,
callTypes, date, duration);
} else {
- details = new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber,
+ details = new PhoneCallDetails(number, formattedNumber, countryIso,
callTypes, date, duration, name, ntype, label, personId, thumbnailUri);
}