From 0ff9993c786f273b3dffe8055ec279cf07b6f301 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Wed, 23 Aug 2017 13:43:59 -0700 Subject: [PATCH] Bug 1390356 - review: getMetadataSlow -> getImageUrl in Item interface. r=mcomella MozReview-Commit-ID: 8pFmBQf4fzp --HG-- extra : rebase_source : 6a004bb45a1d88d8f0c028a5304042a31eca52d3 --- .../homepanel/menu/BottomSheetContextMenu.java | 2 +- .../activitystream/homepanel/model/Highlight.java | 15 +++++++++++++++ .../activitystream/homepanel/model/Item.java | 9 +++++---- .../activitystream/homepanel/model/TopSite.java | 7 ++++--- .../homepanel/stream/HighlightItem.java | 2 +- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java index fd993157e9b2..df40021a805f 100644 --- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java +++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java @@ -89,7 +89,7 @@ import java.net.URISyntaxException; pageIconLayout.setLayoutParams(layoutParams); // We're matching the specific icon behavior for highlights and top sites. - final String overrideIconURL = !shouldOverrideIconWithImageProvider ? null : item.getMetadataSlow().getImageUrl(); + final String overrideIconURL = !shouldOverrideIconWithImageProvider ? null : item.getImageUrl(); pageIconLayout.updateIcon(item.getUrl(), overrideIconURL); navigationView = (NavigationView) content.findViewById(R.id.menu); diff --git a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/Highlight.java b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/Highlight.java index abf10c19cc05..47c77ec02129 100644 --- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/Highlight.java +++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/Highlight.java @@ -138,6 +138,21 @@ public class Highlight implements Item { return metadata; } + /** + * Returns the image URL associated with this Highlight. + * + * This implementation may be slow: see {@link #getMetadataSlow()}. + * + * @return the image URL, or the empty String if there is none. + */ + @NonNull + @Override + public String getImageUrl() { + final Metadata metadata = getMetadataSlow(); + final String imageUrl = metadata.getImageUrl(); + return imageUrl != null ? imageUrl : ""; + } + /** * Returns the image url in the highlight's metadata. This value does not provide valid image url but is * consistent across invocations and can be used to compare against other Highlight's fast image urls. diff --git 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 index ea9eea8388a2..16804de0469a 100644 --- 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 @@ -12,13 +12,14 @@ public interface Item { String getUrl(); /** - * Returns the metadata associated with this stream item. + * Returns the image URL 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. + * Some implementations may be slow due to lazy loading: see {@link Highlight#getImageUrl()}. + * + * @return the image URL, or the empty String when there is none. */ @NonNull - Metadata getMetadataSlow(); + String getImageUrl(); /** * @return True if the item is bookmarked, false otherwise. Might return 'null' if the bookmark diff --git 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 index 9e3bc00c9c41..9e4e9e68c0cf 100644 --- 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 @@ -75,10 +75,11 @@ public class TopSite implements Item { return isPinned; } - @Override @NonNull - public Metadata getMetadataSlow() { - return metadata; + @Override + public String getImageUrl() { + final String imageUrl = metadata.getImageUrl(); + return imageUrl != null ? imageUrl : ""; } @Override diff --git 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 index 76e3560fc05d..f79e81e80dde 100644 --- 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 @@ -111,7 +111,7 @@ public class HighlightItem extends StreamItem { updateUiForSource(highlight.getSource()); updatePageDomain(); - pageIconLayout.updateIcon(highlight.getUrl(), highlight.getMetadataSlow().getImageUrl()); + pageIconLayout.updateIcon(highlight.getUrl(), highlight.getImageUrl()); } private void updateUiForSource(Utils.HighlightSource source) {