diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java index 582253b0..452bbd61 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java @@ -339,7 +339,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity int id = item.getItemId(); switch (id) { case R.id.action_search: - NavigationUtil.goToSearch(this); break; case R.id.action_new_playlist: @@ -520,11 +519,13 @@ public class MainActivity extends AbsSlidingMusicPanelActivity break; } Log.i(TAG, "handleLayoutResType: " + layoutRes); + if (layoutRes != -1) { item.setChecked(true); fragment.setAndSaveLayoutRes(layoutRes); return true; } + return false; } @@ -807,9 +808,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity case R.layout.item_card: subMenu.findItem(R.id.action_layout_card).setChecked(true); break; - case R.layout.item_grid: - subMenu.findItem(R.id.action_layout_normal).setChecked(true); - break; case R.layout.item_card_color: subMenu.findItem(R.id.action_layout_colored_card).setChecked(true); break; @@ -822,6 +820,10 @@ public class MainActivity extends AbsSlidingMusicPanelActivity case R.layout.item_image_gradient: subMenu.findItem(R.id.action_layout_gradient_image).setChecked(true); break; + default: + case R.layout.item_grid: + subMenu.findItem(R.id.action_layout_normal).setChecked(true); + break; } } 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 66d1f4cd..077cac51 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 @@ -29,6 +29,7 @@ import code.name.monkey.retromusic.fragments.player.color.ColorFragment import code.name.monkey.retromusic.fragments.player.fit.FitFragment import code.name.monkey.retromusic.fragments.player.flat.FlatPlayerFragment import code.name.monkey.retromusic.fragments.player.full.FullPlayerFragment +import code.name.monkey.retromusic.fragments.player.gradient.GradientPlayerFragment import code.name.monkey.retromusic.fragments.player.material.MaterialFragment import code.name.monkey.retromusic.fragments.player.normal.PlayerFragment import code.name.monkey.retromusic.fragments.player.peak.PeakPlayerFragment @@ -257,6 +258,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Peak -> PeakPlayerFragment() Circle -> CirclePlayerFragment() Classic -> ClassicPlayerFragment() + Gradient -> GradientPlayerFragment() else -> PlayerFragment() } // must implement AbsPlayerFragment supportFragmentManager.beginTransaction() @@ -316,7 +318,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), super.setLightStatusbar(false) super.setLightNavigationBar(true) super.setNavigationbarColor(Color.BLACK) - } else if (cps == Color || cps == Tiny) { + } else if (cps == Color || cps == Tiny || cps == Gradient) { super.setNavigationbarColor(paletteColor) super.setLightNavigationBar(isColorLight) super.setLightStatusbar(isColorLight) @@ -324,7 +326,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), super.setNavigationbarColor(paletteColor) super.setLightNavigationBar(isColorLight) super.setLightStatusbar(false) - } else if (cps == Classic ) { + } else if (cps == Classic) { super.setLightStatusbar(false) } else if (cps == Fit) { super.setLightStatusbar(false) diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt index 8c0e42f8..b7e61340 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt @@ -47,6 +47,7 @@ open class AlbumAdapter( } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + println("onCreateViewHolder $itemLayoutRes") itemLayoutRes = if (itemLayoutRes >= -1) { itemLayoutRes } else { diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumCoverPagerAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumCoverPagerAdapter.kt index e70a143d..604f3347 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumCoverPagerAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumCoverPagerAdapter.kt @@ -95,6 +95,7 @@ class AlbumCoverPagerAdapter( Fit, Tiny, Classic, + Gradient, Full -> R.layout.fragment_album_full_cover else -> { if (PreferenceUtil.getInstance(requireContext()).carouselEffect() diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlayingQueueAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlayingQueueAdapter.kt index 7f8f8ffb..0a628f2f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlayingQueueAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlayingQueueAdapter.kt @@ -1,9 +1,7 @@ package code.name.monkey.retromusic.adapter.song -import android.graphics.PorterDuff.Mode import android.view.MenuItem import android.view.View -import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity import code.name.monkey.retromusic.R import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -35,7 +33,6 @@ class PlayingQueueAdapter( SwipeableItemAdapter, PopupTextProvider { - private var color = -1 private var songToRemove: Song? = null override fun createViewHolder(view: View): SongAdapter.ViewHolder { @@ -51,23 +48,6 @@ class PlayingQueueAdapter( } } - private fun setColor(holder: SongAdapter.ViewHolder, white: Int) { - - if (holder.title != null) { - holder.title!!.setTextColor(white) - if (color != -1) { - holder.title!!.setTextColor(color) - } - } - - holder.text?.setTextColor(white) - holder.time?.setTextColor(white) - holder.imageText?.setTextColor(white) - if (holder.menu != null) { - (holder.menu as ImageView).setColorFilter(white, Mode.SRC_IN) - } - } - override fun getItemViewType(position: Int): Int { if (position < current) { return HISTORY @@ -139,7 +119,6 @@ class PlayingQueueAdapter( } inner class ViewHolder(itemView: View) : SongAdapter.ViewHolder(itemView) { - @DraggableItemStateFlags private var mDragStateFlags: Int = 0 diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/NowPlayingScreen.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/NowPlayingScreen.kt index 0463d1b2..522a9329 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/NowPlayingScreen.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/NowPlayingScreen.kt @@ -21,6 +21,7 @@ enum class NowPlayingScreen constructor( Fit(R.string.fit, R.drawable.np_fit, 12), Flat(R.string.flat, R.drawable.np_flat, 1), Full(R.string.full, R.drawable.np_full, 2), + Gradient(R.string.gradient, R.drawable.np_gradient, 17), Material(R.string.material, R.drawable.np_material, 11), Normal(R.string.normal, R.drawable.np_normal, 0), Peak(R.string.peak, R.drawable.np_peak, 14), 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 fadf2db7..0ba59b98 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 @@ -84,6 +84,7 @@ class AlbumsFragment : override fun loadLayoutRes(): Int { + println("loadLayoutRes ${PreferenceUtil.getInstance(requireContext()).albumGridStyle}") return PreferenceUtil.getInstance(requireContext()).albumGridStyle } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/PlayerAlbumCoverFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/PlayerAlbumCoverFragment.kt index bf7116c8..9de1f3da 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/PlayerAlbumCoverFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/PlayerAlbumCoverFragment.kt @@ -32,7 +32,7 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(), ViewPager.OnPageChan fun removeSlideEffect() { val transformer = ParallaxPagerTransformer(R.id.player_image) transformer.setSpeed(0.3f) - viewPager.setPageTransformer(true, transformer) + //viewPager.setPageTransformer(true, transformer) } override fun onCreateView( @@ -50,8 +50,7 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(), ViewPager.OnPageChan val metrics = resources.displayMetrics val ratio = metrics.heightPixels.toFloat() / metrics.widthPixels.toFloat() - - if (nps == Full || nps == Classic || nps == Fit) { + if (nps == Full || nps == Classic || nps == Fit || nps == Gradient) { viewPager.offscreenPageLimit = 2 } else if (PreferenceUtil.getInstance(requireContext()).carouselEffect()) { viewPager.clipToPadding = false diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt index 926cf19b..f309bf13 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt @@ -135,7 +135,8 @@ class ClassicPlayerFragment : AbsPlayerFragment(), View.OnLayoutChangeListener, 0 ).build() ) - shapeDrawable.fillColor = ColorStateList.valueOf(ATHUtil.resolveColor(requireContext(), R.attr.colorSurface)) + shapeDrawable.fillColor = + ColorStateList.valueOf(ATHUtil.resolveColor(requireContext(), R.attr.colorSurface)) playerQueueSheet.background = shapeDrawable playerQueueSheet.setOnTouchListener { _, _ -> @@ -358,7 +359,7 @@ class ClassicPlayerFragment : AbsPlayerFragment(), View.OnLayoutChangeListener, ToolbarContentTintHelper.colorizeToolbar( playerToolbar, - ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + Color.WHITE, requireActivity() ) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlaybackControlsFragment.kt index 2ecf3316..c5fb440a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlaybackControlsFragment.kt @@ -42,7 +42,7 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), private var lastPlaybackControlsColor: Int = 0 private var lastDisabledPlaybackControlsColor: Int = 0 - private var progressViewUpdateHelper: MusicProgressViewUpdateHelper? = null + private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -68,12 +68,12 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), override fun onResume() { super.onResume() - progressViewUpdateHelper!!.start() + progressViewUpdateHelper.start() } override fun onPause() { super.onPause() - progressViewUpdateHelper!!.stop() + progressViewUpdateHelper.stop() } @@ -97,7 +97,7 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), lastPlaybackControlsColor = color.primaryTextColor lastDisabledPlaybackControlsColor = ColorUtil.withAlpha(color.primaryTextColor, 0.3f) - val tintList=ColorStateList.valueOf(color.primaryTextColor) + val tintList = ColorStateList.valueOf(color.primaryTextColor) playerMenu.imageTintList = tintList songFavourite.imageTintList = tintList volumeFragment?.setTintableColor(color.primaryTextColor) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/gradient/GradientPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/gradient/GradientPlayerFragment.kt new file mode 100644 index 00000000..0eee1ce0 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/gradient/GradientPlayerFragment.kt @@ -0,0 +1,501 @@ +package code.name.monkey.retromusic.fragments.player.gradient + +import android.content.res.ColorStateList +import android.graphics.Color +import android.graphics.PorterDuff +import android.os.AsyncTask +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.PopupMenu +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.Toolbar +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.view.ViewCompat +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.appthemehelper.util.TintHelper +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.RetroBottomSheetBehavior +import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity +import code.name.monkey.retromusic.adapter.song.PlayingQueueAdapter +import code.name.monkey.retromusic.extensions.hide +import code.name.monkey.retromusic.extensions.ripAlpha +import code.name.monkey.retromusic.extensions.show +import code.name.monkey.retromusic.fragments.VolumeFragment +import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment +import code.name.monkey.retromusic.helper.MusicPlayerRemote +import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper +import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler +import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.service.MusicService +import code.name.monkey.retromusic.util.MusicUtil +import code.name.monkey.retromusic.util.PreferenceUtil +import code.name.monkey.retromusic.util.ViewUtil +import code.name.monkey.retromusic.util.color.MediaNotificationProcessor +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.h6ah4i.android.widget.advrecyclerview.animator.DraggableItemAnimator +import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager +import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager +import com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager +import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils +import kotlinx.android.synthetic.main.fragment_gradient_controls.* +import kotlinx.android.synthetic.main.fragment_gradient_player.* +import kotlinx.android.synthetic.main.status_bar.* + +class GradientPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Callback, + View.OnLayoutChangeListener, PopupMenu.OnMenuItemClickListener { + private var lastColor: Int = 0 + private var lastPlaybackControlsColor: Int = 0 + private var lastDisabledPlaybackControlsColor: Int = 0 + private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper + private var volumeFragment: VolumeFragment? = null + private lateinit var wrappedAdapter: RecyclerView.Adapter<*> + private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null + private var recyclerViewSwipeManager: RecyclerViewSwipeManager? = null + private var recyclerViewTouchActionGuardManager: RecyclerViewTouchActionGuardManager? = null + private var playingQueueAdapter: PlayingQueueAdapter? = null + private var updateIsFavoriteTask: AsyncTask<*, *, *>? = null + private lateinit var linearLayoutManager: LinearLayoutManager + + private val bottomSheetCallbackList = object : BottomSheetBehavior.BottomSheetCallback() { + override fun onSlide(bottomSheet: View, slideOffset: Float) { + (requireActivity() as AbsSlidingMusicPanelActivity).getBottomSheetBehavior() + .setAllowDragging(false) + + playerQueueSheet.setPadding( + playerQueueSheet.paddingLeft, + (slideOffset * status_bar.height).toInt(), + playerQueueSheet.paddingRight, + playerQueueSheet.paddingBottom + ) + } + + override fun onStateChanged(bottomSheet: View, newState: Int) { + val activity = requireActivity() as AbsSlidingMusicPanelActivity + val isDark = ATHUtil.isWindowBackgroundDark(requireContext()); + when (newState) { + BottomSheetBehavior.STATE_EXPANDED, + BottomSheetBehavior.STATE_DRAGGING -> { + activity.getBottomSheetBehavior().setAllowDragging(false) + } + BottomSheetBehavior.STATE_COLLAPSED -> { + resetToCurrentPosition() + activity.getBottomSheetBehavior().setAllowDragging(true) + } + else -> { + activity.getBottomSheetBehavior().setAllowDragging(true) + } + } + } + } + + private fun setupFavourite() { + songFavourite.setOnClickListener { + toggleFavorite(MusicPlayerRemote.currentSong) + } + } + + private fun setupMenu() { + playerMenu.setOnClickListener { + val popupMenu = PopupMenu(requireContext(), it) + popupMenu.setOnMenuItemClickListener(this) + popupMenu.inflate(R.menu.menu_player) + popupMenu.show() + } + } + + private fun setupPanel() { + if (!ViewCompat.isLaidOut(colorBackground) || colorBackground.isLayoutRequested) { + colorBackground.addOnLayoutChangeListener(this) + return + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_gradient_player, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + hideVolumeIfAvailable() + setUpMusicControllers() + setupPanel() + setupRecyclerView() + setupSheet() + setupMenu() + setupFavourite() + } + + private fun setupSheet() { + getQueuePanel().addBottomSheetCallback(bottomSheetCallbackList) + playerQueueSheet.setOnTouchListener { _, _ -> + (requireActivity() as AbsSlidingMusicPanelActivity).getBottomSheetBehavior() + .setAllowDragging(false) + getQueuePanel().setAllowDragging(true) + return@setOnTouchListener false + } + } + + private fun getQueuePanel(): RetroBottomSheetBehavior { + return RetroBottomSheetBehavior.from(playerQueueSheet) as RetroBottomSheetBehavior + } + + override fun onResume() { + super.onResume() + progressViewUpdateHelper.start() + } + + override fun onPause() { + recyclerViewDragDropManager?.cancelDrag() + super.onPause() + progressViewUpdateHelper.stop() + + } + + override fun playerToolbar(): Toolbar? { + return null + } + + override fun onShow() { + + } + + override fun onHide() { + + } + + override fun onBackPressed(): Boolean { + var wasExpanded = false + if (getQueuePanel().state == BottomSheetBehavior.STATE_EXPANDED) { + wasExpanded = getQueuePanel().state == BottomSheetBehavior.STATE_EXPANDED + getQueuePanel().state = BottomSheetBehavior.STATE_COLLAPSED + return wasExpanded + } + return wasExpanded + } + + override fun toolbarIconColor(): Int { + return Color.WHITE + } + + override val paletteColor: Int + get() = lastColor + + override fun onColorChanged(color: MediaNotificationProcessor) { + lastColor = color.backgroundColor + callbacks?.onPaletteColorChanged() + mask.backgroundTintList = ColorStateList.valueOf(color.backgroundColor) + colorBackground.setBackgroundColor(color.backgroundColor) + container.setBackgroundColor(ColorUtil.darkenColor(color.backgroundColor)) + + lastPlaybackControlsColor = color.primaryTextColor + lastDisabledPlaybackControlsColor = color.secondaryTextColor + + title.setTextColor(lastPlaybackControlsColor) + text.setTextColor(lastDisabledPlaybackControlsColor) + playPauseButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + nextButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + previousButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + songFavourite.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + queueIcon.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + playerMenu.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + songCurrentProgress.setTextColor(lastDisabledPlaybackControlsColor) + songTotalTime.setTextColor(lastDisabledPlaybackControlsColor) + nextSong.setTextColor(lastPlaybackControlsColor) + songInfo.setTextColor(lastDisabledPlaybackControlsColor) + + volumeFragment?.setTintableColor(lastPlaybackControlsColor.ripAlpha()) + ViewUtil.setProgressDrawable(progressSlider, color.primaryTextColor.ripAlpha(), true) + + updateRepeatState() + updateShuffleState() + updatePrevNextColor() + } + + override fun toggleFavorite(song: Song) { + super.toggleFavorite(song) + MusicUtil.toggleFavorite(requireContext(), song) + if (song.id == MusicPlayerRemote.currentSong.id) { + updateFavorite() + } + } + + override fun onFavoriteToggled() { + toggleFavorite(MusicPlayerRemote.currentSong) + } + + private fun hideVolumeIfAvailable() { + if (PreferenceUtil.getInstance(requireContext()).volumeToggle) { + childFragmentManager.beginTransaction() + .replace(R.id.volumeFragmentContainer, VolumeFragment.newInstance()) + .commit() + childFragmentManager.executePendingTransactions() + volumeFragment = + childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as VolumeFragment? + } + } + + override fun onServiceConnected() { + super.onServiceConnected() + updateSong() + updatePlayPauseDrawableState() + updatePlayPauseDrawableState() + updateQueue() + } + + override fun onPlayStateChanged() { + updatePlayPauseDrawableState() + } + + override fun onRepeatModeChanged() { + updateRepeatState() + } + + override fun onShuffleModeChanged() { + updateShuffleState() + } + + override fun onPlayingMetaChanged() { + super.onPlayingMetaChanged() + updateSong() + updateQueuePosition() + } + + private fun updateSong() { + val song = MusicPlayerRemote.currentSong + title.text = song.title + text.text = song.artistName + updateLabel() + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo.text = getSongInfo(song) + songInfo.show() + } else { + songInfo.hide() + } + } + + private fun setUpMusicControllers() { + setUpPlayPauseFab() + setUpPrevNext() + setUpRepeatButton() + setUpShuffleButton() + setUpProgressSlider() + title.isSelected = true + text.isSelected = true + } + + private fun updatePlayPauseDrawableState() { + if (MusicPlayerRemote.isPlaying) { + playPauseButton.setImageResource(R.drawable.ic_pause_sharp_white_64dp) + } else { + playPauseButton.setImageResource(R.drawable.ic_play_arrow_sharp_white_64dp) + } + } + + override fun onUpdateProgressViews(progress: Int, total: Int) { + progressSlider.valueTo = total.toFloat() + progressSlider.value = progress.toFloat() + songTotalTime.text = MusicUtil.getReadableDurationString(total.toLong()) + songCurrentProgress.text = MusicUtil.getReadableDurationString(progress.toLong()) + } + + fun setUpProgressSlider() { + progressSlider.addOnChangeListener { _, value, fromUser -> + if (fromUser) { + MusicPlayerRemote.seekTo(value.toInt()) + onUpdateProgressViews( + MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis + ) + } + } + } + + private fun setUpPlayPauseFab() { + playPauseButton.setOnClickListener(PlayPauseButtonOnClickHandler()) + } + + private fun setUpPrevNext() { + updatePrevNextColor() + nextButton.setOnClickListener { MusicPlayerRemote.playNextSong() } + previousButton.setOnClickListener { MusicPlayerRemote.back() } + } + + private fun updatePrevNextColor() { + nextButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + previousButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + } + + private fun setUpShuffleButton() { + shuffleButton.setOnClickListener { MusicPlayerRemote.toggleShuffleMode() } + } + + fun updateShuffleState() { + when (MusicPlayerRemote.shuffleMode) { + MusicService.SHUFFLE_MODE_SHUFFLE -> + shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) + else -> shuffleButton.setColorFilter( + lastDisabledPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) + } + } + + private fun setUpRepeatButton() { + repeatButton.setOnClickListener { MusicPlayerRemote.cycleRepeatMode() } + } + + fun updateRepeatState() { + when (MusicPlayerRemote.repeatMode) { + MusicService.REPEAT_MODE_NONE -> { + repeatButton.setImageResource(R.drawable.ic_repeat_white_24dp) + repeatButton.setColorFilter( + lastDisabledPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) + } + MusicService.REPEAT_MODE_ALL -> { + repeatButton.setImageResource(R.drawable.ic_repeat_white_24dp) + repeatButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + } + MusicService.REPEAT_MODE_THIS -> { + repeatButton.setImageResource(R.drawable.ic_repeat_one_white_24dp) + repeatButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + } + } + } + + private fun updateLabel() { + (MusicPlayerRemote.playingQueue.size - 1).apply { + if (this == (MusicPlayerRemote.position)) { + nextSong.hide() + } else { + val title = MusicPlayerRemote.playingQueue[MusicPlayerRemote.position + 1].title + nextSong.apply { + text = "Next: $title" + show() + } + } + } + } + + override fun onLayoutChange( + v: View?, + left: Int, + top: Int, + right: Int, + bottom: Int, + oldLeft: Int, + oldTop: Int, + oldRight: Int, + oldBottom: Int + ) { + val panel = getQueuePanel() + panel.peekHeight = container.height + } + + private fun setupRecyclerView() { + playingQueueAdapter = PlayingQueueAdapter( + requireActivity() as AppCompatActivity, + MusicPlayerRemote.playingQueue.toMutableList(), + MusicPlayerRemote.position, + R.layout.item_queue + ) + linearLayoutManager = LinearLayoutManager(requireContext()) + recyclerViewTouchActionGuardManager = RecyclerViewTouchActionGuardManager() + recyclerViewDragDropManager = RecyclerViewDragDropManager() + recyclerViewSwipeManager = RecyclerViewSwipeManager() + + val animator = DraggableItemAnimator() + animator.supportsChangeAnimations = false + wrappedAdapter = + recyclerViewDragDropManager?.createWrappedAdapter(playingQueueAdapter!!) as RecyclerView.Adapter<*> + wrappedAdapter = + recyclerViewSwipeManager?.createWrappedAdapter(wrappedAdapter) as RecyclerView.Adapter<*> + recyclerView.layoutManager = linearLayoutManager + recyclerView.adapter = wrappedAdapter + recyclerView.itemAnimator = animator + recyclerViewTouchActionGuardManager?.attachRecyclerView(recyclerView) + recyclerViewDragDropManager?.attachRecyclerView(recyclerView) + recyclerViewSwipeManager?.attachRecyclerView(recyclerView) + + linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0) + } + + override fun onDestroyView() { + super.onDestroyView() + getQueuePanel().removeBottomSheetCallback(bottomSheetCallbackList) + if (recyclerViewDragDropManager != null) { + recyclerViewDragDropManager?.release() + recyclerViewDragDropManager = null + } + + if (recyclerViewSwipeManager != null) { + recyclerViewSwipeManager?.release() + recyclerViewSwipeManager = null + } + + WrapperAdapterUtils.releaseAll(wrappedAdapter) + } + + private fun updateQueuePosition() { + playingQueueAdapter?.setCurrent(MusicPlayerRemote.position) + resetToCurrentPosition() + } + + private fun updateQueue() { + playingQueueAdapter?.swapDataSet(MusicPlayerRemote.playingQueue, MusicPlayerRemote.position) + resetToCurrentPosition() + } + + private fun resetToCurrentPosition() { + recyclerView.stopScroll() + linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0) + } + + fun updateFavorite() { + if (updateIsFavoriteTask != null) { + updateIsFavoriteTask?.cancel(false) + } + updateIsFavoriteTask = object : AsyncTask() { + override fun doInBackground(vararg params: Song): Boolean? { + val activity = activity + return if (activity != null) { + MusicUtil.isFavorite(requireActivity(), params[0]) + } else { + cancel(false) + null + } + } + + override fun onPostExecute(isFavorite: Boolean?) { + val activity = activity + if (activity != null) { + val res = if (isFavorite!!) + R.drawable.ic_favorite_white_24dp + else + R.drawable.ic_favorite_border_white_24dp + + val drawable = TintHelper.createTintedDrawable(activity, res, Color.WHITE) + songFavourite?.setImageDrawable(drawable) + } + } + }.execute(MusicPlayerRemote.currentSong) + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-xxxhdpi/np_gradient.webp b/app/src/main/res/drawable-xxxhdpi/np_gradient.webp new file mode 100644 index 00000000..70f634fd Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/np_gradient.webp differ diff --git a/app/src/main/res/layout/fragment_fit.xml b/app/src/main/res/layout/fragment_fit.xml index ffcf7847..9134e5f8 100644 --- a/app/src/main/res/layout/fragment_fit.xml +++ b/app/src/main/res/layout/fragment_fit.xml @@ -22,7 +22,7 @@ android:layout_height="wrap_content" android:layout_weight="1"> - - + tools:layout="@layout/fragment_gradient_controls" /> - - @@ -143,7 +144,6 @@ android:elevation="20dp" android:padding="16dp" android:visibility="gone" - app:layout_constraintBottom_toTopOf="@id/playbackControlsFragment" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/playerToolbar" diff --git a/app/src/main/res/layout/fragment_gradient_controls.xml b/app/src/main/res/layout/fragment_gradient_controls.xml new file mode 100644 index 00000000..386b6511 --- /dev/null +++ b/app/src/main/res/layout/fragment_gradient_controls.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_gradient_player.xml b/app/src/main/res/layout/fragment_gradient_player.xml new file mode 100644 index 00000000..293030f8 --- /dev/null +++ b/app/src/main/res/layout/fragment_gradient_player.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index b78a50ea..84252a01 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -21,8 +21,8 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7bb8532b..21c38703 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -853,6 +853,7 @@ Try Retro Music Premium Share the app with your friends and family Need more help? + Gradient Song