[Android] Fix empty view UI in compact mode

Nicolas Pomepuy git at videolan.org
Wed Feb 5 10:41:56 UTC 2025


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Feb  5 07:53:24 2025 +0100| [6e3edcc887d1c1582ab701ccbbae627ffddb5df8] | committer: Nicolas Pomepuy

Fix empty view UI in compact mode

Compact mode is used when the empty view only displays an image and a text

Fixes #3141

> https://code.videolan.org/videolan/vlc-android/commit/6e3edcc887d1c1582ab701ccbbae627ffddb5df8
---

 .../vlc-android/res/layout/view_empty_loading.xml  |   2 +-
 .../res/layout/view_empty_loading_compact.xml      | 135 ---------------------
 .../videolan/vlc/gui/view/EmptyLoadingStateView.kt |  12 +-
 3 files changed, 12 insertions(+), 137 deletions(-)

diff --git a/application/vlc-android/res/layout/view_empty_loading.xml b/application/vlc-android/res/layout/view_empty_loading.xml
index 9bf4578872..49dc29e1b0 100644
--- a/application/vlc-android/res/layout/view_empty_loading.xml
+++ b/application/vlc-android/res/layout/view_empty_loading.xml
@@ -52,7 +52,7 @@
 
     <TextView
             android:id="@+id/emptyTextView"
-            android:layout_width="0dp"
+            android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginLeft="16dp"
             android:layout_marginRight="16dp"
diff --git a/application/vlc-android/res/layout/view_empty_loading_compact.xml b/application/vlc-android/res/layout/view_empty_loading_compact.xml
deleted file mode 100644
index ac5e1aecb1..0000000000
--- a/application/vlc-android/res/layout/view_empty_loading_compact.xml
+++ /dev/null
@@ -1,135 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!--
-  ~ *************************************************************************
-  ~  view_empty_loading_compact.xml
-  ~ **************************************************************************
-  ~ Copyright © 2020 VLC authors and VideoLAN
-  ~ Author: Nicolas POMEPUY
-  ~ This program is free software; you can redistribute it and/or modify
-  ~ it under the terms of the GNU General Public License as published by
-  ~ the Free Software Foundation; either version 2 of the License, or
-  ~ (at your option) any later version.
-  ~
-  ~ This program is distributed in the hope that it will be useful,
-  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
-  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  ~ GNU General Public License for more details.
-  ~
-  ~ You should have received a copy of the GNU General Public License
-  ~ along with this program; if not, write to the Free Software
-  ~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
-  ~ ***************************************************************************
-  ~
-  ~
-  -->
-
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:app="http://schemas.android.com/apk/res-auto"
-        xmlns:tools="http://schemas.android.com/tools"
-        android:id="@+id/container"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical">
-
-    <androidx.constraintlayout.widget.Guideline
-            android:id="@+id/guideline12"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            app:layout_constraintGuide_percent="0.5" />
-
-    <TextView
-            android:id="@+id/emptyTextView"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_marginStart="16dp"
-            android:layout_marginEnd="16dp"
-            android:gravity="start"
-            android:textSize="20sp"
-            app:layout_constraintBottom_toBottomOf="@+id/emptyImageView"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintHorizontal_bias="0.5"
-            app:layout_constraintStart_toEndOf="@+id/emptyImageView"
-            app:layout_constraintTop_toTopOf="@+id/emptyImageView"
-            tools:text="No data"
-            tools:visibility="visible" />
-
-    <androidx.appcompat.widget.AppCompatImageView
-            android:id="@+id/emptyImageView"
-            android:layout_width="56dp"
-            android:layout_height="56dp"
-            android:layout_marginStart="16dp"
-            app:layout_constraintBottom_toTopOf="@+id/guideline12"
-            app:layout_constraintHorizontal_chainStyle="packed"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="@+id/guideline12"
-            app:srcCompat="@drawable/ic_empty" />
-
-    <Button
-            android:id="@+id/noMediaButton"
-            style="?attr/empty_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="16dp"
-            android:text="@string/button_medialibrary_preferences"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintLeft_toLeftOf="parent"
-            app:layout_constraintRight_toRightOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/emptyImageView" />
-
-
-    <TextView
-            android:id="@+id/loadingTitle"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:gravity="start"
-            android:text="@string/loading"
-            android:textSize="20sp"
-            app:layout_constraintBottom_toTopOf="@+id/guideline12"
-            app:layout_constraintEnd_toStartOf="@+id/loadingFlipper"
-            app:layout_constraintHorizontal_chainStyle="packed"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="@+id/guideline12" />
-
-    <ViewFlipper
-            android:id="@+id/loadingFlipper"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="start"
-            android:autoStart="true"
-            android:flipInterval="1000"
-            app:layout_constraintBaseline_toBaselineOf="@+id/loadingTitle"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintStart_toEndOf="@+id/loadingTitle">
-
-        <TextView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_gravity="start"
-                android:text="@string/empty"
-                android:textSize="20sp" />
-
-        <TextView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_gravity="start"
-                android:text="@string/load_1_period"
-                android:textSize="20sp" />
-
-        <TextView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_gravity="start"
-                android:text="@string/load_2_period"
-                android:textSize="20sp" />
-
-        <TextView
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_gravity="start"
-                android:text="@string/load_3_period"
-                android:textSize="20sp" />
-    </ViewFlipper>
-
-
-</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt
index 2b05faa138..c8f394cc07 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/EmptyLoadingStateView.kt
@@ -45,6 +45,7 @@ import androidx.transition.TransitionManager
 import kotlinx.coroutines.launch
 import org.videolan.resources.ACTIVITY_RESULT_PREFERENCES
 import org.videolan.tools.AppScope
+import org.videolan.tools.dp
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.BaseActivity
 import org.videolan.vlc.gui.SecondaryActivity
@@ -77,6 +78,8 @@ class EmptyLoadingStateView : FrameLayout {
         }
     var state = EmptyLoadingState.LOADING
         set(value) {
+            compactMode = value  in arrayOf(EmptyLoadingState.EMPTY_SEARCH, EmptyLoadingState.EMPTY, EmptyLoadingState.EMPTY_FAVORITES)
+            applyCompactMode()
             loadingFlipper.visibility = if (value == EmptyLoadingState.LOADING) View.VISIBLE else View.GONE
             loadingTitle.visibility = if (value == EmptyLoadingState.LOADING) View.VISIBLE else View.GONE
             emptyTextView.visibility = if (value in arrayOf(EmptyLoadingState.EMPTY, EmptyLoadingState.EMPTY_SEARCH, EmptyLoadingState.EMPTY_FAVORITES)) View.VISIBLE else View.GONE
@@ -178,13 +181,20 @@ class EmptyLoadingStateView : FrameLayout {
                 (context as BaseActivity).openFile(Uri.parse(""))
             }
         }
+        container = findViewById(R.id.container)
+        normalConstraintSet.clone(container)
+        compactConstraintSet.clone(container)
+        compactConstraintSet.clear(R.id.emptyImageView, ConstraintSet.TOP)
+        compactConstraintSet.setMargin(R.id.emptyImageView, ConstraintSet.BOTTOM, 16.dp)
+        if (compactMode) {
+            applyCompactMode()
+        }
     }
 
     private fun applyCompactMode() {
         if (!::container.isInitialized) return
         TransitionManager.beginDelayedTransition(container)
         if (compactMode) compactConstraintSet.applyTo(container) else normalConstraintSet.applyTo(container)
-        emptyTextView.gravity = if (compactMode) Gravity.START else Gravity.CENTER
     }
 
     private fun initialize() {



More information about the Android mailing list