From 2817dc1db508fe854e0b33100ba6e8219a3acc64 Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Fri, 21 Aug 2020 22:37:10 +0530 Subject: [PATCH] =?UTF-8?q?Code=20refactor=20=F0=9F=A7=91=E2=80=8D?= =?UTF-8?q?=F0=9F=92=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monkey/retromusic/adapter/GenreAdapter.kt | 5 +- .../monkey/retromusic/adapter/HomeAdapter.kt | 11 ++- .../monkey/retromusic/db/HistoryEntity.kt | 21 +---- .../monkey/retromusic/db/PlayCountEntity.kt | 34 ++++++++ .../name/monkey/retromusic/db/PlaylistDao.kt | 22 ++++- .../monkey/retromusic/db/RetroDatabase.kt | 4 +- .../name/monkey/retromusic/db/SongEntity.kt | 23 ----- .../monkey/retromusic/db/SongExtension.kt | 83 +++++++++++++++++++ .../retromusic/dialogs/AddToRetroPlaylist.kt | 4 +- .../dialogs/RemoveSongFromPlaylistDialog.kt | 2 +- .../monkey/retromusic/extensions/ColorExt.kt | 6 ++ .../fragments/DetailListFragment.kt | 1 + .../retromusic/fragments/LibraryViewModel.kt | 9 ++ .../fragments/albums/AlbumDetailsFragment.kt | 3 +- .../artists/ArtistDetailsFragment.kt | 3 +- .../fragments/base/AbsPlayerFragment.kt | 2 + .../retromusic/repository/Repository.kt | 36 ++++++-- .../repository/RoomPlaylistRepository.kt | 41 ++++++--- .../repository/TopPlayedRepository.kt | 8 +- app/src/main/res/drawable/ic_account.xml | 4 +- .../res/layout-land/fragment_banner_home.xml | 2 +- .../main/res/layout-land/fragment_home.xml | 2 +- .../res/layout/fragment_album_content.xml | 10 ++- .../res/layout/fragment_album_details.xml | 6 +- .../res/layout/fragment_artist_content.xml | 12 ++- .../res/layout/fragment_artist_details.xml | 2 +- .../main/res/layout/fragment_banner_home.xml | 2 +- app/src/main/res/layout/fragment_home.xml | 2 +- app/src/main/res/layout/home_content.xml | 41 ++++----- app/src/main/res/layout/item_album_card.xml | 1 + 30 files changed, 285 insertions(+), 117 deletions(-) create mode 100644 app/src/main/java/code/name/monkey/retromusic/db/PlayCountEntity.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/db/SongExtension.kt diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/GenreAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/GenreAdapter.kt index a015b1ad..bf9f1c91 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/GenreAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/GenreAdapter.kt @@ -1,5 +1,6 @@ package code.name.monkey.retromusic.adapter +import android.graphics.Color import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -22,14 +23,14 @@ class GenreAdapter( var dataSet: List, private val mItemLayoutRes: Int ) : RecyclerView.Adapter() { - - + val colors = listOf(Color.RED, Color.BLUE) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { return ViewHolder(LayoutInflater.from(activity).inflate(mItemLayoutRes, parent, false)) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { val genre = dataSet[position] + holder.title?.text = genre.name holder.text?.text = String.format( Locale.getDefault(), diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/HomeAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/HomeAdapter.kt index 0f5e29cd..0ed2272b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/HomeAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/HomeAdapter.kt @@ -40,8 +40,8 @@ class HomeAdapter( } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { - val layout = LayoutInflater.from(activity) - .inflate(R.layout.section_recycler_view, parent, false) + val layout = + LayoutInflater.from(activity).inflate(R.layout.section_recycler_view, parent, false) return when (viewType) { RECENT_ARTISTS, TOP_ARTISTS -> ArtistViewHolder(layout) GENRES -> GenreViewHolder(layout) @@ -205,10 +205,13 @@ class HomeAdapter( fun bind(home: Home) { arrow.hide() title.setText(home.titleRes) + val genreAdapter = GenreAdapter( + activity, + home.arrayList as List, + R.layout.item_grid_genre + ) recyclerView.apply { layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.HORIZONTAL, false) - val genreAdapter = - GenreAdapter(activity, home.arrayList as List, R.layout.item_grid_genre) adapter = genreAdapter } } diff --git a/app/src/main/java/code/name/monkey/retromusic/db/HistoryEntity.kt b/app/src/main/java/code/name/monkey/retromusic/db/HistoryEntity.kt index 090fb892..bbb2471f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/db/HistoryEntity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/db/HistoryEntity.kt @@ -3,7 +3,6 @@ package code.name.monkey.retromusic.db import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey -import code.name.monkey.retromusic.model.Song @Entity class HistoryEntity( @@ -30,22 +29,4 @@ class HistoryEntity( val albumArtist: String?, @ColumnInfo(name = "time_played") val timePlayed: Long -) { - fun toSong(): Song { - return Song( - id, - title, - trackNumber, - year, - duration, - data, - dateModified, - albumId, - albumName, - artistId, - artistName, - composer, - albumArtist - ) - } -} \ No newline at end of file +) \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/db/PlayCountEntity.kt b/app/src/main/java/code/name/monkey/retromusic/db/PlayCountEntity.kt new file mode 100644 index 00000000..94d496d4 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/db/PlayCountEntity.kt @@ -0,0 +1,34 @@ +package code.name.monkey.retromusic.db + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity +class PlayCountEntity( + @PrimaryKey + val id: Int, + val title: String, + @ColumnInfo(name = "track_number") + val trackNumber: Int, + val year: Int, + val duration: Long, + 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, + val composer: String?, + @ColumnInfo(name = "album_artist") + val albumArtist: String?, + @ColumnInfo(name = "time_played") + val timePlayed: Long, + @ColumnInfo(name = "play_count") + var playCount: Int +) \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/db/PlaylistDao.kt b/app/src/main/java/code/name/monkey/retromusic/db/PlaylistDao.kt index a1ef98ad..2b1e64a3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/db/PlaylistDao.kt +++ b/app/src/main/java/code/name/monkey/retromusic/db/PlaylistDao.kt @@ -18,7 +18,7 @@ interface PlaylistDao { suspend fun playlists(): List @Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId") - suspend fun deleteSongsFromPlaylist(playlistId: Int) + suspend fun deleteSongsInPlaylist(playlistId: Int) @Transaction @Query("SELECT * FROM PlaylistEntity") @@ -43,13 +43,13 @@ interface PlaylistDao { suspend fun deletePlaylistEntities(playlistEntities: List) @Delete - suspend fun removeSongsFromPlaylist(songs: List) + suspend fun deleteSongsInPlaylist(songs: List) @Insert(onConflict = OnConflictStrategy.REPLACE) - suspend fun addSong(historyEntity: HistoryEntity) + suspend fun insertSongInHistory(historyEntity: HistoryEntity) @Query("SELECT * FROM HistoryEntity WHERE id = :songId LIMIT 1") - suspend fun songPresentInHistory(songId: Int): HistoryEntity? + suspend fun isSongPresentInHistory(songId: Int): HistoryEntity? @Update suspend fun updateHistorySong(historyEntity: HistoryEntity) @@ -63,4 +63,18 @@ interface PlaylistDao { @Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId") fun favoritesSongs(playlistId: Int): List + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insertSongInPlayCount(playCountEntity: PlayCountEntity) + + @Update + fun updateSongInPlayCount(playCountEntity: PlayCountEntity) + + @Delete + fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) + + @Query("SELECT * FROM PlayCountEntity WHERE id =:songId") + fun checkSongExistInPlayCount(songId: Int): List + + @Query("SELECT * FROM PlayCountEntity ORDER BY play_count DESC") + fun playCountSongs(): List } \ 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 9f3ea990..baa5d726 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 @@ -4,8 +4,8 @@ import androidx.room.Database import androidx.room.RoomDatabase @Database( - entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class], - version = 16, + entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class], + version = 17, 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 715c0231..1d9b13f7 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 @@ -4,7 +4,6 @@ import android.os.Parcelable import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey -import code.name.monkey.retromusic.model.Song import kotlinx.android.parcel.Parcelize @Parcelize @@ -37,27 +36,5 @@ class SongEntity( @ColumnInfo(name = "song_key") var songPrimaryKey: Long = 0 - fun toSong(): Song { - return Song( - id, - title, - trackNumber, - year, - duration, - data, - dateModified, - albumId, - albumName, - artistId, - artistName, - composer, - albumArtist - ) - } } -fun List.toSongs(): List { - return map { - it.toSong() - } -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/db/SongExtension.kt b/app/src/main/java/code/name/monkey/retromusic/db/SongExtension.kt new file mode 100644 index 00000000..f1df038d --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/db/SongExtension.kt @@ -0,0 +1,83 @@ +package code.name.monkey.retromusic.db + +import code.name.monkey.retromusic.model.Song + +fun List.toSongs(): List { + return map { + it.toSong() + } +} + +fun SongEntity.toSong(): Song { + return Song( + id, + title, + trackNumber, + year, + duration, + data, + dateModified, + albumId, + albumName, + artistId, + artistName, + composer, + albumArtist + ) +} + +fun PlayCountEntity.toSong(): Song { + return Song( + id, + title, + trackNumber, + year, + duration, + data, + dateModified, + albumId, + albumName, + artistId, + artistName, + composer, + albumArtist + ) +} + +fun HistoryEntity.toSong(): Song { + return Song( + id, + title, + trackNumber, + year, + duration, + data, + dateModified, + albumId, + albumName, + artistId, + artistName, + composer, + albumArtist + ) +} + +fun Song.toPlayCount(): PlayCountEntity { + return PlayCountEntity( + id, + title, + trackNumber, + year, + duration, + data, + dateModified, + albumId, + albumName, + artistId, + artistName, + composer, + albumArtist, + System.currentTimeMillis(), + 1 + ) +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToRetroPlaylist.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToRetroPlaylist.kt index dca9ebb1..1e9dfbb4 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToRetroPlaylist.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/AddToRetroPlaylist.kt @@ -14,7 +14,7 @@ import code.name.monkey.retromusic.extensions.colorButtons import code.name.monkey.retromusic.extensions.extraNotNull import code.name.monkey.retromusic.extensions.materialDialog import code.name.monkey.retromusic.fragments.LibraryViewModel -import code.name.monkey.retromusic.fragments.ReloadType +import code.name.monkey.retromusic.fragments.ReloadType.Playlists import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.repository.RealRepository import kotlinx.coroutines.Dispatchers @@ -59,7 +59,7 @@ class AddToRetroPlaylist : DialogFragment() { lifecycleScope.launch(Dispatchers.IO) { val songEntities = songs.toSongEntity(playlistEntities[which - 1]) repository.insertSongs(songEntities) - libraryViewModel.forceReload(ReloadType.Playlists) + libraryViewModel.forceReload(Playlists) } } dismiss() diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveSongFromPlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveSongFromPlaylistDialog.kt index f8e93980..3dc64f67 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveSongFromPlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveSongFromPlaylistDialog.kt @@ -65,7 +65,7 @@ class RemoveSongFromPlaylistDialog : DialogFragment() { .setMessage(pair.second) .setPositiveButton(R.string.remove_action) { _, _ -> lifecycleScope.launch(Dispatchers.IO) { - repository.removeSongsFromPlaylist(songs) + repository.deleteSongsInPlaylist(songs) } /* PlaylistsUtil.removeFromPlaylist( requireContext(), diff --git a/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt b/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt index 48a029f2..2059d929 100644 --- a/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt +++ b/app/src/main/java/code/name/monkey/retromusic/extensions/ColorExt.kt @@ -131,6 +131,12 @@ fun MaterialButton.applyColor(color: Int) { iconTint = textColorColorStateList } +fun MaterialButton.applyOutlineColor(color: Int) { + val textColorColorStateList = ColorStateList.valueOf(color) + setTextColor(textColorColorStateList) + iconTint = textColorColorStateList +} + fun TextInputLayout.accentColor() { val accentColor = ThemeStore.accentColor(context) val colorState = ColorStateList.valueOf(accentColor) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/DetailListFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/DetailListFragment.kt index 30484cce..57e11cdd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/DetailListFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/DetailListFragment.kt @@ -12,6 +12,7 @@ import code.name.monkey.retromusic.* import code.name.monkey.retromusic.adapter.album.AlbumAdapter import code.name.monkey.retromusic.adapter.artist.ArtistAdapter import code.name.monkey.retromusic.adapter.song.SongAdapter +import code.name.monkey.retromusic.db.toSong import code.name.monkey.retromusic.fragments.albums.AlbumClickListener import code.name.monkey.retromusic.fragments.artists.ArtistClickListener import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt index c97538fb..607d2299 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import code.name.monkey.retromusic.db.PlaylistWithSongs +import code.name.monkey.retromusic.db.toPlayCount import code.name.monkey.retromusic.fragments.ReloadType.* import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.interfaces.MusicServiceEventListener @@ -127,6 +128,14 @@ class LibraryViewModel( } else { repository.addSongToHistory(MusicPlayerRemote.currentSong) } + val songs = repository.checkSongExistInPlayCount(MusicPlayerRemote.currentSong.id) + if (songs.isNotEmpty()) { + repository.updateSongInPlayCount(songs.first().apply { + playCount += playCount + 1 + }) + } else { + repository.insertSongInPlayCount(MusicPlayerRemote.currentSong.toPlayCount()) + } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt index 526cd5c9..95b0a33e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt @@ -26,6 +26,7 @@ import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter import code.name.monkey.retromusic.dialogs.AddToRetroPlaylist import code.name.monkey.retromusic.dialogs.DeleteSongsDialog import code.name.monkey.retromusic.extensions.applyColor +import code.name.monkey.retromusic.extensions.applyOutlineColor import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.glide.AlbumGlideRequest @@ -240,7 +241,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det private fun setColors(color: MediaNotificationProcessor) { shuffleAction.applyColor(color.backgroundColor) - playAction.applyColor(color.backgroundColor) + playAction.applyOutlineColor(color.backgroundColor) } override fun onAlbumClick(albumId: Int, view: View) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt index 58d59d1d..928f5fd9 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt @@ -22,6 +22,7 @@ import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter import code.name.monkey.retromusic.dialogs.AddToRetroPlaylist import code.name.monkey.retromusic.extensions.applyColor +import code.name.monkey.retromusic.extensions.applyOutlineColor import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.extensions.showToast import code.name.monkey.retromusic.fragments.albums.AlbumClickListener @@ -191,7 +192,7 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d private fun setColors(color: MediaNotificationProcessor) { shuffleAction.applyColor(color.backgroundColor) - playAction.applyColor(color.backgroundColor) + playAction.applyOutlineColor(color.backgroundColor) } override fun onAlbumClick(albumId: Int, view: View) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt index 40277262..975443f7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt @@ -25,6 +25,7 @@ import code.name.monkey.retromusic.dialogs.* import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.whichFragment import code.name.monkey.retromusic.fragments.LibraryViewModel +import code.name.monkey.retromusic.fragments.ReloadType.Playlists import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.interfaces.PaletteColorHolder @@ -169,6 +170,7 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme repository.removeSongFromPlaylist(songEntity) } else { repository.insertSongs(listOf(song.toSongEntity(playlist.playListId))) + libraryViewModel.forceReload(Playlists) } requireContext().sendBroadcast(Intent(MusicService.FAVORITE_STATE_CHANGED)) } diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/Repository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/Repository.kt index 7afc0eec..2d71b368 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/Repository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/Repository.kt @@ -17,10 +17,7 @@ package code.name.monkey.retromusic.repository import android.content.Context import androidx.lifecycle.LiveData import code.name.monkey.retromusic.* -import code.name.monkey.retromusic.db.HistoryEntity -import code.name.monkey.retromusic.db.PlaylistEntity -import code.name.monkey.retromusic.db.PlaylistWithSongs -import code.name.monkey.retromusic.db.SongEntity +import code.name.monkey.retromusic.db.* import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.model.smartplaylist.NotPlayedPlaylist import code.name.monkey.retromusic.network.LastFMService @@ -75,7 +72,7 @@ interface Repository { suspend fun roomPlaylists(): List suspend fun deleteRoomPlaylist(playlists: List) suspend fun renameRoomPlaylist(playlistId: Int, name: String) - suspend fun removeSongsFromPlaylist(songs: List) + suspend fun deleteSongsInPlaylist(songs: List) suspend fun removeSongFromPlaylist(songEntity: SongEntity) suspend fun deleteSongsFromPlaylist(playlists: List) suspend fun favoritePlaylist(): List @@ -86,6 +83,11 @@ interface Repository { suspend fun favoritePlaylistSongs(): List suspend fun recentSongs(): List suspend fun topPlayedSongs(): List + suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity) + suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity) + suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) + suspend fun checkSongExistInPlayCount(songId: Int): List + suspend fun playCountSongs(): List fun historySong(): LiveData> fun favorites(): LiveData> } @@ -185,13 +187,14 @@ class RealRepository( override suspend fun homeSections(): List { val homeSections = mutableListOf() - val sections = listOf( + val sections: List = listOf( suggestionsHome(), topArtistsHome(), topAlbumsHome(), recentArtistsHome(), recentAlbumsHome(), - favoritePlaylistHome() + favoritePlaylistHome(), + genresHome() ) for (section in sections) { if (section.arrayList.isNotEmpty()) { @@ -231,8 +234,8 @@ class RealRepository( override suspend fun renameRoomPlaylist(playlistId: Int, name: String) = roomRepository.renamePlaylistEntity(playlistId, name) - override suspend fun removeSongsFromPlaylist(songs: List) = - roomRepository.removeSongsFromPlaylist(songs) + override suspend fun deleteSongsInPlaylist(songs: List) = + roomRepository.deleteSongsInPlaylist(songs) override suspend fun removeSongFromPlaylist(songEntity: SongEntity) = roomRepository.removeSongFromPlaylist(songEntity) @@ -263,6 +266,21 @@ class RealRepository( override suspend fun topPlayedSongs(): List = topPlayedRepository.topTracks() + override suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity) = + roomRepository.insertSongInPlayCount(playCountEntity) + + override suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity) = + roomRepository.updateSongInPlayCount(playCountEntity) + + override suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) = + roomRepository.deleteSongInPlayCount(playCountEntity) + + override suspend fun checkSongExistInPlayCount(songId: Int): List = + roomRepository.checkSongExistInPlayCount(songId) + + override suspend fun playCountSongs(): List = + roomRepository.playCountSongs() + override fun historySong(): LiveData> = roomRepository.historySongs() diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/RoomPlaylistRepository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/RoomPlaylistRepository.kt index a4c76ba2..8eae0305 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/RoomPlaylistRepository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/RoomPlaylistRepository.kt @@ -15,7 +15,7 @@ interface RoomPlaylistRepository { suspend fun getSongs(playlistEntity: PlaylistEntity): List suspend fun deletePlaylistEntities(playlistEntities: List) suspend fun renamePlaylistEntity(playlistId: Int, name: String) - suspend fun removeSongsFromPlaylist(songs: List) + suspend fun deleteSongsInPlaylist(songs: List) suspend fun deleteSongsFromPlaylist(playlists: List) suspend fun favoritePlaylist(favorite: String): List suspend fun isFavoriteSong(songEntity: SongEntity): List @@ -24,6 +24,11 @@ interface RoomPlaylistRepository { suspend fun songPresentInHistory(song: Song): HistoryEntity? suspend fun updateHistorySong(song: Song) suspend fun favoritePlaylistSongs(favorite: String): List + suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity) + suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity) + suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) + suspend fun checkSongExistInPlayCount(songId: Int): List + suspend fun playCountSongs(): List fun historySongs(): LiveData> fun favoritePlaylistLiveData(favorite: String): LiveData> } @@ -67,12 +72,12 @@ class RealRoomRepository( override suspend fun renamePlaylistEntity(playlistId: Int, name: String) = playlistDao.renamePlaylistEntity(playlistId, name) - override suspend fun removeSongsFromPlaylist(songs: List) = - playlistDao.removeSongsFromPlaylist(songs) + override suspend fun deleteSongsInPlaylist(songs: List) = + playlistDao.deleteSongsInPlaylist(songs) override suspend fun deleteSongsFromPlaylist(playlists: List) { playlists.forEach { - playlistDao.deleteSongsFromPlaylist(it.playListId) + playlistDao.deleteSongsInPlaylist(it.playListId) } } @@ -89,10 +94,10 @@ class RealRoomRepository( playlistDao.removeSong(songEntity.playlistCreatorId, songEntity.id) override suspend fun addSongToHistory(currentSong: Song) = - playlistDao.addSong(currentSong.toHistoryEntity(System.currentTimeMillis())) + playlistDao.insertSongInHistory(currentSong.toHistoryEntity(System.currentTimeMillis())) override suspend fun songPresentInHistory(song: Song): HistoryEntity? = - playlistDao.songPresentInHistory(song.id) + playlistDao.isSongPresentInHistory(song.id) override suspend fun updateHistorySong(song: Song) = playlistDao.updateHistorySong(song.toHistoryEntity(System.currentTimeMillis())) @@ -106,9 +111,25 @@ class RealRoomRepository( playlistDao.checkPlaylistExists(favorite).first().playListId ) - override suspend fun favoritePlaylistSongs(favorite: String): List = - playlistDao.favoritesSongs( - playlistDao.checkPlaylistExists(favorite).first().playListId - ) + override suspend fun favoritePlaylistSongs(favorite: String): List { + return if (playlistDao.checkPlaylistExists(favorite).isNotEmpty()) + playlistDao.favoritesSongs( + playlistDao.checkPlaylistExists(favorite).first().playListId + ) else emptyList() + } + override suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity) = + playlistDao.insertSongInPlayCount(playCountEntity) + + override suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity) = + playlistDao.updateSongInPlayCount(playCountEntity) + + override suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) = + playlistDao.deleteSongInPlayCount(playCountEntity) + + override suspend fun checkSongExistInPlayCount(songId: Int): List = + playlistDao.checkSongExistInPlayCount(songId) + + override suspend fun playCountSongs(): List = + playlistDao.playCountSongs() } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/TopPlayedRepository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/TopPlayedRepository.kt index 2ad30559..e522a092 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/TopPlayedRepository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/TopPlayedRepository.kt @@ -116,13 +116,13 @@ class RealTopPlayedRepository( private fun makeTopTracksCursorImpl(): SortedLongCursor? { // first get the top results ids from the internal database - val songs = + val cursor = SongPlayCountStore.getInstance(context).getTopPlayedResults(NUMBER_OF_TOP_TRACKS) - songs.use { localSongs -> + cursor.use { songs -> return makeSortedCursor( - localSongs, - localSongs.getColumnIndex(SongPlayCountStore.SongPlayCountColumns.ID) + songs, + songs.getColumnIndex(SongPlayCountStore.SongPlayCountColumns.ID) ) } } diff --git a/app/src/main/res/drawable/ic_account.xml b/app/src/main/res/drawable/ic_account.xml index 4414a60e..65de32cf 100644 --- a/app/src/main/res/drawable/ic_account.xml +++ b/app/src/main/res/drawable/ic_account.xml @@ -19,6 +19,6 @@ android:viewportHeight="24"> + android:fillColor="@android:color/white" + android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM7.07,18.28c0.43,-0.9 3.05,-1.78 4.93,-1.78s4.51,0.88 4.93,1.78C15.57,19.36 13.86,20 12,20s-3.57,-0.64 -4.93,-1.72zM18.36,16.83c-1.43,-1.74 -4.9,-2.33 -6.36,-2.33s-4.93,0.59 -6.36,2.33C4.62,15.49 4,13.82 4,12c0,-4.41 3.59,-8 8,-8s8,3.59 8,8c0,1.82 -0.62,3.49 -1.64,4.83zM12,6c-1.94,0 -3.5,1.56 -3.5,3.5S10.06,13 12,13s3.5,-1.56 3.5,-3.5S13.94,6 12,6zM12,11c-0.83,0 -1.5,-0.67 -1.5,-1.5S11.17,8 12,8s1.5,0.67 1.5,1.5S12.83,11 12,11z" /> \ No newline at end of file diff --git a/app/src/main/res/layout-land/fragment_banner_home.xml b/app/src/main/res/layout-land/fragment_banner_home.xml index 52043a54..97e02abb 100644 --- a/app/src/main/res/layout-land/fragment_banner_home.xml +++ b/app/src/main/res/layout-land/fragment_banner_home.xml @@ -87,7 +87,7 @@ android:layout_height="wrap_content" android:layout_marginStart="16dp" android:padding="0dp" - android:textAppearance="@style/TextViewHeadline5" + android:textAppearance="@style/TextViewHeadline6" android:textColor="@color/md_white_1000" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="@+id/userImage" diff --git a/app/src/main/res/layout-land/fragment_home.xml b/app/src/main/res/layout-land/fragment_home.xml index 9da4068d..5e50ad75 100644 --- a/app/src/main/res/layout-land/fragment_home.xml +++ b/app/src/main/res/layout-land/fragment_home.xml @@ -57,7 +57,7 @@ android:layout_height="wrap_content" android:layout_marginStart="16dp" android:padding="0dp" - android:textAppearance="@style/TextViewHeadline5" + android:textAppearance="@style/TextViewHeadline6" android:textColor="?android:attr/textColorPrimary" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="@+id/userImage" diff --git a/app/src/main/res/layout/fragment_album_content.xml b/app/src/main/res/layout/fragment_album_content.xml index e337aa4a..520c55c1 100644 --- a/app/src/main/res/layout/fragment_album_content.xml +++ b/app/src/main/res/layout/fragment_album_content.xml @@ -8,14 +8,17 @@ + tools:text="@tools:sample/full_names" /> + tools:text="@tools:sample/full_names" /> - - - - - - - + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_album_card.xml b/app/src/main/res/layout/item_album_card.xml index 21ebef3d..e7e0bd33 100644 --- a/app/src/main/res/layout/item_album_card.xml +++ b/app/src/main/res/layout/item_album_card.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:padding="2dp" android:background="?attr/rectSelector" android:orientation="vertical">