[Android] Widgets: allow hiding the cover on the mini layout

Nicolas Pomepuy git at videolan.org
Tue Aug 16 09:35:09 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Aug 12 07:07:40 2022 +0200| [4b124e18220762b9cab421a30acdc2e3ff1a8811] | committer: Nicolas Pomepuy

Widgets: allow hiding the cover on the mini layout

Fixes #2632
Fixes #2621

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

 .../src/main/java/org/videolan/vlc/database/MediaDatabase.kt     | 4 ++--
 .../src/main/java/org/videolan/vlc/database/Migrations.kt        | 6 ++++++
 .../src/main/java/org/videolan/vlc/mediadb/models/Widget.kt      | 4 +++-
 application/resources/src/main/res/values/strings.xml            | 1 +
 application/vlc-android/res/xml/preferences_widgets.xml          | 5 +++++
 .../videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt   | 7 +++++++
 .../src/org/videolan/vlc/repository/WidgetRepository.kt          | 2 +-
 .../src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt   | 9 +++++++++
 8 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/application/mediadb/src/main/java/org/videolan/vlc/database/MediaDatabase.kt b/application/mediadb/src/main/java/org/videolan/vlc/database/MediaDatabase.kt
index 2492dcbc0..3438dbe82 100644
--- a/application/mediadb/src/main/java/org/videolan/vlc/database/MediaDatabase.kt
+++ b/application/mediadb/src/main/java/org/videolan/vlc/database/MediaDatabase.kt
@@ -33,7 +33,7 @@ import org.videolan.vlc.mediadb.models.*
 
 private const val DB_NAME = "vlc_database"
 
- at Database(entities = [ExternalSub::class, Slave::class, BrowserFav::class, CustomDirectory::class, Widget::class], version = 32, exportSchema = false)
+ at Database(entities = [ExternalSub::class, Slave::class, BrowserFav::class, CustomDirectory::class, Widget::class], version = 33, exportSchema = false)
 @TypeConverters(Converters::class)
 abstract class MediaDatabase: RoomDatabase() {
     abstract fun externalSubDao(): ExternalSubDao
@@ -54,7 +54,7 @@ private fun buildDatabase(context: Context) = Room.databaseBuilder(context.appli
                 migration_17_18, migration_18_19, migration_19_20, migration_20_21,
                 migration_21_22, migration_22_23, migration_23_24, migration_24_25,
                 migration_25_26, migration_26_27, migration_27_28, migration_28_29,
-                migration_29_30, migration_30_31, migration_31_32)
+                migration_29_30, migration_30_31, migration_31_32, migration_32_33)
         .addCallback(object : RoomDatabase.Callback() {
             override fun onCreate(db: SupportSQLiteDatabase) { if (!AndroidDevices.isTv) populateDB(context) }
         })
diff --git a/application/mediadb/src/main/java/org/videolan/vlc/database/Migrations.kt b/application/mediadb/src/main/java/org/videolan/vlc/database/Migrations.kt
index 4c91eda75..2ff64fb31 100644
--- a/application/mediadb/src/main/java/org/videolan/vlc/database/Migrations.kt
+++ b/application/mediadb/src/main/java/org/videolan/vlc/database/Migrations.kt
@@ -224,6 +224,12 @@ val migration_31_32 = object:Migration(31, 32) {
     }
 }
 
+val migration_32_33 = object:Migration(32, 33) {
+    override fun migrate(database: SupportSQLiteDatabase) {
+        database.execSQL("ALTER TABLE $WIDGET_TABLE_NAME ADD COLUMN show_cover INTEGER NOT NULL DEFAULT 0;")
+    }
+}
+
 @OptIn(DelicateCoroutinesApi::class)
 fun populateDB(context: Context) = GlobalScope.launch(Dispatchers.IO) {
     val uris = listOf(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_URI,
diff --git a/application/mediadb/src/main/java/org/videolan/vlc/mediadb/models/Widget.kt b/application/mediadb/src/main/java/org/videolan/vlc/mediadb/models/Widget.kt
index 482834f95..a13cb0bbb 100644
--- a/application/mediadb/src/main/java/org/videolan/vlc/mediadb/models/Widget.kt
+++ b/application/mediadb/src/main/java/org/videolan/vlc/mediadb/models/Widget.kt
@@ -54,5 +54,7 @@ data class Widget(
         @ColumnInfo(name = "show_configure")
         var showConfigure: Boolean,
         @ColumnInfo(name = "show_seek")
-        var showSeek: Boolean
+        var showSeek: Boolean,
+        @ColumnInfo(name = "show_cover")
+        var showCover: Boolean
 )
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index d700bfef5..a7fca5e34 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -981,6 +981,7 @@
     <string name="widget_preview">Widget preview</string>
     <string name="widget_forward_delay">Forward time delay</string>
     <string name="widget_show_seek">Show seek buttons</string>
+    <string name="widget_show_cover">Show cover</string>
     <string name="widget_rewind_delay">Backward time delay</string>
     <string name="widget_show_configure">Show configuration icon</string>
     <string name="widget_show_configure_summary">Even if it\'s not shown, you can tap the upper right corner to open the configuration</string>
diff --git a/application/vlc-android/res/xml/preferences_widgets.xml b/application/vlc-android/res/xml/preferences_widgets.xml
index 96faa060b..f03c95c84 100644
--- a/application/vlc-android/res/xml/preferences_widgets.xml
+++ b/application/vlc-android/res/xml/preferences_widgets.xml
@@ -60,6 +60,11 @@
                 app:cpv_showAlphaSlider="false"
                 android:title="@string/widget_foreground"/>
 
+        <CheckBoxPreference
+                android:defaultValue="true"
+                android:key="widget_show_cover"
+                android:title="@string/widget_show_cover" />
+
         <CheckBoxPreference
                 android:defaultValue="true"
                 android:key="widget_show_seek"
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 d4b722e54..b863e0ac0 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
@@ -64,6 +64,7 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
     private lateinit var foregroundPreference: ColorPreferenceCompat
     private lateinit var lightThemePreference: CheckBoxPreference
     private lateinit var showSeek: CheckBoxPreference
+    private lateinit var showCover: CheckBoxPreference
     private lateinit var forwardDelay: NumberPickerPreference
     private lateinit var rewindDelay: NumberPickerPreference
 
@@ -93,6 +94,7 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
         backgroundPreference = findPreference("background_color")!!
         foregroundPreference = findPreference("foreground_color")!!
         lightThemePreference = findPreference("widget_light_theme")!!
+        showCover = findPreference("widget_show_cover")!!
         showSeek = findPreference("widget_show_seek")!!
         forwardDelay = findPreference("widget_forward_delay")!!
         rewindDelay = findPreference("widget_rewind_delay")!!
@@ -124,6 +126,7 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
             showSeek.isVisible = showSeekPrefs
             forwardDelay.isVisible = showSeekPrefs
             rewindDelay.isVisible = showSeekPrefs
+            showCover.isVisible = widgetType == WidgetType.MINI
         }
 
         if (!DynamicColors.isDynamicColorAvailable()) {
@@ -181,6 +184,10 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
                 val newValue = sharedPreferences.getBoolean(key, true)
                 model.widget.value?.showSeek = newValue
             }
+            "widget_show_cover" -> {
+                val newValue = sharedPreferences.getBoolean(key, true)
+                model.widget.value?.showCover = newValue
+            }
         }
         updateWidgetEntity()
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/repository/WidgetRepository.kt b/application/vlc-android/src/org/videolan/vlc/repository/WidgetRepository.kt
index 6624390f2..7e1731398 100644
--- a/application/vlc-android/src/org/videolan/vlc/repository/WidgetRepository.kt
+++ b/application/vlc-android/src/org/videolan/vlc/repository/WidgetRepository.kt
@@ -67,7 +67,7 @@ class WidgetRepository(private val widgetDao: WidgetDao) {
     }
 
     suspend fun createNew(context: Context, appWidgetId: Int): Widget {
-        val widget = Widget(appWidgetId, 0, 0, 0, true, ContextCompat.getColor(context, R.color.black), ContextCompat.getColor(context, R.color.white), 10, 10, 100, true, true)
+        val widget = Widget(appWidgetId, 0, 0, 0, true, ContextCompat.getColor(context, R.color.black), ContextCompat.getColor(context, R.color.white), 10, 10, 100, showConfigure = true, showSeek = true, showCover = true)
         addWidget(widget)
         return widget
     }
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 28d5092c3..9626945d0 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -478,6 +478,15 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
      * @param widgetCacheEntry the [WidgetCacheEntry] used for the colors
      */
     private fun displayCover(context: Context, views: RemoteViews, playing: Boolean, widgetType: WidgetType, widgetCacheEntry: WidgetCacheEntry) {
+        if (widgetType == WidgetType.MINI && !widgetCacheEntry.widget.showCover) {
+            views.setViewVisibility(R.id.app_icon, View.GONE)
+            views.setViewVisibility(R.id.cover, View.GONE)
+            views.setViewVisibility(R.id.cover_background, View.GONE)
+            views.setViewVisibility(R.id.cover_parent, View.GONE)
+            views.setViewVisibility(R.id.separator, View.GONE)
+
+            return
+        }
         val foregroundColor = widgetCacheEntry.widget.getForegroundColor(context, palette = widgetCacheEntry.palette)
         log(widgetCacheEntry.widget.widgetId, WidgetLogType.INFO, "Bugfix displayCover: widgetType $widgetType /// playing $playing /// foregroundColor $foregroundColor -> ${java.lang.String.format("#%06X", 0xFFFFFF and foregroundColor)}")
         if (!playing) {



More information about the Android mailing list