Bug 1293790 - Pre: Extract UpdateViewFaviconLoadedListener to allow reuse r=sebastian

MozReview-Commit-ID: 6ud4pRemi0s

--HG--
extra : rebase_source : 54b41fe13154ec6118af2192b41cf62d8e741784
This commit is contained in:
Andrzej Hunt 2016-08-17 10:57:08 -07:00
parent d2547754e6
commit 8de90ea489
3 changed files with 43 additions and 34 deletions

View File

@ -5,8 +5,6 @@
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;
@ -24,10 +22,8 @@ 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;
@ -51,36 +47,6 @@ public class TwoLinePageRow extends LinearLayout
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;

View File

@ -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);
}
}

View File

@ -492,6 +492,7 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
'home/TopSitesPanel.java',
'home/TopSitesThumbnailView.java',
'home/TwoLinePageRow.java',
'home/UpdateViewFaviconLoadedListener.java',
'IntentHelper.java',
'javaaddons/JavaAddonManager.java',
'javaaddons/JavaAddonManagerV1.java',