adding a crashfix when playing an empty playlist

This commit is contained in:
tibbi 2020-04-02 14:12:02 +02:00
parent 886a60db24
commit f2f2283525
1 changed files with 5 additions and 1 deletions

View File

@ -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