just update recordings when appropriate, do not recreate the list
This commit is contained in:
parent
cda6ccdabf
commit
11e03dd0e0
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue