[Android] ContextSheet: add cover when in albums

Duncan McNamara git at videolan.org
Wed May 18 09:50:19 UTC 2022


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Thu Apr  7 17:22:27 2022 +0200| [19e5af9daaca4139bd8bb02547424ff0c66b7b51] | committer: Duncan McNamara

ContextSheet: add cover when in albums

> https://code.videolan.org/videolan/vlc-android/commit/19e5af9daaca4139bd8bb02547424ff0c66b7b51
---

 .../vlc-android/res/layout/contextual_sheet.xml    | 62 +++++++++++++++++++---
 .../org/videolan/vlc/gui/dialogs/ContextSheet.kt   | 25 ++++++++-
 2 files changed, 79 insertions(+), 8 deletions(-)

diff --git a/application/vlc-android/res/layout/contextual_sheet.xml b/application/vlc-android/res/layout/contextual_sheet.xml
index ade8f3c6f..3e3104dc6 100644
--- a/application/vlc-android/res/layout/contextual_sheet.xml
+++ b/application/vlc-android/res/layout/contextual_sheet.xml
@@ -1,26 +1,74 @@
 <?xml version="1.0" encoding="utf-8"?>
 <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent">
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
 
     <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="vertical"
-            android:paddingBottom="16dp">
+            app:layout_goneMarginStart="16dp">
 
-        <TextView
-                android:id="@+id/ctx_title"
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:id="@+id/ctx_cover_layout"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:visibility="gone"
+            tools:visibility="visible"
+            >
+
+            <androidx.cardview.widget.CardView
+                android:id="@+id/ctx_cover_card"
+                android:layout_width="@dimen/audio_cover"
+                android:layout_height="@dimen/audio_cover"
+                app:layout_constraintTop_toTopOf="parent"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintStart_toStartOf="parent"
+                app:cardCornerRadius="4dp"
+                android:layout_margin="@dimen/default_margin"
+                >
+
+                <ImageView
+                    android:id="@+id/ctx_cover"
+                    style="@style/Theme.VLC.BottomSheetTitle"
+                    android:layout_width="@dimen/audio_cover"
+                    android:layout_height="@dimen/audio_cover"
+                    android:scaleType="centerCrop"
+                    />
+
+            </androidx.cardview.widget.CardView>
+
+            <TextView
+                android:id="@+id/ctx_cover_title"
                 style="@style/Theme.VLC.BottomSheetTitle"
-                android:layout_width="wrap_content"
+                android:layout_width="0dp"
                 android:layout_height="wrap_content"
+                app:layout_constraintStart_toEndOf="@id/ctx_cover_card"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintTop_toTopOf="@id/ctx_cover_card"
+                app:layout_constraintBottom_toBottomOf="@id/ctx_cover_card"
                 android:paddingLeft="16dp"
-                android:paddingRight="16dp" />
+                android:paddingRight="16dp"
+                />
+
+        </androidx.constraintlayout.widget.ConstraintLayout>
+
+        <TextView
+            android:id="@+id/ctx_title"
+            style="@style/Theme.VLC.BottomSheetTitle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:paddingLeft="16dp"
+            android:paddingRight="16dp"
+            />
 
         <androidx.recyclerview.widget.RecyclerView
                 android:id="@+id/ctx_list"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content" />
+
     </LinearLayout>
 
 </androidx.core.widget.NestedScrollView>
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
index 2681b7389..361a0f530 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
@@ -24,14 +24,18 @@ import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.widget.ImageView
 import android.widget.TextView
+import androidx.constraintlayout.widget.ConstraintLayout
 import androidx.core.content.ContextCompat
+import androidx.core.net.toUri
 import androidx.core.content.pm.ShortcutManagerCompat
 import androidx.core.os.bundleOf
 import androidx.fragment.app.FragmentActivity
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
+import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.resources.*
 import org.videolan.tools.isStarted
 import org.videolan.vlc.R
@@ -40,6 +44,7 @@ import org.videolan.vlc.databinding.ContextItemBinding
 const val CTX_TITLE_KEY = "CTX_TITLE_KEY"
 const val CTX_POSITION_KEY = "CTX_POSITION_KEY"
 const val CTX_FLAGS_KEY = "CTX_FLAGS_KEY"
+const val CTX_MEDIA_KEY = "CTX_MEDIA_KEY"
 
 class ContextSheet : VLCBottomSheetDialogFragment() {
     override fun getDefaultState(): Int = STATE_EXPANDED
@@ -78,7 +83,16 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
 
     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
         super.onViewCreated(view, savedInstanceState)
-        view.findViewById<TextView>(R.id.ctx_title).text = arguments?.getString(CTX_TITLE_KEY) ?: ""
+        if (arguments?.containsKey(CTX_TITLE_KEY) == true) {
+            view.findViewById<TextView>(R.id.ctx_title).text = arguments?.getString(CTX_TITLE_KEY) ?: ""
+        } else if (arguments?.containsKey(CTX_MEDIA_KEY) == true) {
+            val media: MediaWrapper = arguments?.get(CTX_MEDIA_KEY) as MediaWrapper
+            view.findViewById<TextView>(R.id.ctx_title).visibility = View.GONE
+            view.findViewById<ConstraintLayout>(R.id.ctx_cover_layout).visibility = View.VISIBLE
+            view.findViewById<TextView>(R.id.ctx_cover_title).text = media.title
+            val cover = view.findViewById<ImageView>(R.id.ctx_cover)
+            cover.setImageURI(media.artworkURL.toUri())
+        }
         list = view.findViewById<RecyclerView>(R.id.ctx_list)
         list.layoutManager = LinearLayoutManager(requireContext())
         list.adapter = ContextAdapter()
@@ -164,4 +178,13 @@ fun showContext(activity: FragmentActivity, receiver: CtxActionReceiver, positio
         CTX_FLAGS_KEY to flags)
     ctxDialog.receiver = receiver
     ctxDialog.show(activity.supportFragmentManager, "context")
+}
+
+fun showContext(activity: FragmentActivity, receiver: CtxActionReceiver, position: Int, media: MediaWrapper, flags: Long) {
+    if (!activity.isStarted()) return
+    val ctxDialog = ContextSheet()
+    ctxDialog.arguments = bundleOf(CTX_MEDIA_KEY to media, CTX_POSITION_KEY to position,
+        CTX_FLAGS_KEY to flags)
+    ctxDialog.receiver = receiver
+    ctxDialog.show(activity.supportFragmentManager, "context")
 }
\ No newline at end of file



More information about the Android mailing list