From: masensio Date: Tue, 8 Apr 2014 09:28:50 +0000 (+0200) Subject: Merge branch 'develop' into save_position_in_scroll_when_browsing X-Git-Tag: oc-android-1.7.0_signed~337^2~4 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/812da2727d432f17c6667f381c7a041c34844f62?hp=69d40e505ef57770bddbb24ddc4156e0474993fc 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..b2e4b503 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -1,6 +1,6 @@ /* ownCloud Android client application * Copyright (C) 2011 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2012-2014 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -65,6 +65,10 @@ 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_FIRST_POSITIONS= "FIRST_POSITIONS"; + private static final String KEY_TOPS = "TOPS"; private OCFileListFragment.ContainerActivity mContainerActivity; @@ -73,6 +77,11 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName private Handler mHandler; private OCFile mTargetFile; + + private ArrayList mIndexes; + private ArrayList mFirstPositions; + private ArrayList mTops; + /** * {@inheritDoc} @@ -87,8 +96,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName throw new ClassCastException(activity.toString() + " must implement " + OCFileListFragment.ContainerActivity.class.getSimpleName()); } } - - + + /** * {@inheritDoc} */ @@ -99,7 +108,17 @@ 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); + mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS); + mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS); + + } else { + mIndexes = new ArrayList(); + mFirstPositions = new ArrayList(); + mTops = new ArrayList(); + } + setListAdapter(mAdapter); registerForContextMenu(getListView()); @@ -116,9 +135,11 @@ 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_FIRST_POSITIONS, mFirstPositions); + outState.putIntegerArrayList(KEY_TOPS, mTops); } - - + /** * Call this, when the user presses the up button. * @@ -156,11 +177,56 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName listDirectory(mFile); mContainerActivity.startSyncFolderOperation(mFile); + + // restore index and top position + restoreIndexAndTopPosition(); + } // else - should never happen now return moveCount; } + /* + * Restore index and position + */ + private void restoreIndexAndTopPosition() { + int index = mIndexes.get(mIndexes.size() - 1); + mIndexes.remove(mIndexes.size() - 1); + + int firstPosition = mFirstPositions.get(mFirstPositions.size() - 1); + mFirstPositions.remove(mFirstPositions.size() -1); + + int top = mTops.get(mTops.size() - 1); + mTops.remove(mTops.size() - 1); + + mList.setSelectionFromTop(firstPosition, top); + + // Move the scroll if the selection is not visible + View view = mList.getChildAt(0); + int indexPosition = view.getHeight()*index; + int height = mList.getHeight(); + + if (indexPosition > height) { + mList.smoothScrollToPosition(index); + } + } + + /* + * Save index and top position + */ + private void saveIndexAndTopPosition(int index) { + + mIndexes.add(index); + + int firstPosition = mList.getFirstVisiblePosition(); + mFirstPositions.add(firstPosition); + + View view = mList.getChildAt(0); + int top = (view == null) ? 0 : view.getTop() ; + + mTops.add(top); + } + @Override public void onItemClick(AdapterView l, View v, int position, long id) { OCFile file = (OCFile) mAdapter.getItem(position); @@ -170,6 +236,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName listDirectory(file); // then, notify parent activity to let it update its state and view, and other fragments mContainerActivity.onBrowsedDownTo(file); + // save index and top position + saveIndexAndTopPosition(position); } else { /// Click on a file if (PreviewImageFragment.canBePreviewed(file)) {