Skip to content
Snippets Groups Projects
Commit 5711f759 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Duncan McNamara
Browse files

Widget: fix preview playing state and content

Fixes #2864
parent 4ab42ca1
No related branches found
No related tags found
1 merge request!1703Display the widget using the custom type if needed
......@@ -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))
......
......@@ -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@MiniPlayerConfigureActivity, id, Intent(MiniPlayerAppWidgetProvider.ACTION_WIDGET_INIT), binding.previewPlaying.isChecked, coverBitmap, palette)
val views = provider.layoutWidget(this@MiniPlayerConfigureActivity, id, Intent(MiniPlayerAppWidgetProvider.ACTION_WIDGET_INIT), true, coverBitmap, palette, previewPlaying = binding.previewPlaying.isChecked)
val container = FrameLayout(this@MiniPlayerConfigureActivity).apply {
layoutParams = LayoutParams(width, height)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment