Bug 1390356 - review: getMetadataSlow -> getImageUrl in Item interface. r=mcomella

MozReview-Commit-ID: 8pFmBQf4fzp

--HG--
extra : rebase_source : 6a004bb45a1d88d8f0c028a5304042a31eca52d3
This commit is contained in:
Michael Comella 2017-08-23 13:43:59 -07:00
Родитель 5d0af9f992
Коммит 0ff9993c78
5 изменённых файлов: 26 добавлений и 9 удалений

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

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

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

@ -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.

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

@ -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

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

@ -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

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

@ -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) {