From cc494edbbf9e93b3bd23dd13638f218320460744 Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Sat, 12 Sep 2020 12:23:23 +0530 Subject: [PATCH] Fix songs not loading from SD card --- .../main/java/code/name/monkey/retromusic/db/PlayCountDao.kt | 3 +++ .../java/code/name/monkey/retromusic/db/RetroDatabase.kt | 2 +- .../main/java/code/name/monkey/retromusic/db/SongEntity.kt | 4 ++-- .../code/name/monkey/retromusic/repository/RoomRepository.kt | 5 ++++- .../code/name/monkey/retromusic/repository/SongRepository.kt | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/db/PlayCountDao.kt b/app/src/main/java/code/name/monkey/retromusic/db/PlayCountDao.kt index 17868e7e..0c3fbbae 100644 --- a/app/src/main/java/code/name/monkey/retromusic/db/PlayCountDao.kt +++ b/app/src/main/java/code/name/monkey/retromusic/db/PlayCountDao.kt @@ -21,4 +21,7 @@ interface PlayCountDao { @Query("DELETE FROM SongEntity WHERE id =:songId") fun deleteSong(songId: Int) + + @Query("UPDATE PlayCountEntity SET play_count = play_count + 1 WHERE id = :id") + fun updateQuantity(id: Int) } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/db/RetroDatabase.kt b/app/src/main/java/code/name/monkey/retromusic/db/RetroDatabase.kt index cda6eddd..6be545b6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/db/RetroDatabase.kt +++ b/app/src/main/java/code/name/monkey/retromusic/db/RetroDatabase.kt @@ -5,7 +5,7 @@ import androidx.room.RoomDatabase @Database( entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class, BlackListStoreEntity::class, LyricsEntity::class], - version = 21, + version = 22, exportSchema = false ) abstract class RetroDatabase : RoomDatabase() { diff --git a/app/src/main/java/code/name/monkey/retromusic/db/SongEntity.kt b/app/src/main/java/code/name/monkey/retromusic/db/SongEntity.kt index 1d9b13f7..19a50fe0 100644 --- a/app/src/main/java/code/name/monkey/retromusic/db/SongEntity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/db/SongEntity.kt @@ -3,11 +3,12 @@ package code.name.monkey.retromusic.db import android.os.Parcelable import androidx.room.ColumnInfo import androidx.room.Entity +import androidx.room.Index import androidx.room.PrimaryKey import kotlinx.android.parcel.Parcelize @Parcelize -@Entity +@Entity(indices = [Index(value = ["playlist_creator_id", "id"], unique = true)]) class SongEntity( @ColumnInfo(name = "playlist_creator_id") val playlistCreatorId: Int, @@ -35,6 +36,5 @@ class SongEntity( @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "song_key") var songPrimaryKey: Long = 0 - } diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/RoomRepository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/RoomRepository.kt index 9ded5b73..16100176 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/RoomRepository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/RoomRepository.kt @@ -64,8 +64,11 @@ class RealRoomRepository( playlistDao.playlistsWithSongs() @WorkerThread - override suspend fun insertSongs(songs: List) = + override suspend fun insertSongs(songs: List) { + playlistDao.insertSongsToPlaylist(songs) + } + override fun getSongs(playlistEntity: PlaylistEntity): LiveData> = playlistDao.songsFromPlaylist(playlistEntity.playListId) diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/SongRepository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/SongRepository.kt index 41df3e29..fcfded6a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/SongRepository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/SongRepository.kt @@ -155,7 +155,7 @@ class RealSongRepository(private val context: Context) : SongRepository { val uri = if (VersionUtils.hasQ()) { - MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) + MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL) } else { MediaStore.Audio.Media.EXTERNAL_CONTENT_URI }