diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java index 233cc36b6b89..6ea8e0fe3e1a 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -33,6 +33,7 @@ import android.os.Looper; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -148,7 +149,9 @@ public class ExtendedListFragment extends Fragment implements private ListFragmentBinding binding; protected void setRecyclerViewAdapter(RecyclerView.Adapter recyclerViewAdapter) { + mRecyclerView.getRecycledViewPool().clear(); mRecyclerView.setAdapter(recyclerViewAdapter); + mRecyclerView.getAdapter().notifyDataSetChanged(); } protected RecyclerView getRecyclerView() { @@ -161,13 +164,13 @@ public void setLoading(boolean enabled) { public void switchToGridView() { if (!isGridEnabled()) { - getRecyclerView().setLayoutManager(new GridLayoutManager(getContext(), getColumnsCount())); + getRecyclerView().setLayoutManager(new WrapContentGridLayoutManager(getContext(), getColumnsCount())); } } public void switchToListView() { if (isGridEnabled()) { - getRecyclerView().setLayoutManager(new LinearLayoutManager(getContext())); + getRecyclerView().setLayoutManager(new WrapContentLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); } } @@ -699,3 +702,42 @@ protected void setGridSwitchButton() { } } } +class WrapContentLinearLayoutManager extends LinearLayoutManager { + public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { + super(context, orientation, reverseLayout); + } + + @Override + public boolean supportsPredictiveItemAnimations() { + return false; + } + @Override + public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { + try { + super.onLayoutChildren(recycler, state); + } catch (IndexOutOfBoundsException e) { + Log.e("TAG", "meet a IOOBE in RecyclerView"); + } + } +} + + +class WrapContentGridLayoutManager extends GridLayoutManager { + public WrapContentGridLayoutManager(Context context, int spanCount) { + super(context, spanCount); + } + + @Override + public boolean supportsPredictiveItemAnimations() { + return false; + } + + @Override + public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { + try { + super.onLayoutChildren(recycler, state); + } catch (IndexOutOfBoundsException e) { + Log.e("TAG", "meet a IOOBE in RecyclerView"); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index a188cddbfd5f..58a034ceca1d 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -1436,13 +1436,14 @@ public void switchLayoutManager(boolean grid) { RecyclerView.LayoutManager layoutManager; if (grid) { - layoutManager = new GridLayoutManager(getContext(), getColumnsCount()); - ((GridLayoutManager) layoutManager).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { + //layoutManager = new GridLayoutManager(getContext(), getColumnsCount()); + layoutManager=new WrapContentGridLayoutManager(getContext(),getColumnsCount()); + ((WrapContentGridLayoutManager) layoutManager).setSpanSizeLookup(new WrapContentGridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (position == getAdapter().getItemCount() - 1 || position == 0 && getAdapter().shouldShowHeader()) { - return ((GridLayoutManager) layoutManager).getSpanCount(); + return ((WrapContentGridLayoutManager) layoutManager).getSpanCount(); } else { return 1; } @@ -1450,9 +1451,12 @@ public int getSpanSize(int position) { }); } else { - layoutManager = new LinearLayoutManager(getContext()); + //layoutManager = new LinearLayoutManager(getContext()); + layoutManager=new WrapContentLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false); } + getRecyclerView().getLayoutManager().removeAllViews(); + getRecyclerView().getRecycledViewPool().clear(); getRecyclerView().setLayoutManager(layoutManager); getRecyclerView().scrollToPosition(position); getAdapter().setGridView(grid);