Add specific playback fragment
Add a Playback Fragment that shows more information about what is currently playing.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package org.oxycblt.auxio
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -10,7 +9,7 @@ import org.oxycblt.auxio.theme.accent
|
||||
// FIXME: Fix bug where fast navigation will break the fade animation and
|
||||
// lead to nothing being displayed [Possibly Un-fixable]
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
class MainActivity : AppCompatActivity(R.layout.activity_main) {
|
||||
|
||||
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
|
||||
// Apply the theme
|
||||
@@ -18,9 +17,4 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
return super.onCreateView(name, context, attrs)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import com.google.android.material.tabs.TabLayoutMediator
|
||||
import org.oxycblt.auxio.databinding.FragmentMainBinding
|
||||
import org.oxycblt.auxio.library.LibraryFragment
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.playback.PlaybackFragment
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.songs.SongsFragment
|
||||
import org.oxycblt.auxio.theme.accent
|
||||
import org.oxycblt.auxio.theme.getInactiveAlpha
|
||||
@@ -26,8 +28,9 @@ class MainFragment : Fragment() {
|
||||
MusicViewModel.Factory(requireActivity().application)
|
||||
}
|
||||
|
||||
private val shownFragments = listOf(0, 1)
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
|
||||
private val shownFragments = listOf(0, 1)
|
||||
private val tabIcons = listOf(
|
||||
R.drawable.ic_library,
|
||||
R.drawable.ic_song
|
||||
@@ -72,8 +75,6 @@ class MainFragment : Fragment() {
|
||||
}
|
||||
}.attach()
|
||||
|
||||
binding.compactPlayback.visibility = View.GONE
|
||||
|
||||
// Set up the selected/deselected colors
|
||||
binding.mainTabs.addOnTabSelectedListener(
|
||||
object : TabLayout.OnTabSelectedListener {
|
||||
@@ -91,6 +92,16 @@ class MainFragment : Fragment() {
|
||||
}
|
||||
)
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
playbackModel.shouldOpenPlayback.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
PlaybackFragment().show(requireActivity().supportFragmentManager, "TAG_PLAYBACK")
|
||||
|
||||
playbackModel.doneWithOpenPlayback()
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment Created.")
|
||||
|
||||
return binding.root
|
||||
|
||||
@@ -85,6 +85,7 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
val item = findItem(R.id.action_search)
|
||||
val searchView = item.actionView as SearchView
|
||||
|
||||
searchView.queryHint = getString(R.string.hint_search_library)
|
||||
searchView.setOnQueryTextListener(this@LibraryFragment)
|
||||
searchView.setOnQueryTextFocusChangeListener { _, hasFocus ->
|
||||
libraryModel.updateSearchFocusStatus(hasFocus)
|
||||
|
||||
@@ -33,6 +33,10 @@ class CompactPlaybackFragment : Fragment() {
|
||||
binding.song = musicModel.songs.value!![0]
|
||||
binding.root.visibility = View.GONE
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
playbackModel.openPlayback()
|
||||
}
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
// TODO: Add some kind of animation to when this view becomes visible/invisible.
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.oxycblt.auxio.playback
|
||||
|
||||
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.databinding.FragmentPlaybackBinding
|
||||
|
||||
class PlaybackFragment : BottomSheetDialogFragment() {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
|
||||
// TODO: Implement nav to artists/albums
|
||||
// TODO: Possibly implement a trackbar with a spectrum shown as well.
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val binding = FragmentPlaybackBinding.inflate(inflater)
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
// Make marquee scroll work
|
||||
binding.songName.isSelected = true
|
||||
binding.songAlbum.isSelected = true
|
||||
binding.songArtist.isSelected = true
|
||||
|
||||
// --- VIEWMODEL SETUP --
|
||||
playbackModel.currentSong.observe(viewLifecycleOwner) {
|
||||
binding.song = it
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,24 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.oxycblt.auxio.music.Song
|
||||
|
||||
// TODO: Implement media controls
|
||||
// TODO: Add the playback service itself
|
||||
class PlaybackViewModel : ViewModel() {
|
||||
private val mCurrentSong = MutableLiveData<Song>()
|
||||
val currentSong: LiveData<Song> get() = mCurrentSong
|
||||
|
||||
private val mShouldOpenPlayback = MutableLiveData<Boolean>()
|
||||
val shouldOpenPlayback: LiveData<Boolean> get() = mShouldOpenPlayback
|
||||
|
||||
fun updateSong(song: Song) {
|
||||
mCurrentSong.value = song
|
||||
}
|
||||
|
||||
fun openPlayback() {
|
||||
mShouldOpenPlayback.value = true
|
||||
}
|
||||
|
||||
fun doneWithOpenPlayback() {
|
||||
mShouldOpenPlayback.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.oxycblt.auxio.recycler.ClickListener
|
||||
|
||||
// Shared ViewHolders for each ViewModel, providing basic information
|
||||
// All new instances should be created with from() instead of direct instantiation.
|
||||
// TODO: Add indicators to song recycler items when they're being played.
|
||||
|
||||
class GenreViewHolder private constructor(
|
||||
listener: ClickListener<Genre>,
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.recycler.ClickListener
|
||||
import org.oxycblt.auxio.theme.applyDivider
|
||||
|
||||
class SongsFragment : Fragment() {
|
||||
private val musicModel: MusicViewModel by activityViewModels {
|
||||
MusicViewModel.Factory(requireActivity().application)
|
||||
|
||||
Reference in New Issue
Block a user