Bug 671131 - (Part 2) Make observer to update history tab when history item is removed. r=bnicholson

This commit is contained in:
Margaret Leibovic 2012-05-14 11:44:37 -07:00
parent 9e2144459f
commit 027ab6d4f5
5 changed files with 34 additions and 4 deletions

View File

@ -41,6 +41,7 @@ package org.mozilla.gecko;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -102,6 +103,7 @@ public class AwesomeBarTabs extends TabHost {
private View.OnTouchListener mListTouchListener;
private JSONArray mSearchEngines;
private ContentResolver mContentResolver;
private ContentObserver mContentObserver;
private BookmarksQueryTask mBookmarksQueryTask;
private HistoryQueryTask mHistoryQueryTask;
@ -581,6 +583,17 @@ public class AwesomeBarTabs extends TabHost {
result.second
);
if (mContentObserver == null) {
// Register an observer to update the history tab contents if they change.
mContentObserver = new ContentObserver(GeckoAppShell.getHandler()) {
public void onChange(boolean selfChange) {
mHistoryQueryTask = new HistoryQueryTask();
mHistoryQueryTask.execute();
}
};
BrowserDB.registerHistoryObserver(mContentResolver, mContentObserver);
}
final ExpandableListView historyList =
(ExpandableListView) findViewById(R.id.history_list);
@ -738,6 +751,7 @@ public class AwesomeBarTabs extends TabHost {
mInflated = false;
mSearchEngines = new JSONArray();
mContentResolver = context.getContentResolver();
mContentObserver = null;
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@ -1001,6 +1015,9 @@ public class AwesomeBarTabs extends TabHost {
if (bookmarksCursor != null)
bookmarksCursor.close();
}
if (mContentObserver != null)
BrowserDB.unregisterContentObserver(mContentResolver, mContentObserver);
}
public void filter(String searchTerm) {

View File

@ -139,7 +139,7 @@ public final class Tab {
public void onDestroy() {
mDoorHangers = new HashMap<String, DoorHanger>();
BrowserDB.unregisterBookmarkObserver(mContentResolver, mContentObserver);
BrowserDB.unregisterContentObserver(mContentResolver, mContentObserver);
}
public int getId() {

View File

@ -313,6 +313,10 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface {
registerBookmarkObserverPre11(cr, observer);
}
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer) {
// Not implemented
}
public BitmapDrawable getFaviconForUrl(ContentResolver cr, String uri) {
Cursor c = cr.query(Browser.BOOKMARKS_URI,
new String[] { Browser.BookmarkColumns.FAVICON },

View File

@ -102,6 +102,8 @@ public class BrowserDB {
public byte[] getThumbnailForUrl(ContentResolver cr, String uri);
public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer);
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer);
}
static {
@ -198,7 +200,11 @@ public class BrowserDB {
sDb.registerBookmarkObserver(cr, observer);
}
public static void unregisterBookmarkObserver(ContentResolver cr, ContentObserver observer) {
public static void registerHistoryObserver(ContentResolver cr, ContentObserver observer) {
sDb.registerHistoryObserver(cr, observer);
}
public static void unregisterContentObserver(ContentResolver cr, ContentObserver observer) {
cr.unregisterContentObserver(observer);
}
}

View File

@ -508,8 +508,11 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
}
public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer) {
Uri uri = mBookmarksUriWithProfile;
cr.registerContentObserver(uri, false, observer);
cr.registerContentObserver(mBookmarksUriWithProfile, false, observer);
}
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer) {
cr.registerContentObserver(mHistoryUriWithProfile, false, observer);
}
public void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword) {