diff options
author | ByteHamster <info@bytehamster.com> | 2019-09-13 22:10:59 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-09-13 22:10:59 +0200 |
commit | 46639c2a9181af5cff4af988c8bec281203e7a18 (patch) | |
tree | f0dac8d3ac93f6108e06ad959e5649986c03e22a /app/src/main/java/de/danoeh/antennapod | |
parent | ada0101b0754cf4b34a1719f90f0b20571dab8db (diff) | |
download | AntennaPod-46639c2a9181af5cff4af988c8bec281203e7a18.zip |
Fixed crash when controller is null
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java index 4bebfe4c9..bb8f4df9a 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java @@ -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); } } } |