Make Artist and Entry comparable (thus sortable)

This commit is contained in:
tzugen 2021-05-27 11:14:23 +02:00
parent aa1c0d8baa
commit 154662bec5
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 30 additions and 2 deletions

View File

@ -9,8 +9,22 @@ data class Artist(
var coverArt: String? = null,
var albumCount: Long? = null,
var closeness: Int = 0
) : Serializable, GenericEntry() {
) : Serializable, GenericEntry(), Comparable<Artist> {
companion object {
private const val serialVersionUID = -5790532593784846982L
}
override fun compareTo(other: Artist): Int {
when {
this.closeness == other.closeness -> {
return 0
}
this.closeness > other.closeness -> {
return -1
}
else -> {
return 1
}
}
}
}

View File

@ -66,7 +66,7 @@ class MusicDirectory {
var bookmarkPosition: Int = 0,
var userRating: Int? = null,
var averageRating: Float? = null
) : Serializable, GenericEntry() {
) : Serializable, GenericEntry(), Comparable<Entry> {
fun setDuration(duration: Long) {
this.duration = duration.toInt()
}
@ -74,5 +74,19 @@ class MusicDirectory {
companion object {
private const val serialVersionUID = -3339106650010798108L
}
override fun compareTo(other: Entry): Int {
when {
this.closeness == other.closeness -> {
return 0
}
this.closeness > other.closeness -> {
return -1
}
else -> {
return 1
}
}
}
}
}