Avoid unnecessary updates

This commit is contained in:
Naveen 2023-09-01 20:12:55 +05:30
parent 8dbbe99253
commit 5721ccf615
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3
2 changed files with 7 additions and 13 deletions

View file

@ -8,7 +8,6 @@ import android.view.MenuItem
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat import androidx.core.view.MenuItemCompat
import androidx.media3.common.MediaItem import androidx.media3.common.MediaItem
import androidx.media3.common.Timeline
import com.simplemobiletools.commons.extensions.areSystemAnimationsEnabled import com.simplemobiletools.commons.extensions.areSystemAnimationsEnabled
import com.simplemobiletools.commons.extensions.beGoneIf import com.simplemobiletools.commons.extensions.beGoneIf
import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.extensions.getProperPrimaryColor
@ -60,8 +59,6 @@ class QueueActivity : SimpleControllerActivity() {
getAdapter()?.updateCurrentTrack() getAdapter()?.updateCurrentTrack()
} }
override fun onTimelineChanged(timeline: Timeline, reason: Int) = updateAdapter()
private fun setupOptionsMenu() { private fun setupOptionsMenu() {
setupSearch(binding.queueToolbar.menu) setupSearch(binding.queueToolbar.menu)
binding.queueToolbar.setOnMenuItemClickListener { menuItem -> binding.queueToolbar.setOnMenuItemClickListener { menuItem ->
@ -159,15 +156,6 @@ class QueueActivity : SimpleControllerActivity() {
} }
} }
private fun updateAdapter() {
val adapter = getAdapter() ?: return
withPlayer {
val currentTracks = currentMediaItemsShuffled.toTracks() as ArrayList<Track>
adapter.updateItems(currentTracks)
binding.queueList.lazySmoothScroll(shuffledMediaItemsIndices.indexOf(currentMediaItemIndex))
}
}
private fun createPlaylistFromQueue() { private fun createPlaylistFromQueue() {
NewPlaylistDialog(this) { newPlaylistId -> NewPlaylistDialog(this) { newPlaylistId ->
val tracks = ArrayList<Track>() val tracks = ArrayList<Track>()

View file

@ -1,5 +1,6 @@
package com.simplemobiletools.musicplayer.adapters package com.simplemobiletools.musicplayer.adapters
import android.annotation.SuppressLint
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.Menu import android.view.Menu
import android.widget.ImageView import android.widget.ImageView
@ -155,5 +156,10 @@ abstract class BaseMusicAdapter<Type>(
} }
} }
fun notifyDataChanged() = notifyItemRangeChanged(0, itemCount) @SuppressLint("NotifyDataSetChanged")
fun notifyDataChanged() = if (itemCount == 0) {
notifyDataSetChanged()
} else {
notifyItemRangeChanged(0, itemCount)
}
} }