From: masensio Date: Tue, 8 Apr 2014 11:58:27 +0000 (+0200) Subject: Fix bug: App crashes when coming back from a folder of second level X-Git-Tag: oc-android-1.7.0_signed~337^2~3 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/086985ad26583ffa93e1519383d716f55d0c1d19?ds=sidebyside Fix bug: App crashes when coming back from a folder of second level --- diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index b2e4b503..67d5f8b2 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -69,6 +69,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName private static final String KEY_INDEXES = "INDEXES"; private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS"; private static final String KEY_TOPS = "TOPS"; + private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL"; private OCFileListFragment.ContainerActivity mContainerActivity; @@ -78,10 +79,12 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName private Handler mHandler; private OCFile mTargetFile; + // Save the state of the scroll in browsing private ArrayList mIndexes; private ArrayList mFirstPositions; private ArrayList mTops; + private int mHeightCell = 0; /** * {@inheritDoc} @@ -111,11 +114,13 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES); mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS); mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS); + mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL); } else { mIndexes = new ArrayList(); mFirstPositions = new ArrayList(); mTops = new ArrayList(); + mHeightCell = 0; } @@ -138,6 +143,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName outState.putIntegerArrayList(KEY_INDEXES, mIndexes); outState.putIntegerArrayList(KEY_FIRST_POSITIONS, mFirstPositions); outState.putIntegerArrayList(KEY_TOPS, mTops); + outState.putInt(KEY_HEIGHT_CELL, mHeightCell); } /** @@ -202,8 +208,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName mList.setSelectionFromTop(firstPosition, top); // Move the scroll if the selection is not visible - View view = mList.getChildAt(0); - int indexPosition = view.getHeight()*index; + int indexPosition = mHeightCell*index; int height = mList.getHeight(); if (indexPosition > height) { @@ -225,6 +230,9 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName int top = (view == null) ? 0 : view.getTop() ; mTops.add(top); + + // Save the height of a cell + mHeightCell = (view == null || mHeightCell != 0) ? mHeightCell : view.getHeight(); } @Override