mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-06-05 21:59:31 +02:00
add handling for the case when the currently playing recording is deleted
This commit is contained in:
@@ -118,6 +118,7 @@ class RecordingsAdapter(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val oldRecordingIndex = recordings.indexOfFirst { it.id == currRecordingId }
|
||||||
val recordingsToRemove = recordings.filter { selectedKeys.contains(it.id) } as ArrayList<Recording>
|
val recordingsToRemove = recordings.filter { selectedKeys.contains(it.id) } as ArrayList<Recording>
|
||||||
val positions = getSelectedItemPositions()
|
val positions = getSelectedItemPositions()
|
||||||
recordingsToRemove.forEach {
|
recordingsToRemove.forEach {
|
||||||
@@ -134,6 +135,11 @@ class RecordingsAdapter(
|
|||||||
finishActMode()
|
finishActMode()
|
||||||
} else {
|
} else {
|
||||||
removeSelectedItems(positions)
|
removeSelectedItems(positions)
|
||||||
|
if (recordingsToRemove.map { it.id }.contains(currRecordingId)) {
|
||||||
|
val newRecordingIndex = Math.min(oldRecordingIndex, recordings.size - 1)
|
||||||
|
val newRecording = recordings[newRecordingIndex]
|
||||||
|
refreshListener.playRecording(newRecording)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -182,7 +182,7 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun playRecording(recording: Recording) {
|
override fun playRecording(recording: Recording) {
|
||||||
val recordingUri = ContentUris.withAppendedId(
|
val recordingUri = ContentUris.withAppendedId(
|
||||||
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||||
recording.id.toLong()
|
recording.id.toLong()
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
package com.simplemobiletools.voicerecorder.interfaces
|
package com.simplemobiletools.voicerecorder.interfaces
|
||||||
|
|
||||||
|
import com.simplemobiletools.voicerecorder.models.Recording
|
||||||
|
|
||||||
interface RefreshRecordingsListener {
|
interface RefreshRecordingsListener {
|
||||||
fun refreshRecordings()
|
fun refreshRecordings()
|
||||||
|
|
||||||
|
fun playRecording(recording: Recording)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user