Bug 1301718: Use StreamPageIconLayout in top sites. r=liuche
MozReview-Commit-ID: 7A2e28RfVgf
--- a/mobile/android/app/src/main/res/layout/activity_stream_topsites_card.xml
+++ b/mobile/android/app/src/main/res/layout/activity_stream_topsites_card.xml
@@ -1,21 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:gecko="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
- <org.mozilla.gecko.widget.FaviconView
+ <org.mozilla.gecko.activitystream.homepanel.stream.StreamPageIconLayout
android:id="@+id/favicon"
android:layout_width="match_parent"
android:layout_height="match_parent"
- gecko:enableRoundCorners="false"
tools:background="@drawable/favicon_globe"
android:layout_marginTop="0dp" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#66000000"
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/Item.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/Item.java
@@ -6,16 +6,22 @@ import android.support.annotation.Nullab
* Shared interface for activity stream item models.
*/
public interface Item {
String getTitle();
String getUrl();
/**
+ * Gets the metadata. This may be slow in some implementations: see {@link Highlight#getMetadataSlow()}. imo, it's
+ * better to note this could be slow in the interface than to not document it at all.
+ */
+ Metadata getMetadataSlow();
+
+ /**
* @return True if the item is bookmarked, false otherwise. Might return 'null' if the bookmark
* state is unknown and the database needs to be asked whether the URL is bookmarked.
*/
@Nullable
Boolean isBookmarked();
/**
* @return True if the item is pinned, false otherwise. Will return 'null' if the pinned state
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/TopSite.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/TopSite.java
@@ -69,17 +69,17 @@ public class TopSite implements Item {
public int getType() {
return type;
}
public Boolean isPinned() {
return isPinned;
}
- public Metadata getMetadata() {
+ public Metadata getMetadataSlow() {
return metadata;
}
@Override
public void updateBookmarked(boolean bookmarked) {
this.isBookmarked = bookmarked;
}
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesCard.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesCard.java
@@ -15,47 +15,40 @@ import android.view.View;
import android.widget.FrameLayout;
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.homepanel.menu.ActivityStreamContextMenu;
import org.mozilla.gecko.activitystream.homepanel.model.TopSite;
+import org.mozilla.gecko.activitystream.homepanel.stream.StreamPageIconLayout;
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;
-/* package-local */ class TopSitesCard extends RecyclerView.ViewHolder
- implements IconCallback {
- private final FaviconView faviconView;
+/* package-local */ class TopSitesCard extends RecyclerView.ViewHolder {
+ private final StreamPageIconLayout pageIconLayout;
private final TextView title;
- private Future<IconResponse> ongoingIconLoad;
private TopSite topSite;
private int absolutePosition;
private final HomePager.OnUrlOpenListener onUrlOpenListener;
private final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
/* package-local */ TopSitesCard(final FrameLayout card, final HomePager.OnUrlOpenListener onUrlOpenListener, final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
super(card);
- faviconView = (FaviconView) card.findViewById(R.id.favicon);
+ pageIconLayout = (StreamPageIconLayout) card.findViewById(R.id.favicon);
title = (TextView) card.findViewById(R.id.title);
this.onUrlOpenListener = onUrlOpenListener;
this.onUrlOpenInBackgroundListener = onUrlOpenInBackgroundListener;
card.setOnLongClickListener(new View.OnLongClickListener() {
@Override
@@ -65,17 +58,17 @@ import java.util.concurrent.Future;
.set(ActivityStreamTelemetry.Contract.ACTION_POSITION, absolutePosition);
ActivityStreamContextMenu.show(itemView.getContext(),
card,
extras,
ActivityStreamContextMenu.MenuMode.TOPSITE,
topSite,
onUrlOpenListener, onUrlOpenInBackgroundListener,
- faviconView.getWidth(), faviconView.getHeight());
+ pageIconLayout.getWidth(), pageIconLayout.getHeight());
Telemetry.sendUIEvent(
TelemetryContract.Event.SHOW,
TelemetryContract.Method.CONTEXT_MENU,
extras.build()
);
return true;
@@ -84,51 +77,38 @@ import java.util.concurrent.Future;
ViewUtil.enableTouchRipple(card);
}
void bind(final TopSite topSite, final int absolutePosition) {
this.topSite = topSite;
this.absolutePosition = absolutePosition;
- if (ongoingIconLoad != null) {
- ongoingIconLoad.cancel(true);
- }
-
- ongoingIconLoad = Icons.with(itemView.getContext())
- .pageUrl(topSite.getUrl())
- .skipNetwork()
- .build()
- .execute(this);
+ pageIconLayout.updateIcon(topSite.getUrl(), topSite.getMetadataSlow().getImageUrl());
final Drawable pinDrawable;
if (topSite.isPinned()) {
pinDrawable = DrawableUtil.tintDrawable(itemView.getContext(), R.drawable.as_pin, Color.WHITE);
} else {
pinDrawable = null;
}
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(title, pinDrawable, null, null, null);
- final String provider = topSite.getMetadata().getProvider();
+ final String provider = topSite.getMetadataSlow().getProvider();
if (!TextUtils.isEmpty(provider)) {
title.setText(provider.toLowerCase());
} else {
// Our AsyncTask calls setCenteredText(), which needs to have all drawable's in place to correctly
// layout the text, so we need to wait with requesting the title until we've set our pin icon.
final UpdateCardTitleAsyncTask titleAsyncTask = new UpdateCardTitleAsyncTask(itemView.getContext(),
topSite.getUrl(), title);
titleAsyncTask.execute();
}
}
- @Override
- public void onIconResponse(IconResponse response) {
- faviconView.updateImage(response);
- }
-
/** Updates the text of the given view to the page domain. */
private static class UpdateCardTitleAsyncTask extends URIUtils.GetHostSecondLevelDomainAsyncTask {
private static final int VIEW_TAG_ID = R.id.title; // same as the view.
private final WeakReference<TextView> titleViewWeakReference;
private final UUID viewTagAtStart;
UpdateCardTitleAsyncTask(final Context contextReference, final String uriString, final TextView titleView) {