Add back navigation to detail fragments

Add backwards navigation to the DetailFragment toolbars.
This commit is contained in:
OxygenCobalt 2020-09-26 09:58:14 -06:00
parent 2a6fd45b8b
commit 531825465f
12 changed files with 51 additions and 48 deletions

View file

@ -55,6 +55,10 @@ class AlbumDetailFragment : Fragment() {
binding.songRecycler.applyDivider()
binding.songRecycler.setHasFixedSize(true)
binding.toolbar.setNavigationOnClickListener {
findNavController().navigateUp()
}
// If the album was shown directly from LibraryFragment [No parent artist stored],
// then enable the ability to navigate upwards to the album's parent artist.
if (detailModel.currentArtist == null) {
@ -75,7 +79,6 @@ class AlbumDetailFragment : Fragment() {
binding.artistName.setBackgroundResource(R.drawable.ripple)
}
// Set up sort modes
detailModel.albumSortMode.observe(viewLifecycleOwner) { mode ->
// Update the current sort icon
binding.sortButton.setImageResource(mode.iconRes)
@ -93,7 +96,7 @@ class AlbumDetailFragment : Fragment() {
)
}
// Dont enable the sort button if theres only one song [or less]
// Don't enable the sort button if there's only one song [or less]
if (detailModel.currentAlbum!!.numSongs < 2) {
binding.sortButton.imageTintList = ColorStateList.valueOf(
R.color.inactive_color.toColor(requireContext())

View file

@ -55,6 +55,10 @@ class ArtistDetailFragment : Fragment() {
binding.albumRecycler.applyDivider()
binding.albumRecycler.setHasFixedSize(true)
binding.toolbar.setNavigationOnClickListener {
findNavController().navigateUp()
}
detailModel.artistSortMode.observe(viewLifecycleOwner) { mode ->
// Update the current sort icon
binding.sortButton.setImageResource(mode.iconRes)
@ -72,7 +76,7 @@ class ArtistDetailFragment : Fragment() {
)
}
// Dont enable the sort button if there is only one album [Or less]
// Don't enable the sort button if there is only one album [Or less]
if (detailModel.currentArtist!!.numAlbums < 2) {
binding.sortButton.imageTintList = ColorStateList.valueOf(
R.color.inactive_color.toColor(requireContext())

View file

@ -21,8 +21,6 @@ import org.oxycblt.auxio.music.processing.MusicLoaderResponse
import org.oxycblt.auxio.music.processing.MusicSorter
// ViewModel for music storage. May also be a god object.
// TODO: Move the lists from the music models to a map, would
// make some systems a lot less hacky and maybe decrease memory usage.
class MusicViewModel(private val app: Application) : ViewModel() {
// Coroutine

View file

@ -118,7 +118,7 @@ class MusicLoader(
Genres.Members.getContentUri("external", genre.id),
arrayOf(
Artists._ID, // 0
Artists.ARTIST, // 1
Artists.ARTIST // 1
),
null, null,
Artists.DEFAULT_SORT_ORDER

View file

@ -2,6 +2,7 @@ package org.oxycblt.auxio.theme
import android.content.Context
import android.graphics.drawable.ColorDrawable
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.recyclerview.widget.DividerItemDecoration
@ -34,6 +35,7 @@ private val ACCENTS = listOf(
val accent = ACCENTS[5]
// Get the transparent variant of a color int
@ColorInt
fun getTransparentAccent(context: Context, color: Int, alpha: Int): Int {
return ColorUtils.setAlphaComponent(
ContextCompat.getColor(context, color),
@ -42,11 +44,13 @@ fun getTransparentAccent(context: Context, color: Int, alpha: Int): Int {
}
// Get the inactive transparency of an accent
@ColorInt
fun getInactiveAlpha(color: Int): Int {
return if (color == R.color.yellow) 100 else 150
}
// Convert an integer to a color
@ColorInt
fun Int.toColor(context: Context): Int {
return try {
ContextCompat.getColor(context, this)

View file

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>

View file

@ -5,15 +5,12 @@
android:viewportHeight="24"
android:tint="?android:attr/colorPrimary">
<path
android:fillColor="#FF000000"
android:pathData="m3.6944,17.9917h-2.7188L5.1182,5.9917L8.3877,5.9917L12.5244,17.9917h-2.7188L6.7998,8.7339L6.7061,8.7339ZM3.5244,13.2749h6.4219v1.9805L3.5244,15.2554Z"
android:strokeWidth="0.4125" />
android:pathData="M3.694 17.992H0.976l4.142-12h3.27l4.136 12H9.806L6.8 8.734H6.706zm-0.17-4.717h6.422v1.98H3.524zm10.313 4.717v-1.506l5.988-8.402h-6V5.992h9.188v1.505L17.018 15.9h6.006v2.092z"
android:strokeWidth="0.4125"
android:fillColor="@android:color/white" />
<path
android:fillColor="#FF000000"
android:pathData="m13.8369,17.9917v-1.5059l5.9883,-8.4023h-6L13.8252,5.9917h9.1875L23.0127,7.4975L17.0185,15.8999h6.0059v2.0918z"
android:strokeWidth="0.4125" />
<path
android:pathData="m15.5,20.5355c-2.3333,0 -4.6667,0 -7,0 1.1667,1.152 2.3333,2.304 3.5,3.456 1.1667,-1.152 2.3333,-2.304 3.5,-3.456z"
android:pathData="M15.5 20.535h-7l3.5 3.456 3.5-3.456z"
android:strokeWidth="0.139935"
android:fillColor="#000000" />
android:fillColor="@android:color/white" />
</vector>

View file

@ -5,15 +5,12 @@
android:viewportHeight="24"
android:tint="?android:attr/colorPrimary">
<path
android:fillColor="#FF000000"
android:pathData="m3.6944,17.9917h-2.7188L5.1182,5.9917L8.3877,5.9917L12.5244,17.9917h-2.7188L6.7998,8.7339L6.7061,8.7339ZM3.5244,13.2749h6.4219v1.9805L3.5244,15.2554Z"
android:strokeWidth="0.4125" />
<path
android:fillColor="#FF000000"
android:pathData="m13.8369,17.9917v-1.5059l5.9883,-8.4023h-6L13.8252,5.9917h9.1875L23.0127,7.4975L17.0185,15.8999h6.0059v2.0918z"
android:strokeWidth="0.4125" />
<path
android:pathData="m15.5,3.4478c-2.3333,0 -4.6667,0 -7,0 1.1667,-1.152 2.3333,-2.304 3.5,-3.456 1.1667,1.152 2.3333,2.304 3.5,3.456z"
android:pathData="M15.5 3.448h-7L12-0.008l3.5 3.456z"
android:strokeWidth="0.139935"
android:fillColor="#000000" />
android:fillColor="@android:color/white" />
<path
android:pathData="M3.694 17.992H0.976l4.142-12h3.27l4.136 12H9.806L6.8 8.734H6.706zm-0.17-4.717h6.422v1.98H3.524zm10.313 4.717v-1.506l5.988-8.402h-6V5.992h9.188v1.505L17.018 15.9h6.006v2.092z"
android:strokeWidth="0.4125"
android:fillColor="@android:color/white" />
</vector>

View file

@ -1,19 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorPrimary">
<path
android:pathData="m15.5,20.544c-2.3333,0 -4.6667,0 -7,0 1.1667,1.152 2.3333,2.304 3.5,3.456 1.1667,-1.152 2.3333,-2.304 3.5,-3.456z"
android:pathData="M6.542 18q-1.508-0.006-2.595-0.716-1.082-0.711-1.667-2.06-0.578-1.348-0.573-3.244 0-1.89 0.58-3.221 0.584-1.331 1.665-2.025 1.088-0.7 2.59-0.7 1.503 0 2.584 0.7 1.088 0.7 1.673 2.03 0.584 1.326 0.578 3.216 0 1.902-0.584 3.25-0.579 1.348-1.66 2.06Q8.05 18 6.542 18zm0-2.025q1.03 0 1.643-0.999 0.614-0.998 0.608-2.996 0-1.314-0.28-2.188-0.275-0.875-0.784-1.315-0.503-0.44-1.187-0.44-1.023 0-1.637 0.987-0.614 0.988-0.62 2.957 0 1.33 0.276 2.222 0.28 0.886 0.789 1.332 0.508 0.44 1.193 0.44zM17.51 6q0.924 0 1.777 0.3 0.86 0.293 1.532 0.953 0.679 0.66 1.07 1.749 0.398 1.083 0.404 2.668-0.006 1.472-0.351 2.629-0.34 1.15-0.976 1.958-0.638 0.806-1.538 1.23-0.895 0.417-2.005 0.417-1.199 0-2.117-0.446-0.918-0.45-1.479-1.224-0.555-0.779-0.672-1.749h2.496q0.146 0.632 0.614 0.982 0.468 0.344 1.158 0.344 1.169 0 1.777-0.982 0.608-0.987 0.614-2.702h-0.082Q19.463 12.635 19.007 13q-0.456 0.362-1.046 0.559-0.585 0.197-1.246 0.197-1.058 0-1.894-0.48-0.83-0.479-1.31-1.32-0.479-0.846-0.473-1.929-0.006-1.173 0.555-2.082 0.562-0.914 1.567-1.433Q16.172 5.994 17.51 6zm0.018 1.918q-0.59 0-1.053 0.271Q16.02 8.46 15.75 8.923q-0.263 0.462-0.257 1.038-0.006 0.575 0.252 1.032 0.263 0.457 0.719 0.728 0.456 0.265 1.04 0.265 0.439 0 0.807-0.158 0.374-0.158 0.65-0.434 0.28-0.282 0.438-0.65 0.158-0.372 0.163-0.795-0.005-0.558-0.269-1.02-0.263-0.463-0.725-0.734-0.461-0.277-1.04-0.277z"
android:strokeWidth="0.404319"
android:fillColor="@android:color/white"
tools:ignore="VectorPath" />
<path
android:pathData="M15.5 20.544h-7L12 24l3.5-3.456z"
android:strokeWidth="0.139935"
android:fillColor="#000000" />
<path
android:fillColor="#FF000000"
android:pathData="M6.5424,18.0001Q5.034,17.9945 3.9466,17.2836 2.865,16.5728 2.2804,15.2244 1.7016,13.876 1.7074,11.9804q0,-1.89 0.5788,-3.2214 0.5846,-1.3314 1.6662,-2.0254 1.0874,-0.6996 2.59,-0.6996 1.5025,0 2.5841,0.6996 1.0874,0.6996 1.6721,2.031 0.5846,1.3258 0.5788,3.2158 0,1.9013 -0.5846,3.2496 -0.5788,1.3484 -1.6604,2.0592 -1.0816,0.7109 -2.59,0.7109zM6.5424,15.9748q1.029,0 1.6428,-0.9986 0.6139,-0.9986 0.608,-2.9957 0,-1.3145 -0.2806,-2.189 -0.2748,-0.8745 -0.7834,-1.3145 -0.5028,-0.4401 -1.1868,-0.4401 -1.0231,0 -1.637,0.9873 -0.6139,0.9873 -0.6197,2.9563 0,1.3314 0.2748,2.2228 0.2806,0.8857 0.7893,1.3314 0.5086,0.4401 1.1927,0.4401z"
android:strokeWidth="0.404319" />
<path
android:fillColor="#FF000000"
android:pathData="m17.5102,6.0002q0.9237,0 1.7773,0.299 0.8594,0.2934 1.5318,0.9534 0.6782,0.6601 1.0699,1.7489 0.3976,1.0832 0.4034,2.6685 -0.0058,1.4725 -0.3508,2.629 -0.3391,1.1509 -0.9763,1.9577 -0.6373,0.8068 -1.5376,1.2299 -0.8945,0.4175 -2.0053,0.4175 -1.1985,0 -2.1164,-0.4457 -0.9179,-0.4513 -1.4791,-1.2243 -0.5554,-0.7786 -0.6723,-1.7489h2.4964q0.1462,0.6319 0.6139,0.9817 0.4677,0.3441 1.1576,0.3441 1.1693,0 1.7773,-0.9817 0.608,-0.9873 0.6139,-2.7024h-0.0818q-0.2689,0.5078 -0.725,0.8745 -0.456,0.3611 -1.0465,0.5585 -0.5846,0.1975 -1.2453,0.1975 -1.0582,0 -1.8942,-0.4795 -0.8302,-0.4795 -1.3096,-1.3202 -0.4794,-0.8463 -0.4736,-1.9295 -0.0058,-1.1735 0.5554,-2.0818 0.5613,-0.914 1.5668,-1.433 1.0114,-0.519 2.3503,-0.5134zM17.5278,7.9184q-0.5905,0 -1.0524,0.2708 -0.456,0.2708 -0.725,0.7334 -0.2631,0.4626 -0.2572,1.0381 -0.0058,0.5755 0.2514,1.0324 0.2631,0.457 0.7191,0.7278 0.456,0.2652 1.0407,0.2652 0.4385,0 0.8068,-0.158 0.3742,-0.158 0.6489,-0.4344 0.2806,-0.2821 0.4385,-0.6488 0.1579,-0.3724 0.1637,-0.7955 -0.0058,-0.5585 -0.2689,-1.0211 -0.2631,-0.4626 -0.725,-0.7334 -0.4619,-0.2764 -1.0407,-0.2764z"
android:strokeWidth="0.404319" />
android:fillColor="@android:color/white" />
</vector>

View file

@ -1,19 +1,19 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorPrimary">
<path
android:pathData="m15.5,3.4563c-2.3333,0 -4.6667,0 -7,0 1.1667,-1.152 2.3333,-2.304 3.5,-3.456 1.1667,1.152 2.3333,2.304 3.5,3.456z"
android:pathData="M6.542 18q-1.508-0.006-2.595-0.716-1.082-0.711-1.667-2.06-0.578-1.348-0.573-3.244 0-1.89 0.58-3.221 0.584-1.331 1.665-2.025 1.088-0.7 2.59-0.7 1.503 0 2.584 0.7 1.088 0.7 1.673 2.03 0.584 1.326 0.578 3.216 0 1.902-0.584 3.25-0.579 1.348-1.66 2.06Q8.05 18 6.542 18zm0-2.025q1.03 0 1.643-0.999 0.614-0.998 0.608-2.996 0-1.314-0.28-2.188-0.275-0.875-0.784-1.315-0.503-0.44-1.187-0.44-1.023 0-1.637 0.987-0.614 0.988-0.62 2.957 0 1.33 0.276 2.222 0.28 0.886 0.789 1.332 0.508 0.44 1.193 0.44zM17.51 6q0.924 0 1.777 0.3 0.86 0.293 1.532 0.953 0.679 0.66 1.07 1.749 0.398 1.083 0.404 2.668-0.006 1.472-0.351 2.629-0.34 1.15-0.976 1.958-0.638 0.806-1.538 1.23-0.895 0.417-2.005 0.417-1.199 0-2.117-0.446-0.918-0.45-1.479-1.224-0.555-0.779-0.672-1.749h2.496q0.146 0.632 0.614 0.982 0.468 0.344 1.158 0.344 1.169 0 1.777-0.982 0.608-0.987 0.614-2.702h-0.082Q19.463 12.635 19.007 13q-0.456 0.362-1.046 0.559-0.585 0.197-1.246 0.197-1.058 0-1.894-0.48-0.83-0.479-1.31-1.32-0.479-0.846-0.473-1.929-0.006-1.173 0.555-2.082 0.562-0.914 1.567-1.433Q16.172 5.994 17.51 6zm0.018 1.918q-0.59 0-1.053 0.271Q16.02 8.46 15.75 8.923q-0.263 0.462-0.257 1.038-0.006 0.575 0.252 1.032 0.263 0.457 0.719 0.728 0.456 0.265 1.04 0.265 0.439 0 0.807-0.158 0.374-0.158 0.65-0.434 0.28-0.282 0.438-0.65 0.158-0.372 0.163-0.795-0.005-0.558-0.269-1.02-0.263-0.463-0.725-0.734-0.461-0.277-1.04-0.277z"
android:strokeWidth="0.404319"
android:fillColor="@android:color/white"
tools:ignore="VectorPath" />
<path
android:pathData="M15.5 3.456h-7L12 0l3.5 3.456z"
android:strokeWidth="0.139935"
android:fillColor="#000000" />
<path
android:fillColor="#FF000000"
android:pathData="M6.5424,18.0001Q5.034,17.9945 3.9466,17.2836 2.865,16.5728 2.2804,15.2244 1.7016,13.876 1.7074,11.9804q0,-1.89 0.5788,-3.2214 0.5846,-1.3314 1.6662,-2.0254 1.0874,-0.6996 2.59,-0.6996 1.5025,0 2.5841,0.6996 1.0874,0.6996 1.6721,2.031 0.5846,1.3258 0.5788,3.2158 0,1.9013 -0.5846,3.2496 -0.5788,1.3484 -1.6604,2.0592 -1.0816,0.7109 -2.59,0.7109zM6.5424,15.9748q1.029,0 1.6428,-0.9986 0.6139,-0.9986 0.608,-2.9957 0,-1.3145 -0.2806,-2.189 -0.2748,-0.8745 -0.7834,-1.3145 -0.5028,-0.4401 -1.1868,-0.4401 -1.0231,0 -1.637,0.9873 -0.6139,0.9873 -0.6197,2.9563 0,1.3314 0.2748,2.2228 0.2806,0.8857 0.7893,1.3314 0.5086,0.4401 1.1927,0.4401z"
android:strokeWidth="0.404319" />
<path
android:fillColor="#FF000000"
android:pathData="m17.5102,6.0002q0.9237,0 1.7773,0.299 0.8594,0.2934 1.5318,0.9534 0.6782,0.6601 1.0699,1.7489 0.3976,1.0832 0.4034,2.6685 -0.0058,1.4725 -0.3508,2.629 -0.3391,1.1509 -0.9763,1.9577 -0.6373,0.8068 -1.5376,1.2299 -0.8945,0.4175 -2.0053,0.4175 -1.1985,0 -2.1164,-0.4457 -0.9179,-0.4513 -1.4791,-1.2243 -0.5554,-0.7786 -0.6723,-1.7489h2.4964q0.1462,0.6319 0.6139,0.9817 0.4677,0.3441 1.1576,0.3441 1.1693,0 1.7773,-0.9817 0.608,-0.9873 0.6139,-2.7024h-0.0818q-0.2689,0.5078 -0.725,0.8745 -0.456,0.3611 -1.0465,0.5585 -0.5846,0.1975 -1.2453,0.1975 -1.0582,0 -1.8942,-0.4795 -0.8302,-0.4795 -1.3096,-1.3202 -0.4794,-0.8463 -0.4736,-1.9295 -0.0058,-1.1735 0.5554,-2.0818 0.5613,-0.914 1.5668,-1.433 1.0114,-0.519 2.3503,-0.5134zM17.5278,7.9184q-0.5905,0 -1.0524,0.2708 -0.456,0.2708 -0.725,0.7334 -0.2631,0.4626 -0.2572,1.0381 -0.0058,0.5755 0.2514,1.0324 0.2631,0.457 0.7191,0.7278 0.456,0.2652 1.0407,0.2652 0.4385,0 0.8068,-0.158 0.3742,-0.158 0.6489,-0.4344 0.2806,-0.2821 0.4385,-0.6488 0.1579,-0.3724 0.1637,-0.7955 -0.0058,-0.5585 -0.2689,-1.0211 -0.2631,-0.4626 -0.725,-0.7334 -0.4619,-0.2764 -1.0407,-0.2764z"
android:strokeWidth="0.404319" />
android:fillColor="@android:color/white" />
</vector>

View file

@ -26,6 +26,7 @@
android:background="?android:attr/windowBackground"
android:elevation="@dimen/elevation_normal"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold"
app:navigationIcon="@drawable/ic_back"
app:title="@string/title_library_fragment" />
<androidx.core.widget.NestedScrollView

View file

@ -26,6 +26,7 @@
android:background="?android:attr/windowBackground"
android:elevation="@dimen/elevation_normal"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold"
app:navigationIcon="@drawable/ic_back"
app:title="@string/title_library_fragment" />
<androidx.core.widget.NestedScrollView