Bug 1290014 - Refactor activity stream top sites to use new icon API. r=ahunt
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 01 Sep 2016 15:50:31 +0200
changeset 312475 38d0defa2db77fa8bf209cf60bde4232896660cc
parent 312474 ef83714d122603b428cede37fd3341375f61c6ed
child 312476 57fc4d13d23fb1a473882826ccad08811cd03a4a
child 312487 c39ec15e7e214ea6203ff49f28d3b12c55cbd8f3
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1290014
milestone51.0a1
Bug 1290014 - Refactor activity stream top sites to use new icon API. r=ahunt MozReview-Commit-ID: DDzmqNuiqRC
mobile/android/base/java/org/mozilla/gecko/home/UpdateViewFaviconLoadedListener.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesCard.java
mobile/android/base/moz.build
deleted file mode 100644
--- a/mobile/android/base/java/org/mozilla/gecko/home/UpdateViewFaviconLoadedListener.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-package org.mozilla.gecko.home;
-
-import android.graphics.Bitmap;
-
-import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
-import org.mozilla.gecko.widget.FaviconView;
-
-import java.lang.ref.WeakReference;
-
-// Only holds a reference to the FaviconView itself, so if the row gets
-// discarded while a task is outstanding, we'll leak less memory.
-public class UpdateViewFaviconLoadedListener implements OnFaviconLoadedListener {
-    private final WeakReference<FaviconView> view;
-    public UpdateViewFaviconLoadedListener(FaviconView view) {
-        this.view = new WeakReference<FaviconView>(view);
-    }
-
-    /**
-     * Update this row's favicon.
-     * <p>
-     * This method is always invoked on the UI thread.
-     */
-    @Override
-    public void onFaviconLoaded(String url, String faviconURL, Bitmap favicon) {
-        FaviconView v = view.get();
-        if (v == null) {
-            // Guess we stuck around after the TwoLinePageRow went away.
-            return;
-        }
-
-        if (favicon == null) {
-            v.showDefaultFavicon(url);
-            return;
-        }
-
-        v.updateImage(favicon, faviconURL);
-    }
-}
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesCard.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesCard.java
@@ -7,47 +7,54 @@ package org.mozilla.gecko.home.activitys
 import android.database.Cursor;
 import android.support.v7.widget.CardView;
 import android.support.v7.widget.RecyclerView;
 import android.view.View;
 import android.widget.TextView;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract;
-import org.mozilla.gecko.favicons.Favicons;
-import org.mozilla.gecko.home.UpdateViewFaviconLoadedListener;
+import org.mozilla.gecko.icons.IconCallback;
+import org.mozilla.gecko.icons.IconResponse;
+import org.mozilla.gecko.icons.Icons;
 import org.mozilla.gecko.widget.FaviconView;
 
-import java.util.EnumSet;
+import java.util.concurrent.Future;
 
-class TopSitesCard extends RecyclerView.ViewHolder {
+class TopSitesCard extends RecyclerView.ViewHolder implements IconCallback {
     private final FaviconView faviconView;
 
     private final TextView title;
     private final View menuButton;
-
-    private final UpdateViewFaviconLoadedListener mFaviconListener;
+    private Future<IconResponse> ongoingIconLoad;
 
     private String url;
 
-    private int mLoadFaviconJobId = Favicons.NOT_LOADING;
-
     public TopSitesCard(CardView card) {
         super(card);
 
         faviconView = (FaviconView) card.findViewById(R.id.favicon);
 
         title = (TextView) card.findViewById(R.id.title);
         menuButton = card.findViewById(R.id.menu);
-
-        mFaviconListener = new UpdateViewFaviconLoadedListener(faviconView);
     }
 
     void bind(Cursor cursor) {
         this.url = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL));
 
         title.setText(cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.TITLE)));
 
-        Favicons.cancelFaviconLoad(mLoadFaviconJobId);
+        if (ongoingIconLoad != null) {
+            ongoingIconLoad.cancel(true);
+        }
 
-        mLoadFaviconJobId = Favicons.getSizedFaviconForPageFromLocal(faviconView.getContext(), url, mFaviconListener);
+        ongoingIconLoad = Icons.with(itemView.getContext())
+                .pageUrl(url)
+                .skipNetwork()
+                .build()
+                .execute(this);
+    }
+
+    @Override
+    public void onIconResponse(IconResponse response) {
+        faviconView.updateImage(response);
     }
 }
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -481,17 +481,16 @@ gbjar.sources += ['java/org/mozilla/geck
     'home/SpacingDecoration.java',
     'home/TabMenuStrip.java',
     'home/TabMenuStripLayout.java',
     'home/TopSitesGridItemView.java',
     'home/TopSitesGridView.java',
     'home/TopSitesPanel.java',
     'home/TopSitesThumbnailView.java',
     'home/TwoLinePageRow.java',
-    'home/UpdateViewFaviconLoadedListener.java',
     'icons/decoders/FaviconDecoder.java',
     'icons/decoders/ICODecoder.java',
     'icons/decoders/IconDirectoryEntry.java',
     'icons/decoders/LoadFaviconResult.java',
     'icons/IconCallback.java',
     'icons/IconDescriptor.java',
     'icons/IconDescriptorComparator.java',
     'icons/IconRequest.java',