Fixed crash when controller is null

This commit is contained in:
ByteHamster 2019-09-13 22:10:59 +02:00
parent ada0101b07
commit 46639c2a91
1 changed files with 7 additions and 6 deletions

View File

@ -87,11 +87,10 @@ public class ChaptersFragment extends ListFragment {
controller = null;
}
private void scrollTo(int position) {
getListView().setSelection(position);
}
private int getCurrentChapter(Playable media) {
if (media == null || media.getChapters() == null || media.getChapters().size() == 0 || controller == null) {
return -1;
}
int currentPosition = controller.getPosition();
List<Chapter> chapters = media.getChapters();
@ -126,8 +125,10 @@ public class ChaptersFragment extends ListFragment {
if (adapter != null) {
adapter.setMedia(media);
adapter.notifyDataSetChanged();
if (media != null && media.getChapters() != null && media.getChapters().size() != 0) {
scrollTo(getCurrentChapter(media));
int positionOfCurrentChapter = getCurrentChapter(media);
if (positionOfCurrentChapter != -1) {
getListView().setSelection(positionOfCurrentChapter);
}
}
}