diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-09-13 22:24:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-13 22:24:44 +0200 |
commit | 1fe451b9bbed083898fbd3e7db3ba4d47c13f3ca (patch) | |
tree | 2d32ad393445217d9131bf4991da636d8f30a54a | |
parent | ee737d5d88ac6f2024ac2b0809bbf61439407ff3 (diff) | |
parent | 46639c2a9181af5cff4af988c8bec281203e7a18 (diff) | |
download | AntennaPod-1fe451b9bbed083898fbd3e7db3ba4d47c13f3ca.zip |
Merge pull request #3419 from ByteHamster/crash-fixes
Fixed crash when controller is null
-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); } } } |