From: masensio Date: Mon, 7 Apr 2014 06:58:42 +0000 (+0200) Subject: Merge branch 'develop' into save_position_in_scroll_when_browsing X-Git-Tag: oc-android-1.7.0_signed~337^2~7 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/14a466edebae51f1e83a0393d4e4248163c4b3cf?hp=903bf0286e8e9baae48c4ee3655118a73af9d6dd Merge branch 'develop' into save_position_in_scroll_when_browsing --- diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index cb370070..70432486 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -65,6 +65,9 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ? OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment"; private static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE"; + + private static final String KEY_INDEXES = "INDEXES"; + private static final String KEY_TOPS = "TOPS"; private OCFileListFragment.ContainerActivity mContainerActivity; @@ -73,6 +76,10 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName private Handler mHandler; private OCFile mTargetFile; + + private ArrayList mIndexes; + private ArrayList mTops; + /** * {@inheritDoc} @@ -87,8 +94,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName throw new ClassCastException(activity.toString() + " must implement " + OCFileListFragment.ContainerActivity.class.getSimpleName()); } } - - + + /** * {@inheritDoc} */ @@ -99,7 +106,15 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName mAdapter = new FileListListAdapter(getActivity(), mContainerActivity); if (savedInstanceState != null) { mFile = savedInstanceState.getParcelable(EXTRA_FILE); + mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES); + mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS); + + } else { + mIndexes = new ArrayList(); + mTops = new ArrayList(); + } + setListAdapter(mAdapter); registerForContextMenu(getListView()); @@ -116,9 +131,10 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName public void onSaveInstanceState (Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(EXTRA_FILE, mFile); + outState.putIntegerArrayList(KEY_INDEXES, mIndexes); + outState.putIntegerArrayList(KEY_TOPS, mTops); } - - + /** * Call this, when the user presses the up button. * @@ -156,11 +172,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 +212,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