Skip to content

Commit 1b4292e

Browse files
committed
fix: layout switching for local file indicator
Signed-off-by: alperozturk <[email protected]>
1 parent 96b872e commit 1b4292e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import android.app.Activity;
2020
import android.content.Context;
2121
import android.content.Intent;
22-
import android.os.AsyncTask;
2322
import android.os.Bundle;
2423
import android.os.Handler;
2524
import android.os.Looper;
@@ -1704,39 +1703,46 @@ public void switchToGridView() {
17041703

17051704
@SuppressLint("NotifyDataSetChanged")
17061705
public void switchLayoutManager(boolean grid) {
1706+
final var recyclerView = getRecyclerView();
1707+
final var adapter = getAdapter();
1708+
final var context = getContext();
1709+
1710+
if (context == null || adapter == null || recyclerView == null) {
1711+
Log_OC.e(TAG, "cannot switch layout, arguments are null");
1712+
return;
1713+
}
1714+
17071715
int position = 0;
17081716

1709-
if (getRecyclerView() != null && getRecyclerView().getLayoutManager() != null) {
1710-
position = ((LinearLayoutManager) getRecyclerView().getLayoutManager())
1711-
.findFirstCompletelyVisibleItemPosition();
1717+
if (recyclerView.getLayoutManager() instanceof LinearLayoutManager linearLayoutManager) {
1718+
position = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
17121719
}
17131720

17141721
RecyclerView.LayoutManager layoutManager;
17151722
if (grid) {
1716-
layoutManager = new GridLayoutManager(getContext(), getColumnsCount());
1717-
((GridLayoutManager) layoutManager).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
1723+
layoutManager = new GridLayoutManager(context, getColumnsCount());
1724+
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
1725+
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
17181726
@Override
17191727
public int getSpanSize(int position) {
17201728
if (position == getAdapter().getItemCount() - 1 ||
17211729
position == 0 && getAdapter().shouldShowHeader()) {
1722-
return ((GridLayoutManager) layoutManager).getSpanCount();
1730+
return gridLayoutManager.getSpanCount();
17231731
} else {
17241732
return 1;
17251733
}
17261734
}
17271735
});
1728-
17291736
} else {
1730-
layoutManager = new LinearLayoutManager(getContext());
1737+
layoutManager = new LinearLayoutManager(context);
17311738
}
17321739

1733-
if (getRecyclerView() != null) {
1734-
getRecyclerView().setLayoutManager(layoutManager);
1735-
getRecyclerView().scrollToPosition(position);
1736-
getAdapter().setGridView(grid);
1737-
getRecyclerView().setAdapter(getAdapter());
1738-
getAdapter().notifyDataSetChanged();
1739-
}
1740+
recyclerView.setLayoutManager(layoutManager);
1741+
recyclerView.scrollToPosition(position);
1742+
adapter.setGridView(grid);
1743+
recyclerView.setAdapter(adapter);
1744+
adapter.notifyDataSetChanged();
1745+
onRefresh();
17401746
}
17411747

17421748
public CommonOCFileListAdapterInterface getCommonAdapter() {

0 commit comments

Comments
 (0)