[Android] Add widget DB column and preference for the widget type
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 Mar 13 15:37:34 2023 +0100| [ccd8112627cb7ed41dc5185751e8a2d974617427] | committer: Duncan McNamara
Add widget DB column and preference for the widget type
> https://code.videolan.org/videolan/vlc-android/commit/ccd8112627cb7ed41dc5185751e8a2d974617427
---
.../main/java/org/videolan/vlc/database/MediaDatabase.kt | 5 +++--
.../src/main/java/org/videolan/vlc/database/Migrations.kt | 6 ++++++
.../main/java/org/videolan/vlc/mediadb/models/Widget.kt | 2 ++
application/resources/src/main/res/values/arrays.xml | 15 +++++++++++++++
application/resources/src/main/res/values/strings.xml | 5 +++++
application/vlc-android/res/xml/preferences_widgets.xml | 7 +++++++
.../vlc/gui/preferences/widgets/PreferencesWidgets.kt | 7 +++++++
.../src/org/videolan/vlc/repository/WidgetRepository.kt | 2 +-
8 files changed, 46 insertions(+), 3 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 3438dbe82b..04b3a68732 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 = 33, exportSchema = false)
+ at Database(entities = [ExternalSub::class, Slave::class, BrowserFav::class, CustomDirectory::class, Widget::class], version = 34, exportSchema = false)
@TypeConverters(Converters::class)
abstract class MediaDatabase: RoomDatabase() {
abstract fun externalSubDao(): ExternalSubDao
@@ -54,7 +54,8 @@ 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_32_33)
+ migration_29_30, migration_30_31, migration_31_32, migration_32_33,
+ migration_33_34)
.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 2ff64fb319..74c0fb5bf6 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
@@ -230,6 +230,12 @@ val migration_32_33 = object:Migration(32, 33) {
}
}
+val migration_33_34 = object:Migration(33, 34) {
+ override fun migrate(database: SupportSQLiteDatabase) {
+ database.execSQL("ALTER TABLE $WIDGET_TABLE_NAME ADD COLUMN type 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 a13cb0bbbb..113d89fe9e 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
@@ -39,6 +39,8 @@ data class Widget(
var height: Int,
@ColumnInfo(name = "theme")
var theme: Int,
+ @ColumnInfo(name = "type")
+ var type: Int,
@ColumnInfo(name = "light_theme")
var lightTheme: Boolean,
@ColumnInfo(name = "background_color")
diff --git a/application/resources/src/main/res/values/arrays.xml b/application/resources/src/main/res/values/arrays.xml
index 5e5cfe735b..1062d86d5b 100644
--- a/application/resources/src/main/res/values/arrays.xml
+++ b/application/resources/src/main/res/values/arrays.xml
@@ -487,5 +487,20 @@
<item>1</item>
<item>2</item>
</string-array>
+ <string-array name="widget_type_entries" translatable="false">
+ <item>@string/automatic</item>
+ <item>@string/widget_type_pill</item>
+ <item>@string/widget_type_normal</item>
+ <item>@string/widget_type_circle</item>
+ <item>@string/widget_type_large</item>
+ </string-array>
+
+ <string-array name="widget_type_values" translatable="false">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ <item>4</item>
+ </string-array>
</resources>
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 51daa19b3d..693163cdc2 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -1042,6 +1042,11 @@
<string name="material_you">Material You (pulls colors from wallpaper)</string>
<string name="palette">Palette (pulls colors from the media cover)</string>
<string name="custom">Custom</string>
+ <string name="widget_type">Widget type</string>
+ <string name="widget_type_pill">Pill</string>
+ <string name="widget_type_normal">Normal</string>
+ <string name="widget_type_circle">Circle</string>
+ <string name="widget_type_large">Large</string>
<string name="opacity">Opacity</string>
<string name="widget_background">Background</string>
<string name="widget_foreground">Foreground</string>
diff --git a/application/vlc-android/res/xml/preferences_widgets.xml b/application/vlc-android/res/xml/preferences_widgets.xml
index f03c95c848..381c83687b 100644
--- a/application/vlc-android/res/xml/preferences_widgets.xml
+++ b/application/vlc-android/res/xml/preferences_widgets.xml
@@ -36,6 +36,13 @@
android:entryValues="@array/widget_themes_values"
android:summary="%s"
android:title="@string/widget_theme"/>
+ <ListPreference
+ android:key="widget_type"
+ android:defaultValue="0"
+ android:entries="@array/widget_type_entries"
+ android:entryValues="@array/widget_type_values"
+ android:summary="%s"
+ android:title="@string/widget_type"/>
<CheckBoxPreference
app:singleLineTitle="false"
android:key="widget_light_theme"
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 b863e0ac09..64fa6c8258 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
@@ -100,6 +100,7 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
rewindDelay = findPreference("widget_rewind_delay")!!
val configurationIcon = findPreference<CheckBoxPreference>("widget_show_configure")!!
val themePreference = findPreference<ListPreference>("widget_theme")!!
+ val typePreference = findPreference<ListPreference>("widget_type")!!
val id = (arguments?.getInt(WIDGET_ID) ?: -2)
if (id == -2) throw IllegalStateException("Invalid widget id")
@@ -113,6 +114,7 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
updateWidgetEntity()
}
themePreference.value = widget.theme.toString()
+ typePreference.value = widget.type.toString()
backgroundPreference.isVisible = widget.theme != 0
foregroundPreference.isVisible = widget.theme != 0
backgroundPreference.saveValue(widget.backgroundColor)
@@ -159,6 +161,11 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
foregroundPreference.isVisible = newValue == 2
lightThemePreference.isVisible = newValue != 2
+ }
+ "widget_type" -> {
+ val newValue = sharedPreferences.getString(key, "0")?.toInt() ?: 0
+ model.widget.value?.type = newValue
+
}
"widget_light_theme" -> {
val newValue = sharedPreferences.getBoolean(key, true)
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 7e17313983..941a4996fb 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, showConfigure = true, showSeek = true, showCover = true)
+ val widget = Widget(appWidgetId, 0, 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
}
More information about the Android
mailing list