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 kotlinx.android.synthetic.main.item_recording.view.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList<Recording>, val refreshListener: RefreshRecordingsListener,
|
class RecordingsAdapter(
|
||||||
recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
activity: SimpleActivity, var recordings: ArrayList<Recording>, val refreshListener: RefreshRecordingsListener,
|
||||||
|
recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit
|
||||||
|
) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||||
var currRecordingId = 0
|
var currRecordingId = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -73,6 +75,14 @@ class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList<Reco
|
||||||
|
|
||||||
private fun getItemWithKey(key: Int): Recording? = recordings.firstOrNull { it.id == key }
|
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() {
|
private fun renameRecording() {
|
||||||
val recording = getItemWithKey(selectedKeys.first()) ?: return
|
val recording = getItemWithKey(selectedKeys.first()) ?: return
|
||||||
RenameRecordingDialog(activity, recording) {
|
RenameRecordingDialog(activity, recording) {
|
||||||
|
|
|
@ -107,13 +107,18 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
||||||
|
|
||||||
private fun setupAdapter() {
|
private fun setupAdapter() {
|
||||||
val recordings = getRecordings()
|
val recordings = getRecordings()
|
||||||
RecordingsAdapter(context as SimpleActivity, recordings, this, recordings_list, recordings_fastscroller) {
|
val adapter = getRecordingsAdapter()
|
||||||
playRecording(it as Recording)
|
if (adapter == null) {
|
||||||
if (playedRecordingIDs.isEmpty() || playedRecordingIDs.peek() != it.id) {
|
RecordingsAdapter(context as SimpleActivity, recordings, this, recordings_list, recordings_fastscroller) {
|
||||||
playedRecordingIDs.push(it.id)
|
playRecording(it as Recording)
|
||||||
|
if (playedRecordingIDs.isEmpty() || playedRecordingIDs.peek() != it.id) {
|
||||||
|
playedRecordingIDs.push(it.id)
|
||||||
|
}
|
||||||
|
}.apply {
|
||||||
|
recordings_list.adapter = this
|
||||||
}
|
}
|
||||||
}.apply {
|
} else {
|
||||||
recordings_list.adapter = this
|
adapter.updateItems(recordings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue