Merge pull request #3419 from ByteHamster/crash-fixes

Fixed crash when controller is null
This commit is contained in:
H. Lehmann 2019-09-13 22:24:44 +02:00 committed by GitHub
commit 1fe451b9bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

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