From b9ea6cf17f0adf1deb38b95d6908a1a3621bafd7 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Wed, 14 Nov 2012 17:13:29 -0800 Subject: Use SmartDialCache object for caching Extract caching methods from SmartDialLoaderTask and use a standalone SmartDialCache object instead. This cache object handles caching failures as well as concurrent multiple cache requests. Bug: 6977981 Change-Id: I6df9e273191c7ac434d094e567d7a91814f8c030 --- src/com/android/dialer/dialpad/DialpadFragment.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src/com/android/dialer/dialpad/DialpadFragment.java') diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index f7a9056f5..2c4841685 100644 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -170,7 +170,7 @@ public class DialpadFragment extends Fragment // Vibration (haptic feedback) for dialer key presses. private final HapticFeedback mHaptic = new HapticFeedback(); - private boolean mNeedToCacheSmartDial = false; + private SmartDialCache mSmartDialCache; /** Identifier for the "Add Call" intent extra. */ private static final String ADD_CALL_MODE_KEY = "add_call_mode"; @@ -279,7 +279,7 @@ public class DialpadFragment extends Fragment mContactsPrefs = new ContactsPreferences(getActivity()); mCurrentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); - mNeedToCacheSmartDial = true; + mSmartDialCache = new SmartDialCache(getActivity(), mContactsPrefs.getDisplayOrder()); try { mHaptic.init(getActivity(), getResources().getBoolean(R.bool.config_enable_dialer_key_vibration)); @@ -295,13 +295,6 @@ public class DialpadFragment extends Fragment if (state != null) { mDigitsFilledByIntent = state.getBoolean(PREF_DIGITS_FILLED_BY_INTENT); } - - // Start caching contacts to use for smart dialling only if the dialpad fragment is visible - if (getUserVisibleHint()) { - SmartDialLoaderTask.startCacheContactsTaskIfNeeded( - getActivity(), mContactsPrefs.getDisplayOrder()); - mNeedToCacheSmartDial = false; - } } @Override @@ -1679,10 +1672,8 @@ public class DialpadFragment extends Fragment @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); - if (isVisibleToUser && mNeedToCacheSmartDial) { - SmartDialLoaderTask.startCacheContactsTaskIfNeeded( - getActivity(), mContactsPrefs.getDisplayOrder()); - mNeedToCacheSmartDial = false; + if (isVisibleToUser) { + mSmartDialCache.cacheIfNeeded(); } } @@ -1704,7 +1695,7 @@ public class DialpadFragment extends Fragment if (digits.length() < 2) { mSmartDialAdapter.clear(); } else { - final SmartDialLoaderTask task = new SmartDialLoaderTask(this, digits); + final SmartDialLoaderTask task = new SmartDialLoaderTask(this, digits, mSmartDialCache); // don't execute this in serial, otherwise we have to wait too long for results task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new String[] {}); } -- cgit v1.2.3