Skip to content

Commit 22a9b38

Browse files
author
Cathy Li
committed
[Explore sites]: Fix scrolling issue, where clicking on NTP tiles would sometimes not scroll to the right category on the ESP.
Bug: 910399 Change-Id: Icd9e7cc3a4974d18960458bf633c10df659f968c Reviewed-on: https://chromium-review.googlesource.com/c/1359512 Commit-Queue: Cathy Li <chili@chromium.org> Reviewed-by: Peter Williamson <petewil@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#613365}(cherry picked from commit 95f6901) Reviewed-on: https://chromium-review.googlesource.com/c/1362488 Reviewed-by: Cathy Li <chili@chromium.org> Cr-Commit-Position: refs/branch-heads/3626@{#66} Cr-Branched-From: d897fb1-refs/heads/master@{#612437}
1 parent ebb70fe commit 22a9b38

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

chrome/android/java/src/org/chromium/chrome/browser/explore_sites/ExploreSitesPage.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ protected void initialize(ChromeActivity activity, final NativePageHost host) {
8787

8888
mModel = new PropertyModel.Builder(STATUS_KEY, SCROLL_TO_CATEGORY_KEY, CATEGORY_LIST_KEY)
8989
.with(CATEGORY_LIST_KEY, new ListModel<ExploreSitesCategory>())
90-
.with(SCROLL_TO_CATEGORY_KEY, 0)
9190
.with(STATUS_KEY, CatalogLoadingState.LOADING)
9291
.build();
9392

@@ -141,10 +140,11 @@ private void translateToModel(@Nullable List<ExploreSitesCategory> categoryList)
141140
return;
142141
}
143142
mModel.set(STATUS_KEY, CatalogLoadingState.SUCCESS);
143+
144144
ListModel<ExploreSitesCategory> categoryListModel = mModel.get(CATEGORY_LIST_KEY);
145145
categoryListModel.set(categoryList);
146146
if (mNavFragment != null) {
147-
lookupCategoryAndScroll(mNavFragment);
147+
lookupCategoryAndScroll();
148148
} else {
149149
mModel.set(SCROLL_TO_CATEGORY_KEY,
150150
Math.min(categoryListModel.size() - 1, INITIAL_SCROLL_POSITION));
@@ -177,16 +177,13 @@ public String getTitle() {
177177
@Override
178178
public void updateForUrl(String url) {
179179
super.updateForUrl(url);
180-
String fragment;
181180
try {
182-
fragment = new URI(url).getFragment();
181+
mNavFragment = new URI(url).getFragment();
183182
} catch (URISyntaxException e) {
184-
fragment = "";
183+
mNavFragment = null;
185184
}
186-
if (mModel.get(STATUS_KEY) != CatalogLoadingState.SUCCESS) {
187-
mNavFragment = fragment;
188-
} else {
189-
lookupCategoryAndScroll(fragment);
185+
if (mModel.get(STATUS_KEY) == CatalogLoadingState.SUCCESS) {
186+
lookupCategoryAndScroll();
190187
}
191188
}
192189

@@ -198,20 +195,18 @@ public void destroy() {
198195

199196
private void setTouchEnabled(boolean enabled) {} // Does nothing.
200197

201-
private void lookupCategoryAndScroll(String categoryId) {
202-
int position = 0;
198+
private void lookupCategoryAndScroll() {
203199
try {
204-
int id = Integer.parseInt(categoryId);
200+
int id = Integer.parseInt(mNavFragment);
205201
ListModel<ExploreSitesCategory> categoryList = mModel.get(CATEGORY_LIST_KEY);
206202
for (int i = 0; i < categoryList.size(); i++) {
207203
if (categoryList.get(i).getId() == id) {
208-
position = i;
204+
mModel.set(SCROLL_TO_CATEGORY_KEY, i);
209205
break;
210206
}
211207
}
208+
212209
} catch (NumberFormatException e) {
213210
} // do nothing
214-
mModel.set(SCROLL_TO_CATEGORY_KEY, position);
215-
mNavFragment = null;
216211
}
217212
}

0 commit comments

Comments
 (0)