From 5721ccf6150122c00b0754a4521d6893939d7ede Mon Sep 17 00:00:00 2001 From: Naveen Date: Fri, 1 Sep 2023 20:12:55 +0530 Subject: [PATCH] Avoid unnecessary updates --- .../musicplayer/activities/QueueActivity.kt | 12 ------------ .../musicplayer/adapters/BaseMusicAdapter.kt | 8 +++++++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/QueueActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/QueueActivity.kt index 6aabbfd1..6dbe6671 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/QueueActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/QueueActivity.kt @@ -8,7 +8,6 @@ import android.view.MenuItem import androidx.appcompat.widget.SearchView import androidx.core.view.MenuItemCompat import androidx.media3.common.MediaItem -import androidx.media3.common.Timeline import com.simplemobiletools.commons.extensions.areSystemAnimationsEnabled import com.simplemobiletools.commons.extensions.beGoneIf import com.simplemobiletools.commons.extensions.getProperPrimaryColor @@ -60,8 +59,6 @@ class QueueActivity : SimpleControllerActivity() { getAdapter()?.updateCurrentTrack() } - override fun onTimelineChanged(timeline: Timeline, reason: Int) = updateAdapter() - private fun setupOptionsMenu() { setupSearch(binding.queueToolbar.menu) 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 - adapter.updateItems(currentTracks) - binding.queueList.lazySmoothScroll(shuffledMediaItemsIndices.indexOf(currentMediaItemIndex)) - } - } - private fun createPlaylistFromQueue() { NewPlaylistDialog(this) { newPlaylistId -> val tracks = ArrayList() diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/BaseMusicAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/BaseMusicAdapter.kt index 4ad077dd..d314c5ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/BaseMusicAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/BaseMusicAdapter.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.musicplayer.adapters +import android.annotation.SuppressLint import android.graphics.drawable.Drawable import android.view.Menu import android.widget.ImageView @@ -155,5 +156,10 @@ abstract class BaseMusicAdapter( } } - fun notifyDataChanged() = notifyItemRangeChanged(0, itemCount) + @SuppressLint("NotifyDataSetChanged") + fun notifyDataChanged() = if (itemCount == 0) { + notifyDataSetChanged() + } else { + notifyItemRangeChanged(0, itemCount) + } }