From 11e03dd0e079cd8d07b740cf2cce94f554889809 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 2 Apr 2020 11:30:45 +0200 Subject: [PATCH] just update recordings when appropriate, do not recreate the list --- .../voicerecorder/adapters/RecordingsAdapter.kt | 14 ++++++++++++-- .../voicerecorder/fragments/PlayerFragment.kt | 17 +++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt index 6ebbe71..9ffbabc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt @@ -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, val refreshListener: RefreshRecordingsListener, - recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { +class RecordingsAdapter( + activity: SimpleActivity, var recordings: ArrayList, 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) { + if (newItems.hashCode() != recordings.hashCode()) { + recordings = newItems + finishActMode() + } + fastScroller?.measureRecyclerView() + } + private fun renameRecording() { val recording = getItemWithKey(selectedKeys.first()) ?: return RenameRecordingDialog(activity, recording) { 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 2a05498..b71c76a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt @@ -107,13 +107,18 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager private fun setupAdapter() { val recordings = getRecordings() - RecordingsAdapter(context as SimpleActivity, recordings, this, recordings_list, recordings_fastscroller) { - playRecording(it as Recording) - if (playedRecordingIDs.isEmpty() || playedRecordingIDs.peek() != it.id) { - playedRecordingIDs.push(it.id) + 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) { + playedRecordingIDs.push(it.id) + } + }.apply { + recordings_list.adapter = this } - }.apply { - recordings_list.adapter = this + } else { + adapter.updateItems(recordings) } }