From c23c56649ed8741c0bf93bd0bcbc5952f009d5a1 Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Sat, 3 Oct 2020 00:40:26 +0530 Subject: [PATCH] Code refactor, fix animations on Album and Artist details --- .../base/AbsSlidingMusicPanelActivity.kt | 17 ++-- .../fragments/albums/AlbumDetailsFragment.kt | 11 ++- .../fragments/albums/AlbumsFragment.kt | 87 ++++++++++------ .../fragments/artists/ArtistsFragment.kt | 83 +++++++++++----- .../fragments/songs/SongsFragment.kt | 98 ++++++++++++------- .../monkey/retromusic/util/PreferenceUtil.kt | 2 +- .../layout-land/fragment_album_details.xml | 11 +-- .../layout-land/fragment_artist_details.xml | 10 +- 8 files changed, 205 insertions(+), 114 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt index 56b2629c..277040f6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt @@ -148,7 +148,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { miniPlayerFragment?.view?.alpha = alpha miniPlayerFragment?.view?.visibility = if (alpha == 0f) View.GONE else View.VISIBLE bottomNavigationView.translationY = progress * 500 - bottomNavigationView.alpha = alpha + //bottomNavigationView.alpha = alpha } open fun onPanelCollapsed() { @@ -207,8 +207,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { override fun onQueueChanged() { super.onQueueChanged() - val isEmpty = MusicPlayerRemote.playingQueue.isEmpty() - if (isEmpty) { + if (MusicPlayerRemote.playingQueue.isEmpty()) { libraryViewModel.setPanelState(HIDE) } else { if (bottomNavigationView.isVisible) { @@ -229,6 +228,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { collapsePanel() return true } + return false } @@ -323,17 +323,20 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { val isQueueEmpty = MusicPlayerRemote.playingQueue.isEmpty() when (state) { EXPAND -> { + println("EXPAND") expandPanel() } HIDE -> { - ViewCompat.setElevation(slidingPanel, 0f) - ViewCompat.setElevation(bottomNavigationView, 10f) + println("HIDE") + bottomNavigationView.translateXAnimate(0f) bottomSheetBehavior.isHideable = true bottomSheetBehavior.peekHeightAnimate(0) - bottomNavigationView.translateXAnimate(0f) bottomSheetBehavior.state = STATE_COLLAPSED + ViewCompat.setElevation(slidingPanel, 0f) + ViewCompat.setElevation(bottomNavigationView, 10f) } COLLAPSED_WITH -> { + println("COLLAPSED_WITH") val heightOfBar = bottomNavigationView.height val height = if (isQueueEmpty) 0 else (heightOfBar * 2) - 24 ViewCompat.setElevation(bottomNavigationView, 20f) @@ -343,6 +346,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { bottomNavigationView.translateXAnimate(0f) } COLLAPSED_WITHOUT -> { + println("COLLAPSED_WITHOUT") val heightOfBar = bottomNavigationView.height val height = if (isQueueEmpty) 0 else heightOfBar - 24 ViewCompat.setElevation(bottomNavigationView, 10f) @@ -352,6 +356,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { bottomNavigationView.translateXAnimate(150f) } else -> { + println("else") bottomSheetBehavior.isHideable = true bottomSheetBehavior.peekHeight = 0 collapsePanel() 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 50030a4a..85bd13f2 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 @@ -10,7 +10,6 @@ import androidx.core.text.HtmlCompat import androidx.core.view.ViewCompat import androidx.lifecycle.Observer import androidx.lifecycle.lifecycleScope -import androidx.navigation.findNavController import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs @@ -31,6 +30,7 @@ import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog 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.findActivityNavController import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.glide.AlbumGlideRequest @@ -106,11 +106,14 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det }) setupRecyclerView() - artistImage.setOnClickListener { - requireActivity().findNavController(R.id.fragment_container) + artistImage.setOnClickListener { artistView -> + ViewCompat.setTransitionName(artistView, "artist") + findActivityNavController(R.id.fragment_container) .navigate( R.id.artistDetailsFragment, - bundleOf(EXTRA_ARTIST_ID to album.artistId) + bundleOf(EXTRA_ARTIST_ID to album.artistId), + null, + FragmentNavigatorExtras(artistView to "artist") ) } playAction.setOnClickListener { MusicPlayerRemote.openQueue(album.songs, 0, true) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt index 39c56065..621aef7e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt @@ -10,17 +10,21 @@ import androidx.recyclerview.widget.GridLayoutManager import code.name.monkey.retromusic.EXTRA_ALBUM_ID import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.album.AlbumAdapter +import code.name.monkey.retromusic.extensions.surfaceColor import code.name.monkey.retromusic.fragments.ReloadType import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewCustomGridSizeFragment import code.name.monkey.retromusic.helper.SortOrder import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder import code.name.monkey.retromusic.interfaces.IAlbumClickListener +import code.name.monkey.retromusic.interfaces.ICabHolder import code.name.monkey.retromusic.util.PreferenceUtil +import code.name.monkey.retromusic.util.RetroColorUtil import code.name.monkey.retromusic.util.RetroUtil +import com.afollestad.materialcab.MaterialCab class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment(), - IAlbumClickListener { + IAlbumClickListener, ICabHolder { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -45,7 +49,7 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment sortOrder = AlbumSortOrder.ALBUM_A_Z - R.id.action_album_sort_order_desc -> sortOrder = AlbumSortOrder.ALBUM_Z_A - R.id.action_album_sort_order_artist -> sortOrder = AlbumSortOrder.ALBUM_ARTIST - R.id.action_album_sort_order_year -> sortOrder = AlbumSortOrder.ALBUM_YEAR + val sortOrder: String = when (item.itemId) { + R.id.action_album_sort_order_asc -> AlbumSortOrder.ALBUM_A_Z + R.id.action_album_sort_order_desc -> AlbumSortOrder.ALBUM_Z_A + R.id.action_album_sort_order_artist -> AlbumSortOrder.ALBUM_ARTIST + R.id.action_album_sort_order_year -> AlbumSortOrder.ALBUM_YEAR + else -> PreferenceUtil.albumSortOrder } - if (sortOrder != null) { + if (sortOrder != PreferenceUtil.albumSortOrder) { item.isChecked = true setAndSaveSortOrder(sortOrder) return true @@ -244,16 +247,16 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment layoutRes = R.layout.item_grid - R.id.action_layout_card -> layoutRes = R.layout.item_card - R.id.action_layout_colored_card -> layoutRes = R.layout.item_card_color - R.id.action_layout_circular -> layoutRes = R.layout.item_grid_circle - R.id.action_layout_image -> layoutRes = R.layout.image - R.id.action_layout_gradient_image -> layoutRes = R.layout.item_image_gradient + val layoutRes = when (item.itemId) { + R.id.action_layout_normal -> R.layout.item_grid + R.id.action_layout_card -> R.layout.item_card + R.id.action_layout_colored_card -> R.layout.item_card_color + R.id.action_layout_circular -> R.layout.item_grid_circle + R.id.action_layout_image -> R.layout.image + R.id.action_layout_gradient_image -> R.layout.item_image_gradient + else -> PreferenceUtil.albumGridStyle } - if (layoutRes != -1) { + if (layoutRes != PreferenceUtil.albumGridStyle) { item.isChecked = true setAndSaveLayoutRes(layoutRes) return true @@ -264,16 +267,16 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment gridSize = 1 - R.id.action_grid_size_2 -> gridSize = 2 - R.id.action_grid_size_3 -> gridSize = 3 - R.id.action_grid_size_4 -> gridSize = 4 - R.id.action_grid_size_5 -> gridSize = 5 - R.id.action_grid_size_6 -> gridSize = 6 - R.id.action_grid_size_7 -> gridSize = 7 - R.id.action_grid_size_8 -> gridSize = 8 + val gridSize = when (item.itemId) { + R.id.action_grid_size_1 -> 1 + R.id.action_grid_size_2 -> 2 + R.id.action_grid_size_3 -> 3 + R.id.action_grid_size_4 -> 4 + R.id.action_grid_size_5 -> 5 + R.id.action_grid_size_6 -> 6 + R.id.action_grid_size_7 -> 7 + R.id.action_grid_size_8 -> 8 + else -> 0 } if (gridSize > 0) { item.isChecked = true @@ -283,4 +286,30 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment(), - IArtistClickListener { + IArtistClickListener, ICabHolder { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) libraryViewModel.getArtists().observe(viewLifecycleOwner, Observer { @@ -47,7 +51,7 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment sortOrder = ArtistSortOrder.ARTIST_A_Z - R.id.action_artist_sort_order_desc -> sortOrder = ArtistSortOrder.ARTIST_Z_A + val sortOrder: String = when (item.itemId) { + R.id.action_artist_sort_order_asc -> ArtistSortOrder.ARTIST_A_Z + R.id.action_artist_sort_order_desc -> ArtistSortOrder.ARTIST_Z_A + else -> PreferenceUtil.artistSortOrder } - if (sortOrder != null) { + if (sortOrder != PreferenceUtil.artistSortOrder) { item.isChecked = true setAndSaveSortOrder(sortOrder) return true @@ -222,16 +225,16 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment layoutRes = R.layout.item_grid - R.id.action_layout_card -> layoutRes = R.layout.item_card - R.id.action_layout_colored_card -> layoutRes = R.layout.item_card_color - R.id.action_layout_circular -> layoutRes = R.layout.item_grid_circle - R.id.action_layout_image -> layoutRes = R.layout.image - R.id.action_layout_gradient_image -> layoutRes = R.layout.item_image_gradient + val layoutRes = when (item.itemId) { + R.id.action_layout_normal -> R.layout.item_grid + R.id.action_layout_card -> R.layout.item_card + R.id.action_layout_colored_card -> R.layout.item_card_color + R.id.action_layout_circular -> R.layout.item_grid_circle + R.id.action_layout_image -> R.layout.image + R.id.action_layout_gradient_image -> R.layout.item_image_gradient + else -> PreferenceUtil.artistGridStyle } - if (layoutRes != -1) { + if (layoutRes != PreferenceUtil.artistGridStyle) { item.isChecked = true setAndSaveLayoutRes(layoutRes) return true @@ -242,16 +245,16 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment gridSize = 1 - R.id.action_grid_size_2 -> gridSize = 2 - R.id.action_grid_size_3 -> gridSize = 3 - R.id.action_grid_size_4 -> gridSize = 4 - R.id.action_grid_size_5 -> gridSize = 5 - R.id.action_grid_size_6 -> gridSize = 6 - R.id.action_grid_size_7 -> gridSize = 7 - R.id.action_grid_size_8 -> gridSize = 8 + val gridSize = when (item.itemId) { + R.id.action_grid_size_1 -> 1 + R.id.action_grid_size_2 -> 2 + R.id.action_grid_size_3 -> 3 + R.id.action_grid_size_4 -> 4 + R.id.action_grid_size_5 -> 5 + R.id.action_grid_size_6 -> 6 + R.id.action_grid_size_7 -> 7 + R.id.action_grid_size_8 -> 8 + else -> 0 } if (gridSize > 0) { item.isChecked = true @@ -260,4 +263,30 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment() { +class SongsFragment : AbsRecyclerViewCustomGridSizeFragment(), + ICabHolder { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) libraryViewModel.getSongs().observe(viewLifecycleOwner, Observer { @@ -38,7 +43,7 @@ class SongsFragment : AbsRecyclerViewCustomGridSizeFragment sortOrder = SongSortOrder.SONG_A_Z - R.id.action_song_sort_order_desc -> sortOrder = SongSortOrder.SONG_Z_A - R.id.action_song_sort_order_artist -> sortOrder = SongSortOrder.SONG_ARTIST - R.id.action_song_sort_order_album -> sortOrder = SongSortOrder.SONG_ALBUM - R.id.action_song_sort_order_year -> sortOrder = SongSortOrder.SONG_YEAR - R.id.action_song_sort_order_date -> sortOrder = SongSortOrder.SONG_DATE - R.id.action_song_sort_order_composer -> sortOrder = SongSortOrder.COMPOSER - R.id.action_song_sort_order_date_modified -> sortOrder = - SongSortOrder.SONG_DATE_MODIFIED + val sortOrder: String = when (item.itemId) { + R.id.action_song_sort_order_asc -> SongSortOrder.SONG_A_Z + R.id.action_song_sort_order_desc -> SongSortOrder.SONG_Z_A + R.id.action_song_sort_order_artist -> SongSortOrder.SONG_ARTIST + R.id.action_song_sort_order_album -> SongSortOrder.SONG_ALBUM + R.id.action_song_sort_order_year -> SongSortOrder.SONG_YEAR + R.id.action_song_sort_order_date -> SongSortOrder.SONG_DATE + R.id.action_song_sort_order_composer -> SongSortOrder.COMPOSER + R.id.action_song_sort_order_date_modified -> SongSortOrder.SONG_DATE_MODIFIED + else -> PreferenceUtil.songSortOrder } - if (sortOrder != null) { + if (sortOrder != PreferenceUtil.songSortOrder) { item.isChecked = true setAndSaveSortOrder(sortOrder) return true @@ -251,16 +254,16 @@ class SongsFragment : AbsRecyclerViewCustomGridSizeFragment layoutRes = R.layout.item_grid - R.id.action_layout_card -> layoutRes = R.layout.item_card - R.id.action_layout_colored_card -> layoutRes = R.layout.item_card_color - R.id.action_layout_circular -> layoutRes = R.layout.item_grid_circle - R.id.action_layout_image -> layoutRes = R.layout.image - R.id.action_layout_gradient_image -> layoutRes = R.layout.item_image_gradient + val layoutRes = when (item.itemId) { + R.id.action_layout_normal -> R.layout.item_grid + R.id.action_layout_card -> R.layout.item_card + R.id.action_layout_colored_card -> R.layout.item_card_color + R.id.action_layout_circular -> R.layout.item_grid_circle + R.id.action_layout_image -> R.layout.image + R.id.action_layout_gradient_image -> R.layout.item_image_gradient + else -> PreferenceUtil.songGridStyle } - if (layoutRes != -1) { + if (layoutRes != PreferenceUtil.songGridStyle) { item.isChecked = true setAndSaveLayoutRes(layoutRes) return true @@ -271,16 +274,16 @@ class SongsFragment : AbsRecyclerViewCustomGridSizeFragment gridSize = 1 - R.id.action_grid_size_2 -> gridSize = 2 - R.id.action_grid_size_3 -> gridSize = 3 - R.id.action_grid_size_4 -> gridSize = 4 - R.id.action_grid_size_5 -> gridSize = 5 - R.id.action_grid_size_6 -> gridSize = 6 - R.id.action_grid_size_7 -> gridSize = 7 - R.id.action_grid_size_8 -> gridSize = 8 + val gridSize = when (item.itemId) { + R.id.action_grid_size_1 -> 1 + R.id.action_grid_size_2 -> 2 + R.id.action_grid_size_3 -> 3 + R.id.action_grid_size_4 -> 4 + R.id.action_grid_size_5 -> 5 + R.id.action_grid_size_6 -> 6 + R.id.action_grid_size_7 -> 7 + R.id.action_grid_size_8 -> 8 + else -> 0 } if (gridSize > 0) { item.isChecked = true @@ -299,4 +302,31 @@ class SongsFragment : AbsRecyclerViewCustomGridSizeFragment LabelVisibilityMode.LABEL_VISIBILITY_LABELED 0 -> LabelVisibilityMode.LABEL_VISIBILITY_AUTO diff --git a/app/src/main/res/layout-land/fragment_album_details.xml b/app/src/main/res/layout-land/fragment_album_details.xml index 40e2d12d..30917f45 100644 --- a/app/src/main/res/layout-land/fragment_album_details.xml +++ b/app/src/main/res/layout-land/fragment_album_details.xml @@ -2,6 +2,7 @@ - - @@ -53,9 +51,8 @@ - - @@ -53,9 +52,8 @@ -