Removed room
This commit is contained in:
parent
0d13ad1adb
commit
89ee5a42b1
15 changed files with 0 additions and 423 deletions
|
@ -174,11 +174,6 @@ dependencies {
|
||||||
implementation "com.google.dagger:dagger:$dagger_version"
|
implementation "com.google.dagger:dagger:$dagger_version"
|
||||||
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
||||||
|
|
||||||
def room_version = "2.2.5"
|
|
||||||
implementation "androidx.room:room-runtime:$room_version"
|
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
|
||||||
implementation "androidx.room:room-ktx:$room_version"
|
|
||||||
|
|
||||||
def lifecycle_version = "2.2.0"
|
def lifecycle_version = "2.2.0"
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
|
||||||
|
|
|
@ -14,14 +14,9 @@
|
||||||
package code.name.monkey.retromusic.model
|
package code.name.monkey.retromusic.model
|
||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import code.name.monkey.retromusic.room.SongEntity
|
|
||||||
import code.name.monkey.retromusic.room.SongQueueEntity
|
|
||||||
import code.name.monkey.retromusic.room.playlist.PlaylistEntity
|
|
||||||
import code.name.monkey.retromusic.room.playlist.PlaylistSongEntity
|
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
|
|
||||||
open class Song(
|
open class Song(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val title: String,
|
val title: String,
|
||||||
|
@ -39,57 +34,6 @@ open class Song(
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun toSongEntity(song: Song): SongQueueEntity {
|
|
||||||
return SongQueueEntity(
|
|
||||||
song.id,
|
|
||||||
song.title,
|
|
||||||
song.trackNumber,
|
|
||||||
song.year,
|
|
||||||
song.duration,
|
|
||||||
song.data,
|
|
||||||
song.dateModified,
|
|
||||||
song.albumId,
|
|
||||||
song.albumName,
|
|
||||||
song.artistId,
|
|
||||||
song.artistName,
|
|
||||||
song.composer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toSongQueueEntity(song: Song): SongEntity {
|
|
||||||
return SongEntity(
|
|
||||||
song.id,
|
|
||||||
song.title,
|
|
||||||
song.trackNumber,
|
|
||||||
song.year,
|
|
||||||
song.duration,
|
|
||||||
song.data,
|
|
||||||
song.dateModified,
|
|
||||||
song.albumId,
|
|
||||||
song.albumName,
|
|
||||||
song.artistId,
|
|
||||||
song.artistName,
|
|
||||||
song.composer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toPlaylistSong(song: Song, playlistEntity: PlaylistEntity): PlaylistSongEntity {
|
|
||||||
return PlaylistSongEntity(
|
|
||||||
playlistEntity.playlistId,
|
|
||||||
playlistEntity.playlistName, song.id,
|
|
||||||
song.title,
|
|
||||||
song.trackNumber,
|
|
||||||
song.year,
|
|
||||||
song.duration,
|
|
||||||
song.data,
|
|
||||||
song.dateModified,
|
|
||||||
song.albumId,
|
|
||||||
song.albumName,
|
|
||||||
song.artistId,
|
|
||||||
song.artistName,
|
|
||||||
song.composer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val emptySong = Song(
|
val emptySong = Song(
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.room.Database
|
|
||||||
import androidx.room.Room
|
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import code.name.monkey.retromusic.BuildConfig
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
|
|
||||||
@Database(entities = [SongQueueEntity::class, SongEntity::class], version = 8, exportSchema = false)
|
|
||||||
abstract class MusicPlaybackQueueStoreDatabase : RoomDatabase() {
|
|
||||||
|
|
||||||
abstract fun queueDao(): QueueDao
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
@Volatile
|
|
||||||
private var INSTANCE: MusicPlaybackQueueStoreDatabase? = null
|
|
||||||
|
|
||||||
fun getMusicDatabase(context: Context): MusicPlaybackQueueStoreDatabase {
|
|
||||||
val tempInstance =
|
|
||||||
INSTANCE
|
|
||||||
if (tempInstance != null) {
|
|
||||||
return tempInstance
|
|
||||||
}
|
|
||||||
synchronized(this) {
|
|
||||||
val instance = Room.databaseBuilder(
|
|
||||||
context.applicationContext,
|
|
||||||
MusicPlaybackQueueStoreDatabase::class.java,
|
|
||||||
"music_playback_state"
|
|
||||||
).fallbackToDestructiveMigration().build()
|
|
||||||
INSTANCE = instance
|
|
||||||
return instance
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room
|
|
||||||
|
|
||||||
import androidx.room.Transaction
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
|
|
||||||
class MusicQueueRepository(private val queueDao: QueueDao) {
|
|
||||||
|
|
||||||
fun getQueue(): List<Song> =
|
|
||||||
queueDao.getQueue().map { SongQueueEntity.toSong(it) }
|
|
||||||
|
|
||||||
fun getOriginalQueue(): List<Song> =
|
|
||||||
queueDao.getOriginalQueue().map { SongEntity.toSong(it) }
|
|
||||||
|
|
||||||
suspend fun insertQueue(queue: List<Song>) {
|
|
||||||
deleteAndSave(queue)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
private suspend fun deleteAndSave(queue: List<Song>) {
|
|
||||||
queueDao.deleteQueue()
|
|
||||||
queueDao.saveQueue(queue.map { Song.toSongEntity(it) })
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun insertOriginalQueue(queue: List<Song>) {
|
|
||||||
deleteAndSaveOriginalQueue(queue)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
private suspend fun deleteAndSaveOriginalQueue(queue: List<Song>) {
|
|
||||||
queueDao.deleteOriginalQueue()
|
|
||||||
queueDao.saveOriginalQueue(queue.map { Song.toSongQueueEntity(it) })
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class NowPlayingQueue(context: Context) {
|
|
||||||
|
|
||||||
private val queueDao = MusicPlaybackQueueStoreDatabase.getMusicDatabase(context).queueDao()
|
|
||||||
|
|
||||||
private val musicQueueRepository: MusicQueueRepository = MusicQueueRepository(queueDao)
|
|
||||||
|
|
||||||
fun saveQueue(songs: List<Song>) = GlobalScope.launch(Dispatchers.Default) {
|
|
||||||
musicQueueRepository.insertQueue(songs)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveOriginalQueue(songs: List<Song>) = GlobalScope.launch(Dispatchers.Default) {
|
|
||||||
musicQueueRepository.insertOriginalQueue(songs)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getQueue(): List<Song> {
|
|
||||||
return musicQueueRepository.getQueue()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getOriginalQueue(): List<Song> {
|
|
||||||
return musicQueueRepository.getOriginalQueue()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import code.name.monkey.retromusic.BuildConfig
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by hemanths on 2020-02-23.
|
|
||||||
*/
|
|
||||||
@Dao
|
|
||||||
interface QueueDao {
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun saveQueue(playingQueue: List<SongQueueEntity>)
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun saveOriginalQueue(playingQueue: List<SongEntity>)
|
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT * FROM playing_queue_${BuildConfig.FLAVOR}")
|
|
||||||
fun getQueue(): List<SongQueueEntity>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM original_playing_queue_${BuildConfig.FLAVOR}")
|
|
||||||
fun getOriginalQueue(): List<SongEntity>
|
|
||||||
|
|
||||||
@Query("DELETE FROM playing_queue_${BuildConfig.FLAVOR}")
|
|
||||||
suspend fun deleteQueue()
|
|
||||||
|
|
||||||
@Query("DELETE FROM original_playing_queue_${BuildConfig.FLAVOR}")
|
|
||||||
suspend fun deleteOriginalQueue()
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import code.name.monkey.retromusic.BuildConfig
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
|
|
||||||
@Entity(tableName = "original_playing_queue_${BuildConfig.FLAVOR}")
|
|
||||||
data class SongEntity(
|
|
||||||
@ColumnInfo(name = "id") val id: Int,
|
|
||||||
@ColumnInfo(name = "title") val title: String,
|
|
||||||
@ColumnInfo(name = "track_number") val trackNumber: Int,
|
|
||||||
@ColumnInfo(name = "year") val year: Int,
|
|
||||||
@ColumnInfo(name = "duration") val duration: Long,
|
|
||||||
@ColumnInfo(name = "data") val data: String,
|
|
||||||
@ColumnInfo(name = "date_modified") val dateModified: Long,
|
|
||||||
@ColumnInfo(name = "album_id") val albumId: Int,
|
|
||||||
@ColumnInfo(name = "album_name") val albumName: String,
|
|
||||||
@ColumnInfo(name = "artist_id") val artistId: Int,
|
|
||||||
@ColumnInfo(name = "artist_name") val artistName: String,
|
|
||||||
@ColumnInfo(name = "composer") val composer: String?
|
|
||||||
) {
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "primary_id")
|
|
||||||
var primaryId: Int? = null
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun toSong(song: SongEntity): Song {
|
|
||||||
return Song(
|
|
||||||
song.id,
|
|
||||||
song.title,
|
|
||||||
song.trackNumber,
|
|
||||||
song.year,
|
|
||||||
song.duration,
|
|
||||||
song.data,
|
|
||||||
song.dateModified,
|
|
||||||
song.albumId,
|
|
||||||
song.albumName,
|
|
||||||
song.artistId,
|
|
||||||
song.artistName,
|
|
||||||
song.composer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import code.name.monkey.retromusic.BuildConfig
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
|
|
||||||
@Entity(tableName = "playing_queue_${BuildConfig.FLAVOR}")
|
|
||||||
data class SongQueueEntity(
|
|
||||||
@ColumnInfo(name = "id") var id: Int,
|
|
||||||
@ColumnInfo(name = "title") var title: String,
|
|
||||||
@ColumnInfo(name = "track_number") var trackNumber: Int,
|
|
||||||
@ColumnInfo(name = "year") var year: Int,
|
|
||||||
@ColumnInfo(name = "duration") var duration: Long,
|
|
||||||
@ColumnInfo(name = "data") var data: String,
|
|
||||||
@ColumnInfo(name = "date_modified") var dateModified: Long,
|
|
||||||
@ColumnInfo(name = "album_id") var albumId: Int,
|
|
||||||
@ColumnInfo(name = "album_name") var albumName: String,
|
|
||||||
@ColumnInfo(name = "artist_id") var artistId: Int,
|
|
||||||
@ColumnInfo(name = "artist_name") var artistName: String,
|
|
||||||
@ColumnInfo(name = "composer") var composer: String?
|
|
||||||
) {
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "primary_id")
|
|
||||||
var primaryId: Int? = null
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun toSong(song: SongQueueEntity): Song {
|
|
||||||
return Song(
|
|
||||||
song.id,
|
|
||||||
song.title,
|
|
||||||
song.trackNumber,
|
|
||||||
song.year,
|
|
||||||
song.duration,
|
|
||||||
song.data,
|
|
||||||
song.dateModified,
|
|
||||||
song.albumId,
|
|
||||||
song.albumName,
|
|
||||||
song.artistId,
|
|
||||||
song.artistName,
|
|
||||||
song.composer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room.playlist
|
|
||||||
|
|
||||||
import androidx.room.Database
|
|
||||||
import androidx.room.Room
|
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import code.name.monkey.retromusic.App
|
|
||||||
|
|
||||||
@Database(
|
|
||||||
entities = [PlaylistSongEntity::class, PlaylistEntity::class],
|
|
||||||
version = 6,
|
|
||||||
exportSchema = false
|
|
||||||
)
|
|
||||||
abstract class PlaylistDatabase : RoomDatabase() {
|
|
||||||
abstract fun playlistDao(): PlaylistSongDao
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun instance() = Room.databaseBuilder(
|
|
||||||
App.getContext().applicationContext,
|
|
||||||
PlaylistDatabase::class.java, "retro_playlist"
|
|
||||||
).fallbackToDestructiveMigration().build()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room.playlist
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class PlaylistDatabaseModel() {
|
|
||||||
private val playlistSongDao = PlaylistDatabase.instance().playlistDao();
|
|
||||||
|
|
||||||
suspend fun getPlaylistNames(): List<PlaylistEntity> = playlistSongDao.getPlaylists()
|
|
||||||
|
|
||||||
fun savePlaylist(playlistEntity: PlaylistEntity) = GlobalScope.launch(Dispatchers.IO) {
|
|
||||||
playlistSongDao.addPlaylist(playlistEntity)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addSongsToPlaylist(songs: List<Song>, playlistEntity: PlaylistEntity) =
|
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
|
||||||
songs.map { Song.toPlaylistSong(it, playlistEntity) }.map {
|
|
||||||
val isExist =
|
|
||||||
playlistSongDao.checkPlaylistSongExist(it.playlistId, it.id).isEmpty()
|
|
||||||
if (isExist) {
|
|
||||||
playlistSongDao.insertSingle(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room.playlist
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import kotlinx.android.parcel.Parcelize
|
|
||||||
|
|
||||||
@Parcelize
|
|
||||||
@Entity(tableName = "playlist_table")
|
|
||||||
class PlaylistEntity(
|
|
||||||
@ColumnInfo(name = "playlist_name") val playlistName: String
|
|
||||||
) : Parcelable {
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "playlist_id")
|
|
||||||
var playlistId: Int = 0
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room.playlist
|
|
||||||
|
|
||||||
class PlaylistRepository(private val playlistSongDao: PlaylistSongDao) {
|
|
||||||
suspend fun insertPlaylist(playlistEntity: PlaylistEntity) {
|
|
||||||
playlistSongDao.addPlaylist(playlistEntity)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun insertPlaylistSongs(songs: List<PlaylistSongEntity>) {
|
|
||||||
playlistSongDao.addPlaylistSongs(songs)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room.playlist
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface PlaylistSongDao {
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun addPlaylistSongs(playlistSongs: List<PlaylistSongEntity>)
|
|
||||||
|
|
||||||
@Query("SELECT * FROM playlist_songs WHERE playlist_id =:playlistId AND id=:id")
|
|
||||||
suspend fun checkPlaylistSongExist(playlistId: Int, id: Int): List<PlaylistSongEntity>
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun addPlaylist(playlistEntity: PlaylistEntity)
|
|
||||||
|
|
||||||
@Query("SELECT * FROM playlist_table")
|
|
||||||
suspend fun getPlaylists(): List<PlaylistEntity>
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun insertSingle(playlistSongEntity: PlaylistSongEntity)
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package code.name.monkey.retromusic.room.playlist
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.ForeignKey
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "playlist_songs")
|
|
||||||
class PlaylistSongEntity(
|
|
||||||
@ForeignKey(
|
|
||||||
entity = PlaylistEntity::class,
|
|
||||||
childColumns = ["playlist_id"],
|
|
||||||
parentColumns = ["playlist_id"],
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
)
|
|
||||||
@ColumnInfo(name = "playlist_id") val playlistId: Int,
|
|
||||||
@ColumnInfo(name = "playlist_name") val playlistName: String,
|
|
||||||
|
|
||||||
@ColumnInfo(name = "id") val id: Int,
|
|
||||||
@ColumnInfo(name = "title") val title: String,
|
|
||||||
@ColumnInfo(name = "track_number") val trackNumber: Int,
|
|
||||||
@ColumnInfo(name = "year") val year: Int,
|
|
||||||
@ColumnInfo(name = "duration") val duration: Long,
|
|
||||||
@ColumnInfo(name = "data") val data: String,
|
|
||||||
@ColumnInfo(name = "date_modified") val dateModified: Long,
|
|
||||||
@ColumnInfo(name = "album_id") val albumId: Int,
|
|
||||||
@ColumnInfo(name = "album_name") val albumName: String,
|
|
||||||
@ColumnInfo(name = "artist_id") val artistId: Int,
|
|
||||||
@ColumnInfo(name = "artist_name") val artistName: String,
|
|
||||||
@ColumnInfo(name = "composer") val composer: String?
|
|
||||||
) {
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "song_id")
|
|
||||||
var songId: Int = 0
|
|
||||||
}
|
|
|
@ -8,5 +8,4 @@ android.enableR8.fullMode=false
|
||||||
android.enableJetifier=true
|
android.enableJetifier=true
|
||||||
android.debug.obsoleteApi=true
|
android.debug.obsoleteApi=true
|
||||||
android.enableBuildCache=true
|
android.enableBuildCache=true
|
||||||
android.jetifier.blacklist = butterknife.*\\.jar
|
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
Loading…
Reference in a new issue