Bug 1390356: Use StreamOverridablePageIconLayout in BottomSheetContextMenu. r=liuche

MozReview-Commit-ID: FPM8WUtVviM

--HG--
extra : rebase_source : a0ce0cb638a985a7c41ecac89014e9b4e22c70a4
This commit is contained in:
Michael Comella 2017-08-15 14:21:31 -07:00
Родитель b0cf9b49a1
Коммит 5d0af9f992
8 изменённых файлов: 43 добавлений и 33 удалений

Просмотреть файл

@ -14,20 +14,19 @@
android:layout_height="wrap_content"
android:padding="10dp">
<org.mozilla.gecko.widget.FaviconView
android:id="@+id/icon"
android:layout_width="@dimen/favicon_bg"
android:layout_height="@dimen/favicon_bg"
android:layout_gravity="center"
gecko:enableRoundCorners="false"
tools:background="@drawable/favicon_globe"/>
<org.mozilla.gecko.activitystream.homepanel.stream.StreamOverridablePageIconLayout
android:id="@+id/page_icon_layout"
android:layout_width="@dimen/favicon_bg"
android:layout_height="@dimen/favicon_bg"
android:layout_gravity="center"
tools:background="@drawable/favicon_globe"/>
<TextView
android:id="@+id/url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/icon"
android:layout_toRightOf="@id/icon"
android:layout_toEndOf="@id/page_icon_layout"
android:layout_toRightOf="@id/page_icon_layout"
android:paddingLeft="@dimen/activity_stream_base_margin"
android:paddingStart="@dimen/activity_stream_base_margin"
android:textColor="@color/activity_stream_subtitle"
@ -39,8 +38,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/url"
android:layout_toEndOf="@id/icon"
android:layout_toRightOf="@id/icon"
android:layout_toEndOf="@id/page_icon_layout"
android:layout_toRightOf="@id/page_icon_layout"
android:ellipsize="end"
android:maxLines="3"
android:paddingLeft="@dimen/activity_stream_base_margin"

Просмотреть файл

@ -307,11 +307,15 @@ public abstract class ActivityStreamContextMenu
return true;
}
/**
* @param shouldOverrideIconWithImageProvider true if the favicon should be replaced with an image provider,
* if applicable, false otherwise.
*/
@RobocopTarget
public static ActivityStreamContextMenu show(Context context,
View anchor, ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
final MenuMode menuMode, final Item item,
final boolean shouldOverrideIconWithImageProvider,
HomePager.OnUrlOpenListener onUrlOpenListener,
HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener,
final int tilesWidth, final int tilesHeight) {
@ -320,7 +324,7 @@ public abstract class ActivityStreamContextMenu
if (!HardwareUtils.isTablet()) {
menu = new BottomSheetContextMenu(context,
telemetryExtraBuilder, menuMode,
item, onUrlOpenListener, onUrlOpenInBackgroundListener,
item, shouldOverrideIconWithImageProvider, onUrlOpenListener, onUrlOpenInBackgroundListener,
tilesWidth, tilesHeight);
} else {
menu = new PopupContextMenu(context,

Просмотреть файл

@ -6,8 +6,6 @@ package org.mozilla.gecko.activitystream.homepanel.menu;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.NavigationView;
@ -20,13 +18,10 @@ import android.widget.TextView;
import org.mozilla.gecko.R;
import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
import org.mozilla.gecko.activitystream.homepanel.model.Item;
import org.mozilla.gecko.activitystream.homepanel.stream.StreamOverridablePageIconLayout;
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.StringUtils;
import org.mozilla.gecko.util.URIUtils;
import org.mozilla.gecko.widget.FaviconView;
import java.lang.ref.WeakReference;
import java.net.URI;
@ -47,6 +42,7 @@ import java.net.URISyntaxException;
final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
final MenuMode mode,
final Item item,
final boolean shouldOverrideIconWithImageProvider,
HomePager.OnUrlOpenListener onUrlOpenListener,
HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener,
final int tilesWidth, final int tilesHeight) {
@ -85,22 +81,16 @@ import java.net.URISyntaxException;
}
// Copy layouted parameters from the Highlights / TopSites items to ensure consistency
final FaviconView faviconView = (FaviconView) content.findViewById(R.id.icon);
ViewGroup.LayoutParams layoutParams = faviconView.getLayoutParams();
final StreamOverridablePageIconLayout pageIconLayout =
(StreamOverridablePageIconLayout) content.findViewById(R.id.page_icon_layout);
final ViewGroup.LayoutParams layoutParams = pageIconLayout.getLayoutParams();
layoutParams.width = tilesWidth;
layoutParams.height = tilesHeight;
faviconView.setLayoutParams(layoutParams);
pageIconLayout.setLayoutParams(layoutParams);
Icons.with(context)
.pageUrl(item.getUrl())
.skipNetwork()
.build()
.execute(new IconCallback() {
@Override
public void onIconResponse(IconResponse response) {
faviconView.updateImage(response);
}
});
// We're matching the specific icon behavior for highlights and top sites.
final String overrideIconURL = !shouldOverrideIconWithImageProvider ? null : item.getMetadataSlow().getImageUrl();
pageIconLayout.updateIcon(item.getUrl(), overrideIconURL);
navigationView = (NavigationView) content.findViewById(R.id.menu);
navigationView.setNavigationItemSelectedListener(this);

Просмотреть файл

@ -6,6 +6,7 @@
package org.mozilla.gecko.activitystream.homepanel.model;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
@ -129,6 +130,7 @@ public class Highlight implements Item {
* - {@link #getFastImageURLForComparison()}
* - {@link #hasFastImageURL()}
*/
@NonNull
public Metadata getMetadataSlow() {
if (metadata == null) {
metadata = new Metadata(metadataJSON);

Просмотреть файл

@ -1,5 +1,6 @@
package org.mozilla.gecko.activitystream.homepanel.model;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
/**
@ -10,6 +11,15 @@ public interface Item {
String getUrl();
/**
* Returns the metadata associated with this stream item.
*
* This operation could be slow in some implementations (see {@link Highlight#getMetadataSlow()}), hence the name.
* imo, it is better to expose this possibility in the interface for all implementations rather than hide this fact.
*/
@NonNull
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.

Просмотреть файл

@ -6,6 +6,7 @@
package org.mozilla.gecko.activitystream.homepanel.model;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.mozilla.gecko.db.BrowserContract;
@ -74,7 +75,9 @@ public class TopSite implements Item {
return isPinned;
}
public Metadata getMetadata() {
@Override
@NonNull
public Metadata getMetadataSlow() {
return metadata;
}

Просмотреть файл

@ -81,6 +81,7 @@ public class HighlightItem extends StreamItem {
extras,
ActivityStreamContextMenu.MenuMode.HIGHLIGHT,
highlight,
/* shouldOverrideWithImageProvider */ true, // we use image providers in pageIconLayout.
onUrlOpenListener, onUrlOpenInBackgroundListener,
pageIconLayout.getWidth(), pageIconLayout.getHeight());

Просмотреть файл

@ -71,6 +71,7 @@ import java.util.concurrent.Future;
extras,
ActivityStreamContextMenu.MenuMode.TOPSITE,
topSite,
/* shouldOverrideWithImageProvider */ false, // we only use favicons for top sites.
onUrlOpenListener, onUrlOpenInBackgroundListener,
faviconView.getWidth(), faviconView.getHeight());