Code refactor
This commit is contained in:
parent
5211890607
commit
332c2dc69b
8 changed files with 54 additions and 33 deletions
|
@ -0,0 +1,26 @@
|
|||
package code.name.monkey.retromusic.db
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
|
||||
@Dao
|
||||
interface HistoryDao {
|
||||
companion object {
|
||||
private const val HISTORY_LIMIT = 100
|
||||
}
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSongInHistory(historyEntity: HistoryEntity)
|
||||
|
||||
@Query("SELECT * FROM HistoryEntity WHERE id = :songId LIMIT 1")
|
||||
suspend fun isSongPresentInHistory(songId: Int): HistoryEntity?
|
||||
|
||||
@Update
|
||||
suspend fun updateHistorySong(historyEntity: HistoryEntity)
|
||||
|
||||
@Query("SELECT * FROM HistoryEntity ORDER BY time_played DESC LIMIT $HISTORY_LIMIT")
|
||||
fun historySongs(): List<HistoryEntity>
|
||||
|
||||
@Query("SELECT * FROM HistoryEntity ORDER BY time_played DESC LIMIT $HISTORY_LIMIT")
|
||||
fun observableHistorySongs(): LiveData<List<HistoryEntity>>
|
||||
}
|
|
@ -45,17 +45,6 @@ interface PlaylistDao {
|
|||
@Delete
|
||||
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSongInHistory(historyEntity: HistoryEntity)
|
||||
|
||||
@Query("SELECT * FROM HistoryEntity WHERE id = :songId LIMIT 1")
|
||||
suspend fun isSongPresentInHistory(songId: Int): HistoryEntity?
|
||||
|
||||
@Update
|
||||
suspend fun updateHistorySong(historyEntity: HistoryEntity)
|
||||
|
||||
@Query("SELECT * FROM HistoryEntity ORDER BY time_played DESC")
|
||||
fun historySongs(): LiveData<List<HistoryEntity>>
|
||||
|
||||
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId")
|
||||
fun favoritesSongsLiveData(playlistId: Int): LiveData<List<SongEntity>>
|
||||
|
|
|
@ -12,4 +12,5 @@ abstract class RetroDatabase : RoomDatabase() {
|
|||
abstract fun playlistDao(): PlaylistDao
|
||||
abstract fun blackListStore(): BlackListStoreDao
|
||||
abstract fun playCountDao(): PlayCountDao
|
||||
abstract fun historyDao(): HistoryDao
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue