Added link to lyrics from Color theme

This commit is contained in:
h4h13 2019-12-08 20:11:00 +05:30
parent ce918acb45
commit 648f3c115a

View file

@ -4,16 +4,23 @@ import android.animation.ValueAnimator
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.palette.graphics.Palette import androidx.palette.graphics.Palette
import code.name.monkey.appthemehelper.util.* 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.R
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.glide.* 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.glide.palette.BitmapPaletteWrapper
import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.RetroColorUtil import code.name.monkey.retromusic.util.RetroColorUtil
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.request.animation.GlideAnimation import com.bumptech.glide.request.animation.GlideAnimation
@ -21,169 +28,161 @@ import kotlinx.android.synthetic.main.fragment_color_player.*
class ColorFragment : AbsPlayerFragment() { class ColorFragment : AbsPlayerFragment() {
private var lastColor: Int = 0 private var lastColor: Int = 0
private var backgroundColor: Int = 0 private var backgroundColor: Int = 0
private var playbackControlsFragment: ColorPlaybackControlsFragment? = null private lateinit var playbackControlsFragment: ColorPlaybackControlsFragment
private var valueAnimator: ValueAnimator? = null private var valueAnimator: ValueAnimator? = null
override fun playerToolbar(): Toolbar { override fun playerToolbar(): Toolbar {
return playerToolbar return playerToolbar
} }
override val paletteColor: Int override val paletteColor: Int
get() = backgroundColor get() = backgroundColor
override fun onColorChanged(color: Int) { override fun onColorChanged(color: Int) {
} }
override fun onFavoriteToggled() { override fun onFavoriteToggled() {
} }
override fun onShow() { override fun onShow() {
playbackControlsFragment!!.show() playbackControlsFragment.show()
} }
override fun onHide() { override fun onHide() {
playbackControlsFragment!!.hide() playbackControlsFragment.hide()
onBackPressed() onBackPressed()
} }
override fun onBackPressed(): Boolean { override fun onBackPressed(): Boolean {
return false return false
} }
override fun toolbarIconColor(): Int { override fun toolbarIconColor(): Int {
return lastColor return lastColor
} }
override fun toggleFavorite(song: Song) { override fun toggleFavorite(song: Song) {
super.toggleFavorite(song) super.toggleFavorite(song)
if (song.id == MusicPlayerRemote.currentSong.id) { if (song.id == MusicPlayerRemote.currentSong.id) {
updateIsFavorite() updateIsFavorite()
} }
} }
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
if (valueAnimator != null) { if (valueAnimator != null) {
valueAnimator!!.cancel() valueAnimator!!.cancel()
valueAnimator = null valueAnimator = null
} }
} }
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? { ): View? {
return inflater.inflate(R.layout.fragment_color_player, container, false) return inflater.inflate(R.layout.fragment_color_player, container, false)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
setUpSubFragments() setUpSubFragments()
setUpPlayerToolbar() setUpPlayerToolbar()
} playerImage.setOnClickListener {
NavigationUtil.goToLyrics(requireActivity())
}
}
private fun setUpSubFragments() { private fun setUpSubFragments() {
playbackControlsFragment = childFragmentManager.findFragmentById( playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as ColorPlaybackControlsFragment
R.id.playbackControlsFragment }
) as ColorPlaybackControlsFragment?
} private fun setUpPlayerToolbar() {
playerToolbar.apply {
inflateMenu(R.menu.menu_player)
setNavigationOnClickListener { requireActivity().onBackPressed() }
setOnMenuItemClickListener(this@ColorFragment)
ToolbarContentTintHelper.colorizeToolbar(this, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity())
}
}
private fun setUpPlayerToolbar() { override fun onPlayingMetaChanged() {
playerToolbar.apply { super.onPlayingMetaChanged()
inflateMenu(R.menu.menu_player) updateSong()
setNavigationOnClickListener { requireActivity().onBackPressed() } }
setOnMenuItemClickListener(this@ColorFragment)
ToolbarContentTintHelper.colorizeToolbar(
this, ATHUtil.resolveColor(
context, R.attr.iconColor
), activity
)
}
}
override fun onPlayingMetaChanged() { override fun onServiceConnected() {
super.onPlayingMetaChanged() super.onServiceConnected()
updateSong() updateSong()
} }
override fun onServiceConnected() { private fun updateSong() {
super.onServiceConnected() SongGlideRequest.Builder.from(Glide.with(requireActivity()), MusicPlayerRemote.currentSong)
updateSong() .checkIgnoreMediaStore(requireContext()).generatePalette(requireContext()).build()
} .into(object : RetroMusicColoredTarget(playerImage) {
override fun onColorReady(color: Int) {
private fun updateSong() { }
SongGlideRequest.Builder.from(Glide.with(requireActivity()), MusicPlayerRemote.currentSong)
.checkIgnoreMediaStore(requireContext()).generatePalette(requireContext()).build()
.into(object : RetroMusicColoredTarget(playerImage) {
override fun onColorReady(color: Int) {
} override fun onResourceReady(
resource: BitmapPaletteWrapper?,
glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?
) {
super.onResourceReady(resource, glideAnimation)
resource?.let {
val palette = resource.palette
val swatch = RetroColorUtil.getSwatch(palette)
override fun onResourceReady( val textColor = RetroColorUtil.getTextColor(palette)
resource: BitmapPaletteWrapper?, val backgroundColor = swatch.rgb
glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?
) {
super.onResourceReady(resource, glideAnimation)
resource?.let {
val background = resource.palette.getColor()
val palette = resource.palette setColors(backgroundColor, textColor)
val swatch = RetroColorUtil.getSwatch(palette) }
val textColor = RetroColorUtil.getTextColor(palette) }
val backgroundColor = swatch.rgb
setColors(backgroundColor, textColor) 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 onLoadFailed(e: Exception?, errorDrawable: Drawable?) { private fun setColors(backgroundColor: Int, textColor: Int) {
super.onLoadFailed(e, errorDrawable) playbackControlsFragment.setDark(textColor, backgroundColor)
val backgroundColor = defaultFooterColor colorGradientBackground?.setBackgroundColor(backgroundColor)
val textColor = if (ColorUtil.isColorLight(defaultFooterColor)) MaterialValueHelper.getPrimaryTextColor( ToolbarContentTintHelper.colorizeToolbar(playerToolbar, textColor, activity)
context, lastColor = textColor
true this.backgroundColor = backgroundColor
) playerActivity?.setLightNavigationBar(ColorUtil.isColorLight(backgroundColor))
else MaterialValueHelper.getPrimaryTextColor(context, false) callbacks?.onPaletteColorChanged()
}
setColors(backgroundColor, textColor) companion object {
} fun newInstance(): ColorFragment {
}) val args = Bundle()
} val fragment = ColorFragment()
fragment.arguments = args
private fun setColors( return fragment
backgroundColor: Int, textColor: Int }
) { }
playbackControlsFragment?.setDark(textColor, backgroundColor)
colorGradientBackground?.setBackgroundColor(backgroundColor)
ToolbarContentTintHelper.colorizeToolbar(playerToolbar, textColor, activity)
lastColor = textColor
this.backgroundColor = backgroundColor
playerActivity?.setLightNavigationBar(ColorUtil.isColorLight(backgroundColor))
callbacks?.onPaletteColorChanged()
}
companion object {
fun newInstance(): ColorFragment {
val args = Bundle()
val fragment = ColorFragment()
fragment.arguments = args
return fragment
}
}
} }
fun Palette.getColor(): Int { fun Palette.getColor(): Int {
return when { return when {
darkMutedSwatch != null -> darkMutedSwatch!!.rgb darkMutedSwatch != null -> darkMutedSwatch!!.rgb
mutedSwatch != null -> mutedSwatch!!.rgb mutedSwatch != null -> mutedSwatch!!.rgb
lightMutedSwatch != null -> lightMutedSwatch!!.rgb lightMutedSwatch != null -> lightMutedSwatch!!.rgb
else -> Palette.Swatch(Color.BLACK, 1).rgb else -> Palette.Swatch(Color.BLACK, 1).rgb
} }
} }