Bug 1293790 - Pre: Extract UpdateViewFaviconLoadedListener to allow reuse r?sebastian draft
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 09 Aug 2016 14:20:54 -0700
changeset 400760 a7a5b68c711c064ee01ea68c39e8c47a2abf3374
parent 400759 0c73e035b5ca1f79baca7382d350f56120d310b0
child 400761 67f3b9de75779119f67cd21f15248736297c7d5a
push id26273
push userahunt@mozilla.com
push dateMon, 15 Aug 2016 18:44:55 +0000
reviewerssebastian
bugs1293790
milestone51.0a1
Bug 1293790 - Pre: Extract UpdateViewFaviconLoadedListener to allow reuse r?sebastian MozReview-Commit-ID: 6ud4pRemi0s
mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
mobile/android/base/java/org/mozilla/gecko/home/UpdateViewFaviconLoadedListener.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
@@ -1,17 +1,15 @@
 /* -*- 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 java.lang.ref.WeakReference;
-
 import org.mozilla.gecko.AboutPages;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.distribution.PartnerBookmarksProviderProxy;
 import org.mozilla.gecko.favicons.LoadFaviconTask;
 import org.mozilla.gecko.reader.SavedReaderViewHelper;
 import org.mozilla.gecko.reader.ReaderModeUtils;
 import org.mozilla.gecko.Tab;
@@ -19,20 +17,18 @@ import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserContract.URLColumns;
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
 import org.mozilla.gecko.widget.FaviconView;
 
 import android.content.Context;
 import android.database.Cursor;
-import android.graphics.Bitmap;
 import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.widget.ImageView;
 import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 public class TwoLinePageRow extends LinearLayout
@@ -46,46 +42,16 @@ public class TwoLinePageRow extends Line
 
     private int mSwitchToTabIconId;
 
     private final FaviconView mFavicon;
 
     private boolean mShowIcons;
     private int mLoadFaviconJobId = Favicons.NOT_LOADING;
 
-    // Only holds a reference to the FaviconView itself, so if the row gets
-    // discarded while a task is outstanding, we'll leak less memory.
-    private static 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);
-        }
-    }
-
     // Listener for handling Favicon loads.
     private final OnFaviconLoadedListener mFaviconListener;
 
     // The URL for the page corresponding to this view.
     private String mPageUrl;
 
     private boolean mHasReaderCacheItem;
 
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/home/UpdateViewFaviconLoadedListener.java
@@ -0,0 +1,42 @@
+/* -*- 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);
+    }
+}