[Android] Widget: fix preview playing state and content
Nicolas Pomepuy
git at videolan.org
Mon May 15 14:03:22 UTC 2023
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Mar 17 08:46:29 2023 +0100| [5711f759481002bd45ad5b14a10ee321a0171b67] | committer: Duncan McNamara
Widget: fix preview playing state and content
Fixes #2864
> https://code.videolan.org/videolan/vlc-android/commit/5711f759481002bd45ad5b14a10ee321a0171b67
---
.../vlc/widget/MiniPlayerAppWidgetProvider.kt | 25 ++++++++++++++++------
.../vlc/widget/MiniPlayerConfigureActivity.kt | 2 +-
2 files changed, 19 insertions(+), 8 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 38c90631de..cd27ae9070 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -140,7 +140,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
* @param previewPalette if this is for a preview, the [Palette] to use
* @return the [RemoteViews] to send to the app widget host
*/
- suspend fun layoutWidget(context: Context, appWidgetId: Int, intent: Intent, forPreview: Boolean = false, previewBitmap: Bitmap? = null, previewPalette: Palette? = null): RemoteViews? {
+ suspend fun layoutWidget(context: Context, appWidgetId: Int, intent: Intent, forPreview: Boolean = false, previewBitmap: Bitmap? = null, previewPalette: Palette? = null, previewPlaying:Boolean = false): RemoteViews? {
val partial = ACTION_WIDGET_INIT != intent.action
log(appWidgetId, WidgetLogType.INFO, "layoutWidget widget id $appWidgetId / partial: $partial / action = ${intent.action}")
@@ -161,7 +161,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
// val secondaryBackgroundColor = widgetCacheEntry.widget.getBackgroundColor(context, palette = palette, secondary = true)
val service = PlaybackService.serviceFlow.value
- val playing = service?.isPlaying == true || forPreview
+ val playing = (service?.isPlaying == true && !forPreview) || previewPlaying
val colorChanged = !partial || widgetCacheEntry.foregroundColor != foregroundColor || (widgetCacheEntry.widget.theme == 1 && widgetCacheEntry.playing != playing)
widgetCacheEntry.foregroundColor = foregroundColor
@@ -258,10 +258,21 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
val settings = Settings.getInstance(context)
if (!forPreview) widgetCacheEntry.currentMedia = service?.currentMediaWrapper
- if (!playing)
- setupTexts(context, views, widgetType, settings.getString(KEY_CURRENT_AUDIO_RESUME_TITLE, context.getString(R.string.widget_default_text)), settings.getString(KEY_CURRENT_AUDIO_RESUME_ARTIST, ""))
- else
- setupTexts(context, views, widgetType, service?.title ?: widgetCacheEntry.currentMedia?.title, service?.artist ?: widgetCacheEntry.currentMedia?.artist)
+ val title = when {
+ forPreview -> if (!previewPlaying)context.getString(R.string.widget_default_text) else widgetCacheEntry.currentMedia?.title
+ playing -> service?.title ?: widgetCacheEntry.currentMedia?.title
+ else -> settings.getString(
+ KEY_CURRENT_AUDIO_RESUME_TITLE,
+ context.getString(R.string.widget_default_text)
+ )
+ }
+
+ val artist = when {
+ forPreview -> widgetCacheEntry.currentMedia?.artist
+ playing -> service?.artist ?: widgetCacheEntry.currentMedia?.artist
+ else -> settings.getString(KEY_CURRENT_AUDIO_RESUME_ARTIST, "")
+ }
+ setupTexts(context, views, widgetType, title, artist)
if (widgetCacheEntry.playing != playing || colorChanged) views.setImageViewBitmap(R.id.play_pause, context.getColoredBitmapFromColor(getPlayPauseImage(playing, widgetType), foregroundColor))
views.setContentDescription(R.id.play_pause, context.getString(if (!playing) R.string.resume_playback_short_title else R.string.pause))
@@ -280,7 +291,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
views.setInt(R.id.separator, "setBackgroundColor", widgetCacheEntry.widget.getSeparatorColor(context))
views.setInt(R.id.separator, "setImageAlpha", (widgetCacheEntry.widget.opacity.toFloat() * 255 / 100).toInt())
- if (forPreview) widgetCacheEntry.currentCover = "fake"
+ if (forPreview && previewPlaying) widgetCacheEntry.currentCover = "fake"
if (forPreview) {
displayCover(context, views, true, widgetType, widgetCacheEntry)
views.setImageViewBitmap(R.id.cover, cutBitmapCover(widgetType, previewBitmap!!, widgetCacheEntry))
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerConfigureActivity.kt b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerConfigureActivity.kt
index 45dd05a330..9030f2c728 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerConfigureActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerConfigureActivity.kt
@@ -140,7 +140,7 @@ class MiniPlayerConfigureActivity : BaseActivity() {
val width = if (widget.width <= 0 || widget.height <= 0) 276 else widget.width
val height = if (widget.width <= 0 || widget.height <= 0) 94 else widget.height
- val views = provider.layoutWidget(this at MiniPlayerConfigureActivity, id, Intent(MiniPlayerAppWidgetProvider.ACTION_WIDGET_INIT), binding.previewPlaying.isChecked, coverBitmap, palette)
+ val views = provider.layoutWidget(this at MiniPlayerConfigureActivity, id, Intent(MiniPlayerAppWidgetProvider.ACTION_WIDGET_INIT), true, coverBitmap, palette, previewPlaying = binding.previewPlaying.isChecked)
val container = FrameLayout(this at MiniPlayerConfigureActivity).apply {
layoutParams = LayoutParams(width, height)
}
More information about the Android
mailing list