diff --git a/app/src/main/java/dev/brahmkshatriya/echo/data/models/MediaItem.kt b/app/src/main/java/dev/brahmkshatriya/echo/data/models/MediaItem.kt index a73252c6..b95a0764 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/data/models/MediaItem.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/data/models/MediaItem.kt @@ -15,4 +15,20 @@ sealed class MediaItem { fun List.toMediaItemsContainer(title: String, subtitle: String? = null) = MediaItemsContainer.Category(title, this, subtitle) } + + override fun equals(other: Any?): Boolean { + if(other is MediaItem) { + return when(this) { + is TrackItem -> this.track.uri == (other as? TrackItem)?.track?.uri + is AlbumItem -> this.album.uri == (other as? AlbumItem)?.album?.uri + is ArtistItem -> this.artist.uri == (other as? ArtistItem)?.artist?.uri + is PlaylistItem -> this.playlist.uri == (other as? PlaylistItem)?.playlist?.uri + } + } + return false + } + + override fun hashCode(): Int { + return javaClass.hashCode() + } } \ No newline at end of file diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/MediaItemsContainerAdapter.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/MediaItemsContainerAdapter.kt index 424e0a75..4683271f 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/MediaItemsContainerAdapter.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/MediaItemsContainerAdapter.kt @@ -156,8 +156,8 @@ class MediaItemsContainerAdapter( is MediaItemsContainer.Category -> { val newCategory = newItem as? MediaItemsContainer.Category newCategory ?: return true - oldItem.list.forEach { - if (!newCategory.list.contains(it)) return false + oldItem.list.forEachIndexed { index, mediaItem -> + if (newCategory.list.getOrNull(index) != mediaItem) return false } }