Initial commit
This commit is contained in:
12
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Info.kt
Normal file
12
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Info.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
// I know...
|
||||
@Entity
|
||||
data class Info(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||
val browseId: String?,
|
||||
val text: String
|
||||
)
|
||||
17
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Playlist.kt
Normal file
17
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Playlist.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Playlist(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||
val name: String,
|
||||
) {
|
||||
companion object {
|
||||
val Empty = Playlist(
|
||||
id = 0,
|
||||
name = ""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.Embedded
|
||||
|
||||
data class PlaylistPreview(
|
||||
@Embedded val playlist: Playlist,
|
||||
val songCount: Int
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.*
|
||||
|
||||
|
||||
data class PlaylistWithSongs(
|
||||
@Embedded val playlist: Playlist,
|
||||
@Relation(
|
||||
entity = Song::class,
|
||||
parentColumn = "id",
|
||||
entityColumn = "id",
|
||||
associateBy = Junction(
|
||||
value = SortedSongInPlaylist::class,
|
||||
parentColumn = "playlistId",
|
||||
entityColumn = "songId"
|
||||
)
|
||||
)
|
||||
val songs: List<SongWithInfo>
|
||||
) {
|
||||
companion object {
|
||||
val Empty = PlaylistWithSongs(Playlist(-1, ""), emptyList())
|
||||
val NotFound = PlaylistWithSongs(Playlist(-2, "Not found"), emptyList())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
|
||||
@Immutable
|
||||
@Entity(
|
||||
indices = [
|
||||
Index(
|
||||
value = ["query"],
|
||||
unique = true
|
||||
)
|
||||
]
|
||||
)
|
||||
data class SearchQuery(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||
val query: String
|
||||
)
|
||||
34
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Song.kt
Normal file
34
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Song.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.*
|
||||
|
||||
|
||||
@Entity
|
||||
data class Song(
|
||||
@PrimaryKey val id: String,
|
||||
val title: String,
|
||||
val albumInfoId: Long?,
|
||||
val durationText: String,
|
||||
val thumbnailUrl: String?,
|
||||
val likedAt: Long? = null,
|
||||
val totalPlayTimeMs: Long = 0
|
||||
) {
|
||||
val formattedTotalPlayTime: String
|
||||
get() {
|
||||
val seconds = totalPlayTimeMs / 1000
|
||||
|
||||
val hours = seconds / 3600
|
||||
|
||||
return when {
|
||||
hours == 0L -> "${seconds / 60}m"
|
||||
hours < 24L -> "${hours}h"
|
||||
else -> "${hours / 24}d"
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleLike(): Song {
|
||||
return copy(
|
||||
likedAt = if (likedAt == null) System.currentTimeMillis() else null
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
|
||||
|
||||
@Immutable
|
||||
@Entity(
|
||||
primaryKeys = ["songId", "playlistId"],
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = Song::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["songId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
),
|
||||
ForeignKey(
|
||||
entity = Playlist::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["playlistId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
]
|
||||
)
|
||||
data class SongInPlaylist(
|
||||
@ColumnInfo(index = true) val songId: String,
|
||||
@ColumnInfo(index = true) val playlistId: Long,
|
||||
val position: Int
|
||||
)
|
||||
@@ -0,0 +1,28 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.room.*
|
||||
|
||||
|
||||
@Immutable
|
||||
@Entity(
|
||||
primaryKeys = ["songId", "authorInfoId"],
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = Song::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["songId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
),
|
||||
ForeignKey(
|
||||
entity = Info::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["authorInfoId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
]
|
||||
)
|
||||
data class SongWithAuthors(
|
||||
val songId: String,
|
||||
@ColumnInfo(index = true) val authorInfoId: Long
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Junction
|
||||
import androidx.room.Relation
|
||||
|
||||
open class SongWithInfo(
|
||||
@Embedded val song: Song,
|
||||
@Relation(
|
||||
entity = Info::class,
|
||||
parentColumn = "albumInfoId",
|
||||
entityColumn = "id"
|
||||
) val album: Info?,
|
||||
@Relation(
|
||||
entity = Info::class,
|
||||
parentColumn = "id",
|
||||
entityColumn = "id",
|
||||
associateBy = Junction(
|
||||
value = SongWithAuthors::class,
|
||||
parentColumn = "songId",
|
||||
entityColumn = "authorInfoId"
|
||||
)
|
||||
)
|
||||
val authors: List<Info>?
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.DatabaseView
|
||||
|
||||
@DatabaseView("SELECT * FROM SongInPlaylist ORDER BY position")
|
||||
data class SortedSongInPlaylist(
|
||||
@ColumnInfo(index = true) val songId: String,
|
||||
@ColumnInfo(index = true) val playlistId: Long,
|
||||
val position: Int
|
||||
)
|
||||
Reference in New Issue
Block a user