just update recordings when appropriate, do not recreate the list

This commit is contained in:
tibbi 2020-04-02 11:30:45 +02:00
parent cda6ccdabf
commit 11e03dd0e0
2 changed files with 23 additions and 8 deletions

View File

@ -19,8 +19,10 @@ import com.simplemobiletools.voicerecorder.models.Recording
import kotlinx.android.synthetic.main.item_recording.view.*
import java.util.*
class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList<Recording>, val refreshListener: RefreshRecordingsListener,
recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
class RecordingsAdapter(
activity: SimpleActivity, var recordings: ArrayList<Recording>, val refreshListener: RefreshRecordingsListener,
recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit
) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
var currRecordingId = 0
init {
@ -73,6 +75,14 @@ class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList<Reco
private fun getItemWithKey(key: Int): Recording? = recordings.firstOrNull { it.id == key }
fun updateItems(newItems: ArrayList<Recording>) {
if (newItems.hashCode() != recordings.hashCode()) {
recordings = newItems
finishActMode()
}
fastScroller?.measureRecyclerView()
}
private fun renameRecording() {
val recording = getItemWithKey(selectedKeys.first()) ?: return
RenameRecordingDialog(activity, recording) {

View File

@ -107,6 +107,8 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
private fun setupAdapter() {
val recordings = getRecordings()
val adapter = getRecordingsAdapter()
if (adapter == null) {
RecordingsAdapter(context as SimpleActivity, recordings, this, recordings_list, recordings_fastscroller) {
playRecording(it as Recording)
if (playedRecordingIDs.isEmpty() || playedRecordingIDs.peek() != it.id) {
@ -115,6 +117,9 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
}.apply {
recordings_list.adapter = this
}
} else {
adapter.updateItems(recordings)
}
}
@SuppressLint("InlinedApi")