Bug 1301718: Use StreamPageIconLayout in Highlights. r=liuche
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 04 Aug 2017 17:36:32 -0700
changeset 374635 d662a65a20349fd49e5f8db68fbddc45053f09ef
parent 374634 accde04cd0a51fdb939434dceee63dede3ed5e74
child 374636 9084b3bb0e78efae2701e10b9187cdba14bbc565
push id48752
push usermichael.l.comella@gmail.com
push dateMon, 14 Aug 2017 23:56:27 +0000
treeherderautoland@d662a65a2034 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1301718
milestone57.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 1301718: Use StreamPageIconLayout in Highlights. r=liuche MozReview-Commit-ID: LLdJ9xhC4S7
mobile/android/app/src/main/res/layout/activity_stream_card_history_item.xml
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/HighlightItem.java
--- a/mobile/android/app/src/main/res/layout/activity_stream_card_history_item.xml
+++ b/mobile/android/app/src/main/res/layout/activity_stream_card_history_item.xml
@@ -12,28 +12,27 @@
 
     <!-- On some devices, marginBottom is ignored for Views within a RelativeLayout.
          Wrapping in a FrameLayout appears to be a sufficient workaround for this issue -->
     <FrameLayout
         android:id="@+id/icon_wrapper"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
 
-        <org.mozilla.gecko.widget.FaviconView
-            android:id="@+id/icon"
-            android:layout_width="@dimen/favicon_bg"
-            android:layout_height="@dimen/favicon_bg"
-            android:layout_marginBottom="@dimen/activity_stream_base_margin"
-            android:layout_marginLeft="@dimen/activity_stream_base_margin"
-            android:layout_marginStart="@dimen/activity_stream_base_margin"
-            android:layout_marginTop="@dimen/activity_stream_base_margin"
-            gecko:enableRoundCorners="false"
-            gecko:overrideScaleType="false"
-            android:scaleType="fitCenter"
-            tools:background="@drawable/favicon_globe" />
+        <org.mozilla.gecko.activitystream.homepanel.stream.StreamPageIconLayout
+                android:id="@+id/icon"
+                android:layout_width="@dimen/favicon_bg"
+                android:layout_height="@dimen/favicon_bg"
+                android:layout_marginStart="@dimen/activity_stream_base_margin"
+                android:layout_marginLeft="@dimen/activity_stream_base_margin"
+                android:layout_marginTop="@dimen/activity_stream_base_margin"
+                android:layout_marginBottom="@dimen/activity_stream_base_margin"
+                android:layout_gravity="center"
+                tools:background="@drawable/favicon_globe" />
+        <!-- todo: overrideScaleType, scaleType=fitCnetetr -->
 
     </FrameLayout>
 
     <ImageView
         android:id="@+id/menu"
         android:layout_width="32dp"
         android:layout_height="48dp"
         android:layout_alignParentEnd="true"
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/HighlightItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/HighlightItem.java
@@ -16,56 +16,51 @@ import android.widget.TextView;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
 import org.mozilla.gecko.activitystream.Utils;
 import org.mozilla.gecko.activitystream.homepanel.menu.ActivityStreamContextMenu;
 import org.mozilla.gecko.activitystream.homepanel.model.Highlight;
 import org.mozilla.gecko.home.HomePager;
-import org.mozilla.gecko.icons.IconCallback;
-import org.mozilla.gecko.icons.IconResponse;
-import org.mozilla.gecko.icons.Icons;
 import org.mozilla.gecko.util.DrawableUtil;
 import org.mozilla.gecko.util.TouchTargetUtil;
 import org.mozilla.gecko.util.URIUtils;
 import org.mozilla.gecko.util.ViewUtil;
 import org.mozilla.gecko.widget.FaviconView;
 
 import java.lang.ref.WeakReference;
 import java.util.UUID;
-import java.util.concurrent.Future;
 
-public class HighlightItem extends StreamItem implements IconCallback {
+public class HighlightItem extends StreamItem {
     private static final String LOGTAG = "GeckoHighlightItem";
 
     public static final int LAYOUT_ID = R.layout.activity_stream_card_history_item;
     private static final double SIZE_RATIO = 0.75;
 
     private Highlight highlight;
     private int position;
 
-    private final FaviconView pageIconView;
+    private final StreamPageIconLayout pageIconLayout;
     private final TextView pageTitleView;
     private final TextView pageSourceView;
     private final TextView pageDomainView;
     private final ImageView pageSourceIconView;
 
-    private Future<IconResponse> ongoingIconLoad;
     private int tilesMargin;
 
     public HighlightItem(final View itemView,
                          final HomePager.OnUrlOpenListener onUrlOpenListener,
                          final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
         super(itemView);
 
         tilesMargin = itemView.getResources().getDimensionPixelSize(R.dimen.activity_stream_base_margin);
 
         pageTitleView = (TextView) itemView.findViewById(R.id.card_history_label);
-        pageIconView = (FaviconView) itemView.findViewById(R.id.icon);
+        pageIconLayout = (StreamPageIconLayout) itemView.findViewById(R.id.icon);
         pageSourceView = (TextView) itemView.findViewById(R.id.card_history_source);
         pageDomainView = (TextView) itemView.findViewById(R.id.page);
         pageSourceIconView = (ImageView) itemView.findViewById(R.id.source_icon);
 
         final ImageView menuButton = (ImageView) itemView.findViewById(R.id.menu);
 
         menuButton.setImageDrawable(
                 DrawableUtil.tintDrawable(menuButton.getContext(), R.drawable.menu, Color.LTGRAY));
@@ -81,17 +76,17 @@ public class HighlightItem extends Strea
                         .forHighlightSource(highlight.getSource());
 
                 ActivityStreamContextMenu.show(itemView.getContext(),
                         menuButton,
                         extras,
                         ActivityStreamContextMenu.MenuMode.HIGHLIGHT,
                         highlight,
                         onUrlOpenListener, onUrlOpenInBackgroundListener,
-                        pageIconView.getWidth(), pageIconView.getHeight());
+                        pageIconLayout.getWidth(), pageIconLayout.getHeight());
 
                 Telemetry.sendUIEvent(
                         TelemetryContract.Event.SHOW,
                         TelemetryContract.Method.CONTEXT_MENU,
                         extras.build()
                 );
             }
         });
@@ -102,33 +97,24 @@ public class HighlightItem extends Strea
     public void bind(Highlight highlight, int position, int tilesWidth) {
         this.highlight = highlight;
         this.position = position;
 
         final String backendHightlightTitle = highlight.getTitle();
         final String uiHighlightTitle = !TextUtils.isEmpty(backendHightlightTitle) ? backendHightlightTitle : highlight.getUrl();
         pageTitleView.setText(uiHighlightTitle);
 
-        ViewGroup.LayoutParams layoutParams = pageIconView.getLayoutParams();
+        ViewGroup.LayoutParams layoutParams = pageIconLayout.getLayoutParams();
         layoutParams.width = tilesWidth;
         layoutParams.height = (int) Math.floor(tilesWidth * SIZE_RATIO);
-        pageIconView.setLayoutParams(layoutParams);
+        pageIconLayout.setLayoutParams(layoutParams);
 
         updateUiForSource(highlight.getSource());
         updatePageDomain();
-
-        if (ongoingIconLoad != null) {
-            ongoingIconLoad.cancel(true);
-        }
-
-        ongoingIconLoad = Icons.with(itemView.getContext())
-                .pageUrl(highlight.getUrl())
-                .skipNetwork()
-                .build()
-                .execute(this);
+        pageIconLayout.updateIcon(highlight.getUrl(), highlight.getMetadataSlow().getImageUrl());
     }
 
     private void updateUiForSource(Utils.HighlightSource source) {
         switch (source) {
             case BOOKMARKED:
                 pageSourceView.setText(R.string.activity_stream_highlight_label_bookmarked);
                 pageSourceView.setVisibility(View.VISIBLE);
                 pageSourceIconView.setImageResource(R.drawable.ic_as_bookmarked);
@@ -146,21 +132,16 @@ public class HighlightItem extends Strea
     }
 
     private void updatePageDomain() {
         final UpdatePageDomainAsyncTask hostSLDTask = new UpdatePageDomainAsyncTask(itemView.getContext(),
                 highlight.getUrl(), pageDomainView);
         hostSLDTask.execute();
     }
 
-    @Override
-    public void onIconResponse(IconResponse response) {
-        pageIconView.updateImage(response);
-    }
-
     /** Updates the text of the given view to the host second level domain. */
     private static class UpdatePageDomainAsyncTask extends URIUtils.GetHostSecondLevelDomainAsyncTask {
         private static final int VIEW_TAG_ID = R.id.page; // same as the view.
 
         private final WeakReference<TextView> pageDomainViewWeakReference;
         private final UUID viewTagAtStart;
 
         UpdatePageDomainAsyncTask(final Context contextReference, final String uriString, final TextView pageDomainView) {