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