From: masensio Date: Thu, 3 Apr 2014 12:36:55 +0000 (+0200) Subject: Save the scroll position when moving between folders. REstore scroll position X-Git-Tag: oc-android-1.7.0_signed~337^2~9 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/20e3a5f4201409de316f1ca20aaa8fce04ee0e4f?ds=inline Save the scroll position when moving between folders. REstore scroll position --- diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index cb370070..e25f3dc5 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -73,6 +73,10 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName private Handler mHandler; private OCFile mTargetFile; + + private ArrayList mIndexes; + private ArrayList mTops; + /** * {@inheritDoc} @@ -87,8 +91,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName throw new ClassCastException(activity.toString() + " must implement " + OCFileListFragment.ContainerActivity.class.getSimpleName()); } } - - + + /** * {@inheritDoc} */ @@ -106,6 +110,10 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName getListView().setOnCreateContextMenuListener(this); mHandler = new Handler(); + + mIndexes = new ArrayList(); + mTops = new ArrayList(); + } @@ -117,8 +125,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName super.onSaveInstanceState(outState); outState.putParcelable(EXTRA_FILE, mFile); } - - + /** * Call this, when the user presses the up button. * @@ -156,11 +163,36 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName listDirectory(mFile); mContainerActivity.startSyncFolderOperation(mFile); + + // restore index and position + restoreIndexAndPosition(); + } // else - should never happen now return moveCount; } + /* + * Restore index and position + */ + private void restoreIndexAndPosition() { + int index = mIndexes.get(mIndexes.size() - 1); + mIndexes.remove(mIndexes.size() - 1); + int top = mTops.get(mTops.size() - 1); + mTops.remove(mTops.size() - 1); + mList.setSelectionFromTop(index, top); + } + + /* + * Save index and top position + */ + private void saveIndexAndPosition(int index) { + + mIndexes.add(index); + View view = mList.getChildAt(0); + mTops.add( (view == null) ? 0 : view.getTop() ); + } + @Override public void onItemClick(AdapterView l, View v, int position, long id) { OCFile file = (OCFile) mAdapter.getItem(position); @@ -171,6 +203,9 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName // then, notify parent activity to let it update its state and view, and other fragments mContainerActivity.onBrowsedDownTo(file); + // save index and top position + saveIndexAndPosition(position); + } else { /// Click on a file if (PreviewImageFragment.canBePreviewed(file)) { // preview image - it handles the download, if needed