Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java

Issue 2327083002: Ntp: restore scroll position. (Closed)
Patch Set: Rebase. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.ntp; 5 package org.chromium.chrome.browser.ntp;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.res.Configuration; 9 import android.content.res.Configuration;
10 import android.content.res.Resources; 10 import android.content.res.Resources;
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 /** 289 /**
290 * Initializes the NTP. This must be called immediately after inflation, bef ore this object is 290 * Initializes the NTP. This must be called immediately after inflation, bef ore this object is
291 * used in any other way. 291 * used in any other way.
292 * 292 *
293 * @param manager NewTabPageManager used to perform various actions when the user interacts 293 * @param manager NewTabPageManager used to perform various actions when the user interacts
294 * with the page. 294 * with the page.
295 * @param searchProviderHasLogo Whether the search provider has a logo. 295 * @param searchProviderHasLogo Whether the search provider has a logo.
296 * @param snippetsBridge The optional bridge, that can be used to interact w ith the snippets. 296 * @param snippetsBridge The optional bridge, that can be used to interact w ith the snippets.
297 */ 297 */
298 public void initialize(NewTabPageManager manager, boolean searchProviderHasL ogo, 298 public void initialize(NewTabPageManager manager, boolean searchProviderHasL ogo,
299 SnippetsBridge snippetsBridge) { 299 SnippetsBridge snippetsBridge, int scrollPosition) {
300 mManager = manager; 300 mManager = manager;
301 mUiConfig = new UiConfig(this); 301 mUiConfig = new UiConfig(this);
302 ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub); 302 ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub);
303 303
304 mUseCardsUi = snippetsBridge != null; 304 mUseCardsUi = snippetsBridge != null;
305 if (mUseCardsUi) { 305 if (mUseCardsUi) {
306 stub.setLayoutResource(R.layout.new_tab_page_recycler_view); 306 stub.setLayoutResource(R.layout.new_tab_page_recycler_view);
307 mRecyclerView = (NewTabPageRecyclerView) stub.inflate(); 307 mRecyclerView = (NewTabPageRecyclerView) stub.inflate();
308 308
309 // Don't attach now, the recyclerView itself will determine when to do it. 309 // Don't attach now, the recyclerView itself will determine when to do it.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 345
346 mPendingLoadTasks++; 346 mPendingLoadTasks++;
347 mManager.setMostVisitedURLsObserver( 347 mManager.setMostVisitedURLsObserver(
348 this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo) ); 348 this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo) );
349 349
350 // Set up snippets 350 // Set up snippets
351 if (mUseCardsUi) { 351 if (mUseCardsUi) {
352 mNewTabPageAdapter = 352 mNewTabPageAdapter =
353 new NewTabPageAdapter(mManager, mNewTabPageLayout, snippetsB ridge, mUiConfig); 353 new NewTabPageAdapter(mManager, mNewTabPageLayout, snippetsB ridge, mUiConfig);
354 mRecyclerView.setAdapter(mNewTabPageAdapter); 354 mRecyclerView.setAdapter(mNewTabPageAdapter);
355 mRecyclerView.scrollToPosition(scrollPosition);
355 356
356 // Set up swipe-to-dismiss 357 // Set up swipe-to-dismiss
357 ItemTouchHelper helper = 358 ItemTouchHelper helper =
358 new ItemTouchHelper(mNewTabPageAdapter.getItemTouchCallbacks ()); 359 new ItemTouchHelper(mNewTabPageAdapter.getItemTouchCallbacks ());
359 helper.attachToRecyclerView(mRecyclerView); 360 helper.attachToRecyclerView(mRecyclerView);
360 361
361 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener( ) { 362 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener( ) {
362 private boolean mScrolledOnce = false; 363 private boolean mScrolledOnce = false;
363 @Override 364 @Override
364 public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 365 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 mUiConfig.updateDisplayStyle(); 1172 mUiConfig.updateDisplayStyle();
1172 } 1173 }
1173 1174
1174 private int getVerticalScroll() { 1175 private int getVerticalScroll() {
1175 if (mUseCardsUi) { 1176 if (mUseCardsUi) {
1176 return mRecyclerView.computeVerticalScrollOffset(); 1177 return mRecyclerView.computeVerticalScrollOffset();
1177 } else { 1178 } else {
1178 return mScrollView.getScrollY(); 1179 return mScrollView.getScrollY();
1179 } 1180 }
1180 } 1181 }
1182
1183 public int getScrollPosition() {
Ted C 2016/09/19 19:59:08 javadoc (probably worth noting that it does not ne
Michael van Ouwerkerk 2016/09/20 11:08:16 Done.
1184 return mRecyclerView.getScrollPosition();
1185 }
1181 } 1186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698