-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
291 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...java/code/name/monkey/retromusic/ui/fragments/player/tiny/TinyPlaybackControlsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package code.name.monkey.retromusic.ui.fragments.player.tiny | ||
|
||
import android.graphics.PorterDuff | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
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.service.MusicService | ||
import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerControlsFragment | ||
import kotlinx.android.synthetic.main.fragment_tiny_controls_fragment.* | ||
|
||
class TinyPlaybackControlsFragment : AbsPlayerControlsFragment() { | ||
|
||
override fun show() { | ||
|
||
} | ||
|
||
override fun hide() { | ||
|
||
} | ||
|
||
override fun setUpProgressSlider() { | ||
|
||
} | ||
|
||
override fun setDark(color: Int) { | ||
if (ColorUtil.isColorLight(color)) { | ||
lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(getActivity(), true); | ||
lastDisabledPlaybackControlsColor = MaterialValueHelper.getSecondaryDisabledTextColor(getActivity(), true); | ||
} else { | ||
lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(getActivity(), false); | ||
lastDisabledPlaybackControlsColor = MaterialValueHelper.getPrimaryDisabledTextColor(getActivity(), false); | ||
} | ||
|
||
updateRepeatState(); | ||
updateShuffleState(); | ||
} | ||
|
||
override fun onUpdateProgressViews(progress: Int, total: Int) { | ||
|
||
} | ||
|
||
private var lastPlaybackControlsColor: Int = 0 | ||
private var lastDisabledPlaybackControlsColor: Int = 0 | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(R.layout.fragment_tiny_controls_fragment, container, false); | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setUpMusicControllers() | ||
} | ||
|
||
private fun setUpMusicControllers() { | ||
setUpRepeatButton() | ||
setUpShuffleButton() | ||
setUpProgressSlider() | ||
} | ||
|
||
private fun setUpShuffleButton() { | ||
playerShuffleButton.setOnClickListener { MusicPlayerRemote.toggleShuffleMode() } | ||
} | ||
|
||
private fun setUpRepeatButton() { | ||
playerRepeatButton.setOnClickListener { MusicPlayerRemote.cycleRepeatMode() } | ||
} | ||
|
||
override fun updateShuffleState() { | ||
when (MusicPlayerRemote.shuffleMode) { | ||
MusicService.SHUFFLE_MODE_SHUFFLE -> playerShuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) | ||
else -> playerShuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) | ||
} | ||
} | ||
|
||
override fun updateRepeatState() { | ||
when (MusicPlayerRemote.repeatMode) { | ||
MusicService.REPEAT_MODE_NONE -> { | ||
playerRepeatButton.setImageResource(R.drawable.ic_repeat_white_24dp) | ||
playerRepeatButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) | ||
} | ||
MusicService.REPEAT_MODE_ALL -> { | ||
playerRepeatButton.setImageResource(R.drawable.ic_repeat_white_24dp) | ||
playerRepeatButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) | ||
} | ||
MusicService.REPEAT_MODE_THIS -> { | ||
playerRepeatButton.setImageResource(R.drawable.ic_repeat_one_white_24dp) | ||
playerRepeatButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) | ||
} | ||
} | ||
} | ||
|
||
} |
158 changes: 158 additions & 0 deletions
158
app/src/main/java/code/name/monkey/retromusic/ui/fragments/player/tiny/TinyPlayerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package code.name.monkey.retromusic.ui.fragments.player.tiny | ||
|
||
import android.animation.AnimatorSet | ||
import android.animation.ObjectAnimator | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.animation.LinearInterpolator | ||
import androidx.appcompat.widget.Toolbar | ||
import code.name.monkey.appthemehelper.ThemeStore | ||
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.appthemehelper.util.ToolbarContentTintHelper | ||
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.model.Song | ||
import code.name.monkey.retromusic.ui.fragments.MiniPlayerFragment | ||
import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment | ||
import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment | ||
import code.name.monkey.retromusic.util.MusicUtil | ||
import code.name.monkey.retromusic.util.PreferenceUtil | ||
import kotlinx.android.synthetic.main.fragment_tiny_player.* | ||
|
||
class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Callback { | ||
override fun onUpdateProgressViews(progress: Int, total: Int) { | ||
progressBar.max = total | ||
|
||
val animator = ObjectAnimator.ofInt(progressBar, "progress", progress) | ||
|
||
val animatorSet = AnimatorSet() | ||
animatorSet.playSequentially(animator) | ||
|
||
animatorSet.duration = 1500 | ||
animatorSet.interpolator = LinearInterpolator() | ||
animatorSet.start() | ||
|
||
playerSongTotalTime.text = String.format("%s/%s", MusicUtil.getReadableDurationString(total.toLong()), | ||
MusicUtil.getReadableDurationString(progress.toLong())) | ||
} | ||
|
||
|
||
override fun toolbarGet(): Toolbar { | ||
return playerToolbar | ||
} | ||
|
||
override fun onShow() { | ||
|
||
} | ||
|
||
override fun onHide() { | ||
} | ||
|
||
override fun onBackPressed(): Boolean { | ||
return false | ||
} | ||
|
||
override fun toolbarIconColor(): Int { | ||
return MaterialValueHelper.getSecondaryTextColor(context, ColorUtil.isColorLight(lastColor)) | ||
} | ||
|
||
private var lastColor: Int = 0 | ||
override val paletteColor: Int | ||
get() = lastColor | ||
|
||
override fun onColorChanged(color: Int) { | ||
val lastColor = if (PreferenceUtil.getInstance().adaptiveColor) { | ||
color | ||
} else { | ||
ThemeStore.accentColor(context!!) | ||
} | ||
callbacks?.onPaletteColorChanged() | ||
tinyPlaybackControlsFragment.setDark(lastColor) | ||
|
||
TintHelper.setTintAuto(progressBar, lastColor, false) | ||
|
||
val iconColor = MaterialValueHelper.getSecondaryTextColor(context, ColorUtil.isColorLight(lastColor)) | ||
ToolbarContentTintHelper.colorizeToolbar(playerToolbar, iconColor, activity) | ||
} | ||
|
||
override fun onFavoriteToggled() { | ||
toggleFavorite(MusicPlayerRemote.currentSong) | ||
} | ||
|
||
private lateinit var tinyPlaybackControlsFragment: TinyPlaybackControlsFragment | ||
private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
progressViewUpdateHelper.start() | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
progressViewUpdateHelper.stop() | ||
} | ||
|
||
private fun updateSong() { | ||
val song = MusicPlayerRemote.currentSong | ||
songTitle.text = song.title | ||
songText.text = String.format("%s \nby -%s", song.albumName, song.artistName) | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(R.layout.fragment_tiny_player, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
progressBar.setOnClickListener(PlayPauseButtonOnClickHandler()) | ||
progressBar.setOnTouchListener(MiniPlayerFragment.FlingPlayBackController(activity!!)) | ||
|
||
setUpPlayerToolbar() | ||
setUpSubFragments() | ||
} | ||
|
||
private fun setUpSubFragments() { | ||
tinyPlaybackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as TinyPlaybackControlsFragment | ||
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@TinyPlayerFragment) | ||
} | ||
} | ||
|
||
override fun toggleFavorite(song: Song) { | ||
super.toggleFavorite(song) | ||
if (song.id == MusicPlayerRemote.currentSong.id) { | ||
updateIsFavorite() | ||
} | ||
} | ||
|
||
override fun onServiceConnected() { | ||
super.onServiceConnected() | ||
updateSong() | ||
} | ||
|
||
override fun onPlayingMetaChanged() { | ||
super.onPlayingMetaChanged() | ||
updateSong() | ||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.