From 567cf0781f6006bb4ed7e9ce607df1b85458f418 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Wed, 5 Dec 2018 21:04:26 +0530 Subject: [PATCH] Added more themes --- .../base/AbsSlidingMusicPanelActivity.kt | 4 + .../ui/fragments/NowPlayingScreen.java | 4 +- .../retromusic/ui/fragments/VolumeFragment.kt | 2 +- .../blur/BlurPlaybackControlsFragment.kt | 2 +- .../ui/fragments/player/card/CardFragment.kt | 112 ++++++++ .../card/CardPlaybackControlsFragment.kt | 230 +++++++++++++++ .../fragments/player/color/ColorFragment.kt | 269 ++++++++++++++++++ .../color/ColorPlaybackControlsFragment.kt | 225 +++++++++++++++ .../player/fit/FitPlaybackControlsFragment.kt | 2 +- .../flat/FlatPlaybackControlsFragment.kt | 2 +- .../full/FullPlaybackControlsFragment.kt | 2 +- .../material/MaterialControlsFragment.kt | 212 ++++++++++++++ .../player/material/MaterialFragment.kt | 108 +++++++ .../fragments/player/normal/PlayerFragment.kt | 134 +++++++++ .../normal/PlayerPlaybackControlsFragment.kt | 243 ++++++++++++++++ .../res/layout-land/fragment_color_player.xml | 16 +- .../main/res/layout/fragment_color_player.xml | 14 +- ...ragment_color_player_playback_controls.xml | 140 +-------- 18 files changed, 1565 insertions(+), 156 deletions(-) create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/card/CardFragment.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/card/CardPlaybackControlsFragment.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorPlaybackControlsFragment.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/material/MaterialControlsFragment.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/material/MaterialFragment.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/normal/PlayerFragment.kt create mode 100644 app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/normal/PlayerPlaybackControlsFragment.kt diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/activities/base/AbsSlidingMusicPanelActivity.kt b/app/src/main/java/code/name/monkey/retromusic/ui/activities/base/AbsSlidingMusicPanelActivity.kt index e5eba59b..219152fe 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/activities/base/AbsSlidingMusicPanelActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/activities/base/AbsSlidingMusicPanelActivity.kt @@ -23,9 +23,11 @@ import code.name.monkey.retromusic.ui.fragments.player.adaptive.AdaptiveFragment import code.name.monkey.retromusic.ui.fragments.player.blur.BlurPlayerFragment import code.name.monkey.retromusic.ui.fragments.player.card.CardFragment import code.name.monkey.retromusic.ui.fragments.player.cardblur.CardBlurFragment +import code.name.monkey.retromusic.ui.fragments.player.color.ColorFragment import code.name.monkey.retromusic.ui.fragments.player.fit.FitFragment import code.name.monkey.retromusic.ui.fragments.player.flat.FlatPlayerFragment import code.name.monkey.retromusic.ui.fragments.player.full.FullPlayerFragment +import code.name.monkey.retromusic.ui.fragments.player.material.MaterialFragment import code.name.monkey.retromusic.ui.fragments.player.normal.PlayerFragment import code.name.monkey.retromusic.ui.fragments.player.plain.PlainPlayerFragment import code.name.monkey.retromusic.ui.fragments.player.simple.SimplePlayerFragment @@ -229,6 +231,8 @@ abstract class AbsSlidingMusicPanelActivity protected constructor() : AbsMusicSe NowPlayingScreen.FULL -> FullPlayerFragment() NowPlayingScreen.PLAIN -> PlainPlayerFragment() NowPlayingScreen.SIMPLE -> SimplePlayerFragment() + NowPlayingScreen.MATERIAL -> MaterialFragment() + NowPlayingScreen.COLOR->ColorFragment() else -> PlayerFragment() } // must implement AbsPlayerFragment supportFragmentManager.beginTransaction().replace(R.id.player_fragment_container, fragment).commit() diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/NowPlayingScreen.java b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/NowPlayingScreen.java index d958a452..077d3f13 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/NowPlayingScreen.java +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/NowPlayingScreen.java @@ -11,13 +11,13 @@ public enum NowPlayingScreen { FULL(R.string.full, R.drawable.np_full, 2), PLAIN(R.string.plain, R.drawable.np_plain, 3), BLUR(R.string.blur, R.drawable.np_blur, 4), - //COLOR(R.string.color, R.drawable.np_color, 5), + COLOR(R.string.color, R.drawable.np_color, 5), CARD(R.string.card, R.drawable.np_card, 6), //TINY(R.string.tiny, R.drawable.np_tiny, 7), SIMPLE(R.string.simple, R.drawable.np_simple, 8), BLUR_CARD(R.string.blur_card, R.drawable.np_blur_card, 9), ADAPTIVE(R.string.adaptive, R.drawable.np_adaptive, 10), - //MATERIAL(R.string.material, R.drawable.np_material, 11), + MATERIAL(R.string.material, R.drawable.np_material, 11), FIT(R.string.fit, R.drawable.np_adaptive, 12); @StringRes diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/VolumeFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/VolumeFragment.kt index 5202281e..87da5c72 100755 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/VolumeFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/VolumeFragment.kt @@ -103,7 +103,7 @@ class VolumeFragment : Fragment(), SeekBar.OnSeekBarChangeListener, OnAudioVolum volumeUp.setColorFilter(newColor, PorterDuff.Mode.SRC_IN) } - private fun setTintable(color: Int) { + fun setTintable(color: Int) { setProgressBarColor(color) } diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/blur/BlurPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/blur/BlurPlaybackControlsFragment.kt index 74e2e9cc..4de468ff 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/blur/BlurPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/blur/BlurPlaybackControlsFragment.kt @@ -172,7 +172,7 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { } private fun setUpShuffleButton() { - shuffleButton.setOnClickListener { v -> MusicPlayerRemote.toggleShuffleMode() } + shuffleButton.setOnClickListener { MusicPlayerRemote.toggleShuffleMode() } } override fun updateShuffleState() { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/card/CardFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/card/CardFragment.kt new file mode 100644 index 00000000..297b4fd2 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/card/CardFragment.kt @@ -0,0 +1,112 @@ +package code.name.monkey.retromusic.ui.fragments.player.card + +import android.graphics.Color +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.helper.MusicPlayerRemote +import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment +import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment +import code.name.monkey.retromusic.ui.fragments.player.normal.PlayerFragment +import kotlinx.android.synthetic.main.fragment_card_player.* + +class CardFragment : AbsPlayerFragment(), PlayerAlbumCoverFragment.Callbacks { + override fun toolbarGet(): Toolbar { + return playerToolbar + } + + private var lastColor: Int = 0 + override val paletteColor: Int + get() = lastColor + + private lateinit var playbackControlsFragment: CardPlaybackControlsFragment + + override fun onShow() { + playbackControlsFragment.show() + } + + override fun onHide() { + playbackControlsFragment.hide() + onBackPressed() + } + + override fun onBackPressed(): Boolean { + return false + } + + override fun toolbarIconColor(): Int { + return Color.WHITE + } + + override fun onColorChanged(color: Int) { + playbackControlsFragment.setDark(color) + lastColor = color + callbacks!!.onPaletteColorChanged() + + ToolbarContentTintHelper.colorizeToolbar(playerToolbar, Color.WHITE, activity) + } + + override fun toggleFavorite(song: Song) { + super.toggleFavorite(song) + if (song.id == MusicPlayerRemote.currentSong.id) { + updateIsFavorite() + } + } + + override fun onFavoriteToggled() { + toggleFavorite(MusicPlayerRemote.currentSong) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + + return inflater.inflate(R.layout.fragment_card_player, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setUpSubFragments() + setUpPlayerToolbar() + } + + private fun setUpSubFragments() { + playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as CardPlaybackControlsFragment + val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + playerAlbumCoverFragment.setCallbacks(this) + playerAlbumCoverFragment.removeSlideEffect() + } + + private fun setUpPlayerToolbar() { + playerToolbar.inflateMenu(R.menu.menu_player) + playerToolbar.setNavigationOnClickListener { activity!!.onBackPressed() } + playerToolbar.setOnMenuItemClickListener(this) + + ToolbarContentTintHelper.colorizeToolbar(playerToolbar, Color.WHITE, activity) + + } + + override fun onServiceConnected() { + updateIsFavorite() + } + + override fun onPlayingMetaChanged() { + updateIsFavorite() + } + + companion object { + + fun newInstance(): PlayerFragment { + val args = Bundle() + val fragment = PlayerFragment() + fragment.arguments = args + return fragment + } + } + + +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/card/CardPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/card/CardPlaybackControlsFragment.kt new file mode 100644 index 00000000..5646881d --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/card/CardPlaybackControlsFragment.kt @@ -0,0 +1,230 @@ +package code.name.monkey.retromusic.ui.fragments.player.card + +import android.animation.ObjectAnimator +import android.graphics.PorterDuff +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.animation.LinearInterpolator +import android.widget.SeekBar +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.appthemehelper.util.MaterialValueHelper +import code.name.monkey.appthemehelper.util.TintHelper +import code.name.monkey.retromusic.R +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.misc.SimpleOnSeekbarChangeListener +import code.name.monkey.retromusic.service.MusicService +import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerControlsFragment +import code.name.monkey.retromusic.util.MusicUtil +import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.* +import kotlinx.android.synthetic.main.media_button.* + +class CardPlaybackControlsFragment : AbsPlayerControlsFragment() { + + private var lastPlaybackControlsColor: Int = 0 + private var lastDisabledPlaybackControlsColor: Int = 0 + private var progressViewUpdateHelper: MusicProgressViewUpdateHelper? = null + + 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_card_player_playback_controls, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setUpMusicControllers() + + setupControls() + + playPauseButton.setOnClickListener { + if (MusicPlayerRemote.isPlaying) { + MusicPlayerRemote.pauseSong() + } else { + MusicPlayerRemote.resumePlaying() + } + showBonceAnimation(playPauseButton) + } + } + + private fun setupControls() { + image.apply { + setImageResource(R.drawable.ic_play_circle_filled_white_24dp) + val iconPadding = activity!!.resources.getDimensionPixelSize(R.dimen.list_item_image_icon_padding) + setPadding(iconPadding, iconPadding, iconPadding, iconPadding) + } + } + + private fun updateSong() { + val song = MusicPlayerRemote.currentSong + songTitle.text = song.title + songText.text = song.artistName + + } + + override fun onResume() { + super.onResume() + progressViewUpdateHelper!!.start() + } + + override fun onPause() { + super.onPause() + progressViewUpdateHelper!!.stop() + } + + override fun onServiceConnected() { + updatePlayPauseDrawableState() + updateRepeatState() + updateShuffleState() + updateSong() + } + + override fun onPlayingMetaChanged() { + super.onPlayingMetaChanged() + updateSong() + } + + override fun onPlayStateChanged() { + updatePlayPauseDrawableState() + } + + override fun onRepeatModeChanged() { + updateRepeatState() + } + + override fun onShuffleModeChanged() { + updateShuffleState() + } + + override fun setDark(color: Int) { + image!!.setColorFilter(color, PorterDuff.Mode.SRC_IN) + if (ColorUtil.isColorLight(ATHUtil.resolveColor(context, android.R.attr.windowBackground))) { + lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(activity, true) + lastDisabledPlaybackControlsColor = MaterialValueHelper.getSecondaryDisabledTextColor(activity, true) + } else { + lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(activity, false) + lastDisabledPlaybackControlsColor = MaterialValueHelper.getPrimaryDisabledTextColor(activity, false) + } + + updateRepeatState() + updateShuffleState() + updatePrevNextColor() + updatePlayPauseColor() + updateProgressTextColor() + + TintHelper.setTintAuto(playPauseButton!!, MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color)), false) + TintHelper.setTintAuto(playPauseButton!!, color, true) + } + + private fun updatePlayPauseColor() { + //playPauseButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN); + } + + private fun setUpPlayPauseFab() { + playPauseButton.setOnClickListener(PlayPauseButtonOnClickHandler()) + } + + private fun updatePlayPauseDrawableState() { + if (MusicPlayerRemote.isPlaying) { + playPauseButton.setImageResource(R.drawable.ic_pause_white_24dp) + } else { + playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_24dp) + } + } + + private fun setUpMusicControllers() { + setUpPlayPauseFab() + setUpPrevNext() + setUpRepeatButton() + setUpShuffleButton() + setUpProgressSlider() + } + + 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() } + } + + override 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() } + } + + override 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) + } + } + } + + override fun onUpdateProgressViews(progress: Int, total: Int) { + progressSlider.max = total + + val animator = ObjectAnimator.ofInt(progressSlider, "progress", progress) + animator.duration = 1500 + animator.interpolator = LinearInterpolator() + animator.start() + + songTotalTime.text = MusicUtil.getReadableDurationString(total.toLong()) + songCurrentProgress.text = MusicUtil.getReadableDurationString(progress.toLong()) + } + + private fun updateProgressTextColor() { + val color = MaterialValueHelper.getPrimaryTextColor(context, false) + songTotalTime!!.setTextColor(color) + songCurrentProgress!!.setTextColor(color) + } + + public override fun show() { + //Ignore + } + + public override fun hide() { + //Ignore + } + + override fun setUpProgressSlider() { + progressSlider.setOnSeekBarChangeListener(object : SimpleOnSeekbarChangeListener() { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + if (fromUser) { + MusicPlayerRemote.seekTo(progress) + onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, MusicPlayerRemote.songDurationMillis) + } + } + }) + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt new file mode 100644 index 00000000..e462252d --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorFragment.kt @@ -0,0 +1,269 @@ +package code.name.monkey.retromusic.ui.fragments.player.color + +import android.animation.ArgbEvaluator +import android.animation.ValueAnimator +import android.annotation.SuppressLint +import android.content.Intent +import android.graphics.drawable.Drawable +import android.os.AsyncTask +import android.os.Bundle +import android.text.TextUtils +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.appthemehelper.util.MaterialValueHelper +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.glide.RetroMusicColoredTarget +import code.name.monkey.retromusic.glide.SongGlideRequest +import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper +import code.name.monkey.retromusic.helper.MusicPlayerRemote +import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.model.lyrics.Lyrics +import code.name.monkey.retromusic.ui.activities.LyricsActivity +import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment +import code.name.monkey.retromusic.util.MusicUtil +import code.name.monkey.retromusic.util.RetroColorUtil +import code.name.monkey.retromusic.util.ViewUtil +import com.bumptech.glide.Glide +import com.bumptech.glide.request.animation.GlideAnimation +import kotlinx.android.synthetic.main.fragment_color_player.* + +class ColorFragment : AbsPlayerFragment() { + override fun toolbarGet(): Toolbar { + return playerToolbar + } + + override val paletteColor: Int + get() = backgroundColor + + override fun onColorChanged(color: Int) { + + } + + override fun onFavoriteToggled() { + + } + + + private var lastColor: Int = 0 + private var backgroundColor: Int = 0 + + private var playbackControlsFragment: ColorPlaybackControlsFragment? = null + + private var valueAnimator: ValueAnimator? = null + private var updateLyricsAsyncTask: AsyncTask<*, *, *>? = null + private var lyrics: Lyrics? = null + + override fun onShow() { + playbackControlsFragment!!.show() + } + + override fun onHide() { + playbackControlsFragment!!.hide() + onBackPressed() + } + + override fun onBackPressed(): Boolean { + return false + } + + override fun toolbarIconColor(): Int { + return lastColor + } + + override fun toggleFavorite(song: Song) { + super.toggleFavorite(song) + if (song.id == MusicPlayerRemote.currentSong.id) { + updateIsFavorite() + } + } + + override fun onDestroyView() { + super.onDestroyView() + if (valueAnimator != null) { + valueAnimator!!.cancel() + valueAnimator = null + } + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + + return inflater.inflate(R.layout.fragment_color_player, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setUpSubFragments() + setUpPlayerToolbar() + setupViews() + } + + private fun setUpSubFragments() { + playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as ColorPlaybackControlsFragment? + + } + + private fun setUpPlayerToolbar() { + playerToolbar.apply { + inflateMenu(R.menu.menu_player) + setNavigationOnClickListener { activity!!.onBackPressed() } + setOnMenuItemClickListener(this@ColorFragment) + ToolbarContentTintHelper.colorizeToolbar(this, ATHUtil.resolveColor(context, R.attr.iconColor), activity) + } + } + + override fun onPlayingMetaChanged() { + super.onPlayingMetaChanged() + updateSong() + updateLyricsLocal() + } + + override fun onServiceConnected() { + super.onServiceConnected() + updateSong() + updateLyricsLocal() + } + + private fun updateSong() { + val activity = activity + + SongGlideRequest.Builder.from(Glide.with(activity), MusicPlayerRemote.currentSong) + .checkIgnoreMediaStore(activity) + .generatePalette(activity).build().dontAnimate() + .into(object : RetroMusicColoredTarget(playerImage) { + override fun onColorReady(color: Int) { + //setColors(color); + } + + override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) { + super.onLoadFailed(e, errorDrawable) + + val backgroundColor = defaultFooterColor + val textColor = if (ColorUtil.isColorLight(defaultFooterColor)) + MaterialValueHelper.getPrimaryTextColor(context, true) + else + MaterialValueHelper.getPrimaryTextColor(context, false) + + setColors(backgroundColor, textColor) + } + + override fun onResourceReady(resource: BitmapPaletteWrapper, + glideAnimation: GlideAnimation?) { + super.onResourceReady(resource, glideAnimation) + /* MediaNotificationProcessor processor = new MediaNotificationProcessor(getContext(), + getContext()); + Palette.Builder builder = MediaNotificationProcessor + .generatePalette(resource.getBitmap()); + + int backgroundColor = processor.getBackgroundColor(builder); + int textColor = processor.getTextColor(builder);*/ + + val palette = resource.palette + val swatch = RetroColorUtil.getSwatch(palette) + + val textColor = RetroColorUtil.getTextColor(palette) + val backgroundColor = swatch.rgb + + setColors(backgroundColor, textColor) + } + }) + } + + private fun setColors(backgroundColor: Int, textColor: Int) { + playbackControlsFragment!!.setDark(textColor, backgroundColor) + + colorGradientBackground.setBackgroundColor(backgroundColor) + + ToolbarContentTintHelper.colorizeToolbar(playerToolbar, textColor, activity) + + lastColor = textColor + + this.backgroundColor = backgroundColor + + if (playerActivity != null) { + playerActivity!!.setLightNavigationBar(ColorUtil.isColorLight(backgroundColor)) + } + callbacks!!.onPaletteColorChanged() + + } + + private fun colorize(i: Int) { + if (valueAnimator != null) { + valueAnimator!!.cancel() + } + + valueAnimator = ValueAnimator.ofObject(ArgbEvaluator(), paletteColor, i) + valueAnimator!!.addUpdateListener { animation -> + colorGradientBackground.setBackgroundColor(animation.animatedValue as Int) + } + valueAnimator!!.setDuration(ViewUtil.RETRO_MUSIC_ANIM_TIME.toLong()).start() + } + + @SuppressLint("StaticFieldLeak") + private fun updateLyricsLocal() { + if (updateLyricsAsyncTask != null) { + updateLyricsAsyncTask!!.cancel(false) + } + val song = MusicPlayerRemote.currentSong + updateLyricsAsyncTask = object : AsyncTask() { + override fun onPreExecute() { + super.onPreExecute() + lyrics = null + playerToolbar.menu.removeItem(R.id.action_show_lyrics) + } + + override fun doInBackground(vararg params: Void): Lyrics? { + val data = MusicUtil.getLyrics(song) + return if (TextUtils.isEmpty(data)) { + null + } else Lyrics.parse(song, data) + } + + override fun onPostExecute(l: Lyrics?) { + lyrics = l + if (lyrics == null) { + lyricsView.setText(R.string.no_lyrics_found) + } else { + lyricsView.text = lyrics!!.text + } + } + + override fun onCancelled(s: Lyrics) { + onPostExecute(null) + } + }.execute() + } + + private fun setupViews() { + lyricsView.setOnClickListener { + if (lyricsContainer!!.visibility == View.GONE) { + lyricsContainer!!.visibility = View.VISIBLE + } else { + lyricsContainer!!.visibility = View.GONE + } + } + playerImage.setOnClickListener { + if (lyricsContainer!!.visibility == View.GONE) { + lyricsContainer!!.visibility = View.VISIBLE + } else { + lyricsContainer!!.visibility = View.GONE + } + } + expand.setOnClickListener { startActivity(Intent(context, LyricsActivity::class.java)) } + } + + companion object { + + fun newInstance(): ColorFragment { + val args = Bundle() + val fragment = ColorFragment() + fragment.arguments = args + return fragment + } + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorPlaybackControlsFragment.kt new file mode 100644 index 00000000..ec9b4dc7 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/color/ColorPlaybackControlsFragment.kt @@ -0,0 +1,225 @@ +package code.name.monkey.retromusic.ui.fragments.player.color + +import android.animation.ObjectAnimator +import android.graphics.Color +import android.graphics.PorterDuff +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.animation.DecelerateInterpolator +import android.view.animation.LinearInterpolator +import android.widget.SeekBar +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.helper.MusicPlayerRemote +import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper +import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler +import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener +import code.name.monkey.retromusic.service.MusicService +import code.name.monkey.retromusic.ui.fragments.VolumeFragment +import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerControlsFragment +import code.name.monkey.retromusic.util.MusicUtil +import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.* +import kotlinx.android.synthetic.main.media_button.* +import kotlinx.android.synthetic.main.player_time.* + +class ColorPlaybackControlsFragment : AbsPlayerControlsFragment() { + + private var lastPlaybackControlsColor: Int = 0 + private var lastDisabledPlaybackControlsColor: Int = 0 + private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper + private lateinit var volumeFragment: VolumeFragment + + 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_color_player_playback_controls, container, false) + } + + override fun onResume() { + super.onResume() + progressViewUpdateHelper.start() + } + + override fun onPause() { + super.onPause() + progressViewUpdateHelper.stop() + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setUpMusicControllers() + + volumeFragment = childFragmentManager.findFragmentById(R.id.volumeFragment) as VolumeFragment + } + + private fun updateSong() { + val song = MusicPlayerRemote.currentSong + title.text = song.title + text.text = song.artistName + } + + override fun onServiceConnected() { + updatePlayPauseDrawableState() + updateRepeatState() + updateShuffleState() + updateSong() + } + + override fun onPlayingMetaChanged() { + super.onPlayingMetaChanged() + updateSong() + } + + override fun onPlayStateChanged() { + updatePlayPauseDrawableState() + } + + override fun onRepeatModeChanged() { + updateRepeatState() + } + + override fun onShuffleModeChanged() { + updateShuffleState() + } + + + fun setDark(textColor: Int, background: Int) { + setDark(textColor) + TintHelper.setTintAuto(playPauseButton, background, false) + TintHelper.setTintAuto(playPauseButton, textColor, true) + } + + override fun setDark(color: Int) { + lastPlaybackControlsColor = color + lastDisabledPlaybackControlsColor = ColorUtil.withAlpha(color, 0.5f) + + title!!.setTextColor(lastPlaybackControlsColor) + text!!.setTextColor(lastDisabledPlaybackControlsColor) + + TintHelper.setTintAuto(progressSlider!!, lastPlaybackControlsColor, false) + + volumeFragment.setTintable(lastPlaybackControlsColor) + + songCurrentProgress.setTextColor(lastDisabledPlaybackControlsColor) + songTotalTime.setTextColor(lastDisabledPlaybackControlsColor) + + updateRepeatState() + updateShuffleState() + updatePrevNextColor() + } + + + private fun setUpPlayPauseFab() { + TintHelper.setTintAuto(playPauseButton, Color.WHITE, true) + TintHelper.setTintAuto(playPauseButton, Color.BLACK, false) + playPauseButton.setOnClickListener(PlayPauseButtonOnClickHandler()) + } + + + private fun updatePlayPauseDrawableState() { + when { + MusicPlayerRemote.isPlaying -> playPauseButton.setImageResource(R.drawable.ic_pause_white_24dp) + else -> playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_24dp) + } + } + + + private fun setUpMusicControllers() { + setUpPlayPauseFab() + setUpPrevNext() + setUpRepeatButton() + setUpShuffleButton() + setUpProgressSlider() + } + + 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() } + } + + override 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() } + } + + override 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) + } + } + } + + + public override fun show() { + playPauseButton!!.animate() + .scaleX(1f) + .scaleY(1f) + .rotation(360f) + .setInterpolator(DecelerateInterpolator()) + .start() + } + + public override fun hide() { + playPauseButton.apply { + scaleX = 0f + scaleY = 0f + rotation = 0f + } + } + + override fun setUpProgressSlider() { + progressSlider.setOnSeekBarChangeListener(object : SimpleOnSeekbarChangeListener() { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + if (fromUser) { + MusicPlayerRemote.seekTo(progress) + onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, MusicPlayerRemote.songDurationMillis) + } + } + }) + } + + override fun onUpdateProgressViews(progress: Int, total: Int) { + progressSlider!!.max = total + + val animator = ObjectAnimator.ofInt(progressSlider, "progress", progress) + animator.duration = 1500 + animator.interpolator = LinearInterpolator() + animator.start() + + songTotalTime.text = MusicUtil.getReadableDurationString(total.toLong()) + songCurrentProgress.text = MusicUtil.getReadableDurationString(progress.toLong()) + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/fit/FitPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/fit/FitPlaybackControlsFragment.kt index 71216c22..3a3857f7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/fit/FitPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/fit/FitPlaybackControlsFragment.kt @@ -161,7 +161,7 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { } private fun setUpShuffleButton() { - shuffleButton.setOnClickListener { v -> MusicPlayerRemote.toggleShuffleMode() } + shuffleButton.setOnClickListener { MusicPlayerRemote.toggleShuffleMode() } } override fun updateShuffleState() { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/flat/FlatPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/flat/FlatPlaybackControlsFragment.kt index bab7b04f..cb4e9c8c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/flat/FlatPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/flat/FlatPlaybackControlsFragment.kt @@ -196,7 +196,7 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback { } private fun setUpRepeatButton() { - repeatButton.setOnClickListener { v -> MusicPlayerRemote.cycleRepeatMode() } + repeatButton.setOnClickListener { MusicPlayerRemote.cycleRepeatMode() } } override fun updateRepeatState() { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/full/FullPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/full/FullPlaybackControlsFragment.kt index fb1e73b2..fae53acc 100644 --- a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/full/FullPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/full/FullPlaybackControlsFragment.kt @@ -201,7 +201,7 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment() { } private fun setUpShuffleButton() { - shuffleButton.setOnClickListener { v -> MusicPlayerRemote.toggleShuffleMode() } + shuffleButton.setOnClickListener { MusicPlayerRemote.toggleShuffleMode() } } override fun updateShuffleState() { diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/material/MaterialControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/material/MaterialControlsFragment.kt new file mode 100644 index 00000000..fb0299cc --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/material/MaterialControlsFragment.kt @@ -0,0 +1,212 @@ +package code.name.monkey.retromusic.ui.fragments.player.material + +import android.animation.ObjectAnimator +import android.graphics.PorterDuff +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.animation.LinearInterpolator +import android.widget.SeekBar +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.appthemehelper.util.MaterialValueHelper +import code.name.monkey.retromusic.R +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.misc.SimpleOnSeekbarChangeListener +import code.name.monkey.retromusic.service.MusicService +import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerControlsFragment +import code.name.monkey.retromusic.util.MusicUtil +import code.name.monkey.retromusic.util.PreferenceUtil +import kotlinx.android.synthetic.main.fragment_material_playback_controls.* +import kotlinx.android.synthetic.main.player_time.* + +/** + * @author Hemanth S (h4h13). + */ +class MaterialControlsFragment : AbsPlayerControlsFragment() { + + private var lastPlaybackControlsColor: Int = 0 + private var lastDisabledPlaybackControlsColor: Int = 0 + private var progressViewUpdateHelper: MusicProgressViewUpdateHelper? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + val view = inflater.inflate(R.layout.fragment_material_playback_controls, container, false) + + return view + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setUpMusicControllers() + } + + private fun updateSong() { + val song = MusicPlayerRemote.currentSong + title.text = song.title + text.text = song.artistName + } + + override fun onResume() { + super.onResume() + progressViewUpdateHelper!!.start() + } + + override fun onPause() { + super.onPause() + progressViewUpdateHelper!!.stop() + } + + override fun onServiceConnected() { + updatePlayPauseDrawableState() + updateRepeatState() + updateShuffleState() + updateSong() + } + + override fun onPlayingMetaChanged() { + super.onPlayingMetaChanged() + updateSong() + } + + override fun onPlayStateChanged() { + updatePlayPauseDrawableState() + } + + override fun onRepeatModeChanged() { + updateRepeatState() + } + + override fun onShuffleModeChanged() { + updateShuffleState() + } + + override fun setDark(color: Int) { + val colorBg = ATHUtil.resolveColor(activity, android.R.attr.colorBackground) + if (ColorUtil.isColorLight(colorBg)) { + lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(activity, true) + lastDisabledPlaybackControlsColor = MaterialValueHelper.getSecondaryDisabledTextColor(activity, true) + } else { + lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(activity, false) + lastDisabledPlaybackControlsColor = MaterialValueHelper.getPrimaryDisabledTextColor(activity, false) + } + + updateRepeatState() + updateShuffleState() + + if (PreferenceUtil.getInstance().adaptiveColor) { + lastPlaybackControlsColor = color + text.setTextColor(color) + } + + updatePlayPauseColor() + updatePrevNextColor() + } + + private fun updatePlayPauseColor() { + playPauseButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + } + + private fun setUpPlayPauseFab() { + playPauseButton.setOnClickListener(PlayPauseButtonOnClickHandler()) + } + + private fun updatePlayPauseDrawableState() { + if (MusicPlayerRemote.isPlaying) { + playPauseButton.setImageResource(R.drawable.ic_pause_white_24dp) + } else { + playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_24dp) + } + } + + private fun setUpMusicControllers() { + setUpPlayPauseFab() + setUpPrevNext() + setUpRepeatButton() + setUpShuffleButton() + setUpProgressSlider() + } + + 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() } + } + + override 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() } + } + + override 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) + } + } + } + + public override fun show() { + + } + + public override fun hide() { + + } + + override fun setUpProgressSlider() { + progressSlider.setOnSeekBarChangeListener(object : SimpleOnSeekbarChangeListener() { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + if (fromUser) { + MusicPlayerRemote.seekTo(progress) + onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis) + } + } + }) + } + + override fun onUpdateProgressViews(progress: Int, total: Int) { + progressSlider!!.max = total + + val animator = ObjectAnimator.ofInt(progressSlider, "progress", progress) + animator.duration = 1500 + animator.interpolator = LinearInterpolator() + animator.start() + + songTotalTime.text = MusicUtil.getReadableDurationString(total.toLong()) + songCurrentProgress.text = MusicUtil.getReadableDurationString(progress.toLong()) + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/material/MaterialFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/material/MaterialFragment.kt new file mode 100644 index 00000000..68306542 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/material/MaterialFragment.kt @@ -0,0 +1,108 @@ +package code.name.monkey.retromusic.ui.fragments.player.material + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.helper.MusicPlayerRemote +import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment +import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment +import code.name.monkey.retromusic.ui.fragments.player.normal.PlayerFragment +import kotlinx.android.synthetic.main.fragment_material.* + +/** + * @author Hemanth S (h4h13). + */ +class MaterialFragment : AbsPlayerFragment(), PlayerAlbumCoverFragment.Callbacks { + override fun toolbarGet(): Toolbar { + return playerToolbar + } + + private var lastColor: Int = 0 + override val paletteColor: Int + get() = lastColor + + private lateinit var playbackControlsFragment: MaterialControlsFragment + + override fun onShow() { + playbackControlsFragment.show() + } + + override fun onHide() { + playbackControlsFragment.hide() + onBackPressed() + } + + override fun onBackPressed(): Boolean { + return false + } + + override fun toolbarIconColor(): Int { + return ATHUtil.resolveColor(context, R.attr.iconColor) + } + + override fun onColorChanged(color: Int) { + playbackControlsFragment.setDark(color) + lastColor = color + callbacks!!.onPaletteColorChanged() + + ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(context, R.attr.iconColor), activity) + } + + override fun toggleFavorite(song: Song) { + super.toggleFavorite(song) + if (song.id == MusicPlayerRemote.currentSong.id) { + updateIsFavorite() + } + } + + override fun onFavoriteToggled() { + toggleFavorite(MusicPlayerRemote.currentSong) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_material, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setUpSubFragments() + setUpPlayerToolbar() + } + + private fun setUpSubFragments() { + playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as MaterialControlsFragment + val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + playerAlbumCoverFragment.setCallbacks(this) + } + + private fun setUpPlayerToolbar() { + playerToolbar.apply { + inflateMenu(R.menu.menu_player) + setNavigationOnClickListener { activity!!.onBackPressed() } + setOnMenuItemClickListener(this@MaterialFragment) + ToolbarContentTintHelper.colorizeToolbar(this, ATHUtil.resolveColor(context, R.attr.iconColor), activity) + } + } + + override fun onServiceConnected() { + updateIsFavorite() + } + + override fun onPlayingMetaChanged() { + updateIsFavorite() + } + + companion object { + + fun newInstance(): PlayerFragment { + return PlayerFragment() + } + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/normal/PlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/normal/PlayerFragment.kt new file mode 100644 index 00000000..04ccc628 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/normal/PlayerFragment.kt @@ -0,0 +1,134 @@ +package code.name.monkey.retromusic.ui.fragments.player.normal + +import android.animation.ArgbEvaluator +import android.animation.ValueAnimator +import android.graphics.drawable.GradientDrawable +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.helper.MusicPlayerRemote +import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment +import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment +import code.name.monkey.retromusic.util.PreferenceUtil +import code.name.monkey.retromusic.util.ViewUtil +import code.name.monkey.retromusic.views.DrawableGradient +import kotlinx.android.synthetic.main.fragment_player.* + + +class PlayerFragment : AbsPlayerFragment(), PlayerAlbumCoverFragment.Callbacks { + + private var lastColor: Int = 0 + override val paletteColor: Int + get() = lastColor + + private lateinit var playbackControlsFragment: PlayerPlaybackControlsFragment + private var valueAnimator: ValueAnimator? = null + + + private fun colorize(i: Int) { + if (valueAnimator != null) { + valueAnimator!!.cancel() + } + + valueAnimator = ValueAnimator.ofObject(ArgbEvaluator(), android.R.color.transparent, i) + valueAnimator!!.addUpdateListener { animation -> + val drawable = DrawableGradient(GradientDrawable.Orientation.TOP_BOTTOM, + intArrayOf(animation.animatedValue as Int, android.R.color.transparent), 0) + colorGradientBackground.background = drawable + } + valueAnimator!!.setDuration(ViewUtil.RETRO_MUSIC_ANIM_TIME.toLong()).start() + } + + override fun onShow() { + playbackControlsFragment.show() + } + + override fun onHide() { + playbackControlsFragment.hide() + onBackPressed() + } + + override fun onBackPressed(): Boolean { + return false + } + + override fun toolbarIconColor(): Int { + return ATHUtil.resolveColor(context, R.attr.iconColor) + } + + override fun onColorChanged(color: Int) { + playbackControlsFragment.setDark(color) + lastColor = color + callbacks!!.onPaletteColorChanged() + + ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(context, R.attr.iconColor), activity) + + if (PreferenceUtil.getInstance().adaptiveColor) { + colorize(color) + } + } + + override fun toggleFavorite(song: Song) { + super.toggleFavorite(song) + if (song.id == MusicPlayerRemote.currentSong.id) { + updateIsFavorite() + } + } + + override fun onFavoriteToggled() { + toggleFavorite(MusicPlayerRemote.currentSong) + } + + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + + return inflater.inflate(R.layout.fragment_player, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setUpSubFragments() + setUpPlayerToolbar() + } + + private fun setUpSubFragments() { + playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as PlayerPlaybackControlsFragment + val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + playerAlbumCoverFragment.setCallbacks(this) + } + + private fun setUpPlayerToolbar() { + playerToolbar.inflateMenu(R.menu.menu_player) + playerToolbar.setNavigationOnClickListener { activity!!.onBackPressed() } + playerToolbar.setOnMenuItemClickListener(this) + + ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(context, R.attr.iconColor), activity) + } + + override fun onServiceConnected() { + updateIsFavorite() + + } + + override fun onPlayingMetaChanged() { + updateIsFavorite() + } + + override fun toolbarGet(): Toolbar { + return playerToolbar + } + + companion object { + + fun newInstance(): PlayerFragment { + return PlayerFragment() + } + } +} diff --git a/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/normal/PlayerPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/normal/PlayerPlaybackControlsFragment.kt new file mode 100644 index 00000000..cc728489 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/normal/PlayerPlaybackControlsFragment.kt @@ -0,0 +1,243 @@ +package code.name.monkey.retromusic.ui.fragments.player.normal + +import android.animation.ObjectAnimator +import android.graphics.PorterDuff +import android.graphics.drawable.ClipDrawable +import android.graphics.drawable.LayerDrawable +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.animation.DecelerateInterpolator +import android.view.animation.LinearInterpolator +import android.widget.SeekBar +import code.name.monkey.appthemehelper.ThemeStore +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.appthemehelper.util.MaterialValueHelper +import code.name.monkey.appthemehelper.util.TintHelper +import code.name.monkey.retromusic.R +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.misc.SimpleOnSeekbarChangeListener +import code.name.monkey.retromusic.service.MusicService +import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerControlsFragment +import code.name.monkey.retromusic.util.MusicUtil +import code.name.monkey.retromusic.util.PreferenceUtil +import kotlinx.android.synthetic.main.fragment_player_playback_controls.* +import kotlinx.android.synthetic.main.media_button.* +import kotlinx.android.synthetic.main.player_time.* +import kotlinx.android.synthetic.main.volume_controls.* + +class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment() { + + private var lastPlaybackControlsColor: Int = 0 + private var lastDisabledPlaybackControlsColor: Int = 0 + private var progressViewUpdateHelper: MusicProgressViewUpdateHelper? = null + + 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_player_playback_controls, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setUpMusicControllers() + playPauseButton.setOnClickListener { + if (MusicPlayerRemote.isPlaying) { + MusicPlayerRemote.pauseSong() + } else { + MusicPlayerRemote.resumePlaying() + } + showBonceAnimation(playPauseButton) + } + } + + override fun setDark(color: Int) { + val colorBg = ATHUtil.resolveColor(activity, android.R.attr.colorBackground) + if (ColorUtil.isColorLight(colorBg)) { + lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(activity, true) + lastDisabledPlaybackControlsColor = MaterialValueHelper.getSecondaryDisabledTextColor(activity, true) + } else { + lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(activity, false) + lastDisabledPlaybackControlsColor = MaterialValueHelper.getPrimaryDisabledTextColor(activity, false) + } + + if (PreferenceUtil.getInstance().adaptiveColor) { + setFabColor(color) + } else { + setFabColor(ThemeStore.accentColor(context!!)) + } + + updateRepeatState() + updateShuffleState() + updatePrevNextColor() + } + + private fun setFabColor(i: Int) { + TintHelper.setTintAuto(playPauseButton, MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(i)), false) + TintHelper.setTintAuto(playPauseButton, i, true) + setProgressBarColor(i) + } + + private fun updateSong() { + val song = MusicPlayerRemote.currentSong + title.text = song.title + text.text = song.artistName + } + + override fun onResume() { + super.onResume() + progressViewUpdateHelper!!.start() + } + + override fun onPause() { + super.onPause() + progressViewUpdateHelper!!.stop() + } + + override fun onServiceConnected() { + updatePlayPauseDrawableState() + updateRepeatState() + updateShuffleState() + updateSong() + } + + override fun onPlayingMetaChanged() { + super.onPlayingMetaChanged() + updateSong() + } + + override fun onPlayStateChanged() { + updatePlayPauseDrawableState() + } + + override fun onRepeatModeChanged() { + updateRepeatState() + } + + override fun onShuffleModeChanged() { + updateShuffleState() + } + + + private fun setProgressBarColor(newColor: Int) { + val ld = progressSlider.progressDrawable as LayerDrawable + val clipDrawable = ld.findDrawableByLayerId(android.R.id.progress) as ClipDrawable + clipDrawable.setColorFilter(newColor, PorterDuff.Mode.SRC_IN) + } + + private fun setUpPlayPauseFab() { + playPauseButton.setOnClickListener(PlayPauseButtonOnClickHandler()) + } + + private fun updatePlayPauseDrawableState() { + if (MusicPlayerRemote.isPlaying) { + playPauseButton.setImageResource(R.drawable.ic_pause_white_24dp) + } else { + playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_24dp) + } + } + + private fun setUpMusicControllers() { + setUpPlayPauseFab() + setUpPrevNext() + setUpRepeatButton() + setUpShuffleButton() + setUpProgressSlider() + } + + 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() } + } + + override 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() } + } + + override 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) + } + } + } + + public override fun show() { + playPauseButton!!.animate() + .scaleX(1f) + .scaleY(1f) + .rotation(360f) + .setInterpolator(DecelerateInterpolator()) + .start() + } + + public override fun hide() { + if (playPauseButton != null) { + playPauseButton!!.apply { + scaleX = 0f + scaleY = 0f + rotation = 0f + } + } + } + + override fun setUpProgressSlider() { + progressSlider.setOnSeekBarChangeListener(object : SimpleOnSeekbarChangeListener() { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + if (fromUser) { + MusicPlayerRemote.seekTo(progress) + onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis) + } + } + }) + } + + override fun onUpdateProgressViews(progress: Int, total: Int) { + progressSlider.max = total + + val animator = ObjectAnimator.ofInt(progressSlider, "progress", progress) + animator.duration = 1500 + animator.interpolator = LinearInterpolator() + animator.start() + + songTotalTime.text = MusicUtil.getReadableDurationString(total.toLong()) + songCurrentProgress.text = MusicUtil.getReadableDurationString(progress.toLong()) + } + +} diff --git a/app/src/main/res/layout-land/fragment_color_player.xml b/app/src/main/res/layout-land/fragment_color_player.xml index 79e1de1e..f3350851 100644 --- a/app/src/main/res/layout-land/fragment_color_player.xml +++ b/app/src/main/res/layout-land/fragment_color_player.xml @@ -8,7 +8,7 @@ android:background="?android:attr/windowBackground"> @@ -37,7 +37,6 @@ android:orientation="horizontal"> @@ -49,14 +48,14 @@ app:cardPreventCornerOverlap="false" app:cardUseCompatPadding="true"> - diff --git a/app/src/main/res/layout/fragment_color_player.xml b/app/src/main/res/layout/fragment_color_player.xml index 422bbd50..e8572805 100644 --- a/app/src/main/res/layout/fragment_color_player.xml +++ b/app/src/main/res/layout/fragment_color_player.xml @@ -9,7 +9,7 @@ android:focusable="true"> @@ -43,21 +43,20 @@ app:cardUseCompatPadding="true"> diff --git a/app/src/main/res/layout/fragment_color_player_playback_controls.xml b/app/src/main/res/layout/fragment_color_player_playback_controls.xml index 0091586a..3dade10c 100644 --- a/app/src/main/res/layout/fragment_color_player_playback_controls.xml +++ b/app/src/main/res/layout/fragment_color_player_playback_controls.xml @@ -1,6 +1,5 @@ - - - - - - - - + - + - - - - - - - - - - - - - - - - - - +