Fix scroll position in episode list of podcast preview (#7862)

ID is needed so that `CoordinatorLayout` automatically saves its state
This commit is contained in:
schasi 2025-07-03 13:34:48 +02:00 committed by GitHub
parent b65062d18d
commit 21a4d7d876
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -104,6 +104,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
private Feed feed;
private Disposable disposable;
private FeedItemListFragmentBinding viewBinding;
private Pair<Integer, Integer> scrollPosition = null;
/**
* Creates new ItemlistFragment which shows the Feeditems of a specific
@ -248,6 +249,12 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
viewBinding.recyclerView.getPaddingRight(), paddingBottom);
}
@Override
public void onPause() {
super.onPause();
scrollPosition = viewBinding.recyclerView.getScrollPosition();
}
@Override
public void onDestroyView() {
super.onDestroyView();
@ -654,6 +661,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
adapter.updateItems(feed.getItems());
adapter.setTotalNumberOfItems(result.second);
updateToolbar();
viewBinding.recyclerView.restoreScrollPosition(scrollPosition);
scrollPosition = null;
}, error -> {
feed = null;
refreshHeaderView();

View File

@ -2,6 +2,7 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">