Add backwards navigation from album to artist
Add a way for AlbumDetailFragment to return to ArtistDetailFragment.
This commit is contained in:
parent
a81860bed2
commit
19a9ab4098
6 changed files with 53 additions and 5 deletions
|
@ -24,5 +24,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// I wish I knew somewhere else to put this
|
// RecyclerView click listener
|
||||||
|
// Dont ask why its here
|
||||||
class ClickListener<T>(val onClick: (T) -> Unit)
|
class ClickListener<T>(val onClick: (T) -> Unit)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.navigation.fragment.navArgs
|
import androidx.navigation.fragment.navArgs
|
||||||
import org.oxycblt.auxio.ClickListener
|
import org.oxycblt.auxio.ClickListener
|
||||||
import org.oxycblt.auxio.databinding.FragmentAlbumDetailBinding
|
import org.oxycblt.auxio.databinding.FragmentAlbumDetailBinding
|
||||||
|
@ -17,6 +18,7 @@ import org.oxycblt.auxio.theme.applyDivider
|
||||||
class AlbumDetailFragment : Fragment() {
|
class AlbumDetailFragment : Fragment() {
|
||||||
|
|
||||||
private val args: AlbumDetailFragmentArgs by navArgs()
|
private val args: AlbumDetailFragmentArgs by navArgs()
|
||||||
|
private val detailModel: DetailViewModel by activityViewModels()
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
@ -31,6 +33,7 @@ class AlbumDetailFragment : Fragment() {
|
||||||
val album = musicModel.albums.value?.find { it.id == args.albumId }!!
|
val album = musicModel.albums.value?.find { it.id == args.albumId }!!
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
binding.detailModel = detailModel
|
||||||
binding.album = album
|
binding.album = album
|
||||||
|
|
||||||
binding.songRecycler.adapter = DetailSongAdapter(
|
binding.songRecycler.adapter = DetailSongAdapter(
|
||||||
|
@ -42,6 +45,16 @@ class AlbumDetailFragment : Fragment() {
|
||||||
binding.songRecycler.applyDivider()
|
binding.songRecycler.applyDivider()
|
||||||
binding.songRecycler.setHasFixedSize(true)
|
binding.songRecycler.setHasFixedSize(true)
|
||||||
|
|
||||||
|
detailModel.navToParentArtist.observe(viewLifecycleOwner) {
|
||||||
|
if (it) {
|
||||||
|
findNavController().navigate(
|
||||||
|
AlbumDetailFragmentDirections.actionShowParentArtist(album.artist.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
detailModel.doneWithNavToParent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log.d(this::class.simpleName, "Fragment created.")
|
Log.d(this::class.simpleName, "Fragment created.")
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
|
|
|
@ -1,7 +1,20 @@
|
||||||
package org.oxycblt.auxio.detail
|
package org.oxycblt.auxio.detail
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
class DetailViewModel : ViewModel() {
|
class DetailViewModel : ViewModel() {
|
||||||
var isAlreadyNavigating = false
|
var isAlreadyNavigating = false
|
||||||
|
|
||||||
|
private val mNavToParentArtist = MutableLiveData<Boolean>()
|
||||||
|
val navToParentArtist: LiveData<Boolean> get() = mNavToParentArtist
|
||||||
|
|
||||||
|
fun navToParent() {
|
||||||
|
mNavToParentArtist.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doneWithNavToParent() {
|
||||||
|
mNavToParentArtist.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,8 @@ fun String.toNamedGenre(): String? {
|
||||||
PAREN_FILTER.indexOf(it) > -1
|
PAREN_FILTER.indexOf(it) > -1
|
||||||
}.toInt()
|
}.toInt()
|
||||||
|
|
||||||
|
// If the conversion fails [Due to the genre using an extension that isn't from winamp],
|
||||||
|
// then return null.
|
||||||
return ID3_GENRES.getOrNull(intGenre)
|
return ID3_GENRES.getOrNull(intGenre)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
<variable
|
<variable
|
||||||
name="album"
|
name="album"
|
||||||
type="org.oxycblt.auxio.music.models.Album" />
|
type="org.oxycblt.auxio.music.models.Album" />
|
||||||
|
|
||||||
|
<variable
|
||||||
|
name="detailModel"
|
||||||
|
type="org.oxycblt.auxio.detail.DetailViewModel" />
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -69,10 +73,14 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/artist_name"
|
android:id="@+id/artist_name"
|
||||||
|
android:background="@drawable/ripple"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:onClick="@{() -> detailModel.navToParent()}"
|
||||||
android:layout_marginStart="@dimen/margin_medium"
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
android:text="@{album.artist.name}"
|
android:text="@{album.artist.name}"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
|
@ -13,9 +13,12 @@
|
||||||
android:id="@+id/action_to_main"
|
android:id="@+id/action_to_main"
|
||||||
app:destination="@id/main_fragment"
|
app:destination="@id/main_fragment"
|
||||||
app:enterAnim="@anim/fragment_fade_enter"
|
app:enterAnim="@anim/fragment_fade_enter"
|
||||||
app:exitAnim="@anim/fragment_open_exit"
|
app:exitAnim="@anim/fragment_fade_exit"
|
||||||
|
app:popEnterAnim="@anim/fragment_fade_enter"
|
||||||
|
app:popExitAnim="@anim/fragment_fade_exit"
|
||||||
app:popUpTo="@id/loading_fragment"
|
app:popUpTo="@id/loading_fragment"
|
||||||
app:popUpToInclusive="true" />
|
app:popUpToInclusive="true"
|
||||||
|
app:launchSingleTop="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/main_fragment"
|
android:id="@+id/main_fragment"
|
||||||
|
@ -24,11 +27,12 @@
|
||||||
tools:layout="@layout/fragment_main">
|
tools:layout="@layout/fragment_main">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_show_artist"
|
android:id="@+id/action_show_artist"
|
||||||
app:destination="@id/artist_detail_fragment"
|
|
||||||
app:enterAnim="@anim/fragment_fade_enter"
|
app:enterAnim="@anim/fragment_fade_enter"
|
||||||
app:exitAnim="@anim/fragment_fade_exit"
|
app:exitAnim="@anim/fragment_fade_exit"
|
||||||
app:popEnterAnim="@anim/fragment_fade_enter"
|
app:popEnterAnim="@anim/fragment_fade_enter"
|
||||||
app:popExitAnim="@anim/fragment_fade_exit" />
|
app:popExitAnim="@anim/fragment_fade_exit"
|
||||||
|
app:destination="@id/artist_detail_fragment"
|
||||||
|
app:launchSingleTop="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/artist_detail_fragment"
|
android:id="@+id/artist_detail_fragment"
|
||||||
|
@ -54,5 +58,12 @@
|
||||||
<argument
|
<argument
|
||||||
android:name="albumId"
|
android:name="albumId"
|
||||||
app:argType="long" />
|
app:argType="long" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_show_parent_artist"
|
||||||
|
app:enterAnim="@anim/fragment_fade_enter"
|
||||||
|
app:exitAnim="@anim/fragment_fade_exit"
|
||||||
|
app:popEnterAnim="@anim/fragment_fade_enter"
|
||||||
|
app:popExitAnim="@anim/fragment_fade_exit"
|
||||||
|
app:destination="@id/artist_detail_fragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
Loading…
Reference in a new issue