PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/model/Song.kt

112 lines
3.7 KiB
Kotlin
Raw Normal View History

2019-03-04 03:55:09 +00:00
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.model
import android.net.Uri
2019-03-04 03:55:09 +00:00
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
2019-03-04 03:55:09 +00:00
// update equals and hashcode if fields changes
2019-03-04 03:55:09 +00:00
@Parcelize
2019-11-13 13:07:44 +00:00
open class Song(
open val id: Long,
open val title: String,
open val trackNumber: Int,
open val year: Int,
open val duration: Long,
// stream path
open val data: String,
open val dateModified: Long,
open val albumId: Long,
open val albumName: String,
open val artistId: Long,
open val artistName: String,
open val composer: String?,
open val albumArtist: String?,
open val coverArt: String?,
// TODO: store genres in a smarter way
open val genres: Array<String>?
2019-11-13 13:07:44 +00:00
) : Parcelable {
2020-08-21 14:19:15 +00:00
val coverArtUri: Uri?
get() = Uri.parse(coverArt)
2019-03-04 03:55:09 +00:00
// need to override manually because is open and cannot be a data class
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Song
if (id != other.id) return false
if (title != other.title) return false
if (trackNumber != other.trackNumber) return false
if (year != other.year) return false
if (duration != other.duration) return false
if (data != other.data) return false
if (dateModified != other.dateModified) return false
if (albumId != other.albumId) return false
if (albumName != other.albumName) return false
if (artistId != other.artistId) return false
if (artistName != other.artistName) return false
if (composer != other.composer) return false
if (albumArtist != other.albumArtist) return false
if (coverArt != other.coverArt) return false
if (!genres.contentEquals(other.genres)) return false
return true
}
override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + title.hashCode()
result = 31 * result + trackNumber
result = 31 * result + year
result = 31 * result + duration.hashCode()
result = 31 * result + data.hashCode()
result = 31 * result + dateModified.hashCode()
result = 31 * result + albumId.hashCode()
result = 31 * result + albumName.hashCode()
result = 31 * result + artistId.hashCode()
result = 31 * result + artistName.hashCode()
result = 31 * result + (composer?.hashCode() ?: 0)
result = 31 * result + (albumArtist?.hashCode() ?: 0)
result = 31 * result + (coverArt?.hashCode() ?: 0)
result = 31 * result + (genres?.contentHashCode() ?: 0)
return result
}
2019-03-04 03:55:09 +00:00
companion object {
2019-03-04 03:55:09 +00:00
@JvmStatic
2019-11-13 13:07:44 +00:00
val emptySong = Song(
id = -1,
title = "",
trackNumber = -1,
year = -1,
duration = -1,
data = "",
dateModified = -1,
albumId = -1,
albumName = "",
artistId = -1,
artistName = "",
composer = "",
albumArtist = "",
coverArt = "",
genres = emptyArray()
2019-11-13 13:07:44 +00:00
)
2019-03-04 03:55:09 +00:00
}
}