Twelve: AudioBottomSheetDialogFragment: Add genre shortcut

Change-Id: I40f6f1db4f66cd708878824df02ecc1b4de3f9ce
diff --git a/app/src/main/java/org/lineageos/twelve/fragments/AudioBottomSheetDialogFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/AudioBottomSheetDialogFragment.kt
index 176f042..4ab883d 100644
--- a/app/src/main/java/org/lineageos/twelve/fragments/AudioBottomSheetDialogFragment.kt
+++ b/app/src/main/java/org/lineageos/twelve/fragments/AudioBottomSheetDialogFragment.kt
@@ -47,6 +47,7 @@
     private val fullscreenLoadingProgressBar by getViewProperty<FullscreenLoadingProgressBar>(R.id.fullscreenLoadingProgressBar)
     private val openAlbumListItem by getViewProperty<ListItem>(R.id.openAlbumListItem)
     private val openArtistListItem by getViewProperty<ListItem>(R.id.openArtistListItem)
+    private val openGenreListItem by getViewProperty<ListItem>(R.id.openGenreListItem)
     private val playNextListItem by getViewProperty<ListItem>(R.id.playNextListItem)
     private val removeFromPlaylistListItem by getViewProperty<ListItem>(R.id.removeFromPlaylistListItem)
     private val titleTextView by getViewProperty<TextView>(R.id.titleTextView)
@@ -58,6 +59,8 @@
         get() = requireArguments().getBoolean(ARG_FROM_ALBUM)
     private val fromArtist: Boolean
         get() = requireArguments().getBoolean(ARG_FROM_ARTIST)
+    private val fromGenre: Boolean
+        get() = requireArguments().getBoolean(ARG_FROM_GENRE)
     private val playlistUri: Uri?
         get() = requireArguments().getParcelable(ARG_PLAYLIST_URI, Uri::class)
 
@@ -143,6 +146,16 @@
                             ArtistFragment.createBundle(audio.artistUri)
                         )
                     }
+
+                    openGenreListItem.isVisible = !fromGenre && audio.genreUri != null
+                    openGenreListItem.setOnClickListener {
+                        audio.genreUri?.let { genreUri ->
+                            findNavController().navigate(
+                                R.id.action_audioBottomSheetDialogFragment_to_fragment_genre,
+                                GenreFragment.createBundle(genreUri)
+                            )
+                        }
+                    }
                 }
 
                 is RequestStatus.Error -> {
@@ -163,6 +176,7 @@
         private const val ARG_AUDIO_URI = "audio_uri"
         private const val ARG_FROM_ALBUM = "from_album"
         private const val ARG_FROM_ARTIST = "from_artist"
+        private const val ARG_FROM_GENRE = "from_genre"
         private const val ARG_PLAYLIST_URI = "playlist_uri"
 
         /**
@@ -170,17 +184,20 @@
          * @param audioUri The URI of the audio to display
          * @param fromAlbum Whether this fragment was opened from an album
          * @param fromArtist Whether this fragment was opened from an artist
+         * @param fromGenre Whether this fragment was opened from a genre
          * @param playlistUri If the audio has been opened from a playlist, the URI of the playlist
          */
         fun createBundle(
             audioUri: Uri,
             fromAlbum: Boolean = false,
             fromArtist: Boolean = false,
+            fromGenre: Boolean = false,
             playlistUri: Uri? = null,
         ) = bundleOf(
             ARG_AUDIO_URI to audioUri,
             ARG_FROM_ALBUM to fromAlbum,
             ARG_FROM_ARTIST to fromArtist,
+            ARG_FROM_GENRE to fromGenre,
             ARG_PLAYLIST_URI to playlistUri,
         )
     }
diff --git a/app/src/main/java/org/lineageos/twelve/fragments/GenreFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/GenreFragment.kt
index 9fc07bc..38678b6 100644
--- a/app/src/main/java/org/lineageos/twelve/fragments/GenreFragment.kt
+++ b/app/src/main/java/org/lineageos/twelve/fragments/GenreFragment.kt
@@ -144,7 +144,10 @@
                     item?.let {
                         findNavController().navigate(
                             R.id.action_genreFragment_to_fragment_audio_bottom_sheet_dialog,
-                            AudioBottomSheetDialogFragment.createBundle(it.uri)
+                            AudioBottomSheetDialogFragment.createBundle(
+                                it.uri,
+                                fromGenre = true,
+                            )
                         )
 
                         true
diff --git a/app/src/main/res/layout/fragment_audio_bottom_sheet_dialog.xml b/app/src/main/res/layout/fragment_audio_bottom_sheet_dialog.xml
index 0f1b7af..ae6f920 100644
--- a/app/src/main/res/layout/fragment_audio_bottom_sheet_dialog.xml
+++ b/app/src/main/res/layout/fragment_audio_bottom_sheet_dialog.xml
@@ -92,6 +92,13 @@
             app:headlineText="@string/open_artist"
             app:leadingIconImage="@drawable/ic_person" />
 
+        <org.lineageos.twelve.ui.views.ListItem
+            android:id="@+id/openGenreListItem"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            app:headlineText="@string/open_genre"
+            app:leadingIconImage="@drawable/ic_genres" />
+
     </LinearLayout>
 
     <org.lineageos.twelve.ui.views.FullscreenLoadingProgressBar
diff --git a/app/src/main/res/navigation/fragment_audio_bottom_sheet_dialog.xml b/app/src/main/res/navigation/fragment_audio_bottom_sheet_dialog.xml
index 23e96fb..5419479 100644
--- a/app/src/main/res/navigation/fragment_audio_bottom_sheet_dialog.xml
+++ b/app/src/main/res/navigation/fragment_audio_bottom_sheet_dialog.xml
@@ -38,6 +38,14 @@
             app:popEnterAnim="@anim/nav_default_pop_enter_anim"
             app:popExitAnim="@anim/nav_default_pop_exit_anim" />
 
+        <action
+            android:id="@+id/action_audioBottomSheetDialogFragment_to_fragment_genre"
+            app:destination="@+id/fragment_genre"
+            app:enterAnim="@anim/nav_default_enter_anim"
+            app:exitAnim="@anim/nav_default_exit_anim"
+            app:popEnterAnim="@anim/nav_default_pop_enter_anim"
+            app:popExitAnim="@anim/nav_default_pop_exit_anim" />
+
     </dialog>
 
 </navigation>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a5b4542..94584a7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -67,6 +67,7 @@
     <string name="audio_add_or_remove_from_playlists">Add or remove from playlists</string>
     <string name="open_album">Open album</string>
     <string name="open_artist">Open artist</string>
+    <string name="open_genre">Open genre</string>
 
     <!-- Playlist fragment -->
     <string name="playlist_tracks_info">%1$d tracks, %2$d minutes</string>