- migrated ids from int to long

- some cleaning
This commit is contained in:
Eugeniu Olog 2020-09-17 23:25:41 +02:00
parent 90bca59192
commit 9e46d74507
58 changed files with 708 additions and 635 deletions

View file

@ -7,8 +7,8 @@ import org.koin.core.KoinComponent
import org.koin.core.inject
abstract class AbsCustomPlaylist(
id: Int = -1,
name: String = ""
id: Long,
name: String
) : Playlist(id, name), KoinComponent {
abstract fun songs(): List<Song>

View file

@ -14,19 +14,15 @@
package code.name.monkey.retromusic.model
import java.util.*
class Album {
val songs: ArrayList<Song>?
val id: Int
get() = safeGetFirstSong().albumId
data class Album(
val id: Long,
val songs: List<Song>
) {
val title: String?
get() = safeGetFirstSong().albumName
val artistId: Int
val artistId: Long
get() = safeGetFirstSong().artistId
val artistName: String?
@ -39,20 +35,17 @@ class Album {
get() = safeGetFirstSong().dateModified
val songCount: Int
get() = songs!!.size
get() = songs.size
val albumArtist: String?
get() = safeGetFirstSong().albumArtist
constructor(songs: ArrayList<Song>) {
this.songs = songs
}
constructor() {
this.songs = ArrayList()
}
fun safeGetFirstSong(): Song {
return if (songs!!.isEmpty()) Song.emptySong else songs[0]
return songs.firstOrNull() ?: Song.emptySong
}
companion object {
val empty = Album(-1, emptyList())
}
}

View file

@ -17,11 +17,10 @@ package code.name.monkey.retromusic.model
import code.name.monkey.retromusic.util.MusicUtil
import java.util.*
class Artist {
val albums: ArrayList<Album>?
val id: Int
get() = safeGetFirstAlbum().artistId
data class Artist(
val id: Long,
val albums: List<Album>
) {
val name: String
get() {
@ -34,37 +33,25 @@ class Artist {
val songCount: Int
get() {
var songCount = 0
for (album in albums!!) {
for (album in albums) {
songCount += album.songCount
}
return songCount
}
val albumCount: Int
get() = albums!!.size
get() = albums.size
val songs: ArrayList<Song>
get() {
val songs = ArrayList<Song>()
for (album in albums!!) {
songs.addAll(album.songs!!)
}
return songs
}
constructor(albums: ArrayList<Album>) {
this.albums = albums
}
constructor() {
this.albums = ArrayList()
}
val songs: List<Song>
get() = albums.flatMap { it.songs }
fun safeGetFirstAlbum(): Album {
return if (albums!!.isEmpty()) Album() else albums[0]
return albums.firstOrNull() ?: Album.empty
}
companion object {
const val UNKNOWN_ARTIST_DISPLAY_NAME = "Unknown Artist"
val empty = Artist(-1, emptyList())
}
}

View file

@ -1,82 +0,0 @@
/*
* 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.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
import code.name.monkey.retromusic.R;
public class CategoryInfo implements Parcelable {
public static final Creator<CategoryInfo> CREATOR = new Creator<CategoryInfo>() {
public CategoryInfo createFromParcel(Parcel source) {
return new CategoryInfo(source);
}
public CategoryInfo[] newArray(int size) {
return new CategoryInfo[size];
}
};
public Category category;
public boolean visible;
public CategoryInfo(Category category, boolean visible) {
this.category = category;
this.visible = visible;
}
private CategoryInfo(Parcel source) {
category = (Category) source.readSerializable();
visible = source.readInt() == 1;
}
@Override
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(category);
dest.writeInt(visible ? 1 : 0);
}
public enum Category {
Home(R.id.action_home, R.string.for_you, R.drawable.ic_face),
Songs(R.id.action_song, R.string.songs, R.drawable.ic_audiotrack),
Albums(R.id.action_album, R.string.albums, R.drawable.ic_album),
Artists(R.id.action_artist, R.string.artists, R.drawable.ic_artist),
Playlists(R.id.action_playlist, R.string.playlists, (R.drawable.ic_queue_music)),
Genres(R.id.action_genre, R.string.genres, R.drawable.ic_guitar),
Folder(R.id.action_folder, R.string.folders, R.drawable.ic_folder);
public final int icon;
public final int id;
public final int stringRes;
Category(int id, @StringRes int stringRes, @DrawableRes int icon) {
this.stringRes = stringRes;
this.id = id;
this.icon = icon;
}
}
}

View file

@ -0,0 +1,43 @@
/*
* 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.os.Parcelable
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import code.name.monkey.retromusic.R
import kotlinx.android.parcel.Parcelize
@Parcelize
data class CategoryInfo(
val category: Category,
@get:JvmName("isVisible")
var visible: Boolean
) : Parcelable {
enum class Category(
val id: Int,
@StringRes val stringRes: Int,
@DrawableRes val icon: Int
) {
Home(R.id.action_home, R.string.for_you, R.drawable.ic_face),
Songs(R.id.action_song, R.string.songs, R.drawable.ic_audiotrack),
Albums(R.id.action_album, R.string.albums, R.drawable.ic_album),
Artists(R.id.action_artist, R.string.artists, R.drawable.ic_artist),
Playlists(R.id.action_playlist, R.string.playlists, R.drawable.ic_queue_music),
Genres(R.id.action_genre, R.string.genres, R.drawable.ic_guitar),
Folder(R.id.action_folder, R.string.folders, R.drawable.ic_folder);
}
}

View file

@ -16,8 +16,10 @@ package code.name.monkey.retromusic.model
import com.google.gson.annotations.SerializedName
class Contributor(
data class Contributor(
val name: String,
val summary: String,
val link: String, @SerializedName("profile_image") val profileImage: String
val link: String,
@SerializedName("profile_image")
val profileImage: String
)

View file

@ -18,4 +18,8 @@ import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
@Parcelize
data class Genre(val id: Int = -1, val name: String, val songCount: Int) : Parcelable
data class Genre(
val id: Long,
val name: String,
val songCount: Int
) : Parcelable

View file

@ -17,7 +17,7 @@ package code.name.monkey.retromusic.model
import androidx.annotation.StringRes
import code.name.monkey.retromusic.HomeSection
class Home(
data class Home(
val arrayList: List<Any>,
@HomeSection
val homeSection: Int,

View file

@ -10,10 +10,14 @@ import org.koin.core.get
@Parcelize
open class Playlist(
val id: Int = -1,
val name: String = ""
val id: Long,
val name: String
) : Parcelable, KoinComponent {
companion object {
val empty = Playlist(-1, "")
}
// this default implementation covers static playlists
fun getSongs(): List<Song> {
return RealPlaylistRepository(get()).playlistSongs(id)
@ -27,4 +31,24 @@ open class Playlist(
""
)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Playlist
if (id != other.id) return false
if (name != other.name) return false
return true
}
override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + name.hashCode()
return result
}
}

View file

@ -1,58 +0,0 @@
/*
* 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 org.jetbrains.annotations.NotNull;
import kotlinx.android.parcel.Parcelize;
/**
* Created by hemanths on 3/4/19
*/
@Parcelize
public class PlaylistSong extends Song {
final int idInPlayList;
final int playlistId;
public PlaylistSong(int id,
@NotNull String title,
int trackNumber,
int year,
long duration,
@NotNull String data,
long dateModified,
int albumId,
@NotNull String albumName,
int artistId,
@NotNull String artistName,
int playlistId,
int idInPlayList,
@NotNull String composer,
String albumArtist) {
super(id, title, trackNumber, year, duration, data, dateModified, albumId, albumName, artistId, artistName, composer, albumArtist);
this.playlistId = playlistId;
this.idInPlayList = idInPlayList;
}
public int getIdInPlayList() {
return idInPlayList;
}
public int getPlaylistId() {
return playlistId;
}
}

View file

@ -0,0 +1,99 @@
/*
* 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 kotlinx.android.parcel.Parcelize
/**
* Created by hemanths on 3/4/19
*/
@Parcelize
class PlaylistSong(
override val id: Long,
override val title: String,
override val trackNumber: Int,
override val year: Int,
override val duration: Long,
override val data: String,
override val dateModified: Long,
override val albumId: Long,
override val albumName: String,
override val artistId: Long,
override val artistName: String,
val playlistId: Long,
val idInPlayList: Long,
override val composer: String,
override val albumArtist: String?
) : Song(
id = id,
title = title,
trackNumber = trackNumber,
year = year,
duration = duration,
data = data,
dateModified = dateModified,
albumId = albumId,
albumName = albumName,
artistId = artistId,
artistName = artistName,
composer = composer,
albumArtist = albumArtist
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false
other as PlaylistSong
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 (playlistId != other.playlistId) return false
if (idInPlayList != other.idInPlayList) return false
if (composer != other.composer) return false
if (albumArtist != other.albumArtist) return false
return true
}
override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * 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 + playlistId.hashCode()
result = 31 * result + idInPlayList.hashCode()
result = 31 * result + composer.hashCode()
result = 31 * result + (albumArtist?.hashCode() ?: 0)
return result
}
}

View file

@ -18,78 +18,120 @@ import code.name.monkey.retromusic.db.HistoryEntity
import code.name.monkey.retromusic.db.SongEntity
import kotlinx.android.parcel.Parcelize
// update equals and hashcode if fields changes
@Parcelize
open class Song(
val id: Int,
val title: String,
val trackNumber: Int,
val year: Int,
val duration: Long,
val data: String,
val dateModified: Long,
val albumId: Int,
val albumName: String,
val artistId: Int,
val artistName: String,
val composer: String?,
val albumArtist: String?
open val id: Long,
open val title: String,
open val trackNumber: Int,
open val year: Int,
open val duration: Long,
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?
) : Parcelable {
fun toHistoryEntity(timePlayed: Long): HistoryEntity {
return HistoryEntity(
id,
title,
trackNumber,
year,
duration,
data,
dateModified,
albumId,
albumName,
artistId,
artistName,
composer,
albumArtist,
timePlayed
id = id,
title = title,
trackNumber = trackNumber,
year = year,
duration = duration,
data = data,
dateModified = dateModified,
albumId = albumId,
albumName = albumName,
artistId = artistId,
artistName = artistName,
composer = composer,
albumArtist = albumArtist,
timePlayed = timePlayed
)
}
fun toSongEntity(playListId: Int): SongEntity {
fun toSongEntity(playListId: Long): SongEntity {
return SongEntity(
playListId,
id,
title,
trackNumber,
year,
duration,
data,
dateModified,
albumId,
albumName,
artistId,
artistName,
composer,
albumArtist
playlistCreatorId = playListId,
id = id,
title = title,
trackNumber = trackNumber,
year = year,
duration = duration,
data = data,
dateModified = dateModified,
albumId = albumId,
albumName = albumName,
artistId = artistId,
artistName = artistName,
composer = composer,
albumArtist = albumArtist
)
}
// 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
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)
return result
}
companion object {
@JvmStatic
val emptySong = Song(
-1,
"",
-1,
-1,
-1,
"",
-1,
-1,
"",
-1,
"",
"",
""
id = -1,
title = "",
trackNumber = -1,
year = -1,
duration = -1,
data = "",
dateModified = -1,
albumId = -1,
albumName = "",
artistId = -1,
artistName = "",
composer = "",
albumArtist = ""
)
}
}

View file

@ -5,6 +5,9 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.AbsCustomPlaylist
abstract class AbsSmartPlaylist(
name: String = "",
name: String,
@DrawableRes val iconRes: Int = R.drawable.ic_queue_music
) : AbsCustomPlaylist(-Math.abs(31 * name.hashCode() + iconRes * name.hashCode() * 31 * 31), name)
) : AbsCustomPlaylist(
id = PlaylistIdGenerator(name, iconRes),
name = name
)

View file

@ -7,12 +7,11 @@ import kotlinx.android.parcel.Parcelize
import org.koin.core.KoinComponent
@Parcelize
class HistoryPlaylist :
AbsSmartPlaylist(
App.getContext().getString(R.string.history),
R.drawable.ic_history
),
KoinComponent {
class HistoryPlaylist : AbsSmartPlaylist(
name = App.getContext().getString(R.string.history),
iconRes = R.drawable.ic_history
), KoinComponent {
override fun songs(): List<Song> {
return topPlayedRepository.recentlyPlayedTracks()
}

View file

@ -6,8 +6,10 @@ import code.name.monkey.retromusic.model.Song
import kotlinx.android.parcel.Parcelize
@Parcelize
class LastAddedPlaylist :
AbsSmartPlaylist(App.getContext().getString(R.string.last_added), R.drawable.ic_library_add) {
class LastAddedPlaylist : AbsSmartPlaylist(
name = App.getContext().getString(R.string.last_added),
iconRes = R.drawable.ic_library_add
) {
override fun songs(): List<Song> {
return lastAddedRepository.recentSongs()
}

View file

@ -7,8 +7,8 @@ import kotlinx.android.parcel.Parcelize
@Parcelize
class NotPlayedPlaylist : AbsSmartPlaylist(
App.getContext().getString(R.string.not_recently_played),
R.drawable.ic_watch_later
name = App.getContext().getString(R.string.not_recently_played),
iconRes = R.drawable.ic_watch_later
) {
override fun songs(): List<Song> {
return topPlayedRepository.notRecentlyPlayedTracks()

View file

@ -0,0 +1,12 @@
package code.name.monkey.retromusic.model.smartplaylist
import androidx.annotation.DrawableRes
import kotlin.math.abs
object PlaylistIdGenerator {
operator fun invoke(name: String, @DrawableRes iconRes: Int): Long {
return -abs(31L * name.hashCode() + iconRes * name.hashCode() * 31L * 31L)
}
}

View file

@ -7,8 +7,8 @@ import kotlinx.android.parcel.Parcelize
@Parcelize
class ShuffleAllPlaylist : AbsSmartPlaylist(
App.getContext().getString(R.string.action_shuffle_all),
R.drawable.ic_shuffle
name = App.getContext().getString(R.string.action_shuffle_all),
iconRes = R.drawable.ic_shuffle
) {
override fun songs(): List<Song> {
return songRepository.songs()

View file

@ -7,8 +7,8 @@ import kotlinx.android.parcel.Parcelize
@Parcelize
class TopTracksPlaylist : AbsSmartPlaylist(
App.getContext().getString(R.string.my_top_tracks),
R.drawable.ic_trending_up
name = App.getContext().getString(R.string.my_top_tracks),
iconRes = R.drawable.ic_trending_up
) {
override fun songs(): List<Song> {
return topPlayedRepository.topTracks()