home: re-add navigation code
Re-add support for the navToItem system [this time w/o any navbar magic] and fix its associated issues.
This commit is contained in:
parent
776776690d
commit
6c5a68c929
5 changed files with 63 additions and 20 deletions
|
@ -29,7 +29,9 @@ import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around the home
|
* A wrapper around the home fragment that shows the playback fragment and controls
|
||||||
|
* the more high-level navigation features.
|
||||||
|
* TODO: Re-add the nice playback slide in animation
|
||||||
*/
|
*/
|
||||||
class MainFragment : Fragment() {
|
class MainFragment : Fragment() {
|
||||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||||
|
|
|
@ -32,21 +32,29 @@ import com.google.android.material.tabs.TabLayoutMediator
|
||||||
import org.oxycblt.auxio.MainFragmentDirections
|
import org.oxycblt.auxio.MainFragmentDirections
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.FragmentHomeBinding
|
import org.oxycblt.auxio.databinding.FragmentHomeBinding
|
||||||
|
import org.oxycblt.auxio.detail.DetailViewModel
|
||||||
import org.oxycblt.auxio.logD
|
import org.oxycblt.auxio.logD
|
||||||
import org.oxycblt.auxio.logE
|
import org.oxycblt.auxio.logE
|
||||||
|
import org.oxycblt.auxio.music.Album
|
||||||
|
import org.oxycblt.auxio.music.Artist
|
||||||
|
import org.oxycblt.auxio.music.Genre
|
||||||
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||||
import org.oxycblt.auxio.recycler.DisplayMode
|
import org.oxycblt.auxio.recycler.DisplayMode
|
||||||
import java.lang.Exception
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main "Launching Point" fragment of Auxio, allowing navigation to the detail
|
* The main "Launching Point" fragment of Auxio, allowing navigation to the detail
|
||||||
* views for each respective fragment.
|
* views for each respective fragment.
|
||||||
* TODO: Re-add sorting (but new and improved)
|
* TODO: Re-add sorting (but new and improved)
|
||||||
* TODO: Add lift-on-scroll eventually
|
* TODO: Add lift-on-scroll eventually [when I can file a bug report or hack it into working]
|
||||||
|
* FIXME: Fix issue where for the toolbar will default to its collapsed state for basically no
|
||||||
|
* reason
|
||||||
* @author OxygenCobalt
|
* @author OxygenCobalt
|
||||||
*/
|
*/
|
||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||||
|
private val detailModel: DetailViewModel by activityViewModels()
|
||||||
|
|
||||||
private val tabs = arrayOf(
|
private val tabs = arrayOf(
|
||||||
DisplayMode.SHOW_SONGS, DisplayMode.SHOW_ALBUMS,
|
DisplayMode.SHOW_SONGS, DisplayMode.SHOW_ALBUMS,
|
||||||
DisplayMode.SHOW_ARTISTS, DisplayMode.SHOW_GENRES
|
DisplayMode.SHOW_ARTISTS, DisplayMode.SHOW_GENRES
|
||||||
|
@ -63,6 +71,9 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
binding.lifecycleOwner = viewLifecycleOwner
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
|
// For some insane reason certain navigation actions will collapse the app bar
|
||||||
|
binding.homeAppbar.setExpanded(true)
|
||||||
|
|
||||||
binding.homeToolbar.setOnMenuItemClickListener { item ->
|
binding.homeToolbar.setOnMenuItemClickListener { item ->
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.action_settings -> {
|
R.id.action_settings -> {
|
||||||
|
@ -89,7 +100,7 @@ class HomeFragment : Fragment() {
|
||||||
// Derived from: https://al-e-shevelev.medium.com/how-to-reduce-scroll-sensitivity-of-viewpager2-widget-87797ad02414
|
// Derived from: https://al-e-shevelev.medium.com/how-to-reduce-scroll-sensitivity-of-viewpager2-widget-87797ad02414
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val recycler = ViewPager2::class.java.getDeclaredField("mRecyclerView").apply {
|
val recycler = ViewPager2::class.java.getDeclaredField("mRecyclerView").run {
|
||||||
isAccessible = true
|
isAccessible = true
|
||||||
get(binding.homePager)
|
get(binding.homePager)
|
||||||
}
|
}
|
||||||
|
@ -98,7 +109,7 @@ class HomeFragment : Fragment() {
|
||||||
isAccessible = true
|
isAccessible = true
|
||||||
|
|
||||||
val slop = get(recycler) as Int
|
val slop = get(recycler) as Int
|
||||||
set(recycler, slop * 8)
|
set(recycler, slop * 3) // 3x seems to be the best fit here
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logE("Unable to reduce ViewPager sensitivity")
|
logE("Unable to reduce ViewPager sensitivity")
|
||||||
|
@ -121,6 +132,29 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
playbackModel.setupPlayback(requireContext())
|
playbackModel.setupPlayback(requireContext())
|
||||||
|
|
||||||
|
detailModel.navToItem.observe(viewLifecycleOwner) { item ->
|
||||||
|
when (item) {
|
||||||
|
is Song -> findNavController().navigate(
|
||||||
|
HomeFragmentDirections.actionShowAlbum(item.album.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
is Album -> findNavController().navigate(
|
||||||
|
HomeFragmentDirections.actionShowAlbum(item.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
is Artist -> findNavController().navigate(
|
||||||
|
HomeFragmentDirections.actionShowArtist(item.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
is Genre -> findNavController().navigate(
|
||||||
|
HomeFragmentDirections.actionShowGenre(item.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logD("Fragment Created.")
|
logD("Fragment Created.")
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
|
|
|
@ -27,6 +27,7 @@ import androidx.fragment.app.viewModels
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import org.oxycblt.auxio.databinding.FragmentHomeListBinding
|
import org.oxycblt.auxio.databinding.FragmentHomeListBinding
|
||||||
|
import org.oxycblt.auxio.logD
|
||||||
import org.oxycblt.auxio.music.Album
|
import org.oxycblt.auxio.music.Album
|
||||||
import org.oxycblt.auxio.music.Artist
|
import org.oxycblt.auxio.music.Artist
|
||||||
import org.oxycblt.auxio.music.Genre
|
import org.oxycblt.auxio.music.Genre
|
||||||
|
@ -88,17 +89,22 @@ class HomeListFragment : Fragment() {
|
||||||
|
|
||||||
// --- VIEWMODEL SETUP ---
|
// --- VIEWMODEL SETUP ---
|
||||||
|
|
||||||
val data = when (displayMode) {
|
val toObserve = when (displayMode) {
|
||||||
DisplayMode.SHOW_SONGS -> homeModel.songs
|
DisplayMode.SHOW_SONGS -> homeModel.songs
|
||||||
DisplayMode.SHOW_ALBUMS -> homeModel.albums
|
DisplayMode.SHOW_ALBUMS -> homeModel.albums
|
||||||
DisplayMode.SHOW_ARTISTS -> homeModel.artists
|
DisplayMode.SHOW_ARTISTS -> homeModel.artists
|
||||||
DisplayMode.SHOW_GENRES -> homeModel.genres
|
DisplayMode.SHOW_GENRES -> homeModel.genres
|
||||||
}
|
}
|
||||||
|
|
||||||
data.observe(viewLifecycleOwner) { data ->
|
// Make sure that this RecyclerView has data before startup
|
||||||
|
homeAdapter.updateData(toObserve.value!!)
|
||||||
|
|
||||||
|
toObserve.observe(viewLifecycleOwner) { data ->
|
||||||
homeAdapter.updateData(data)
|
homeAdapter.updateData(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logD("Fragment created")
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,34 +72,34 @@ class SearchViewModel : ViewModel() {
|
||||||
|
|
||||||
// A filter mode of null means to not filter at all.
|
// A filter mode of null means to not filter at all.
|
||||||
|
|
||||||
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_SONGS) {
|
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_ARTISTS) {
|
||||||
musicStore.songs.filterByOrNull(query)?.let { songs ->
|
musicStore.artists.filterByOrNull(query)?.let { artists ->
|
||||||
results.add(Header(id = -2, name = context.getString(R.string.lbl_songs)))
|
results.add(Header(id = -1, name = context.getString(R.string.lbl_artists)))
|
||||||
results.addAll(songs)
|
results.addAll(artists)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_ALBUMS) {
|
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_ALBUMS) {
|
||||||
musicStore.albums.filterByOrNull(query)?.let { albums ->
|
musicStore.albums.filterByOrNull(query)?.let { albums ->
|
||||||
results.add(Header(id = -3, name = context.getString(R.string.lbl_albums)))
|
results.add(Header(id = -2, name = context.getString(R.string.lbl_albums)))
|
||||||
results.addAll(albums)
|
results.addAll(albums)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_ARTISTS) {
|
|
||||||
musicStore.artists.filterByOrNull(query)?.let { artists ->
|
|
||||||
results.add(Header(id = -4, name = context.getString(R.string.lbl_artists)))
|
|
||||||
results.addAll(artists)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_GENRES) {
|
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_GENRES) {
|
||||||
musicStore.genres.filterByOrNull(query)?.let { genres ->
|
musicStore.genres.filterByOrNull(query)?.let { genres ->
|
||||||
results.add(Header(id = -5, name = context.getString(R.string.lbl_genres)))
|
results.add(Header(id = -3, name = context.getString(R.string.lbl_genres)))
|
||||||
results.addAll(genres)
|
results.addAll(genres)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mFilterMode == null || mFilterMode == DisplayMode.SHOW_SONGS) {
|
||||||
|
musicStore.songs.filterByOrNull(query)?.let { songs ->
|
||||||
|
results.add(Header(id = -4, name = context.getString(R.string.lbl_songs)))
|
||||||
|
results.addAll(songs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mSearchResults.value = results
|
mSearchResults.value = results
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<!-- Base theme -->
|
<!-- Base theme -->
|
||||||
<style name="Theme.Base" parent="Theme.Splash">
|
<style name="Theme.Base" parent="Theme.Splash">
|
||||||
<!-- TODO: Improve the color contrast on the dark theme [colorOnSurface] -->
|
<!-- TODO: Improve the color contrast on the dark theme [colorOnSurface] -->
|
||||||
|
<!-- TODO: Migrate to liftOnScroll everywhere that is not HomeFragment -->
|
||||||
|
|
||||||
<!-- Colors -->
|
<!-- Colors -->
|
||||||
<item name="colorSurface">@color/surface</item>
|
<item name="colorSurface">@color/surface</item>
|
||||||
|
|
Loading…
Reference in a new issue