Commit 081f28c2 authored by Theresa's avatar Theresa Committed by Commit Bot

[Clear Tab] Finish cleaning up scroll to Zine behavior

BUG=875867

Change-Id: Ic70b274c96d000c2aa05fa2399475806bb3d640f
Reviewed-on: https://chromium-review.googlesource.com/1181524
Commit-Queue: Theresa <twellington@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590528}
parent 6851abbc
......@@ -241,11 +241,6 @@ public class FeedNewTabPage extends NewTabPage {
// This behavior is handled by the StreamLifecycleManager and the Feed library.
}
@Override
protected void scrollToSuggestions() {
// TODO(twellington): implement this method.
}
@Override
public boolean shouldCaptureThumbnail() {
return mNewTabPageLayout.shouldCaptureThumbnail() || mMediator.shouldCaptureThumbnail();
......
......@@ -76,8 +76,6 @@ public class UrlConstants {
public static final String CHROME_MEMEX_URL = "https://chrome-memex.appspot.com/";
public static final String CHROME_MEMEX_DEV_URL = "https://chrome-memex-dev.appspot.com/";
public static final String CONTENT_SUGGESTIONS_SUFFIX = "#suggestions";
public static final String EXPLORE_HOST = "explore";
public static final String EXPLORE_URL = "chrome-native://explore";
}
......@@ -225,9 +225,6 @@ public class NewTabPage
NewTabPageUma.recordNTPImpression(NewTabPageUma.NTP_IMPRESSION_REGULAR);
// If not visible when loading completes, wait until onShown is received.
if (!mTab.isHidden()) recordNTPShown();
if (mTab.getUrl().contains(UrlConstants.CONTENT_SUGGESTIONS_SUFFIX)) {
scrollToSuggestions();
}
}
}
......@@ -372,13 +369,6 @@ public class NewTabPage
index, NAVIGATION_ENTRY_SCROLL_POSITION_KEY, Integer.toString(scrollPosition));
}
/**
* Scroll to the list of suggested articles.
*/
protected void scrollToSuggestions() {
mNewTabPageView.scrollToSuggestions();
}
/** @return The view container for the new tab page. */
@VisibleForTesting
public NewTabPageView getNewTabPageView() {
......
......@@ -26,7 +26,6 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.suggestions.SuggestionsDependencyFactory;
import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate;
import org.chromium.chrome.browser.suggestions.TileGroup;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.browser.util.ViewUtils;
......@@ -315,43 +314,6 @@ public class NewTabPageView extends FrameLayout {
mNewTabPageRecyclerViewChanged = false;
}
/**
* Scrolls to the top of content suggestions header if one exists. If not, scrolls to the top
* of the first article suggestion. Uses scrollToPositionWithOffset to position the suggestions
* below the toolbar and not below the status bar.
*/
void scrollToSuggestions() {
int scrollPosition = getSuggestionsScrollPosition();
// Nothing to scroll to; return early.
if (scrollPosition == RecyclerView.NO_POSITION) return;
// Scrolling doesn't occur if it's called too soon i.e. the ntp hasn't finished loading.
if (mTab.isLoading()) {
mTab.addObserver(new EmptyTabObserver() {
@Override
public void onPageLoadFinished(Tab tab) {
mRecyclerView.getLinearLayoutManager().scrollToPositionWithOffset(
scrollPosition, mScrollToSuggestionsOffset);
mTab.removeObserver(this);
}
});
return;
}
mRecyclerView.getLinearLayoutManager().scrollToPositionWithOffset(
scrollPosition, mScrollToSuggestionsOffset);
}
/**
* Retrieves the position of articles or of their header in the NTP adapter to scroll to.
* @return The header's position if a header is present. Otherwise, the first
* suggestion card's position.
*/
private int getSuggestionsScrollPosition() {
// Header always exists.
return mRecyclerView.getNewTabPageAdapter().getArticleHeaderPosition();
}
/**
* @return The adapter position the user has scrolled to.
*/
......
......@@ -179,39 +179,6 @@ public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder>
return getFirstPositionForType(ItemViewType.HEADER);
}
public int getFirstSnippetPosition() {
return getFirstPositionForType(ItemViewType.SNIPPET);
}
/**
* Returns the position in the adapter of the header to the article suggestions if it exists.
* @return The article header position. RecyclerView.NO_POSITION if articles or their header
* does not exist.
*/
public int getArticleHeaderPosition() {
SuggestionsSection suggestions = mSections.getSection(KnownCategories.ARTICLES);
if (suggestions == null || !suggestions.hasCards()) return RecyclerView.NO_POSITION;
int articlesRank = RecyclerView.NO_POSITION;
int emptySectionCount = 0;
int[] categories = mUiDelegate.getSuggestionsSource().getCategories();
for (int i = 0; i < categories.length; i++) {
// The categories array includes empty sections.
if (mSections.getSection(categories[i]) == null) emptySectionCount++;
if (categories[i] == KnownCategories.ARTICLES) {
articlesRank = i - emptySectionCount;
break;
}
}
if (articlesRank == RecyclerView.NO_POSITION) return RecyclerView.NO_POSITION;
int headerRank = RecyclerView.NO_POSITION;
for (int i = 0; i < getItemCount(); i++) {
if (getItemViewType(i) == ItemViewType.HEADER && ++headerRank == articlesRank) return i;
}
return RecyclerView.NO_POSITION;
}
public int getFirstCardPosition() {
for (int i = 0; i < getItemCount(); ++i) {
if (CardViewHolder.isCard(getItemViewType(i))) return i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment