Skip to content

Commit

Permalink
Better MediaItem checking
Browse files Browse the repository at this point in the history
  • Loading branch information
brahmkshatriya committed Feb 16, 2024
1 parent 5dbb332 commit dfb9df3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions app/src/main/java/dev/brahmkshatriya/echo/data/models/MediaItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,20 @@ sealed class MediaItem {
fun List<MediaItem>.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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit dfb9df3

Please sign in to comment.