diff options
author | John Reck <jreck@google.com> | 2010-11-16 15:40:34 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2010-12-10 13:04:25 -0800 |
commit | 4b59db8bc6b609307dfcb346283378c5ea993d7c (patch) | |
tree | f90dd5cf3fa5bca80f69b042be77fd0d2fd539c4 /src/com/android | |
parent | 40411f008112113e769722d8d3ef8da0ef571df6 (diff) | |
download | packages_apps_browser-4b59db8bc6b609307dfcb346283378c5ea993d7c.zip packages_apps_browser-4b59db8bc6b609307dfcb346283378c5ea993d7c.tar.gz packages_apps_browser-4b59db8bc6b609307dfcb346283378c5ea993d7c.tar.bz2 |
Implements the bookmark star in the History tab
Bug: 3198742
This change wires up the bookmark star in the history tab.
The user can now add and remove a history item from their bookmarks.
Change-Id: I98f40bb5b4d3e82a9d305e83c750d87efb11a03e
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/browser/Bookmarks.java | 9 | ||||
-rw-r--r-- | src/com/android/browser/BrowserHistoryPage.java | 42 | ||||
-rw-r--r-- | src/com/android/browser/HistoryItem.java | 9 |
3 files changed, 39 insertions, 21 deletions
diff --git a/src/com/android/browser/Bookmarks.java b/src/com/android/browser/Bookmarks.java index 383ae7f..fef634f 100644 --- a/src/com/android/browser/Bookmarks.java +++ b/src/com/android/browser/Bookmarks.java @@ -108,22 +108,21 @@ import java.io.ByteArrayOutputStream; ContentResolver cr, String url, String title) { Cursor cursor = null; try { - cursor = cr.query(BrowserContract.Bookmarks.CONTENT_URI, + Uri uri = BookmarkUtils.getBookmarksUri(context); + cursor = cr.query(uri, new String[] { BrowserContract.Bookmarks._ID }, BrowserContract.Bookmarks.URL + " = ? AND " + BrowserContract.Bookmarks.TITLE + " = ?", new String[] { url, title }, null); - // Should be in the database no matter what if (!cursor.moveToFirst()) { - throw new AssertionError("URL is not in the database! " + url - + " " + title); + return; } // Remove from bookmarks WebIconDatabase.getInstance().releaseIconForPageUrl(url); - Uri uri = ContentUris.withAppendedId(BrowserContract.Bookmarks.CONTENT_URI, + uri = ContentUris.withAppendedId(BrowserContract.Bookmarks.CONTENT_URI, cursor.getLong(0)); cr.delete(uri, null, null); if (context != null) { diff --git a/src/com/android/browser/BrowserHistoryPage.java b/src/com/android/browser/BrowserHistoryPage.java index 2a095ad..18feee9 100644 --- a/src/com/android/browser/BrowserHistoryPage.java +++ b/src/com/android/browser/BrowserHistoryPage.java @@ -28,6 +28,7 @@ import android.content.CursorLoader; import android.content.DialogInterface; import android.content.Intent; import android.content.Loader; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.Cursor; @@ -36,9 +37,11 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.preference.PreferenceManager; import android.provider.Browser; import android.provider.BrowserContract; -import android.provider.BrowserContract.History; +import android.provider.BrowserContract.Combined; +import android.text.TextUtils; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; @@ -85,12 +88,13 @@ public class BrowserHistoryPage extends Fragment static interface HistoryQuery { static final String[] PROJECTION = new String[] { - History._ID, // 0 - History.DATE_LAST_VISITED, // 1 - History.TITLE, // 2 - History.URL, // 3 - History.FAVICON, // 4 - History.VISITS // 5 + Combined._ID, // 0 + Combined.DATE_LAST_VISITED, // 1 + Combined.TITLE, // 2 + Combined.URL, // 3 + Combined.FAVICON, // 4 + Combined.VISITS, // 5 + Combined.IS_BOOKMARK, // 6 }; static final int INDEX_ID = 0; @@ -99,6 +103,7 @@ public class BrowserHistoryPage extends Fragment static final int INDEX_URL = 3; static final int INDEX_FAVICON = 4; static final int INDEX_VISITS = 5; + static final int INDEX_IS_BOOKMARK = 6; } private void copy(CharSequence text) { @@ -116,20 +121,32 @@ public class BrowserHistoryPage extends Fragment @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( + getActivity()); + String accountType = prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_TYPE, null); + String accountName = prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_NAME, null); + Uri.Builder combinedBuilder = Combined.CONTENT_URI.buildUpon(); + if (!TextUtils.isEmpty(accountName) && !TextUtils.isEmpty(accountName)) { + combinedBuilder.appendQueryParameter(BrowserContract.Bookmarks.PARAM_ACCOUNT_TYPE, accountType); + combinedBuilder.appendQueryParameter(BrowserContract.Bookmarks.PARAM_ACCOUNT_NAME, accountName); + } + switch (id) { case LOADER_HISTORY: { - CursorLoader loader = new CursorLoader(getActivity(), History.CONTENT_URI, - HistoryQuery.PROJECTION, null, null, null); + String sort = Combined.DATE_LAST_VISITED + " DESC"; + String where = Combined.VISITS + " > 0"; + CursorLoader loader = new CursorLoader(getActivity(), combinedBuilder.build(), + HistoryQuery.PROJECTION, where, null, sort); return loader; } case LOADER_MOST_VISITED: { - Uri uri = History.CONTENT_URI - .buildUpon() + Uri uri = combinedBuilder .appendQueryParameter(BrowserContract.PARAM_LIMIT, mMostVisitsLimit) .build(); + String where = Combined.VISITS + " > 0"; CursorLoader loader = new CursorLoader(getActivity(), uri, - HistoryQuery.PROJECTION, null, null, History.VISITS + " DESC"); + HistoryQuery.PROJECTION, where, null, Combined.VISITS + " DESC"); return loader; } @@ -501,6 +518,7 @@ public class BrowserHistoryPage extends Fragment item.setFavicon(CombinedBookmarkHistoryView .getIconListenerSet().getFavicon(url)); } + item.setIsBookmark(cursor.getInt(HistoryQuery.INDEX_IS_BOOKMARK) == 1); return item; } } diff --git a/src/com/android/browser/HistoryItem.java b/src/com/android/browser/HistoryItem.java index 11198f0..ccedc01 100644 --- a/src/com/android/browser/HistoryItem.java +++ b/src/com/android/browser/HistoryItem.java @@ -18,6 +18,7 @@ package com.android.browser; import android.content.Context; +import android.provider.Browser; import android.view.View; import android.widget.CompoundButton; @@ -41,10 +42,10 @@ import android.widget.CompoundButton; public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - // FIXME: For now, add at the root level. Should we - // open AddBookmark from here? - Bookmarks.addBookmark(getContext(), true, mUrl, getName(), null, true, 0); - LogTag.logBookmarkAdded(mUrl, "history"); + // Uncheck ourseves. When the bookmark is actually added, + // we will be notified + setIsBookmark(false); + Browser.saveBookmark(getContext(), getName(), mUrl); } else { Bookmarks.removeFromBookmarks(getContext(), getContext().getContentResolver(), mUrl, getName()); |