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) {
|
||||
|
||||
private var currentSongIndex = 0
|
||||
private var songsHashCode = songs.hashCode()
|
||||
var isThirdPartyIntent = false
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab
|
||||
|
@ -171,9 +172,13 @@ class SongAdapter(activity: SimpleActivity, var songs: ArrayList<Song>, recycler
|
|||
}
|
||||
|
||||
fun updateSongs(newSongs: ArrayList<Song>) {
|
||||
songs = newSongs
|
||||
currentSongIndex = -1
|
||||
notifyDataSetChanged()
|
||||
val newHashCode = newSongs.hashCode()
|
||||
if (newHashCode != songsHashCode) {
|
||||
songsHashCode = newHashCode
|
||||
songs = newSongs
|
||||
currentSongIndex = -1
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCurrentSongIndex(index: Int) {
|
||||
|
|
Loading…
Reference in a new issue