Enable albums on LibraryFragment
Readd album support to LibraryFragment.
This commit is contained in:
parent
fddf5e4472
commit
f754a82ba7
5 changed files with 53 additions and 19 deletions
|
@ -21,9 +21,6 @@ import org.oxycblt.auxio.theme.toColor
|
|||
class MainFragment : Fragment() {
|
||||
private val shownFragments = listOf(0, 1)
|
||||
|
||||
private val libraryFragment: LibraryFragment by lazy { LibraryFragment() }
|
||||
private val songsFragment: SongsFragment by lazy { SongsFragment() }
|
||||
|
||||
private val tabIcons = listOf(
|
||||
R.drawable.ic_library,
|
||||
R.drawable.ic_song
|
||||
|
@ -81,10 +78,10 @@ class MainFragment : Fragment() {
|
|||
|
||||
private fun fragmentAt(position: Int): Fragment {
|
||||
return when (position) {
|
||||
0 -> libraryFragment
|
||||
1 -> songsFragment
|
||||
0 -> LibraryFragment()
|
||||
1 -> SongsFragment()
|
||||
|
||||
else -> libraryFragment
|
||||
else -> SongsFragment()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,13 +96,14 @@ class MainFragment : Fragment() {
|
|||
return fragmentAt(position)
|
||||
}
|
||||
|
||||
// Not sure how this would happen but it might
|
||||
// If a fragment that shouldn't be shown is somehow shown anyway, just return
|
||||
// its intended fragment.
|
||||
Log.e(
|
||||
this::class.simpleName,
|
||||
"Attempted to index a fragment that shouldn't be shown. Returning libraryFragment."
|
||||
"Attempted to index a fragment that shouldn't be shown."
|
||||
)
|
||||
|
||||
return libraryFragment
|
||||
return fragmentAt(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,14 +10,20 @@ import androidx.fragment.app.activityViewModels
|
|||
import androidx.navigation.fragment.findNavController
|
||||
import org.oxycblt.auxio.MainFragmentDirections
|
||||
import org.oxycblt.auxio.databinding.FragmentLibraryBinding
|
||||
import org.oxycblt.auxio.library.adapters.AlbumAdapter
|
||||
import org.oxycblt.auxio.library.adapters.ArtistAdapter
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.music.models.Album
|
||||
import org.oxycblt.auxio.music.models.Artist
|
||||
import org.oxycblt.auxio.recycler.ClickListener
|
||||
import org.oxycblt.auxio.theme.SHOW_ARTISTS
|
||||
import org.oxycblt.auxio.theme.applyDivider
|
||||
|
||||
class LibraryFragment : Fragment() {
|
||||
|
||||
// FIXME: Temp value, remove when there are actual preferences
|
||||
private val libraryMode = SHOW_ARTISTS
|
||||
|
||||
private val musicModel: MusicViewModel by activityViewModels()
|
||||
private val libraryModel: LibraryViewModel by activityViewModels()
|
||||
|
||||
|
@ -28,12 +34,21 @@ class LibraryFragment : Fragment() {
|
|||
): View? {
|
||||
val binding = FragmentLibraryBinding.inflate(inflater)
|
||||
|
||||
binding.libraryRecycler.adapter = ArtistAdapter(
|
||||
musicModel.artists.value!!,
|
||||
ClickListener {
|
||||
navToArtist(it)
|
||||
}
|
||||
)
|
||||
binding.libraryRecycler.adapter = when (libraryMode) {
|
||||
SHOW_ARTISTS -> ArtistAdapter(
|
||||
musicModel.artists.value!!,
|
||||
ClickListener {
|
||||
navToArtist(it)
|
||||
}
|
||||
)
|
||||
|
||||
else -> AlbumAdapter(
|
||||
musicModel.albums.value!!,
|
||||
ClickListener {
|
||||
navToAlbum(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
binding.libraryRecycler.applyDivider()
|
||||
binding.libraryRecycler.setHasFixedSize(true)
|
||||
|
@ -50,12 +65,26 @@ class LibraryFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun navToArtist(artist: Artist) {
|
||||
// Don't navigate if an item already has been selected.
|
||||
// Dont navigate if an item has already been selected
|
||||
if (!libraryModel.isAlreadyNavigating) {
|
||||
libraryModel.isAlreadyNavigating = true
|
||||
|
||||
findNavController().navigate(
|
||||
MainFragmentDirections.actionShowArtist(artist.id)
|
||||
MainFragmentDirections.actionShowArtist(
|
||||
artist.id
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun navToAlbum(album: Album) {
|
||||
if (!libraryModel.isAlreadyNavigating) {
|
||||
libraryModel.isAlreadyNavigating = true
|
||||
|
||||
findNavController().navigate(
|
||||
MainFragmentDirections.actionShowAlbum(
|
||||
album.id
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,6 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
|||
}
|
||||
|
||||
// Force an error screen if the permissions are denied or the prompt needs to be shown.
|
||||
// This should be in MusicRepository, but the response comes faster than the view creation
|
||||
// itself and therefore causes the error screen to not appear.
|
||||
if (checkPerms()) {
|
||||
onNoPerms()
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package org.oxycblt.auxio.theme
|
||||
|
||||
// Preference Constants
|
||||
const val SHOW_ARTISTS = 0
|
||||
const val SHOW_ALBUMS = 1
|
||||
const val SHOW_GENRES = 2
|
|
@ -33,6 +33,9 @@
|
|||
app:popExitAnim="@anim/fragment_fade_exit"
|
||||
app:destination="@id/artist_detail_fragment"
|
||||
app:launchSingleTop="true" />
|
||||
<action
|
||||
android:id="@+id/action_show_album"
|
||||
app:destination="@id/album_detail_fragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/artist_detail_fragment"
|
||||
|
|
Loading…
Reference in a new issue