diff --git a/mobile/android/base/db/BrowserContract.java.in b/mobile/android/base/db/BrowserContract.java.in
index 1030388af10e..78a6947bbbda 100644
--- a/mobile/android/base/db/BrowserContract.java.in
+++ b/mobile/android/base/db/BrowserContract.java.in
@@ -110,6 +110,7 @@ public class BrowserContract {
public static final int FIXED_ROOT_ID = 0;
public static final int FAKE_DESKTOP_FOLDER_ID = -1;
public static final int FIXED_READING_LIST_ID = -2;
+ public static final int FIXED_PINNED_LIST_ID = -3;
public static final String MOBILE_FOLDER_GUID = "mobile";
public static final String PLACES_FOLDER_GUID = "places";
@@ -119,6 +120,7 @@ public class BrowserContract {
public static final String UNFILED_FOLDER_GUID = "unfiled";
public static final String READING_LIST_FOLDER_GUID = "readinglist";
public static final String FAKE_DESKTOP_FOLDER_GUID = "desktop";
+ public static final String PINNED_FOLDER_GUID = "pinned";
public static final int TYPE_FOLDER = 0;
public static final int TYPE_BOOKMARK = 1;
diff --git a/mobile/android/base/db/BrowserDB.java b/mobile/android/base/db/BrowserDB.java
index afad486254d7..d880f8044309 100644
--- a/mobile/android/base/db/BrowserDB.java
+++ b/mobile/android/base/db/BrowserDB.java
@@ -96,6 +96,14 @@ public class BrowserDB {
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer);
public int getCount(ContentResolver cr, String database);
+
+ public void pinSite(ContentResolver cr, String url, String title, int position);
+
+ public void unpinSite(ContentResolver cr, int position);
+
+ public void unpinAllSites(ContentResolver cr);
+
+ public Cursor getPinnedSites(ContentResolver cr, int limit);
}
static {
@@ -245,6 +253,22 @@ public class BrowserDB {
return sDb.getCount(cr, database);
}
+ public static void pinSite(ContentResolver cr, String url, String title, int position) {
+ sDb.pinSite(cr, url, title, position);
+ }
+
+ public static void unpinSite(ContentResolver cr, int position) {
+ sDb.unpinSite(cr, position);
+ }
+
+ public static void unpinAllSites(ContentResolver cr) {
+ sDb.unpinAllSites(cr);
+ }
+
+ public static Cursor getPinnedSites(ContentResolver cr, int limit) {
+ return sDb.getPinnedSites(cr, limit);
+ }
+
/* Cursor wrapper that forces top sites to contain at least
* mNumberOfTopSites entries. For rows outside the wrapped cursor
* will return empty strings and zero.
diff --git a/mobile/android/base/db/BrowserProvider.java.in b/mobile/android/base/db/BrowserProvider.java.in
index dbc43e37536f..c38bb0faec43 100644
--- a/mobile/android/base/db/BrowserProvider.java.in
+++ b/mobile/android/base/db/BrowserProvider.java.in
@@ -73,7 +73,7 @@ public class BrowserProvider extends ContentProvider {
static final String DATABASE_NAME = "browser.db";
- static final int DATABASE_VERSION = 13;
+ static final int DATABASE_VERSION = 14;
// Maximum age of deleted records to be cleaned up (20 days in ms)
static final long MAX_AGE_OF_DELETED_RECORDS = 86400000 * 20;
@@ -1101,6 +1101,8 @@ public class BrowserProvider extends ContentProvider {
R.string.bookmarks_folder_unfiled, 4);
createOrUpdateSpecialFolder(db, Bookmarks.READING_LIST_FOLDER_GUID,
R.string.bookmarks_folder_reading_list, 5);
+ createOrUpdateSpecialFolder(db, Bookmarks.PINNED_FOLDER_GUID,
+ R.string.bookmarks_folder_pinned, 6);
}
private void createOrUpdateSpecialFolder(SQLiteDatabase db,
@@ -1114,6 +1116,8 @@ public class BrowserProvider extends ContentProvider {
values.put(Bookmarks._ID, Bookmarks.FIXED_ROOT_ID);
else if (guid.equals(Bookmarks.READING_LIST_FOLDER_GUID))
values.put(Bookmarks._ID, Bookmarks.FIXED_READING_LIST_ID);
+ else if (guid.equals(Bookmarks.PINNED_FOLDER_GUID))
+ values.put(Bookmarks._ID, Bookmarks.FIXED_PINNED_LIST_ID);
// Set the parent to 0, which sync assumes is the root
values.put(Bookmarks.PARENT, Bookmarks.FIXED_ROOT_ID);
@@ -1567,6 +1571,11 @@ public class BrowserProvider extends ContentProvider {
db.execSQL("DROP TABLE IF EXISTS " + Obsolete.TABLE_IMAGES);
}
+ private void upgradeDatabaseFrom13to14(SQLiteDatabase db) {
+ createOrUpdateSpecialFolder(db, Bookmarks.PINNED_FOLDER_GUID,
+ R.string.bookmarks_folder_pinned, 6);
+ }
+
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
debug("Upgrading browser.db: " + db.getPath() + " from " +
@@ -1625,6 +1634,10 @@ public class BrowserProvider extends ContentProvider {
case 13:
upgradeDatabaseFrom12to13(db);
break;
+
+ case 14:
+ upgradeDatabaseFrom13to14(db);
+ break;
}
}
diff --git a/mobile/android/base/db/LocalBrowserDB.java b/mobile/android/base/db/LocalBrowserDB.java
index e3c77b341f9d..5075a923f4d1 100644
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -444,9 +444,11 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
Cursor c = cr.query(bookmarksUriWithLimit(1),
new String[] { Bookmarks._ID },
Bookmarks.URL + " = ? AND " +
+ Bookmarks.PARENT + " != ? AND " +
Bookmarks.PARENT + " != ?",
new String[] { uri,
- String.valueOf(Bookmarks.FIXED_READING_LIST_ID) },
+ String.valueOf(Bookmarks.FIXED_READING_LIST_ID),
+ String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) },
Bookmarks.URL);
count = c.getCount();
c.close();
@@ -1084,4 +1086,65 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
return super.getColumnIndexOrThrow(translateColumnName(columnName));
}
}
+
+
+ public void pinSite(ContentResolver cr, String url, String title, int position) {
+ ContentValues values = new ContentValues();
+ final long now = System.currentTimeMillis();
+ values.put(Bookmarks.TITLE, title);
+ values.put(Bookmarks.URL, url);
+ values.put(Bookmarks.PARENT, Bookmarks.FIXED_PINNED_LIST_ID);
+ values.put(Bookmarks.DATE_MODIFIED, now);
+ values.put(Bookmarks.POSITION, position);
+ values.put(Bookmarks.IS_DELETED, 0);
+
+ // If this site is already pinned, unpin it
+ cr.delete(mBookmarksUriWithProfile,
+ Bookmarks.PARENT + " == ? AND " + Bookmarks.URL + " == ?",
+ new String[] {
+ String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID),
+ url
+ });
+
+ // If something is already pinned in this spot update it
+ int updated = cr.update(mBookmarksUriWithProfile,
+ values,
+ Bookmarks.POSITION + " = ? AND " +
+ Bookmarks.PARENT + " = ?",
+ new String[] { Integer.toString(position),
+ String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) });
+
+ // Otherwise just insert a new item
+ if (updated == 0) {
+ cr.insert(mBookmarksUriWithProfile, values);
+ }
+ }
+
+ public Cursor getPinnedSites(ContentResolver cr, int limit) {
+ return cr.query(bookmarksUriWithLimit(limit),
+ new String[] { Bookmarks._ID,
+ Bookmarks.URL,
+ Bookmarks.TITLE,
+ Bookmarks.POSITION },
+ Bookmarks.PARENT + " == ?",
+ new String[] { String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) },
+ Bookmarks.POSITION + " ASC");
+ }
+
+ public void unpinSite(ContentResolver cr, int position) {
+ cr.delete(mBookmarksUriWithProfile,
+ Bookmarks.PARENT + " == ? AND " + Bookmarks.POSITION + " = ?",
+ new String[] {
+ String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID),
+ Integer.toString(position)
+ });
+ }
+
+ public void unpinAllSites(ContentResolver cr) {
+ cr.delete(mBookmarksUriWithProfile,
+ Bookmarks.PARENT + " == ?",
+ new String[] {
+ String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID)
+ });
+ }
}
diff --git a/mobile/android/base/locales/en-US/sync_strings.dtd b/mobile/android/base/locales/en-US/sync_strings.dtd
index 3f43683c4c3c..ba03de40c0e9 100644
--- a/mobile/android/base/locales/en-US/sync_strings.dtd
+++ b/mobile/android/base/locales/en-US/sync_strings.dtd
@@ -83,6 +83,8 @@
+
+
diff --git a/mobile/android/services/strings.xml.in b/mobile/android/services/strings.xml.in
index b411027fc10d..418c761e9f0a 100644
--- a/mobile/android/services/strings.xml.in
+++ b/mobile/android/services/strings.xml.in
@@ -76,6 +76,7 @@
&bookmarks.folder.desktop.label;
&bookmarks.folder.mobile.label;
&bookmarks.folder.readinglist.label;
+ &bookmarks.folder.pinned.label;
&sync.notification.oneaccount.label;