mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 10:18:59 +03:00
Save the scroll position when moving between folders. REstore scroll position
This commit is contained in:
parent
901b6ac61e
commit
20e3a5f420
1 changed files with 39 additions and 4 deletions
|
@ -74,6 +74,10 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
private OCFile mTargetFile;
|
private OCFile mTargetFile;
|
||||||
|
|
||||||
|
private ArrayList<Integer> mIndexes;
|
||||||
|
private ArrayList<Integer> mTops;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -107,6 +111,10 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
|
||||||
|
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
|
|
||||||
|
mIndexes = new ArrayList<Integer>();
|
||||||
|
mTops = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,7 +126,6 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
|
||||||
outState.putParcelable(EXTRA_FILE, mFile);
|
outState.putParcelable(EXTRA_FILE, mFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this, when the user presses the up button.
|
* Call this, when the user presses the up button.
|
||||||
*
|
*
|
||||||
|
@ -156,11 +163,36 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
|
||||||
listDirectory(mFile);
|
listDirectory(mFile);
|
||||||
|
|
||||||
mContainerActivity.startSyncFolderOperation(mFile);
|
mContainerActivity.startSyncFolderOperation(mFile);
|
||||||
|
|
||||||
|
// restore index and position
|
||||||
|
restoreIndexAndPosition();
|
||||||
|
|
||||||
} // else - should never happen now
|
} // else - should never happen now
|
||||||
|
|
||||||
return moveCount;
|
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
|
@Override
|
||||||
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
||||||
OCFile file = (OCFile) mAdapter.getItem(position);
|
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
|
// then, notify parent activity to let it update its state and view, and other fragments
|
||||||
mContainerActivity.onBrowsedDownTo(file);
|
mContainerActivity.onBrowsedDownTo(file);
|
||||||
|
|
||||||
|
// save index and top position
|
||||||
|
saveIndexAndPosition(position);
|
||||||
|
|
||||||
} else { /// Click on a file
|
} else { /// Click on a file
|
||||||
if (PreviewImageFragment.canBePreviewed(file)) {
|
if (PreviewImageFragment.canBePreviewed(file)) {
|
||||||
// preview image - it handles the download, if needed
|
// preview image - it handles the download, if needed
|
||||||
|
|
Loading…
Reference in a new issue