Bug 1293710 - Display highlights in activity stream panel. r=ahunt
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 31 Aug 2016 19:40:28 +0200
changeset 312666 8f5162613934
parent 312665 02c5c53bd1f8
child 312667 d5c476180ab0
push id30652
push userphilringnalda@gmail.com
push date2016-09-05 20:05 +0000
treeherdermozilla-central@91a0bc34de8a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1293710
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1293710 - Display highlights in activity stream panel. r=ahunt MozReview-Commit-ID: CnE0Ivq6OXz
mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
@@ -587,16 +587,18 @@ public class BrowserContract {
         public static final String HISTORY_ID = "history_id";
         public static final String TYPE = "type";
 
         public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "topsites");
     }
 
     public static final class Highlights {
         public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "highlights");
+
+        public static final String DATE = "date";
     }
 
     @RobocopTarget
     public static final class SearchHistory implements CommonColumns, HistoryColumns {
         private SearchHistory() {}
 
         public static final String CONTENT_TYPE = "vnd.android.cursor.dir/searchhistory";
         public static final String QUERY = "query";
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -14,16 +14,17 @@ import java.util.Map;
 
 import org.mozilla.gecko.AboutPages;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserContract.FaviconColumns;
 import org.mozilla.gecko.db.BrowserContract.Favicons;
+import org.mozilla.gecko.db.BrowserContract.Highlights;
 import org.mozilla.gecko.db.BrowserContract.History;
 import org.mozilla.gecko.db.BrowserContract.Visits;
 import org.mozilla.gecko.db.BrowserContract.Schema;
 import org.mozilla.gecko.db.BrowserContract.Tabs;
 import org.mozilla.gecko.db.BrowserContract.Thumbnails;
 import org.mozilla.gecko.db.BrowserContract.TopSites;
 import org.mozilla.gecko.db.BrowserContract.UrlAnnotations;
 import org.mozilla.gecko.db.DBUtils.UpdateOperation;
@@ -1156,17 +1157,18 @@ public class BrowserProvider extends Sha
         final long threeDaysAgo = System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 3);
         final long bookmarkLimit = 1;
 
         // Select recent bookmarks that have not been visited much
         final String bookmarksQuery = "SELECT * FROM (SELECT " +
                 DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks._ID) + " AS " + Combined.BOOKMARK_ID + ", " +
                 "-1 AS " + Combined.HISTORY_ID + ", " +
                 DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.URL) + ", " +
-                DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.TITLE) + " " +
+                DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.TITLE) + ", " +
+                DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.DATE_CREATED) + " AS " + Highlights.DATE + " " +
                 "FROM " + Bookmarks.TABLE_NAME + " " +
                 "LEFT JOIN " + History.TABLE_NAME + " ON " +
                     DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.URL) + " = " +
                     DBUtils.qualifyColumn(History.TABLE_NAME, History.URL) + " " +
                 "WHERE " + DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.DATE_CREATED) + " > " + threeDaysAgo + " " +
                 "AND " + DBUtils.qualifyColumn(History.TABLE_NAME, History.VISITS) + " <= 3 " +
                 "AND " + DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.IS_DELETED)  + " = 0 " +
                 // TODO: Implement block list (bug 1298783)
@@ -1176,17 +1178,18 @@ public class BrowserProvider extends Sha
         final long last30Minutes = System.currentTimeMillis() - (1000 * 60 * 30);
         final long historyLimit = totalLimit - bookmarkLimit;
 
         // Select recent history that has not been visited much.
         final String historyQuery = "SELECT * FROM (SELECT " +
                 History._ID + " AS " + Combined.HISTORY_ID + ", " +
                 "-1 AS " + Combined.BOOKMARK_ID + ", " +
                 History.URL + ", " +
-                History.TITLE + " " +
+                History.TITLE + ", " +
+                History.DATE_LAST_VISITED + " AS " + Highlights.DATE + " " +
                 "FROM " + History.TABLE_NAME + " " +
                 "WHERE " + History.DATE_LAST_VISITED + " < " + last30Minutes + " " +
                 "AND " + History.VISITS + " <= 3 " +
                 "AND " + History.TITLE + " NOT NULL AND " + History.TITLE + " != '' " +
                 "AND " + History.IS_DELETED + " = 0 " +
                 // TODO: Implement block list (bug 1298783)
                 // TODO: Implement domain black list (bug 1298786)
                 // TODO: Group by host (bug 1298785)
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
@@ -51,39 +51,24 @@ public class ActivityStream extends Fram
         lm.initLoader(LOADER_ID_TOPSITES, null, callbacks);
     }
 
     public void unload() {
         adapter.swapHighlightsCursor(null);
         adapter.swapTopSitesCursor(null);
     }
 
-    /**
-     * This is a temporary cursor loader. We'll probably need a completely new query for AS,
-     * at that time we can switch to the new CursorLoader, as opposed to using our outdated
-     * SimpleCursorLoader.
-     */
-    private static class HistoryLoader extends SimpleCursorLoader {
-        public HistoryLoader(Context context) {
-            super(context);
-        }
-
-        @Override
-        protected Cursor loadCursor() {
-            final Context context = getContext();
-            return GeckoProfile.get(context).getDB()
-                    .getRecentHistory(context.getContentResolver(), 10);
-        }
-    }
-
     private class CursorLoaderCallbacks implements LoaderManager.LoaderCallbacks<Cursor> {
         @Override
         public Loader<Cursor> onCreateLoader(int id, Bundle args) {
             if (id == LOADER_ID_HIGHLIGHTS) {
-                return new HistoryLoader(getContext());
+                final Context context = getContext();
+                return GeckoProfile.get(context)
+                        .getDB()
+                        .getHighlights(context, 10);
             } else if (id == LOADER_ID_TOPSITES) {
                 return GeckoProfile.get(getContext()).getDB().getActivityStreamTopSites(getContext(),
                         TopSitesPagerAdapter.TOTAL_ITEMS);
             } else {
                 throw new IllegalArgumentException("Can't handle loader id " + id);
             }
         }
 
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
@@ -64,20 +64,20 @@ public abstract class StreamItem extends
         public CompactItem(View itemView) {
             super(itemView);
             vLabel = (TextView) itemView.findViewById(R.id.card_history_label);
             vTimeSince = (TextView) itemView.findViewById(R.id.card_history_time_since);
         }
 
         @Override
         public void bind(Cursor cursor) {
-            vLabel.setText(cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.History.TITLE)));
+            final long time = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Highlights.DATE));
+            final String ago = DateUtils.getRelativeTimeSpanString(time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0).toString();
 
-            final long timeVisited = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.History.DATE_LAST_VISITED));
-            final String ago = DateUtils.getRelativeTimeSpanString(timeVisited, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0).toString();
+            vLabel.setText(cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.History.TITLE)));
             vTimeSince.setText(ago);
         }
     }
 
     public static class HighlightItem extends StreamItem {
         public static final int LAYOUT_ID = R.layout.activity_stream_card_highlights_item;
 
         final TextView vLabel;
@@ -90,15 +90,15 @@ public abstract class StreamItem extends
             vTimeSince = (TextView) itemView.findViewById(R.id.card_highlights_time_since);
             vThumbnail = (ImageView) itemView.findViewById(R.id.card_highlights_thumbnail);
         }
 
         @Override
         public void bind(Cursor cursor) {
             vLabel.setText(cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.History.TITLE)));
 
-            final long timeVisited = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.History.DATE_LAST_VISITED));
-            final String ago = DateUtils.getRelativeTimeSpanString(timeVisited, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0).toString();
+            final long time = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Highlights.DATE));
+            final String ago = DateUtils.getRelativeTimeSpanString(time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0).toString();
             vTimeSince.setText(ago);
         }
     }
 
 }