avoid unnecessary adapter updates
This commit is contained in:
parent
6e0bb617ba
commit
bdf32e0834
1 changed files with 8 additions and 3 deletions
|
@ -35,6 +35,7 @@ class SongAdapter(activity: SimpleActivity, var songs: ArrayList<Song>, recycler
|
||||||
: MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
: MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||||
|
|
||||||
private var currentSongIndex = 0
|
private var currentSongIndex = 0
|
||||||
|
private var songsHashCode = songs.hashCode()
|
||||||
var isThirdPartyIntent = false
|
var isThirdPartyIntent = false
|
||||||
|
|
||||||
override fun getActionMenuId() = R.menu.cab
|
override fun getActionMenuId() = R.menu.cab
|
||||||
|
@ -171,9 +172,13 @@ class SongAdapter(activity: SimpleActivity, var songs: ArrayList<Song>, recycler
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateSongs(newSongs: ArrayList<Song>) {
|
fun updateSongs(newSongs: ArrayList<Song>) {
|
||||||
songs = newSongs
|
val newHashCode = newSongs.hashCode()
|
||||||
currentSongIndex = -1
|
if (newHashCode != songsHashCode) {
|
||||||
notifyDataSetChanged()
|
songsHashCode = newHashCode
|
||||||
|
songs = newSongs
|
||||||
|
currentSongIndex = -1
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateCurrentSongIndex(index: Int) {
|
fun updateCurrentSongIndex(index: Int) {
|
||||||
|
|
Loading…
Reference in a new issue