Update album artist navigation

Make it so that when an album is navigated to from an artist, navigation to the parent artist is disabled.
This commit is contained in:
OxygenCobalt
2021-01-05 08:29:29 -07:00
parent d5f28cf374
commit 35db7792bb
14 changed files with 80 additions and 48 deletions
@@ -86,9 +86,7 @@ class AlbumDetailFragment : DetailFragment() {
detailModel.navToParent.observe(viewLifecycleOwner) {
if (it) {
if (args.fromArtist) {
findNavController().navigateUp()
} else {
if (!args.fromArtist) {
findNavController().navigate(
AlbumDetailFragmentDirections.actionShowParentArtist(
detailModel.currentAlbum.value!!.artist.id
@@ -12,6 +12,7 @@ import org.oxycblt.auxio.recycler.SortMode
/**
* ViewModel that stores data for the [DetailFragment]s, such as what they're showing & what
* [SortMode] they are currently on.
* TODO: Preserve previous backstack when doing playing item navigation
*/
class DetailViewModel : ViewModel() {
private var mIsNavigating = false
@@ -9,7 +9,7 @@ import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentLoadingBinding
@@ -23,7 +23,8 @@ import org.oxycblt.auxio.music.processing.MusicLoader
* @author OxygenCobalt
*/
class LoadingFragment : Fragment(R.layout.fragment_loading) {
private val loadingModel: LoadingViewModel by activityViewModels {
// LoadingViewModel is scoped to this fragment only
private val loadingModel: LoadingViewModel by viewModels {
LoadingViewModel.Factory(requireActivity().application)
}
@@ -86,7 +86,7 @@ class LoadingViewModel(private val app: Application) : ViewModel() {
* Factory for [LoadingViewModel] instances.
*/
class Factory(private val application: Application) : ViewModelProvider.Factory {
@Suppress("unchecked_cast")
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(LoadingViewModel::class.java)) {
return LoadingViewModel(application) as T
@@ -17,12 +17,13 @@ import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.playback.state.PlaybackMode
/**
* A wrapper around [PopupMenu] that automates a ton of things across all the menus in Auxio
* A wrapper around [PopupMenu] that automates the menu creation for nearly every datatype in Auxio.
* @param activity [AppCompatActivity] required as both a context and ViewModelStore owner.
* @param anchor [View] This should be centered around
* @param data [BaseModel] this menu corresponds to
* @param flag Any extra flags to accompany the data.
* @param flag (Optional, defaults to [FLAG_NONE]) Any extra flags to accompany the data.
* See [FLAG_NONE], [FLAG_IN_ALBUM], [FLAG_IN_ARTIST] and [FLAG_IN_GENRE] for more details.
* @throws IllegalArgumentException When there is no menu for this specific datatype/flag
*/
class ActionMenu(
activity: AppCompatActivity,
@@ -32,6 +33,7 @@ class ActionMenu(
) : PopupMenu(activity, anchor) {
private val context = activity.applicationContext
// Get viewmodels using the activity as the store owner
private val detailModel: DetailViewModel by lazy {
ViewModelProvider(activity).get(DetailViewModel::class.java)
}
@@ -43,7 +45,9 @@ class ActionMenu(
init {
val menuRes = determineMenu()
check(menuRes != -1) { "There is no menu associated with this configuration." }
check(menuRes != -1) {
"There is no menu associated with datatype ${data::class.simpleName} and flag $flag"
}
inflate(menuRes)
setOnMenuItemClickListener {
@@ -158,11 +162,11 @@ class ActionMenu(
companion object {
/** No Flags **/
const val FLAG_NONE = -1
/** Flag for when an item is accessed from an artist **/
/** Flag for when a menu is opened from an artist (See [org.oxycblt.auxio.detail.ArtistDetailFragment]) **/
const val FLAG_IN_ARTIST = 0
/** Flag for when an item is accessed from an album **/
/** Flag for when a menu is opened from an album (See [org.oxycblt.auxio.detail.AlbumDetailFragment]) **/
const val FLAG_IN_ALBUM = 1
/** Flag or when an item is accessed from a genre **/
/** Flag for when a menu is opened from a genre (See [org.oxycblt.auxio.detail.GenreDetailFragment]) **/
const val FLAG_IN_GENRE = 2
}
}