Add Upsert to PlayCountDao
This commit is contained in:
parent
8024700b7d
commit
025e908c22
4 changed files with 21 additions and 37 deletions
|
@ -131,14 +131,11 @@ abstract class AbsMusicServiceActivity : AbsBaseActivity(), IMusicServiceEventLi
|
||||||
repository.addSongToHistory(MusicPlayerRemote.currentSong)
|
repository.addSongToHistory(MusicPlayerRemote.currentSong)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val songs = repository.checkSongExistInPlayCount(MusicPlayerRemote.currentSong.id)
|
val song = repository.findSongExistInPlayCount(MusicPlayerRemote.currentSong.id)
|
||||||
if (songs.isNotEmpty()) {
|
?.apply { playCount += 1 }
|
||||||
repository.updateSongInPlayCount(songs.first().apply {
|
?: MusicPlayerRemote.currentSong.toPlayCount()
|
||||||
playCount += 1
|
|
||||||
})
|
repository.upsertSongInPlayCount(song)
|
||||||
} else {
|
|
||||||
repository.insertSongInPlayCount(MusicPlayerRemote.currentSong.toPlayCount())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,24 +18,19 @@ import androidx.room.*
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface PlayCountDao {
|
interface PlayCountDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
fun insertSongInPlayCount(playCountEntity: PlayCountEntity)
|
|
||||||
|
|
||||||
@Update
|
@Upsert
|
||||||
fun updateSongInPlayCount(playCountEntity: PlayCountEntity)
|
fun upsertSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||||
|
|
||||||
@Query("SELECT * FROM PlayCountEntity WHERE id =:songId")
|
@Query("SELECT * FROM PlayCountEntity WHERE id =:songId LIMIT 1")
|
||||||
fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity>
|
fun findSongExistInPlayCount(songId: Long): PlayCountEntity?
|
||||||
|
|
||||||
@Query("SELECT * FROM PlayCountEntity ORDER BY play_count DESC")
|
@Query("SELECT * FROM PlayCountEntity ORDER BY play_count DESC")
|
||||||
fun playCountSongs(): List<PlayCountEntity>
|
fun playCountSongs(): List<PlayCountEntity>
|
||||||
|
|
||||||
@Query("DELETE FROM SongEntity WHERE id =:songId")
|
@Query("DELETE FROM SongEntity WHERE id =:songId")
|
||||||
fun deleteSong(songId: Long)
|
fun deleteSong(songId: Long)
|
||||||
|
|
||||||
@Query("UPDATE PlayCountEntity SET play_count = play_count + 1 WHERE id = :id")
|
|
||||||
fun updateQuantity(id: Long)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,12 +84,11 @@ interface Repository {
|
||||||
suspend fun favoritePlaylistSongs(): List<SongEntity>
|
suspend fun favoritePlaylistSongs(): List<SongEntity>
|
||||||
suspend fun recentSongs(): List<Song>
|
suspend fun recentSongs(): List<Song>
|
||||||
suspend fun topPlayedSongs(): List<Song>
|
suspend fun topPlayedSongs(): List<Song>
|
||||||
suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity)
|
suspend fun upsertSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||||
suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity)
|
|
||||||
suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||||
suspend fun deleteSongInHistory(songId: Long)
|
suspend fun deleteSongInHistory(songId: Long)
|
||||||
suspend fun clearSongHistory()
|
suspend fun clearSongHistory()
|
||||||
suspend fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity>
|
suspend fun findSongExistInPlayCount(songId: Long): PlayCountEntity?
|
||||||
suspend fun playCountSongs(): List<PlayCountEntity>
|
suspend fun playCountSongs(): List<PlayCountEntity>
|
||||||
suspend fun deleteSongs(songs: List<Song>)
|
suspend fun deleteSongs(songs: List<Song>)
|
||||||
suspend fun contributor(): List<Contributor>
|
suspend fun contributor(): List<Contributor>
|
||||||
|
@ -285,11 +284,8 @@ class RealRepository(
|
||||||
|
|
||||||
override suspend fun topPlayedSongs(): List<Song> = topPlayedRepository.topTracks()
|
override suspend fun topPlayedSongs(): List<Song> = topPlayedRepository.topTracks()
|
||||||
|
|
||||||
override suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity) =
|
override suspend fun upsertSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||||
roomRepository.insertSongInPlayCount(playCountEntity)
|
roomRepository.upsertSongInPlayCount(playCountEntity)
|
||||||
|
|
||||||
override suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity) =
|
|
||||||
roomRepository.updateSongInPlayCount(playCountEntity)
|
|
||||||
|
|
||||||
override suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) =
|
override suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||||
roomRepository.deleteSongInPlayCount(playCountEntity)
|
roomRepository.deleteSongInPlayCount(playCountEntity)
|
||||||
|
@ -301,8 +297,8 @@ class RealRepository(
|
||||||
roomRepository.clearSongHistory()
|
roomRepository.clearSongHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity> =
|
override suspend fun findSongExistInPlayCount(songId: Long): PlayCountEntity? =
|
||||||
roomRepository.checkSongExistInPlayCount(songId)
|
roomRepository.findSongExistInPlayCount(songId)
|
||||||
|
|
||||||
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
||||||
roomRepository.playCountSongs()
|
roomRepository.playCountSongs()
|
||||||
|
|
|
@ -34,12 +34,11 @@ interface RoomRepository {
|
||||||
suspend fun songPresentInHistory(song: Song): HistoryEntity?
|
suspend fun songPresentInHistory(song: Song): HistoryEntity?
|
||||||
suspend fun updateHistorySong(song: Song)
|
suspend fun updateHistorySong(song: Song)
|
||||||
suspend fun favoritePlaylistSongs(favorite: String): List<SongEntity>
|
suspend fun favoritePlaylistSongs(favorite: String): List<SongEntity>
|
||||||
suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity)
|
suspend fun upsertSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||||
suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity)
|
|
||||||
suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||||
suspend fun deleteSongInHistory(songId: Long)
|
suspend fun deleteSongInHistory(songId: Long)
|
||||||
suspend fun clearSongHistory()
|
suspend fun clearSongHistory()
|
||||||
suspend fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity>
|
suspend fun findSongExistInPlayCount(songId: Long): PlayCountEntity?
|
||||||
suspend fun playCountSongs(): List<PlayCountEntity>
|
suspend fun playCountSongs(): List<PlayCountEntity>
|
||||||
suspend fun deleteSongs(songs: List<Song>)
|
suspend fun deleteSongs(songs: List<Song>)
|
||||||
suspend fun isSongFavorite(context: Context, songId: Long): Boolean
|
suspend fun isSongFavorite(context: Context, songId: Long): Boolean
|
||||||
|
@ -155,11 +154,8 @@ class RealRoomRepository(
|
||||||
playlistDao.playlist(favorite).first().playListId
|
playlistDao.playlist(favorite).first().playListId
|
||||||
) else emptyList()
|
) else emptyList()
|
||||||
|
|
||||||
override suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity) =
|
override suspend fun upsertSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||||
playCountDao.insertSongInPlayCount(playCountEntity)
|
playCountDao.upsertSongInPlayCount(playCountEntity)
|
||||||
|
|
||||||
override suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity) =
|
|
||||||
playCountDao.updateSongInPlayCount(playCountEntity)
|
|
||||||
|
|
||||||
override suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) =
|
override suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||||
playCountDao.deleteSongInPlayCount(playCountEntity)
|
playCountDao.deleteSongInPlayCount(playCountEntity)
|
||||||
|
@ -172,8 +168,8 @@ class RealRoomRepository(
|
||||||
historyDao.clearHistory()
|
historyDao.clearHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity> =
|
override suspend fun findSongExistInPlayCount(songId: Long): PlayCountEntity? =
|
||||||
playCountDao.checkSongExistInPlayCount(songId)
|
playCountDao.findSongExistInPlayCount(songId)
|
||||||
|
|
||||||
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
||||||
playCountDao.playCountSongs()
|
playCountDao.playCountSongs()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue