Initial commit

This commit is contained in:
vfsfitvnm
2022-06-02 18:59:18 +02:00
commit 1e673ad582
160 changed files with 10800 additions and 0 deletions

View 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
)

View 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 = ""
)
}
}

View File

@@ -0,0 +1,8 @@
package it.vfsfitvnm.vimusic.models
import androidx.room.Embedded
data class PlaylistPreview(
@Embedded val playlist: Playlist,
val songCount: Int
)

View File

@@ -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())
}
}

View File

@@ -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
)

View 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
)
}
}

View File

@@ -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
)

View File

@@ -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
)

View File

@@ -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>?
)

View File

@@ -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
)