[Android] Improve widgets threading to avoid race conditions
Nicolas Pomepuy
git at videolan.org
Mon May 23 08:21:01 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri May 20 13:30:03 2022 +0200| [207fc65d7c06c2340979ce1b1b1b9e60e3f8bc66] | committer: Duncan McNamara
Improve widgets threading to avoid race conditions
> https://code.videolan.org/videolan/vlc-android/commit/207fc65d7c06c2340979ce1b1b1b9e60e3f8bc66
---
.../videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
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 e92a6b00b..c25dbfc41 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -331,19 +331,25 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
when (widgetType) {
WidgetType.MICRO -> {
val bitmap = widgetCacheEntry.generateCircularProgressbar(context, 128.dp.toFloat(), pos)
- views.setImageViewBitmap(R.id.progress_round, bitmap)
- if (!forPreview) applyUpdate(context, views, partial, appWidgetId)
+ runOnMainThread {
+ views.setImageViewBitmap(R.id.progress_round, bitmap)
+ if (!forPreview) applyUpdate(context, views, partial, appWidgetId)
+ }
}
WidgetType.PILL -> {
widgetCacheEntry.generatePillProgressbar(context, pos)?.let { bitmap ->
- views.setImageViewBitmap(R.id.progress_round, bitmap)
+ runOnMainThread {
+ views.setImageViewBitmap(R.id.progress_round, bitmap)
+ if (!forPreview) applyUpdate(context, views, partial, appWidgetId)
+ }
}
- if (!forPreview) applyUpdate(context, views, partial, appWidgetId)
}
WidgetType.MINI, WidgetType.MACRO -> {
val bitmap = widgetCacheEntry.generateCircularProgressbar(context, 32.dp.toFloat(), pos, 3.dp.toFloat())
- views.setImageViewBitmap(R.id.progress_round, bitmap)
- if (!forPreview) applyUpdate(context, views, partial, appWidgetId)
+ runOnMainThread {
+ views.setImageViewBitmap(R.id.progress_round, bitmap)
+ if (!forPreview) applyUpdate(context, views, partial, appWidgetId)
+ }
}
}
}
More information about the Android
mailing list