[Android] Fix HeaderMediaListActivity top margin and editor

Nicolas Pomepuy git at videolan.org
Thu Jan 26 09:37:24 UTC 2023


vlc-android | branch: 3.5.x | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jan 26 10:07:42 2023 +0100| [98366949efdcb04b729e57dafffb48b17ffdfaa5] | committer: Duncan McNamara

Fix HeaderMediaListActivity top margin and editor

> https://code.videolan.org/videolan/vlc-android/commit/98366949efdcb04b729e57dafffb48b17ffdfaa5
---

 application/vlc-android/res/layout/header_media_list_activity.xml | 8 +++++++-
 .../src/org/videolan/vlc/gui/HeaderMediaListActivity.kt           | 4 ++++
 application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt  | 8 ++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/res/layout/header_media_list_activity.xml b/application/vlc-android/res/layout/header_media_list_activity.xml
index 5bd3c96220..47d6777d2f 100644
--- a/application/vlc-android/res/layout/header_media_list_activity.xml
+++ b/application/vlc-android/res/layout/header_media_list_activity.xml
@@ -23,6 +23,9 @@
         <variable
                 name="releaseYear"
                 type="String" />
+        <variable
+                name="topmargin"
+                type="Integer" />
     </data>
 
     <androidx.coordinatorlayout.widget.CoordinatorLayout
@@ -59,6 +62,7 @@
                 <androidx.constraintlayout.widget.ConstraintLayout
                         android:id="@+id/header_layout"
                         android:layout_width="@dimen/default_content_width"
+                        tools:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:layout_gravity="center_horizontal"
                         android:clipChildren="false"
@@ -81,7 +85,8 @@
                             android:layout_width="128dp"
                             android:layout_height="128dp"
                             android:layout_marginStart="@dimen/default_margin"
-                            android:layout_marginTop="86dp"
+                            tools:layout_marginTop="86dp"
+                            vlc:layoutMarginTop="@{topmargin}"
                             android:layout_marginEnd="@dimen/default_margin"
                             android:fitsSystemWindows="true"
                             android:scaleType="fitCenter"
@@ -219,6 +224,7 @@
         <androidx.recyclerview.widget.RecyclerView
                 android:id="@+id/songs"
                 android:layout_width="@dimen/default_content_width"
+                tools:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:layout_gravity="center_horizontal|top"
                 android:background="?attr/background_default"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index 6945fb4b36..58086e8032 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -104,6 +104,10 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
         originalBottomPadding = fragmentContainer.paddingBottom
         supportActionBar?.setDisplayHomeAsUpEnabled(true)
         supportActionBar?.title = ""
+        binding.topmargin = 86.dp
+        toolbar.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
+            binding.topmargin = bottom + 8.dp
+        }
 
         val playlist = if (savedInstanceState != null)
             savedInstanceState.getParcelable<Parcelable>(AudioBrowserFragment.TAG_ITEM) as MediaLibraryItem?
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 58cc57d91b..0a0c28e871 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -14,6 +14,7 @@ import android.text.style.DynamicDrawableSpan
 import android.text.style.ImageSpan
 import android.util.DisplayMetrics
 import android.view.View
+import android.view.ViewGroup.MarginLayoutParams
 import android.widget.TextView
 import androidx.annotation.WorkerThread
 import androidx.appcompat.app.AppCompatActivity
@@ -208,6 +209,13 @@ fun asyncTextItem(view: TextView, item: MediaLibraryItem?) {
     setTextAsync(view, text, params)
 }
 
+ at BindingAdapter("layoutMarginTop")
+fun setLayoutMarginTop(view: View, dimen: Int) {
+    val layoutParams = view.layoutParams as MarginLayoutParams
+    layoutParams.topMargin = dimen
+    view.layoutParams = layoutParams
+}
+
 private fun setTextAsync(view: TextView, text: CharSequence, params: PrecomputedTextCompat.Params) {
     val ref = WeakReference(view)
     AppScope.launch(Dispatchers.Default) {



More information about the Android mailing list