diff --git a/app/src/main/java/code/name/monkey/retromusic/Constants.kt b/app/src/main/java/code/name/monkey/retromusic/Constants.kt index 443655c5..32e91aca 100644 --- a/app/src/main/java/code/name/monkey/retromusic/Constants.kt +++ b/app/src/main/java/code/name/monkey/retromusic/Constants.kt @@ -53,7 +53,6 @@ object Constants { ) const val NUMBER_OF_TOP_TRACKS = 99 } -const val HISTORY = 8 const val EXTRA_GENRE = "extra_genre" const val EXTRA_PLAYLIST = "extra_playlist" const val EXTRA_PLAYLIST_ID = "extra_playlist_id" diff --git a/app/src/main/java/code/name/monkey/retromusic/HomeSection.kt b/app/src/main/java/code/name/monkey/retromusic/HomeSection.kt index 6dd15c6e..f5312054 100644 --- a/app/src/main/java/code/name/monkey/retromusic/HomeSection.kt +++ b/app/src/main/java/code/name/monkey/retromusic/HomeSection.kt @@ -23,3 +23,6 @@ const val SUGGESTIONS = 5 const val FAVOURITES = 4 const val GENRES = 6 const val PLAYLISTS = 7 +const val HISTORY_PLAYLIST = 8 +const val LAST_ADDED_PLAYLIST = 9 +const val TOP_PLAYED_PLAYLIST = 10 \ No newline at end of file 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 a2b9302b..30484cce 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 @@ -49,7 +49,43 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de loadAlbums(R.string.recent_albums, RECENT_ALBUMS) } FAVOURITES -> loadFavorite() - HISTORY -> loadHistory() + HISTORY_PLAYLIST -> loadHistory() + LAST_ADDED_PLAYLIST -> lastAddedSongs() + TOP_PLAYED_PLAYLIST -> topPlayed() + } + } + + private fun lastAddedSongs() { + toolbar.setTitle(R.string.last_added) + val songAdapter = SongAdapter( + requireActivity(), + mutableListOf(), + R.layout.item_list, null + ) + recyclerView.apply { + adapter = songAdapter + layoutManager = linearLayoutManager() + } + lifecycleScope.launch(IO) { + val songs = repository.recentSongs() + withContext(Main) { songAdapter.swapDataSet(songs) } + } + } + + private fun topPlayed() { + toolbar.setTitle(R.string.my_top_tracks) + val songAdapter = SongAdapter( + requireActivity(), + mutableListOf(), + R.layout.item_list, null + ) + recyclerView.apply { + adapter = songAdapter + layoutManager = linearLayoutManager() + } + lifecycleScope.launch(IO) { + val songs = repository.recentSongs() + withContext(Main) { songAdapter.swapDataSet(songs) } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/home/HomeFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/home/HomeFragment.kt index 36343edb..47d0918f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/home/HomeFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/home/HomeFragment.kt @@ -22,9 +22,10 @@ import androidx.core.os.bundleOf import androidx.lifecycle.Observer import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager -import code.name.monkey.retromusic.EXTRA_PLAYLIST -import code.name.monkey.retromusic.HISTORY +import code.name.monkey.retromusic.HISTORY_PLAYLIST +import code.name.monkey.retromusic.LAST_ADDED_PLAYLIST import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.TOP_PLAYED_PLAYLIST import code.name.monkey.retromusic.adapter.HomeAdapter import code.name.monkey.retromusic.extensions.findActivityNavController import code.name.monkey.retromusic.fragments.LibraryViewModel @@ -32,8 +33,6 @@ import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.glide.ProfileBannerGlideRequest import code.name.monkey.retromusic.glide.UserProfileGlideRequest import code.name.monkey.retromusic.helper.MusicPlayerRemote -import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist -import code.name.monkey.retromusic.model.smartplaylist.TopTracksPlaylist import code.name.monkey.retromusic.repository.Repository import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil @@ -73,15 +72,15 @@ class HomeFragment : lastAdded.setOnClickListener { findActivityNavController(R.id.fragment_container).navigate( - R.id.playlistDetailsFragment, - bundleOf(EXTRA_PLAYLIST to LastAddedPlaylist()) + R.id.detailListFragment, + bundleOf("type" to LAST_ADDED_PLAYLIST) ) } topPlayed.setOnClickListener { findActivityNavController(R.id.fragment_container).navigate( - R.id.playlistDetailsFragment, - bundleOf(EXTRA_PLAYLIST to TopTracksPlaylist()) + R.id.detailListFragment, + bundleOf("type" to TOP_PLAYED_PLAYLIST) ) } @@ -97,7 +96,7 @@ class HomeFragment : history.setOnClickListener { findActivityNavController(R.id.fragment_container).navigate( R.id.detailListFragment, - bundleOf("type" to HISTORY) + bundleOf("type" to HISTORY_PLAYLIST) ) } 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 0ac0caad..7afc0eec 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 @@ -84,6 +84,8 @@ interface Repository { suspend fun songPresentInHistory(currentSong: Song): HistoryEntity? suspend fun updateHistorySong(currentSong: Song) suspend fun favoritePlaylistSongs(): List + suspend fun recentSongs(): List + suspend fun topPlayedSongs(): List fun historySong(): LiveData> fun favorites(): LiveData> } @@ -98,7 +100,7 @@ class RealRepository( private val lastAddedRepository: LastAddedRepository, private val playlistRepository: PlaylistRepository, private val searchRepository: RealSearchRepository, - private val playedTracksRepository: TopPlayedRepository, + private val topPlayedRepository: TopPlayedRepository, private val roomRepository: RoomPlaylistRepository ) : Repository { @@ -116,9 +118,9 @@ class RealRepository( override suspend fun recentAlbums(): List = lastAddedRepository.recentAlbums() - override suspend fun topArtists(): List = playedTracksRepository.topArtists() + override suspend fun topArtists(): List = topPlayedRepository.topArtists() - override suspend fun topAlbums(): List = playedTracksRepository.topAlbums() + override suspend fun topAlbums(): List = topPlayedRepository.topAlbums() override suspend fun allPlaylists(): List = playlistRepository.playlists() @@ -254,10 +256,13 @@ class RealRepository( override suspend fun updateHistorySong(currentSong: Song) = roomRepository.updateHistorySong(currentSong) - override suspend fun favoritePlaylistSongs(): List = roomRepository.favoritePlaylistSongs(context.getString(R.string.favorites)) + override suspend fun recentSongs(): List = lastAddedRepository.recentSongs() + + override suspend fun topPlayedSongs(): List = topPlayedRepository.topTracks() + override fun historySong(): LiveData> = roomRepository.historySongs() @@ -293,12 +298,12 @@ class RealRepository( } override suspend fun topAlbumsHome(): Home { - val albums = playedTracksRepository.topAlbums().take(5) + val albums = topPlayedRepository.topAlbums().take(5) return Home(albums, TOP_ALBUMS, R.string.top_albums) } override suspend fun topArtistsHome(): Home { - val artists = playedTracksRepository.topArtists().take(5) + val artists = topPlayedRepository.topArtists().take(5) return Home(artists, TOP_ARTISTS, R.string.top_artists) }