compare songs by their hashcode by default, not by id

This commit is contained in:
tibbi 2018-02-08 16:34:22 +01:00
parent 1bd07a6c34
commit baf1cb42dd
2 changed files with 3 additions and 9 deletions

View file

@ -467,7 +467,7 @@ class MainActivity : SimpleActivity(), SongListListener {
songs_playlist_empty_add_folder.beVisibleIf(songs.isEmpty())
}
private fun getSongIndex(song: Song): Int = songs.indexOfFirstOrNull { it == song } ?: 0
private fun getSongIndex(song: Song) = songs.indexOfFirstOrNull { it == song } ?: 0
private fun getSongsAdapter() = songs_list.adapter as? SongAdapter
@ -507,9 +507,9 @@ class MainActivity : SimpleActivity(), SongListListener {
}
private fun markCurrentSong() {
val newSongId = MusicService.mCurrSong?.id ?: -1L
val newSong = MusicService.mCurrSong
val cnt = songs.size - 1
val songIndex = (0..cnt).firstOrNull { songs[it].id == newSongId }?.plus(0) ?: -1
val songIndex = (0..cnt).firstOrNull { songs[it] == newSong } ?: -1
getSongsAdapter()?.updateCurrentSongIndex(songIndex)
}

View file

@ -49,12 +49,6 @@ data class Song(val id: Long, var title: String, var artist: String, var path: S
return res
}
override fun equals(other: Any?): Boolean = when {
this === other -> true
other == null -> false
else -> id == (other as Song).id
}
fun getBubbleText() = when {
sorting and SORT_BY_TITLE != 0 -> title
sorting and SORT_BY_ARTIST != 0 -> artist