[Android] Warn the user if the widget type is too large for the in-home size

Nicolas Pomepuy git at videolan.org
Mon May 15 14:03:22 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon May 15 13:56:36 2023 +0200| [e943b15ace7febf76d9c38697beee5d80029eb0a] | committer: Duncan McNamara

Warn the user if the widget type is too large for the in-home size

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

 application/resources/src/main/res/values/strings.xml       |  1 +
 .../vlc/gui/preferences/widgets/PreferencesWidgets.kt       | 10 ++++++++++
 .../src/org/videolan/vlc/widget/utils/WidgetUtils.kt        | 13 +++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 693163cdc2..20d9f3f678 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -1047,6 +1047,7 @@
     <string name="widget_type_normal">Normal</string>
     <string name="widget_type_circle">Circle</string>
     <string name="widget_type_large">Large</string>
+    <string name="widget_type_error">This widget type is too large for the widget size. It can lead to visual issues</string>
     <string name="opacity">Opacity</string>
     <string name="widget_background">Background</string>
     <string name="widget_foreground">Foreground</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt
index 4307ac0dff..eebd1c4bce 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt
@@ -45,11 +45,14 @@ import org.videolan.tools.WIDGETS_BACKGROUND_LAST_COLORS
 import org.videolan.tools.WIDGETS_FOREGROUND_LAST_COLORS
 import org.videolan.tools.putSingle
 import org.videolan.vlc.R
+import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.preferences.BasePreferenceFragment
 import org.videolan.vlc.gui.view.NumberPickerPreference
 import org.videolan.vlc.repository.WidgetRepository
 import org.videolan.vlc.widget.WidgetViewModel
+import org.videolan.vlc.widget.utils.WidgetSizeUtil
 import org.videolan.vlc.widget.utils.WidgetType
+import org.videolan.vlc.widget.utils.WidgetUtils
 import org.videolan.vlc.widget.utils.WidgetUtils.getWidgetType
 import org.videolan.vlc.widget.utils.WidgetUtils.hasEnoughSpaceForSeek
 
@@ -165,7 +168,14 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
             "widget_type" -> {
                 val newValue = sharedPreferences.getString(key, "0")?.toInt() ?: 0
                 model.widget.value?.type = newValue
+                model.widget.value?.let {
+                    val size = WidgetSizeUtil.getWidgetsSize(requireActivity(), it.widgetId)
+                    val minimalSize = WidgetUtils.getMinimalWidgetSize(WidgetUtils.getWidgetType(it))
+                    if (size.first < minimalSize.first || size.second < minimalSize.second) {
+                        UiTools.snackerConfirm(requireActivity(), getString(R.string.widget_type_error)) { }
+                    }
 
+                }
             }
             "widget_light_theme" -> {
                 val newValue = sharedPreferences.getBoolean(key, true)
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
index 5455010dd1..b477af5703 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
@@ -295,6 +295,19 @@ object WidgetUtils {
         else -> WidgetType.PILL
     }
 
+    /**
+     * Minimal size for this widget type
+     *
+     * @param type the widget type to check
+     * @return the minimal size
+     */
+    fun getMinimalWidgetSize(type: WidgetType):Pair<Int, Int> = when(type){
+        WidgetType.MACRO -> Pair(220,200)
+        WidgetType.MINI -> Pair(220,72)
+        WidgetType.MICRO -> Pair(128,148)
+        else -> Pair(0,0)
+    }
+
     /**
      * Check if the widget has enough space to display the seek icons
      *



More information about the Android mailing list