diff --git a/app/build.gradle b/app/build.gradle index cac506dd..56c45942 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -129,7 +129,8 @@ dependencies { implementation "com.afollestad.material-dialogs:core:$material_dialog_version" implementation "com.afollestad.material-dialogs:commons:$material_dialog_version" implementation 'com.afollestad:material-cab:0.1.12' - + implementation 'com.afollestad:recyclical:1.1.1' + implementation 'com.github.bumptech.glide:glide:3.8.0' implementation 'com.github.bumptech.glide:okhttp3-integration:1.5.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0' @@ -180,5 +181,8 @@ dependencies { implementation "androidx.room:room-runtime:$room_version" kapt "androidx.room:room-compiler:$room_version" implementation "androidx.room:room-ktx:$room_version" + + + debugImplementation 'com.amitshekhar.android:debug-db:1.0.6' } \ No newline at end of file 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 52eaf5ee..0f5e29cd 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 @@ -64,7 +64,7 @@ class HomeAdapter( when (getItemViewType(position)) { RECENT_ALBUMS -> { val viewHolder = holder as AlbumViewHolder - viewHolder.bindView(home.arrayList as List, R.string.recent_albums) + viewHolder.bindView(home) viewHolder.clickableArea.setOnClickListener { activity.findNavController(R.id.fragment_container).navigate( R.id.detailListFragment, @@ -74,7 +74,7 @@ class HomeAdapter( } TOP_ALBUMS -> { val viewHolder = holder as AlbumViewHolder - viewHolder.bindView(home.arrayList as List, R.string.top_albums) + viewHolder.bindView(home) viewHolder.clickableArea.setOnClickListener { activity.findNavController(R.id.fragment_container).navigate( R.id.detailListFragment, @@ -84,7 +84,7 @@ class HomeAdapter( } RECENT_ARTISTS -> { val viewHolder = holder as ArtistViewHolder - viewHolder.bindView(home.arrayList, R.string.recent_artists) + viewHolder.bindView(home) viewHolder.clickableArea.setOnClickListener { activity.findNavController(R.id.fragment_container).navigate( R.id.detailListFragment, @@ -94,7 +94,7 @@ class HomeAdapter( } TOP_ARTISTS -> { val viewHolder = holder as ArtistViewHolder - viewHolder.bindView(home.arrayList, R.string.top_artists) + viewHolder.bindView(home) viewHolder.clickableArea.setOnClickListener { activity.findNavController(R.id.fragment_container).navigate( R.id.detailListFragment, @@ -104,11 +104,11 @@ class HomeAdapter( } SUGGESTIONS -> { val viewHolder = holder as SuggestionsViewHolder - viewHolder.bindView(home.arrayList) + viewHolder.bindView(home) } FAVOURITES -> { val viewHolder = holder as PlaylistViewHolder - viewHolder.bindView(home.arrayList, R.string.favorites) + viewHolder.bindView(home) viewHolder.clickableArea.setOnClickListener { activity.findNavController(R.id.fragment_container).navigate( R.id.detailListFragment, @@ -118,7 +118,7 @@ class HomeAdapter( } GENRES -> { val viewHolder = holder as GenreViewHolder - viewHolder.bind(home.arrayList, R.string.genres) + viewHolder.bind(home) } PLAYLISTS -> { @@ -136,22 +136,22 @@ class HomeAdapter( } private inner class AlbumViewHolder(view: View) : AbsHomeViewItem(view) { - fun bindView(albums: List, titleRes: Int) { - title.text = activity.getString(titleRes) + fun bindView(home: Home) { + title.setText(home.titleRes) recyclerView.apply { - adapter = albumAdapter(albums) + adapter = albumAdapter(home.arrayList as List) layoutManager = gridLayoutManager() } } } private inner class ArtistViewHolder(view: View) : AbsHomeViewItem(view) { - fun bindView(artists: List, titleRes: Int) { + fun bindView(home: Home) { + title.setText(home.titleRes) recyclerView.apply { layoutManager = linearLayoutManager() - adapter = artistsAdapter(artists as List) + adapter = artistsAdapter(home.arrayList as List) } - title.text = activity.getString(titleRes) } } @@ -167,8 +167,7 @@ class HomeAdapter( R.id.image8 ) - fun bindView(songs: List) { - songs as List + fun bindView(home: Home) { val color = ThemeStore.accentColor(activity) itemView.findViewById(R.id.message).setTextColor(color) itemView.findViewById(R.id.card6).apply { @@ -176,9 +175,9 @@ class HomeAdapter( } images.forEachIndexed { index, id -> itemView.findViewById(id).setOnClickListener { - MusicPlayerRemote.playNext(songs[index]) + MusicPlayerRemote.playNext(home.arrayList[index] as Song) } - SongGlideRequest.Builder.from(Glide.with(activity), songs[index]) + SongGlideRequest.Builder.from(Glide.with(activity), home.arrayList[index] as Song) .asBitmap() .build() .into(itemView.findViewById(id)) @@ -188,28 +187,28 @@ class HomeAdapter( } private inner class PlaylistViewHolder(view: View) : AbsHomeViewItem(view) { - fun bindView(songs: List, titleRes: Int) { + fun bindView(home: Home) { + title.setText(home.titleRes) recyclerView.apply { val songAdapter = SongAdapter( activity, - songs as MutableList, + home.arrayList as MutableList, R.layout.item_album_card, null ) layoutManager = linearLayoutManager() adapter = songAdapter } - title.text = activity.getString(titleRes) } } private inner class GenreViewHolder(itemView: View) : AbsHomeViewItem(itemView) { - fun bind(genres: List, titleRes: Int) { + fun bind(home: Home) { arrow.hide() - title.text = activity.getString(titleRes) + title.setText(home.titleRes) recyclerView.apply { layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.HORIZONTAL, false) val genreAdapter = - GenreAdapter(activity, genres as List, R.layout.item_grid_genre) + 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/PlaylistDao.kt b/app/src/main/java/code/name/monkey/retromusic/db/PlaylistDao.kt index fd3d6b43..c321b1bf 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 @@ -43,5 +43,5 @@ interface PlaylistDao { @Delete suspend fun removeSongsFromPlaylist(songs: List) - + } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Home.kt b/app/src/main/java/code/name/monkey/retromusic/model/Home.kt index e848d25c..2224417f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/Home.kt +++ b/app/src/main/java/code/name/monkey/retromusic/model/Home.kt @@ -14,10 +14,13 @@ package code.name.monkey.retromusic.model +import androidx.annotation.StringRes import code.name.monkey.retromusic.HomeSection class Home( val arrayList: List, @HomeSection - val homeSection: Int + val homeSection: Int, + @StringRes + val titleRes: Int ) \ No newline at end of file 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 8fd90bfb..cbd717e7 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 @@ -236,10 +236,6 @@ class RealRepository( return homeSections } - override suspend fun playlists(): Home { - val playlist = playlistRepository.playlists() - return Home(playlist, TOP_ALBUMS) - } override suspend fun playlist(playlistId: Int) = playlistRepository.playlist(playlistId) @@ -291,33 +287,37 @@ class RealRepository( NotPlayedPlaylist().songs().shuffled().takeIf { it.size > 9 } ?: emptyList() - return Home(songs, SUGGESTIONS) + return Home(songs, SUGGESTIONS, R.string.suggestion_songs) } override suspend fun genresHome(): Home { val genres = genreRepository.genres().shuffled() - return Home(genres, GENRES) + return Home(genres, GENRES, R.string.genres) } + override suspend fun playlists(): Home { + val playlist = playlistRepository.playlists() + return Home(playlist, PLAYLISTS, R.string.playlists) + } override suspend fun recentArtistsHome(): Home { val artists = lastAddedRepository.recentArtists().take(5) - return Home(artists, RECENT_ARTISTS) + return Home(artists, RECENT_ARTISTS, R.string.recent_artists) } override suspend fun recentAlbumsHome(): Home { val albums = lastAddedRepository.recentAlbums().take(5) - return Home(albums, RECENT_ALBUMS) + return Home(albums, RECENT_ALBUMS, R.string.recent_albums) } override suspend fun topAlbumsHome(): Home { val albums = playedTracksRepository.topAlbums().take(5) - return Home(albums, TOP_ALBUMS) + return Home(albums, TOP_ALBUMS, R.string.top_albums) } override suspend fun topArtistsHome(): Home { val artists = playedTracksRepository.topArtists().take(5) - return Home(artists, TOP_ARTISTS) + return Home(artists, TOP_ARTISTS, R.string.top_artists) } override suspend fun favoritePlaylistHome(): Home { @@ -327,7 +327,7 @@ class RealRepository( PlaylistSongsLoader.getPlaylistSongList(context, playlists[0]) else emptyList() - return Home(songs, FAVOURITES) + return Home(songs, FAVOURITES, R.string.favorites) } override fun songsFlow(): Flow>> = flow { diff --git a/app/src/main/res/layout/home_content.xml b/app/src/main/res/layout/home_content.xml index f97294c1..72599522 100644 --- a/app/src/main/res/layout/home_content.xml +++ b/app/src/main/res/layout/home_content.xml @@ -39,9 +39,8 @@ android:layout_height="wrap_content" android:nestedScrollingEnabled="false" android:overScrollMode="never" - app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" - app:spanCount="3" tools:itemCount="3" + tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager" tools:listitem="@layout/item_album_card" />