[Android] Use constants for MediaItemDetailsFragment extras

Nicolas Pomepuy git at videolan.org
Wed Feb 9 14:56:39 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Feb  9 08:02:01 2022 +0100| [9ad3e7dfde5598b7c88a439f444ad2f14e621ecf] | committer: Nicolas Pomepuy

Use constants for MediaItemDetailsFragment extras

> https://code.videolan.org/videolan/vlc-android/commit/9ad3e7dfde5598b7c88a439f444ad2f14e621ecf
---

 .../main/java/org/videolan/television/ui/MainTvFragment.kt   |  7 ++-----
 .../org/videolan/television/ui/MediaItemDetailsFragment.kt   | 12 +++++++-----
 .../src/main/java/org/videolan/television/ui/TvUtil.kt       |  4 ++--
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt b/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
index 61f5e9060..8aca81e5a 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
@@ -30,10 +30,8 @@ import androidx.leanback.app.BackgroundManager
 import androidx.leanback.app.BrowseSupportFragment
 import androidx.leanback.widget.*
 import androidx.lifecycle.lifecycleScope
-import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi
-import kotlinx.coroutines.launch
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
@@ -55,7 +53,6 @@ import org.videolan.vlc.gui.helpers.UiTools.showDonations
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.reloadLibrary
 import org.videolan.vlc.util.Permissions
-import org.videolan.vlc.util.cleanupWatchNextList
 
 private const val TAG = "VLC/MainTvFragment"
 
@@ -293,8 +290,8 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
         if (media.type != MediaWrapper.TYPE_DIR) return false
         val intent = Intent(requireActivity(), DetailsActivity::class.java)
         // pass the item information
-        intent.putExtra("media", media)
-        intent.putExtra("item", MediaItemDetails(media.title, media.artist, media.album, media.location, media.artworkURL))
+        intent.putExtra(EXTRA_MEDIA, media)
+        intent.putExtra(EXTRA_ITEM, MediaItemDetails(media.title, media.artist, media.album, media.location, media.artworkURL))
         startActivity(intent)
         return true
     }
diff --git a/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt b/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
index 1309a5eed..c563da7f3 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
@@ -84,6 +84,8 @@ private const val ID_REMOVE_FROM_HISTORY = 12
 private const val ID_NAVIGATE_PARENT = 13
 private const val ID_FAVORITE_EDIT = 14
 const val EXTRA_FROM_HISTORY = "from_history"
+const val EXTRA_ITEM = "item"
+const val EXTRA_MEDIA = "media"
 
 @ExperimentalCoroutinesApi
 @ObsoleteCoroutinesApi
@@ -126,10 +128,10 @@ class MediaItemDetailsFragment : DetailsSupportFragment(), CoroutineScope by Mai
         arrayObjectAdapterPosters = ArrayObjectAdapter(MediaImageCardPresenter(requireActivity(), MediaImageType.POSTER))
 
         val extras = requireActivity().intent.extras ?: savedInstanceState ?: return
-        viewModel.mediaItemDetails = extras.getParcelable("item") ?: return
-        val hasMedia = extras.containsKey("media")
+        viewModel.mediaItemDetails = extras.getParcelable(EXTRA_ITEM) ?: return
+        val hasMedia = extras.containsKey(org.videolan.television.ui.EXTRA_MEDIA)
         fromHistory = extras.getBoolean(EXTRA_FROM_HISTORY, false)
-        val media = (extras.getParcelable<Parcelable>("media")
+        val media = (extras.getParcelable<Parcelable>(org.videolan.television.ui.EXTRA_MEDIA)
                 ?: MLServiceLocator.getAbstractMediaWrapper(AndroidUtil.LocationToUri(viewModel.mediaItemDetails.location))) as MediaWrapper
 
         viewModel.media = media
@@ -171,8 +173,8 @@ class MediaItemDetailsFragment : DetailsSupportFragment(), CoroutineScope by Mai
     }
 
     override fun onSaveInstanceState(outState: Bundle) {
-        outState.putParcelable("item", viewModel.mediaItemDetails)
-        outState.putParcelable("media", viewModel.media)
+        outState.putParcelable(EXTRA_ITEM, viewModel.mediaItemDetails)
+        outState.putParcelable(org.videolan.television.ui.EXTRA_MEDIA, viewModel.media)
         super.onSaveInstanceState(outState)
     }
 
diff --git a/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt b/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
index ef6a46b4a..d409f3166 100644
--- a/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
@@ -296,7 +296,7 @@ object TvUtil {
         when (mediaLibraryItem.itemType) {
             MediaLibraryItem.TYPE_ALBUM, MediaLibraryItem.TYPE_PLAYLIST -> {
                 val intent = Intent(context, MediaListActivity::class.java)
-                intent.putExtra(ITEM, mediaLibraryItem)
+                intent.putExtra(EXTRA_ITEM, mediaLibraryItem)
                 context.startActivity(intent)
             }
             MediaLibraryItem.TYPE_MEDIA -> {
@@ -305,7 +305,7 @@ object TvUtil {
             }
             else -> {
                 val intent = Intent(context, VerticalGridActivity::class.java)
-                intent.putExtra(ITEM, mediaLibraryItem)
+                intent.putExtra(EXTRA_ITEM, mediaLibraryItem)
                 intent.putExtra(CATEGORY, CATEGORY_ALBUMS)
                 intent.putExtra(MainTvActivity.BROWSER_TYPE, HEADER_CATEGORIES)
                 context.startActivity(intent)



More information about the Android mailing list