Bug 1234328 - Show "switch to tab" for readercached items too r?sebastian
We will already switch to the currently open tab, so we need to ensure we
show the "switch to tab" indicator.
MozReview-Commit-ID: 9q1kDM2flSi
--- a/mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
@@ -80,16 +80,18 @@ public class TwoLinePageRow extends Line
}
// Listener for handling Favicon loads.
private final OnFaviconLoadedListener mFaviconListener;
// The URL for the page corresponding to this view.
private String mPageUrl;
+ private boolean mHasCacheItem;
+
public TwoLinePageRow(Context context) {
this(context, null);
}
public TwoLinePageRow(Context context, AttributeSet attrs) {
super(context, attrs);
setGravity(Gravity.CENTER_VERTICAL);
@@ -190,29 +192,37 @@ public class TwoLinePageRow extends Line
final int visibility = toShow ? VISIBLE : GONE;
mStatusIcon.setVisibility(visibility);
}
/**
* Stores the page URL, so that we can use it to replace "Switch to tab" if the open
* tab changes or is closed.
*/
- private void updateDisplayedUrl(String url) {
+ private void updateDisplayedUrl(String url, boolean hasCacheItem) {
mPageUrl = url;
+ mHasCacheItem = hasCacheItem;
updateDisplayedUrl();
}
/**
* Replaces the page URL with "Switch to tab" if there is already a tab open with that URL.
* Only looks for tabs that are either private or non-private, depending on the current
* selected tab.
*/
protected void updateDisplayedUrl() {
boolean isPrivate = Tabs.getInstance().getSelectedTab().isPrivate();
- Tab tab = Tabs.getInstance().getFirstTabForUrl(mPageUrl, isPrivate);
+
+ // We always want to display the underlying page url, however for readermode pages
+ // we navigate to the about:reader equivalent, hence we need to use that url when finding
+ // existing tabs
+ final String navigationUrl = mHasCacheItem ? ReaderModeUtils.getAboutReaderForUrl(mPageUrl) : mPageUrl;
+ Tab tab = Tabs.getInstance().getFirstTabForUrl(navigationUrl, isPrivate);
+
+
if (!mShowIcons || tab == null) {
setUrl(mPageUrl);
setSwitchToTabIcon(NO_ICON);
} else {
setUrl(R.string.switch_to_tab);
setSwitchToTabIcon(R.drawable.ic_url_bar_tab);
}
}
@@ -257,17 +267,17 @@ public class TwoLinePageRow extends Line
Favicons.cancelFaviconLoad(mLoadFaviconJobId);
// Displayed RecentTabsPanel URLs may refer to pages opened in reader mode, so we
// remove the about:reader prefix to ensure the Favicon loads properly.
final String pageURL = AboutPages.isAboutReader(url) ?
ReaderModeUtils.getUrlFromAboutReader(url) : url;
mLoadFaviconJobId = Favicons.getSizedFaviconForPageFromLocal(getContext(), pageURL, mFaviconListener);
- updateDisplayedUrl(url);
+ updateDisplayedUrl(url, hasCacheItem);
mCached.setVisibility(hasCacheItem ? View.VISIBLE : View.INVISIBLE);
}
/**
* Update the data displayed by this row.
* <p>
* This method must be invoked on the UI thread.