summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-03-20 17:09:41 -0700
committerAndrew Lee <anwlee@google.com>2015-03-20 17:12:41 -0700
commit5f0db7af79e696db4fade49720edf4930f1e0858 (patch)
treeff37b5bdcdf90fc128a4522372439c695f9b50d4 /src
parentf181b45d59f114c72e71053f9390f3b83034d881 (diff)
Update smart dial results after adding contact.
+ Add a URI for smart dial database updates, and notify this URI with the content resolver after finishing an update. + Add a content observer to the SmartDialCursorLoader, to force a reload of its contents when notified. Bug: 19372539 Change-Id: I963d0d0fcb519e672f580ea8d33dc80d0c3f7799
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/database/DialerDatabaseHelper.java6
-rw-r--r--src/com/android/dialer/dialpad/SmartDialCursorLoader.java20
2 files changed, 26 insertions, 0 deletions
diff --git a/src/com/android/dialer/database/DialerDatabaseHelper.java b/src/com/android/dialer/database/DialerDatabaseHelper.java
index 511c2a7bc..2177878c6 100644
--- a/src/com/android/dialer/database/DialerDatabaseHelper.java
+++ b/src/com/android/dialer/database/DialerDatabaseHelper.java
@@ -93,6 +93,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
static final String PROPERTIES = "properties";
}
+ public static final Uri SMART_DIAL_UPDATED_URI =
+ Uri.parse("content://com.android.dialer/smart_dial_updated");
+
public interface SmartDialDbColumns {
static final String _ID = "id";
static final String DATA_ID = "data_id";
@@ -893,6 +896,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
final SharedPreferences.Editor editor = databaseLastUpdateSharedPref.edit();
editor.putLong(LAST_UPDATED_MILLIS, currentMillis);
editor.commit();
+
+ // Notify content observers that smart dial database has been updated.
+ mContext.getContentResolver().notifyChange(SMART_DIAL_UPDATED_URI, null, false);
}
}
diff --git a/src/com/android/dialer/dialpad/SmartDialCursorLoader.java b/src/com/android/dialer/dialpad/SmartDialCursorLoader.java
index d01776c61..372692eae 100644
--- a/src/com/android/dialer/dialpad/SmartDialCursorLoader.java
+++ b/src/com/android/dialer/dialpad/SmartDialCursorLoader.java
@@ -18,8 +18,10 @@ package com.android.dialer.dialpad;
import android.content.AsyncTaskLoader;
import android.content.Context;
+import android.content.Loader.ForceLoadContentObserver;
import android.database.Cursor;
import android.database.MatrixCursor;
+import android.net.Uri;
import android.util.Log;
import com.android.contacts.common.list.PhoneNumberListAdapter.PhoneQuery;
@@ -44,6 +46,8 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> {
private String mQuery;
private SmartDialNameMatcher mNameMatcher;
+ private ForceLoadContentObserver mObserver;
+
public SmartDialCursorLoader(Context context) {
super(context);
mContext = context;
@@ -110,6 +114,12 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> {
Cursor oldCursor = mCursor;
mCursor = cursor;
+ if (mObserver == null) {
+ mObserver = new ForceLoadContentObserver();
+ mContext.getContentResolver().registerContentObserver(
+ DialerDatabaseHelper.SMART_DIAL_UPDATED_URI, true, mObserver);
+ }
+
if (isStarted()) {
/** If the Loader is in a started state, deliver the results to the client. */
super.deliverResult(cursor);
@@ -144,6 +154,11 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> {
/** Ensure the loader has been stopped. */
onStopLoading();
+ if (mObserver != null) {
+ mContext.getContentResolver().unregisterContentObserver(mObserver);
+ mObserver = null;
+ }
+
/** Release all previously saved query results. */
if (mCursor != null) {
releaseResources(mCursor);
@@ -155,6 +170,11 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> {
public void onCanceled(Cursor cursor) {
super.onCanceled(cursor);
+ if (mObserver != null) {
+ mContext.getContentResolver().unregisterContentObserver(mObserver);
+ mObserver = null;
+ }
+
/** The load has been canceled, so we should release the resources associated with 'data'.*/
releaseResources(cursor);
}