From f2f2283525f1e29f9e834e43ebb15f76041d50c7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 2 Apr 2020 14:12:02 +0200 Subject: [PATCH] adding a crashfix when playing an empty playlist --- .../voicerecorder/fragments/PlayerFragment.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt index c9826a0..6a3a470 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt @@ -92,7 +92,11 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager } next_btn.setOnClickListener { - val adapter = getRecordingsAdapter() ?: return@setOnClickListener + val adapter = getRecordingsAdapter() + if (adapter == null || adapter.recordings.isEmpty()) { + return@setOnClickListener + } + val oldRecordingIndex = adapter.recordings.indexOfFirst { it.id == adapter.currRecordingId } val newRecordingIndex = (oldRecordingIndex + 1) % adapter.recordings.size val newRecording = adapter.recordings.getOrNull(newRecordingIndex) ?: return@setOnClickListener