creating an Albums db table
This commit is contained in:
parent
6f98c23830
commit
9a976c62e5
3 changed files with 38 additions and 10 deletions
|
@ -11,18 +11,12 @@ import com.simplemobiletools.musicplayer.extensions.getAllInitialTracks
|
|||
import com.simplemobiletools.musicplayer.extensions.playlistDAO
|
||||
import com.simplemobiletools.musicplayer.helpers.ALL_TRACKS_PLAYLIST_ID
|
||||
import com.simplemobiletools.musicplayer.helpers.RoomHelper
|
||||
import com.simplemobiletools.musicplayer.interfaces.ArtistsDao
|
||||
import com.simplemobiletools.musicplayer.interfaces.PlaylistsDao
|
||||
import com.simplemobiletools.musicplayer.interfaces.QueueItemsDao
|
||||
import com.simplemobiletools.musicplayer.interfaces.SongsDao
|
||||
import com.simplemobiletools.musicplayer.models.Artist
|
||||
import com.simplemobiletools.musicplayer.models.Playlist
|
||||
import com.simplemobiletools.musicplayer.models.QueueItem
|
||||
import com.simplemobiletools.musicplayer.models.Track
|
||||
import com.simplemobiletools.musicplayer.interfaces.*
|
||||
import com.simplemobiletools.musicplayer.models.*
|
||||
import com.simplemobiletools.musicplayer.objects.MyExecutor
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
@Database(entities = [Track::class, Playlist::class, QueueItem::class, Artist::class], version = 7)
|
||||
@Database(entities = [Track::class, Playlist::class, QueueItem::class, Artist::class, Album::class], version = 7)
|
||||
abstract class SongsDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun SongsDao(): SongsDao
|
||||
|
@ -33,6 +27,8 @@ abstract class SongsDatabase : RoomDatabase() {
|
|||
|
||||
abstract fun ArtistsDao(): ArtistsDao
|
||||
|
||||
abstract fun AlbumsDao(): AlbumsDao
|
||||
|
||||
companion object {
|
||||
private var db: SongsDatabase? = null
|
||||
|
||||
|
@ -145,6 +141,9 @@ abstract class SongsDatabase : RoomDatabase() {
|
|||
database.apply {
|
||||
execSQL("CREATE TABLE `artists` (`id` INTEGER NOT NULL PRIMARY KEY, `title` TEXT NOT NULL, `album_cnt` INTEGER NOT NULL, `track_cnt` INTEGER NOT NULL, `album_art_id` INTEGER NOT NULL)")
|
||||
execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_artists_id` ON `artists` (`id`)")
|
||||
|
||||
execSQL("CREATE TABLE `albums` (`id` INTEGER NOT NULL PRIMARY KEY, `artist` TEXT NOT NULL, `title` TEXT NOT NULL, `cover_art` TEXT NOT NULL, `year` INTEGER NOT NULL)")
|
||||
execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_albums_id` ON `albums` (`id`)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.simplemobiletools.musicplayer.interfaces
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.simplemobiletools.musicplayer.models.Album
|
||||
|
||||
@Dao
|
||||
interface AlbumsDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(album: Album): Long
|
||||
|
||||
@Query("SELECT * FROM albums")
|
||||
fun getAll(): List<Album>
|
||||
|
||||
@Query("DELETE FROM albums WHERE id = :id")
|
||||
fun deleteAlbum(id: Long)
|
||||
}
|
|
@ -1,12 +1,22 @@
|
|||
package com.simplemobiletools.musicplayer.models
|
||||
|
||||
import android.provider.MediaStore
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import com.simplemobiletools.commons.helpers.AlphanumericComparator
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.musicplayer.helpers.PLAYER_SORT_BY_ARTIST_TITLE
|
||||
import com.simplemobiletools.musicplayer.helpers.PLAYER_SORT_BY_TITLE
|
||||
|
||||
data class Album(val id: Long, val artist: String, val title: String, val coverArt: String, val year: Int) : ListItem(), Comparable<Album> {
|
||||
@Entity(tableName = "albums", indices = [(Index(value = ["id"], unique = true))])
|
||||
data class Album(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long,
|
||||
@ColumnInfo(name = "artist") val artist: String,
|
||||
@ColumnInfo(name = "title") val title: String,
|
||||
@ColumnInfo(name = "cover_art") val coverArt: String,
|
||||
@ColumnInfo(name = "year") val year: Int) : ListItem(), Comparable<Album> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue