Bug 727449 - Only show mobile bookmarks folder contents if there are no desktop bookmarks. r=lucasr

This commit is contained in:
Margaret Leibovic 2012-03-19 11:22:33 -07:00
parent 3dcc146a2a
commit 357f2588fd
4 changed files with 59 additions and 2 deletions

View File

@ -413,6 +413,10 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
super.onResume();
if (mText != null && mText.getText() != null)
updateGoButton(mText.getText().toString());
// Invlidate the cached value that keeps track of whether or
// not desktop bookmarks exist
BrowserDB.invalidateCachedState();
}
@Override

View File

@ -64,6 +64,10 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface {
private static final Uri BOOKMARKS_CONTENT_URI_POST_11 = Uri.parse("content://com.android.browser/bookmarks");
public void invalidateCachedState() {
// Do nothing
}
private Cursor filterAllSites(ContentResolver cr, String[] projection, CharSequence constraint, int limit, CharSequence urlFilter) {
Cursor c = cr.query(Browser.BOOKMARKS_URI,
projection,

View File

@ -58,6 +58,8 @@ public class BrowserDB {
private static BrowserDBIface sDb;
public interface BrowserDBIface {
public void invalidateCachedState();
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit);
public Cursor getTopSites(ContentResolver cr, int limit);
@ -107,6 +109,10 @@ public class BrowserDB {
sDb = new LocalBrowserDB(BrowserContract.DEFAULT_PROFILE);
}
public static void invalidateCachedState() {
sDb.invalidateCachedState();
}
public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
return sDb.filter(cr, constraint, limit);
}

View File

@ -80,7 +80,9 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
private final String mProfile;
private long mMobileFolderId;
private long mTagsFolderId;
// Use wrapped Boolean so that we can have a null state
private Boolean mDesktopBookmarksExist;
private final Uri mBookmarksUriWithProfile;
private final Uri mParentsUriWithProfile;
@ -100,7 +102,7 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
public LocalBrowserDB(String profile) {
mProfile = profile;
mMobileFolderId = -1;
mTagsFolderId = -1;
mDesktopBookmarksExist = null;
mBookmarksUriWithProfile = appendProfile(Bookmarks.CONTENT_URI);
mParentsUriWithProfile = appendProfile(Bookmarks.PARENTS_CONTENT_URI);
@ -111,11 +113,21 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
appendQueryParameter(BrowserContract.PARAM_SHOW_DELETED, "1").build();
}
// Invalidate cached data
public void invalidateCachedState() {
mDesktopBookmarksExist = null;
}
private Uri historyUriWithLimit(int limit) {
return mHistoryUriWithProfile.buildUpon().appendQueryParameter(BrowserContract.PARAM_LIMIT,
String.valueOf(limit)).build();
}
private Uri bookmarksUriWithLimit(int limit) {
return mBookmarksUriWithProfile.buildUpon().appendQueryParameter(BrowserContract.PARAM_LIMIT,
String.valueOf(limit)).build();
}
private Uri appendProfile(Uri uri) {
return uri.buildUpon().appendQueryParameter(BrowserContract.PARAM_PROFILE, mProfile).build();
}
@ -330,6 +342,11 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
public Cursor getBookmarksInFolder(ContentResolver cr, long folderId) {
Cursor c = null;
// If there are no desktop bookmarks, use the mobile bookmarks folder
// for the root folder view
if (folderId == Bookmarks.FIXED_ROOT_ID && !desktopBookmarksExist(cr))
folderId = getMobileBookmarksFolderId(cr);
if (folderId == Bookmarks.FIXED_ROOT_ID) {
// Because of sync, we can end up with some additional records under
// the root node that we don't want to see. Since sync doesn't
@ -359,6 +376,32 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
return new LocalDBCursor(c);
}
// Returns true if any desktop bookmarks exist, which will be true if the user
// has set up sync at one point, or done a profile migration from XUL fennec.
private boolean desktopBookmarksExist(ContentResolver cr) {
if (mDesktopBookmarksExist != null)
return mDesktopBookmarksExist;
Cursor c = null;
int count = 0;
try {
c = cr.query(bookmarksUriWithLimit(1),
new String[] { Bookmarks._ID },
Bookmarks.PARENT + " != ? AND " +
Bookmarks.PARENT + " != ?",
new String[] { String.valueOf(getMobileBookmarksFolderId(cr)),
String.valueOf(Bookmarks.FIXED_ROOT_ID) },
null);
count = c.getCount();
} finally {
c.close();
}
// Cache result for future queries
mDesktopBookmarksExist = (count == 1);
return mDesktopBookmarksExist;
}
public boolean isBookmark(ContentResolver cr, String uri) {
Cursor cursor = cr.query(mBookmarksUriWithProfile,
new String[] { Bookmarks._ID },