Bug 1553474 - "Remove bookmark" option is displayed for pages that were not bookmarked; r=petru a=jcristau
authordiana.iacos <diana.iacos@softvision.ro>
Mon, 27 May 2019 07:43:43 +0000
changeset 536594 e996cd24ede06d7c8c2a822092a7437ba9cfea15
parent 536593 8877cfc4f1087be21bc4c856d2c1646952955e8b
child 536595 8536ebb1c16ffc0ae48a1efb51770744db176fe5
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru, jcristau
bugs1553474
milestone68.0
Bug 1553474 - "Remove bookmark" option is displayed for pages that were not bookmarked; r=petru a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D32664
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanelRow.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanelRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanelRow.java
@@ -121,33 +121,39 @@ public class TopPanelRow extends StreamV
         final MatrixCursor filteredCursor = new MatrixCursor(projection);
         final Set<String> urls = new HashSet<String>(limit);
         do {
             String baseUrl = getBaseForUrl(cursor.getString(cursor.getColumnIndex(BrowserContract.Combined.URL)));
             boolean isPinned = isTopSitePinned(cursor.getInt(cursor.getColumnIndex(BrowserContract.TopSites.TYPE)));
             if (isPinned || !urls.contains(baseUrl)) {
                 final Object[] originalColumns = new Object[] {
                         cursor.getLong(cursor.getColumnIndex(BrowserContract.Combined._ID)),
-                        cursor.getLong(cursor.getColumnIndex(BrowserContract.Combined.BOOKMARK_ID)),
+                        getBookmarkId(cursor),
                         cursor.getLong(cursor.getColumnIndex(BrowserContract.Combined.HISTORY_ID)),
                         cursor.getString(cursor.getColumnIndex(BrowserContract.Combined.URL)),
                         cursor.getString(cursor.getColumnIndex(BrowserContract.Combined.TITLE)),
                         cursor.getInt(cursor.getColumnIndex(BrowserContract.Highlights.POSITION)),
                         cursor.getInt(cursor.getColumnIndex(BrowserContract.TopSites.TYPE)),
                         Metadata.fromCursor(cursor, BrowserContract.TopSites.PAGE_METADATA_JSON)
                 };
                 // match the original cursor fields
                 filteredCursor.addRow(originalColumns);
                 urls.add(baseUrl);
             }
         } while (filteredCursor.getCount() < limit && cursor.moveToNext());
 
         return filteredCursor;
     }
 
+    private Long getBookmarkId(Cursor cursor) {
+        // If the value of BOOKMARK_ID column it's null that means the url is not bookmarked
+        final int columnIndex = cursor.getColumnIndex(BrowserContract.Combined.BOOKMARK_ID);
+        return cursor.isNull(columnIndex) ? null : cursor.getLong(columnIndex);
+    }
+
     private boolean isTopSitePinned(final int topSiteType) {
         return topSiteType == BrowserContract.TopSites.TYPE_PINNED;
     }
 
     private String getBaseForUrl(final String url) {
         try {
             return new URL(url).getHost();
         } catch (MalformedURLException e) {