Do not jump chapter screen when switching to new chapter

This commit is contained in:
ByteHamster 2022-02-25 19:53:00 +01:00
parent ecaba7525f
commit 441928b046
1 changed files with 6 additions and 6 deletions

View File

@ -71,7 +71,7 @@ public class ChaptersFragment extends AppCompatDialogFragment {
}
Chapter chapter = adapter.getItem(pos);
controller.seekTo((int) chapter.getStart());
updateChapterSelection(pos);
updateChapterSelection(pos, true);
});
recyclerView.setAdapter(adapter);
@ -117,7 +117,7 @@ public class ChaptersFragment extends AppCompatDialogFragment {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(PlaybackPositionEvent event) {
updateChapterSelection(getCurrentChapter(media));
updateChapterSelection(getCurrentChapter(media), false);
adapter.notifyTimeChanged(event.getPosition());
}
@ -160,10 +160,10 @@ public class ChaptersFragment extends AppCompatDialogFragment {
}
adapter.setMedia(media);
int positionOfCurrentChapter = getCurrentChapter(media);
updateChapterSelection(positionOfCurrentChapter);
updateChapterSelection(positionOfCurrentChapter, true);
}
private void updateChapterSelection(int position) {
private void updateChapterSelection(int position, boolean scrollTo) {
if (adapter == null) {
return;
}
@ -171,8 +171,8 @@ public class ChaptersFragment extends AppCompatDialogFragment {
if (position != -1 && focusedChapter != position) {
focusedChapter = position;
adapter.notifyChapterChanged(focusedChapter);
if (layoutManager.findFirstCompletelyVisibleItemPosition() >= position
|| layoutManager.findLastCompletelyVisibleItemPosition() <= position) {
if (scrollTo && (layoutManager.findFirstCompletelyVisibleItemPosition() >= position
|| layoutManager.findLastCompletelyVisibleItemPosition() <= position)) {
layoutManager.scrollToPositionWithOffset(position, 100);
}
}