[Android] Display the widget using the custom type if needed

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Mar 14 08:55:03 2023 +0100| [9dafba193f2d8fc9aae223c87dc118209ae70c92] | committer: Duncan McNamara

Display the widget using the custom type if needed

Fixes #2806

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

 .../gui/preferences/widgets/PreferencesWidgets.kt    |  4 ++--
 .../vlc/widget/MiniPlayerAppWidgetProvider.kt        |  6 +++---
 .../src/org/videolan/vlc/widget/utils/WidgetUtils.kt | 20 ++++++++++++--------
 3 files changed, 17 insertions(+), 13 deletions(-)

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 64fa6c8258..4307ac0dff 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
@@ -50,7 +50,7 @@ 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.WidgetType
-import org.videolan.vlc.widget.utils.WidgetUtils.getWidgetTypeFromSize
+import org.videolan.vlc.widget.utils.WidgetUtils.getWidgetType
 import org.videolan.vlc.widget.utils.WidgetUtils.hasEnoughSpaceForSeek
 
 const val WIDGET_ID = "WIDGET_ID"
@@ -123,7 +123,7 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
             lightThemePreference.isChecked = widget.lightTheme
             lightThemePreference.isVisible = widget.theme != 2
             configurationIcon.isChecked = widget.showConfigure
-            val widgetType = getWidgetTypeFromSize(widget.width, widget.height)
+            val widgetType = getWidgetType(widget)
             val showSeekPrefs = (widgetType == WidgetType.MINI || widgetType == WidgetType.MACRO) && hasEnoughSpaceForSeek(widget, widgetType)
             showSeek.isVisible = showSeekPrefs
             forwardDelay.isVisible = showSeekPrefs
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
index c5f2ff3818..38c90631de 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -59,7 +59,7 @@ import org.videolan.vlc.repository.WidgetRepository
 import org.videolan.vlc.util.TextUtils
 import org.videolan.vlc.util.getPendingIntent
 import org.videolan.vlc.widget.utils.*
-import org.videolan.vlc.widget.utils.WidgetUtils.getWidgetTypeFromSize
+import org.videolan.vlc.widget.utils.WidgetUtils.getWidgetType
 import org.videolan.vlc.widget.utils.WidgetUtils.shouldShowSeek
 import java.util.*
 
@@ -167,7 +167,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
 
 
         //determine layout
-        val oldType = getWidgetTypeFromSize(widgetCacheEntry.widget.width, widgetCacheEntry.widget.height)
+        val oldType = getWidgetType(widgetCacheEntry.widget)
 
         val size = WidgetSizeUtil.getWidgetsSize(context, appWidgetId)
         if (size.first != 0 && size.second != 0 && (widgetCacheEntry.widget.width != size.first || widgetCacheEntry.widget.height != size.second)) {
@@ -183,7 +183,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
             Pair(widgetCacheEntry.widget.width, widgetCacheEntry.widget.height)
         } else size
         log(appWidgetId, WidgetLogType.INFO, "New widget size by provider: ${correctedSize.first} / ${correctedSize.second} // ratio = ${correctedSize.first.toFloat() / correctedSize.second}")
-        val widgetType = getWidgetTypeFromSize(correctedSize.first, correctedSize.second)
+        val widgetType = getWidgetType(widgetCacheEntry.widget)
 
 
         val views = RemoteViews(context.packageName, widgetType.layout)
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 7ca7023c16..5455010dd1 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
@@ -278,16 +278,20 @@ enum class WidgetType(@LayoutRes val layout: Int) {
 
 object WidgetUtils {
     /**
-     * Calculate the [WidgetType] depending on the size
+     * Calculate the [WidgetType] depending on the widget's settings and size
      *
-     * @param width the widget width
-     * @param height the widget height
-     * @return the [WidgetType] for this size
+     * @param widget the widget to check
+     * @returnthe [WidgetType] for this widget
      */
-    fun getWidgetTypeFromSize(width: Int, height: Int) = when {
-        width > 220 && height > 220 -> WidgetType.MACRO
-        width > 220 && height > 72 -> WidgetType.MINI
-        width > 128 && height > 148 -> WidgetType.MICRO
+    fun getWidgetType(widget: Widget) = when {
+
+        widget.type == 1 -> WidgetType.PILL
+        widget.type == 2 -> WidgetType.MINI
+        widget.type == 3 -> WidgetType.MICRO
+        widget.type == 4 -> WidgetType.MACRO
+        widget.width > 220 && widget.height > 220 -> WidgetType.MACRO
+        widget.width > 220 && widget.height > 72 -> WidgetType.MINI
+        widget.width > 128 && widget.height > 148 -> WidgetType.MICRO
         else -> WidgetType.PILL
     }
 



More information about the Android mailing list