avoid unnecessary adapter updates

This commit is contained in:
tibbi 2018-01-25 12:11:12 +01:00
parent 6e0bb617ba
commit bdf32e0834

View file

@ -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) {