浏览代码

Make Room models @Immutable

vfsfitvnm 2 年之前
父节点
当前提交
305d6c80c5

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Album.kt

@@ -1,8 +1,10 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.Entity
 import androidx.room.Entity
 import androidx.room.PrimaryKey
 import androidx.room.PrimaryKey
 
 
+@Immutable
 @Entity
 @Entity
 data class Album(
 data class Album(
     @PrimaryKey val id: String,
     @PrimaryKey val id: String,

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Artist.kt

@@ -1,8 +1,10 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.Entity
 import androidx.room.Entity
 import androidx.room.PrimaryKey
 import androidx.room.PrimaryKey
 
 
+@Immutable
 @Entity
 @Entity
 data class Artist(
 data class Artist(
     @PrimaryKey val id: String,
     @PrimaryKey val id: String,

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/DetailedSong.kt

@@ -1,8 +1,10 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.Junction
 import androidx.room.Junction
 import androidx.room.Relation
 import androidx.room.Relation
 
 
+@Immutable
 open class DetailedSong(
 open class DetailedSong(
     val id: String,
     val id: String,
     val title: String,
     val title: String,

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/DetailedSongWithContentLength.kt

@@ -1,7 +1,9 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.Relation
 import androidx.room.Relation
 
 
+@Immutable
 class DetailedSongWithContentLength(
 class DetailedSongWithContentLength(
     id: String,
     id: String,
     title: String,
     title: String,

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Playlist.kt

@@ -1,8 +1,10 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.Entity
 import androidx.room.Entity
 import androidx.room.PrimaryKey
 import androidx.room.PrimaryKey
 
 
+@Immutable
 @Entity
 @Entity
 data class Playlist(
 data class Playlist(
     @PrimaryKey(autoGenerate = true) val id: Long = 0,
     @PrimaryKey(autoGenerate = true) val id: Long = 0,

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/PlaylistPreview.kt

@@ -1,7 +1,9 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.Embedded
 import androidx.room.Embedded
 
 
+@Immutable
 data class PlaylistPreview(
 data class PlaylistPreview(
     @Embedded val playlist: Playlist,
     @Embedded val playlist: Playlist,
     val songCount: Int
     val songCount: Int

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/PlaylistWithSongs.kt

@@ -1,9 +1,11 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.Embedded
 import androidx.room.Embedded
 import androidx.room.Junction
 import androidx.room.Junction
 import androidx.room.Relation
 import androidx.room.Relation
 
 
+@Immutable
 data class PlaylistWithSongs(
 data class PlaylistWithSongs(
     @Embedded val playlist: Playlist,
     @Embedded val playlist: Playlist,
     @Relation(
     @Relation(

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/QueuedMediaItem.kt

@@ -1,10 +1,12 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.media3.common.MediaItem
 import androidx.media3.common.MediaItem
 import androidx.room.ColumnInfo
 import androidx.room.ColumnInfo
 import androidx.room.Entity
 import androidx.room.Entity
 import androidx.room.PrimaryKey
 import androidx.room.PrimaryKey
 
 
+@Immutable
 @Entity
 @Entity
 class QueuedMediaItem(
 class QueuedMediaItem(
     @PrimaryKey(autoGenerate = true) val id: Long = 0,
     @PrimaryKey(autoGenerate = true) val id: Long = 0,

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Song.kt

@@ -1,8 +1,10 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.Entity
 import androidx.room.Entity
 import androidx.room.PrimaryKey
 import androidx.room.PrimaryKey
 
 
+@Immutable
 @Entity
 @Entity
 data class Song(
 data class Song(
     @PrimaryKey val id: String,
     @PrimaryKey val id: String,

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/SongArtistMap.kt

@@ -1,9 +1,11 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.ColumnInfo
 import androidx.room.ColumnInfo
 import androidx.room.Entity
 import androidx.room.Entity
 import androidx.room.ForeignKey
 import androidx.room.ForeignKey
 
 
+@Immutable
 @Entity(
 @Entity(
     primaryKeys = ["songId", "artistId"],
     primaryKeys = ["songId", "artistId"],
     foreignKeys = [
     foreignKeys = [

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/SongPlaylistMap.kt

@@ -1,9 +1,11 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.ColumnInfo
 import androidx.room.ColumnInfo
 import androidx.room.Entity
 import androidx.room.Entity
 import androidx.room.ForeignKey
 import androidx.room.ForeignKey
 
 
+@Immutable
 @Entity(
 @Entity(
     primaryKeys = ["songId", "playlistId"],
     primaryKeys = ["songId", "playlistId"],
     foreignKeys = [
     foreignKeys = [

+ 2 - 0
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/SortedSongPlaylistMap.kt

@@ -1,8 +1,10 @@
 package it.vfsfitvnm.vimusic.models
 package it.vfsfitvnm.vimusic.models
 
 
+import androidx.compose.runtime.Immutable
 import androidx.room.ColumnInfo
 import androidx.room.ColumnInfo
 import androidx.room.DatabaseView
 import androidx.room.DatabaseView
 
 
+@Immutable
 @DatabaseView("SELECT * FROM SongPlaylistMap ORDER BY position")
 @DatabaseView("SELECT * FROM SongPlaylistMap ORDER BY position")
 data class SortedSongPlaylistMap(
 data class SortedSongPlaylistMap(
     @ColumnInfo(index = true) val songId: String,
     @ColumnInfo(index = true) val songId: String,