Add play/pause controls
Add play/pause controls to the playback fragments.
This commit is contained in:
@@ -103,7 +103,7 @@ class AlbumDetailFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
binding.albumArtist.setBackgroundResource(R.drawable.ripple)
|
||||
binding.albumArtist.setBackgroundResource(R.drawable.ui_ripple)
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
@@ -109,7 +109,7 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
||||
) == PackageManager.PERMISSION_DENIED
|
||||
}
|
||||
|
||||
// Remove the loading indicator and show the error groups
|
||||
// Remove the loading ui_indicator and show the error groups
|
||||
private fun showError(binding: FragmentLoadingBinding) {
|
||||
binding.loadingBar.visibility = View.GONE
|
||||
binding.loadingErrorIcon.visibility = View.VISIBLE
|
||||
|
||||
@@ -66,7 +66,7 @@ class MusicLoader(
|
||||
private fun loadGenres() {
|
||||
Log.d(this::class.simpleName, "Starting genre search...")
|
||||
|
||||
// First, get a cursor for every genre in the android system
|
||||
// First, get a ui_cursor for every genre in the android system
|
||||
genreCursor = resolver.query(
|
||||
Genres.EXTERNAL_CONTENT_URI,
|
||||
arrayOf(
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentCompactPlaybackBinding
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
|
||||
@@ -31,6 +32,7 @@ class CompactPlaybackFragment : Fragment() {
|
||||
// Put a placeholder song in the binding & hide the playback fragment initially,
|
||||
// as for some reason the attach event doesn't register anymore w/LiveData
|
||||
binding.song = musicModel.songs.value!![0]
|
||||
binding.playbackModel = playbackModel
|
||||
binding.root.visibility = View.GONE
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
@@ -54,6 +56,15 @@ class CompactPlaybackFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Animate this icon
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
binding.songControls.setImageResource(R.drawable.ic_pause)
|
||||
} else {
|
||||
binding.songControls.setImageResource(R.drawable.ic_play)
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment Created")
|
||||
|
||||
return binding.root
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
package org.oxycblt.auxio.playback
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentPlaybackBinding
|
||||
import org.oxycblt.auxio.theme.accent
|
||||
import org.oxycblt.auxio.theme.toColor
|
||||
|
||||
class PlaybackFragment : BottomSheetDialogFragment() {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
|
||||
// TODO: Implement nav to artists/albums
|
||||
// TODO: Add a full playback fragment
|
||||
// TODO: Possibly implement a trackbar with a spectrum shown as well.
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@@ -20,18 +25,39 @@ class PlaybackFragment : BottomSheetDialogFragment() {
|
||||
): View? {
|
||||
val binding = FragmentPlaybackBinding.inflate(inflater)
|
||||
|
||||
val accentColor = ColorStateList.valueOf(accent.first.toColor(requireContext()))
|
||||
val white = ColorStateList.valueOf(android.R.color.white.toColor(requireContext()))
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
binding.playbackModel = playbackModel
|
||||
|
||||
// Make marquee scroll work
|
||||
binding.songName.isSelected = true
|
||||
binding.songAlbum.isSelected = true
|
||||
binding.songArtist.isSelected = true
|
||||
binding.playbackSong.isSelected = true
|
||||
binding.playbackAlbum.isSelected = true
|
||||
binding.playbackArtist.isSelected = true
|
||||
|
||||
// Override the accents manually because the BottomSheetFragment is too dumb to do it themselves.
|
||||
binding.playbackSeekBar.thumbTintList = accentColor
|
||||
binding.playbackSeekBar.progressTintList = accentColor
|
||||
binding.playbackSeekBar.progressBackgroundTintList = accentColor
|
||||
|
||||
// --- VIEWMODEL SETUP --
|
||||
|
||||
playbackModel.currentSong.observe(viewLifecycleOwner) {
|
||||
binding.song = it
|
||||
}
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
binding.playbackPlayPause.setImageResource(R.drawable.ic_pause)
|
||||
binding.playbackPlayPause.backgroundTintList = accentColor
|
||||
} else {
|
||||
binding.playbackPlayPause.setImageResource(R.drawable.ic_play)
|
||||
binding.playbackPlayPause.backgroundTintList = white
|
||||
}
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.oxycblt.auxio.music.Song
|
||||
|
||||
// TODO: Implement media controls
|
||||
// TODO: Add the playback service itself
|
||||
// TODO: Possibly add some swipe-to-next-track function, could require a ViewPager.
|
||||
// A ViewModel that acts as an intermediary between PlaybackService and the Playback Fragments.
|
||||
class PlaybackViewModel : ViewModel() {
|
||||
private val mCurrentSong = MutableLiveData<Song>()
|
||||
val currentSong: LiveData<Song> get() = mCurrentSong
|
||||
@@ -14,8 +16,12 @@ class PlaybackViewModel : ViewModel() {
|
||||
private val mShouldOpenPlayback = MutableLiveData<Boolean>()
|
||||
val shouldOpenPlayback: LiveData<Boolean> get() = mShouldOpenPlayback
|
||||
|
||||
private val mIsPlaying = MutableLiveData(false)
|
||||
val isPlaying: LiveData<Boolean> get() = mIsPlaying
|
||||
|
||||
fun updateSong(song: Song) {
|
||||
mCurrentSong.value = song
|
||||
mIsPlaying.value = true
|
||||
}
|
||||
|
||||
fun openPlayback() {
|
||||
@@ -25,4 +31,9 @@ class PlaybackViewModel : ViewModel() {
|
||||
fun doneWithOpenPlayback() {
|
||||
mShouldOpenPlayback.value = false
|
||||
}
|
||||
|
||||
// Invert, not directly set the p
|
||||
fun invertPlayingStatus() {
|
||||
mIsPlaying.value = !mIsPlaying.value!!
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user