A cross platform Audiobookshelf client for Android and iOS
Dart
Slim the 4x1 widget down to title and controls, show a spinner while play starts, and fix the first tap doing nothing after the app dies
Barnabas9b2ebe163178
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.ktindex 4330c41a..c34e16d7 100644--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidget.kt@@ -49,37 +49,7 @@ class NowPlayingWidget : AppWidgetProvider() {override fun onReceive(context: Context, intent: Intent) {if (intent.action == ACTION_TOGGLE_PLAYBACK) {- // Optimistic UI for pause only. Never mark the widget playing- // before the audio service confirms there is actually audio.- val widgetData = HomeWidgetPlugin.getData(context)- widgetData.edit().putBoolean("widget_is_playing", false).apply()-- // Re-render every now-playing widget size so they stay in sync.- // A render failure here must not stop the broadcast below, or the- // tap silently does nothing instead of toggling playback.- val mgr = AppWidgetManager.getInstance(context)- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidget::class.java))) {- try { updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidget", "toggle update failed", e)- }- }- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidgetCompact::class.java))) {- try { NowPlayingWidgetCompact.updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidget", "toggle update failed", e)- }- }- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidgetTiny::class.java))) {- try { NowPlayingWidgetTiny.updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidget", "toggle update failed", e)- }- }-- // Forward to MediaButtonReceiver for the actual playback toggle.- val mediaIntent = Intent(Intent.ACTION_MEDIA_BUTTON).apply {- component = ComponentName(context, "com.ryanheise.audioservice.MediaButtonReceiver")- putExtra(Intent.EXTRA_KEY_EVENT, KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE))- }- context.sendBroadcast(mediaIntent)+ WidgetClock.handleToggleTap(context)return}super.onReceive(context, intent)@@ -188,10 +158,18 @@ class NowPlayingWidget : AppWidgetProvider() {views.setViewVisibility(R.id.widget_progress_row, View.VISIBLE)views.setViewVisibility(R.id.widget_controls, View.VISIBLE)- if (isPlaying) {- views.setImageViewResource(R.id.widget_play_pause, R.drawable.ic_widget_pause_dark)+ if (WidgetClock.pendingPlay(widgetData, isPlaying)) {+ // Tap registered, audio not started yet (cold start can+ // take seconds) - spin instead of looking dead.+ views.setImageViewResource(R.id.widget_play_pause, android.R.color.transparent)+ views.setViewVisibility(R.id.widget_play_pending, View.VISIBLE)} else {- views.setImageViewResource(R.id.widget_play_pause, R.drawable.ic_widget_play_dark)+ views.setViewVisibility(R.id.widget_play_pending, View.GONE)+ if (isPlaying) {+ views.setImageViewResource(R.id.widget_play_pause, R.drawable.ic_widget_pause_dark)+ } else {+ views.setImageViewResource(R.id.widget_play_pause, R.drawable.ic_widget_play_dark)+ }}// Cover art from file (rounded corners)@@ -225,6 +203,7 @@ class NowPlayingWidget : AppWidgetProvider() {views.setViewVisibility(R.id.widget_progress_row, View.INVISIBLE)views.setViewVisibility(R.id.widget_controls, View.GONE)views.setViewVisibility(R.id.widget_chapter, View.GONE)+ views.setViewVisibility(R.id.widget_play_pending, View.GONE)views.setImageViewResource(R.id.widget_cover, R.mipmap.ic_launcher)}diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.ktindex c51cef59..8b56bb16 100644--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetCompact.kt@@ -49,33 +49,7 @@ class NowPlayingWidgetCompact : AppWidgetProvider() {override fun onReceive(context: Context, intent: Intent) {if (intent.action == ACTION_TOGGLE_PLAYBACK) {- val widgetData = HomeWidgetPlugin.getData(context)- widgetData.edit().putBoolean("widget_is_playing", false).apply()-- // A render failure here must not stop the broadcast below, or the- // tap silently does nothing instead of toggling playback.- val mgr = AppWidgetManager.getInstance(context)- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidgetCompact::class.java))) {- try { updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidgetCompact", "toggle update failed", e)- }- }- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidget::class.java))) {- try { NowPlayingWidget.updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidgetCompact", "toggle update failed", e)- }- }- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidgetTiny::class.java))) {- try { NowPlayingWidgetTiny.updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidgetCompact", "toggle update failed", e)- }- }-- val mediaIntent = Intent(Intent.ACTION_MEDIA_BUTTON).apply {- component = ComponentName(context, "com.ryanheise.audioservice.MediaButtonReceiver")- putExtra(Intent.EXTRA_KEY_EVENT, KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE))- }- context.sendBroadcast(mediaIntent)+ WidgetClock.handleToggleTap(context)return}super.onReceive(context, intent)@@ -139,7 +113,6 @@ class NowPlayingWidgetCompact : AppWidgetProvider() {val title = widgetData.getString("widget_title", null)val hasBook = widgetData.getBoolean("widget_has_book", false)val canControl = (hasBook || !title.isNullOrEmpty()) && WidgetClock.isEngineAlive()- val author = widgetData.getString("widget_author", null)val isPlaying = widgetData.getBoolean("widget_is_playing", false)val coverPath = widgetData.getString("widget_cover_path", null)val skipBack = widgetData.getInt("widget_skip_back", 10)@@ -149,36 +122,25 @@ class NowPlayingWidgetCompact : AppWidgetProvider() {views.setTextViewText(R.id.widget_skip_forward_text, skipForward.toString())if (!title.isNullOrEmpty()) {+ // Just the title and the transport row - no author/progress/+ // clocks, so the card fits the shorter 1-cell heights on+ // Samsung-style launchers.views.setTextViewText(R.id.widget_title, title)- views.setTextViewText(R.id.widget_author, author ?: "")+ views.setViewVisibility(R.id.widget_author, View.GONE)views.setViewVisibility(R.id.widget_controls, View.VISIBLE)- // Squiggle strip + elapsed/remaining clocks at the ends of the- // controls row; the WidgetClock ticker keeps them live.- val times = WidgetClock.computeTimes(widgetData)- val fraction = times?.fraction ?: (widgetData.getInt("widget_progress", 0) / 1000f)- val density = context.resources.displayMetrics.density- val widthDp = appWidgetManager.getAppWidgetOptions(appWidgetId)- .getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, 250)- views.setImageViewBitmap(- R.id.widget_progress,- WidgetClock.drawProgressBar(WidgetClock.compactBarWidthPx(widthDp, density), (8 * density).toInt(), fraction, isPlaying, density)- )- views.setViewVisibility(R.id.widget_progress, View.VISIBLE)- if (times != null) {- views.setTextViewText(R.id.widget_time_elapsed, WidgetClock.fmtTime(times.elapsedMs))- views.setTextViewText(R.id.widget_time_remaining, "-" + WidgetClock.fmtTime(times.remainingMs))- views.setViewVisibility(R.id.widget_time_elapsed, View.VISIBLE)- views.setViewVisibility(R.id.widget_time_remaining, View.VISIBLE)- } else {- views.setViewVisibility(R.id.widget_time_elapsed, View.GONE)- views.setViewVisibility(R.id.widget_time_remaining, View.GONE)- }-- if (isPlaying) {- views.setImageViewResource(R.id.widget_play_pause, R.drawable.ic_widget_pause_dark)+ if (WidgetClock.pendingPlay(widgetData, isPlaying)) {+ // Tap registered, audio not started yet (cold start can+ // take seconds) - spin instead of looking dead.+ views.setImageViewResource(R.id.widget_play_pause, android.R.color.transparent)+ views.setViewVisibility(R.id.widget_play_pending, View.VISIBLE)} else {- views.setImageViewResource(R.id.widget_play_pause, R.drawable.ic_widget_play_dark)+ views.setViewVisibility(R.id.widget_play_pending, View.GONE)+ if (isPlaying) {+ views.setImageViewResource(R.id.widget_play_pause, R.drawable.ic_widget_pause_dark)+ } else {+ views.setImageViewResource(R.id.widget_play_pause, R.drawable.ic_widget_play_dark)+ }}// Cover art from file (rounded corners)@@ -209,10 +171,9 @@ class NowPlayingWidgetCompact : AppWidgetProvider() {// Idle stateviews.setTextViewText(R.id.widget_title, "Absorb")views.setTextViewText(R.id.widget_author, "Not playing")+ views.setViewVisibility(R.id.widget_author, View.VISIBLE)views.setViewVisibility(R.id.widget_controls, View.GONE)- views.setViewVisibility(R.id.widget_progress, View.GONE)- views.setViewVisibility(R.id.widget_time_elapsed, View.GONE)- views.setViewVisibility(R.id.widget_time_remaining, View.GONE)+ views.setViewVisibility(R.id.widget_play_pending, View.GONE)views.setImageViewResource(R.id.widget_cover, R.mipmap.ic_launcher)}diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetTiny.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetTiny.ktindex efed4068..a37a413f 100644--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetTiny.kt+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetTiny.kt@@ -70,35 +70,7 @@ class NowPlayingWidgetTiny : AppWidgetProvider() {override fun onReceive(context: Context, intent: Intent) {if (intent.action == ACTION_TOGGLE_PLAYBACK) {- // Optimistic UI for pause only. Never mark the widget playing- // before the audio service confirms there is actually audio.- val widgetData = HomeWidgetPlugin.getData(context)- widgetData.edit().putBoolean("widget_is_playing", false).apply()-- // A render failure here must not stop the broadcast below, or the- // tap silently does nothing instead of toggling playback.- val mgr = AppWidgetManager.getInstance(context)- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidgetTiny::class.java))) {- try { updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidgetTiny", "toggle update failed", e)- }- }- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidget::class.java))) {- try { NowPlayingWidget.updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidgetTiny", "toggle update failed", e)- }- }- for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidgetCompact::class.java))) {- try { NowPlayingWidgetCompact.updateWidget(context, mgr, id) } catch (e: Exception) {- android.util.Log.e("NowPlayingWidgetTiny", "toggle update failed", e)- }- }-- val mediaIntent = Intent(Intent.ACTION_MEDIA_BUTTON).apply {- component = ComponentName(context, "com.ryanheise.audioservice.MediaButtonReceiver")- putExtra(Intent.EXTRA_KEY_EVENT, KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE))- }- context.sendBroadcast(mediaIntent)+ WidgetClock.handleToggleTap(context)return}super.onReceive(context, intent)@@ -230,6 +202,9 @@ class NowPlayingWidgetTiny : AppWidgetProvider() {}val playPauseIcon = if (isPlaying) R.drawable.ic_widget_pause_dark else R.drawable.ic_widget_play_dark+ // Tap registered, audio not started yet (cold start can take+ // seconds) - spin instead of looking dead.+ val pendingPlay = WidgetClock.pendingPlay(widgetData, isPlaying)if (showPanel) {// Larger size: hide the centered dot, show the player panel.@@ -259,7 +234,14 @@ class NowPlayingWidgetTiny : AppWidgetProvider() {// compact notification).views.setTextViewText(R.id.widget_skip_back_text, widgetData.getInt("widget_skip_back", 10).toString())views.setTextViewText(R.id.widget_skip_forward_text, widgetData.getInt("widget_skip_forward", 30).toString())- views.setImageViewResource(R.id.widget_pp, playPauseIcon)+ if (pendingPlay) {+ views.setImageViewResource(R.id.widget_pp, android.R.color.transparent)+ views.setViewVisibility(R.id.widget_play_pending, View.VISIBLE)+ } else {+ views.setViewVisibility(R.id.widget_play_pending, View.GONE)+ views.setImageViewResource(R.id.widget_pp, playPauseIcon)+ }+ views.setViewVisibility(R.id.widget_play_pending_tile, View.GONE)val times = WidgetClock.computeTimes(widgetData)val fraction = times?.fraction ?: (widgetData.getInt("widget_progress", 0) / 1000f)@@ -326,9 +308,16 @@ class NowPlayingWidgetTiny : AppWidgetProvider() {views.setViewVisibility(R.id.widget_panel, View.GONE)if (canControl) {views.setViewVisibility(R.id.widget_play_pause, View.VISIBLE)- views.setImageViewResource(R.id.widget_play_pause, playPauseIcon)+ if (pendingPlay) {+ views.setImageViewResource(R.id.widget_play_pause, android.R.color.transparent)+ views.setViewVisibility(R.id.widget_play_pending_tile, View.VISIBLE)+ } else {+ views.setViewVisibility(R.id.widget_play_pending_tile, View.GONE)+ views.setImageViewResource(R.id.widget_play_pause, playPauseIcon)+ }} else {views.setViewVisibility(R.id.widget_play_pause, View.GONE)+ views.setViewVisibility(R.id.widget_play_pending_tile, View.GONE)}val tapIntent = if (canControl) {diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/WidgetClock.kt b/android/app/src/main/kotlin/com/barnabas/absorb/WidgetClock.ktindex f5439f84..68314be0 100644--- a/android/app/src/main/kotlin/com/barnabas/absorb/WidgetClock.kt+++ b/android/app/src/main/kotlin/com/barnabas/absorb/WidgetClock.kt@@ -3,16 +3,20 @@ package com.barnabas.absorbimport android.appwidget.AppWidgetManagerimport android.content.ComponentNameimport android.content.Context+import android.content.Intentimport android.content.SharedPreferencesimport android.graphics.Bitmapimport android.graphics.Canvasimport android.graphics.Paintimport android.graphics.Path+import android.net.Uriimport android.os.Handlerimport android.os.Looperimport android.os.PowerManager+import android.view.KeyEventimport android.widget.RemoteViewsimport com.ryanheise.audioservice.AudioServicePlugin+import es.antonborri.home_widget.HomeWidgetLaunchIntentimport es.antonborri.home_widget.HomeWidgetPluginimport io.flutter.embedding.engine.FlutterEngineCacheimport org.json.JSONArray@@ -39,6 +43,101 @@ internal object WidgetClock {fun isEngineAlive(): Boolean =FlutterEngineCache.getInstance().get(AudioServicePlugin.getFlutterEngineId()) != null+ // The widgets' play/pause tap, shared by all three sizes. While the engine+ // is alive the MediaSession broadcast toggles playback without opening the+ // app. When the process died since the button was wired (nothing re-renders+ // widgets at engine death, so the wiring goes stale), that broadcast is a+ // dead end - AudioService never creates an engine - and the tap used to do+ // nothing until a second tap hit the re-wired button. Fall back to the same+ // cold-start launch the render-time wiring uses when it knows the app is+ // dead: open the app with the play deep link.+ fun sendPlayPause(context: Context) {+ if (isEngineAlive()) {+ val mediaIntent = Intent(Intent.ACTION_MEDIA_BUTTON).apply {+ component = ComponentName(context, "com.ryanheise.audioservice.MediaButtonReceiver")+ putExtra(Intent.EXTRA_KEY_EVENT, KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE))+ }+ context.sendBroadcast(mediaIntent)+ return+ }+ try {+ HomeWidgetLaunchIntent.getActivity(+ context, MainActivity::class.java,+ Uri.parse("absorb://widget/play_pause")+ ).send()+ } catch (e: Exception) {+ android.util.Log.e("WidgetClock", "cold-start launch from widget tap failed", e)+ }+ }++ // A play tap can take seconds to produce audio (a cold start boots the+ // whole app first), and a button that doesn't react reads as dead. Taps+ // that should START playback stamp this; renders show a spinner on the+ // play pill until real state arrives or the window expires.+ private const val PENDING_PLAY_WINDOW_MS = 15_000L+ private const val PENDING_TAP_DEBOUNCE_MS = 2_500L++ fun pendingPlay(widgetData: SharedPreferences, isPlaying: Boolean): Boolean {+ val at = widgetData.getLong("widget_pending_play_at", 0L)+ if (at == 0L) return false+ if (isPlaying || System.currentTimeMillis() - at > PENDING_PLAY_WINDOW_MS) {+ widgetData.edit().remove("widget_pending_play_at").apply()+ return false+ }+ return true+ }++ fun renderAllNowPlaying(context: Context) {+ val mgr = AppWidgetManager.getInstance(context)+ for (id in ids(context, mgr, NowPlayingWidget::class.java)) {+ try { NowPlayingWidget.updateWidget(context, mgr, id) } catch (e: Exception) {+ android.util.Log.e("WidgetClock", "render failed", e)+ }+ }+ for (id in ids(context, mgr, NowPlayingWidgetCompact::class.java)) {+ try { NowPlayingWidgetCompact.updateWidget(context, mgr, id) } catch (e: Exception) {+ android.util.Log.e("WidgetClock", "render failed", e)+ }+ }+ for (id in ids(context, mgr, NowPlayingWidgetTiny::class.java)) {+ try { NowPlayingWidgetTiny.updateWidget(context, mgr, id) } catch (e: Exception) {+ android.util.Log.e("WidgetClock", "render failed", e)+ }+ }+ }++ // Shared ACTION_TOGGLE_PLAYBACK handler for all three widget sizes.+ // Optimistic UI for pause only - never mark the widget playing before the+ // audio service confirms there is actually audio. Resume taps show the+ // pending spinner immediately and are debounced so mashing a slow-to-+ // react button doesn't queue extra toggles that pause it again.+ fun handleToggleTap(context: Context) {+ val widgetData = HomeWidgetPlugin.getData(context)+ val now = System.currentTimeMillis()+ val wasPlaying = widgetData.getBoolean("widget_is_playing", false)+ if (!wasPlaying &&+ now - widgetData.getLong("widget_pending_play_at", 0L) < PENDING_TAP_DEBOUNCE_MS) {+ return+ }+ val edit = widgetData.edit().putBoolean("widget_is_playing", false)+ if (!wasPlaying) {+ edit.putLong("widget_pending_play_at", now)+ } else {+ edit.remove("widget_pending_play_at")+ }+ edit.apply()+ renderAllNowPlaying(context)+ if (!wasPlaying) {+ // Self-heal: if playback never materialises, a re-render after the+ // window clears the spinner instead of leaving it forever.+ val app = context.applicationContext+ tickHandler.postDelayed({+ try { renderAllNowPlaying(app) } catch (_: Exception) {}+ }, PENDING_PLAY_WINDOW_MS + 500L)+ }+ sendPlayPause(context)+ }+// Width gate for the tiny widget's clocks beside the progress bar.// Measured: 2 real cells report 171dp (Pixel) / 201dp (One UI), 3 cells// 266dp / 315dp - so 230 means "at least 3 cells wide" on both.@@ -169,16 +268,13 @@ internal object WidgetClock {// Bar bitmap width estimates per widget. The bars are stretched with// fitXY, so these only need to be close: the tiny widget's row padding// eats ~36dp and its two clocks ~110dp; the big widget loses its cover- // and text padding; the compact its cover.+ // and text padding.fun tinyBarWidthPx(widthDp: Int, showTimes: Boolean, density: Float): Int =((widthDp - 36 - if (showTimes) 110 else 0).coerceAtLeast(40) * density).toInt()fun bigBarWidthPx(widthDp: Int, density: Float): Int =((widthDp - 160).coerceAtLeast(60) * density).toInt()- fun compactBarWidthPx(widthDp: Int, density: Float): Int =- ((widthDp - 110).coerceAtLeast(60) * density).toInt()-// ── Per-second ticker ──private val tickHandler = Handler(Looper.getMainLooper())@@ -213,9 +309,10 @@ internal object WidgetClock {var shouldTick = hasPlayableItem &&widgetData.getBoolean("widget_is_playing", false)if (shouldTick) {+ // The compact widget shows no clocks or progress, so it never+ // needs ticks - only the big and (2+ cells wide) tiny widgets do.val mgr = AppWidgetManager.getInstance(app)shouldTick = ids(app, mgr, NowPlayingWidget::class.java).isNotEmpty() ||- ids(app, mgr, NowPlayingWidgetCompact::class.java).isNotEmpty() ||ids(app, mgr, NowPlayingWidgetTiny::class.java).any { cellsFor(minWidthDp(mgr, it)) >= 2 }}if (shouldTick && !ticking) {@@ -277,18 +374,5 @@ internal object WidgetClock {}mgr.partiallyUpdateAppWidget(id, partial)}-- for (id in ids(context, mgr, NowPlayingWidgetCompact::class.java)) {- val partial = RemoteViews(context.packageName, R.layout.now_playing_widget_compact)- partial.setTextViewText(R.id.widget_time_elapsed, elapsed)- partial.setTextViewText(R.id.widget_time_remaining, remaining)- if (refreshBar) {- partial.setImageViewBitmap(- R.id.widget_progress,- drawProgressBar(compactBarWidthPx(minWidthDp(mgr, id), density), (8 * density).toInt(), times.fraction, true, density)- )- }- mgr.partiallyUpdateAppWidget(id, partial)- }}}diff --git a/android/app/src/main/res/layout/now_playing_widget.xml b/android/app/src/main/res/layout/now_playing_widget.xmlindex 2f2b8b8b..75891e70 100644--- a/android/app/src/main/res/layout/now_playing_widget.xml+++ b/android/app/src/main/res/layout/now_playing_widget.xml@@ -122,15 +122,28 @@</FrameLayout><!-- Play/pause: white circle with dark icon -->- <ImageButton- android:id="@+id/widget_play_pause"- android:layout_width="56dp"- android:layout_height="40dp"- android:padding="8dp"- android:src="@drawable/ic_widget_play_dark"- android:background="@drawable/widget_play_btn_bg"- android:contentDescription="Play or pause"- android:scaleType="centerInside" />+ <FrameLayout+ android:layout_width="wrap_content"+ android:layout_height="wrap_content">+ <ImageButton+ android:id="@+id/widget_play_pause"+ android:layout_width="56dp"+ android:layout_height="40dp"+ android:padding="8dp"+ android:src="@drawable/ic_widget_play_dark"+ android:background="@drawable/widget_play_btn_bg"+ android:contentDescription="Play or pause"+ android:scaleType="centerInside" />+ <ProgressBar+ android:id="@+id/widget_play_pending"+ style="?android:attr/progressBarStyleSmall"+ android:layout_width="18dp"+ android:layout_height="18dp"+ android:layout_gravity="center"+ android:indeterminate="true"+ android:indeterminateTint="#1A1A1A"+ android:visibility="gone" />+ </FrameLayout><!-- Skip forward: arrow icon with duration overlay --><FrameLayoutdiff --git a/android/app/src/main/res/layout/now_playing_widget_compact.xml b/android/app/src/main/res/layout/now_playing_widget_compact.xmlindex 8e17acae..7c50116b 100644--- a/android/app/src/main/res/layout/now_playing_widget_compact.xml+++ b/android/app/src/main/res/layout/now_playing_widget_compact.xml@@ -1,5 +1,8 @@<?xml version="1.0" encoding="utf-8"?>-<!-- Compact 4x1 now-playing widget -->+<!-- Compact 4x1 now-playing widget: cover + title + transport only. No+ author/progress/clock rows - OEM launchers (Samsung) give a 1-cell+ widget much less height than the Pixel, and the stacked version+ overflowed there. --><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/widget_outer"android:layout_width="match_parent"@@ -28,16 +31,17 @@android:src="@mipmap/ic_launcher"android:contentDescription="Cover art" />- <!-- Right side: title/author on top, controls centered below -->+ <!-- Right side: title above the transport, centered as a group --><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:orientation="vertical"- android:paddingTop="4dp"- android:paddingBottom="4dp">+ android:gravity="center_vertical"+ android:paddingTop="6dp"+ android:paddingBottom="6dp">- <!-- Title -->+ <!-- Title (chapter when available, else book) --><TextViewandroid:id="@+id/widget_title"android:layout_width="match_parent"@@ -52,7 +56,7 @@android:ellipsize="end"android:fontFamily="sans-serif-medium" />- <!-- Author -->+ <!-- "Not playing" subtitle, idle state only --><TextViewandroid:id="@+id/widget_author"android:layout_width="match_parent"@@ -65,45 +69,18 @@android:maxLines="1"android:ellipsize="end" />- <!-- Thin squiggle progress strip (bitmap from WidgetClock) -->- <ImageView- android:id="@+id/widget_progress"- android:layout_width="match_parent"- android:layout_height="8dp"- android:layout_marginStart="10dp"- android:layout_marginEnd="10dp"- android:layout_marginTop="2dp"- android:scaleType="fitXY"- android:contentDescription="Progress"- android:visibility="gone" />-- <!-- Equal spacers above and below controls to center them -->- <FrameLayout- android:layout_width="match_parent"- android:layout_height="0dp"- android:layout_weight="1" />-- <!-- Controls spread across full width -->+ <!-- Controls spread across full width, inset from the card edges --><LinearLayoutandroid:id="@+id/widget_controls"android:layout_width="match_parent"android:layout_height="wrap_content"+ android:layout_marginTop="8dp"android:orientation="horizontal"android:gravity="center_vertical"- android:paddingStart="4dp"- android:paddingEnd="4dp"+ android:paddingStart="12dp"+ android:paddingEnd="12dp"android:visibility="gone">- <TextView- android:id="@+id/widget_time_elapsed"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:paddingStart="8dp"- android:textColor="#99FFFFFF"- android:textSize="9sp"- android:fontFamily="sans-serif-medium"- android:visibility="gone" />-<FrameLayoutandroid:id="@+id/widget_skip_back"android:layout_width="0dp"@@ -130,15 +107,28 @@android:fontFamily="sans-serif-medium" /></FrameLayout>- <ImageButton- android:id="@+id/widget_play_pause"- android:layout_width="56dp"- android:layout_height="40dp"- android:padding="8dp"- android:src="@drawable/ic_widget_play_dark"- android:background="@drawable/widget_play_btn_bg"- android:contentDescription="Play or pause"- android:scaleType="centerInside" />+ <FrameLayout+ android:layout_width="wrap_content"+ android:layout_height="wrap_content">+ <ImageButton+ android:id="@+id/widget_play_pause"+ android:layout_width="56dp"+ android:layout_height="40dp"+ android:padding="8dp"+ android:src="@drawable/ic_widget_play_dark"+ android:background="@drawable/widget_play_btn_bg"+ android:contentDescription="Play or pause"+ android:scaleType="centerInside" />+ <ProgressBar+ android:id="@+id/widget_play_pending"+ style="?android:attr/progressBarStyleSmall"+ android:layout_width="18dp"+ android:layout_height="18dp"+ android:layout_gravity="center"+ android:indeterminate="true"+ android:indeterminateTint="#1A1A1A"+ android:visibility="gone" />+ </FrameLayout><FrameLayoutandroid:id="@+id/widget_skip_forward"@@ -166,23 +156,8 @@android:fontFamily="sans-serif-medium" /></FrameLayout>- <TextView- android:id="@+id/widget_time_remaining"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:paddingEnd="8dp"- android:textColor="#99FFFFFF"- android:textSize="9sp"- android:fontFamily="sans-serif-medium"- android:visibility="gone" />-</LinearLayout>- <FrameLayout- android:layout_width="match_parent"- android:layout_height="0dp"- android:layout_weight="1" />-</LinearLayout></LinearLayout>diff --git a/android/app/src/main/res/layout/now_playing_widget_tiny.xml b/android/app/src/main/res/layout/now_playing_widget_tiny.xmlindex 6fc3189d..eb7067a4 100644--- a/android/app/src/main/res/layout/now_playing_widget_tiny.xml+++ b/android/app/src/main/res/layout/now_playing_widget_tiny.xml@@ -39,6 +39,16 @@android:scaleType="centerInside"android:contentDescription="Play or pause" />+ <ProgressBar+ android:id="@+id/widget_play_pending_tile"+ style="?android:attr/progressBarStyleSmall"+ android:layout_width="18dp"+ android:layout_height="18dp"+ android:layout_gravity="center"+ android:indeterminate="true"+ android:indeterminateTint="#1A1A1A"+ android:visibility="gone" />+<!-- Player panel pinned to the bottom of the cover. The scrim is the panel'sown background so it always wraps whatever rows are visible. --><LinearLayout@@ -177,15 +187,28 @@</FrameLayout><!-- Play/pause: white circle with dark icon -->- <ImageButton- android:id="@+id/widget_pp"- android:layout_width="72dp"- android:layout_height="52dp"- android:padding="12dp"- android:src="@drawable/ic_widget_play_dark"- android:background="@drawable/widget_play_btn_bg"- android:contentDescription="Play or pause"- android:scaleType="centerInside" />+ <FrameLayout+ android:layout_width="wrap_content"+ android:layout_height="wrap_content">+ <ImageButton+ android:id="@+id/widget_pp"+ android:layout_width="72dp"+ android:layout_height="52dp"+ android:padding="12dp"+ android:src="@drawable/ic_widget_play_dark"+ android:background="@drawable/widget_play_btn_bg"+ android:contentDescription="Play or pause"+ android:scaleType="centerInside" />+ <ProgressBar+ android:id="@+id/widget_play_pending"+ style="?android:attr/progressBarStyleSmall"+ android:layout_width="20dp"+ android:layout_height="20dp"+ android:layout_gravity="center"+ android:indeterminate="true"+ android:indeterminateTint="#1A1A1A"+ android:visibility="gone" />+ </FrameLayout><!-- Skip forward: arrow icon with duration overlay --><FrameLayoutdiff --git a/lib/services/home_widget_service.dart b/lib/services/home_widget_service.dartindex 62559c3c..e9f00850 100644--- a/lib/services/home_widget_service.dart+++ b/lib/services/home_widget_service.dart@@ -338,18 +338,18 @@ class HomeWidgetService {'Caller:\n${StackTrace.current}',);- // When there's an active session the widget uses a MediaSession media button- // instead of launching the app, so this path is only hit for cold resume.+ // A session can already be loaded when this fires: iOS always routes+ // widget links here, and on Android the launch path races the session+ // restore (or arrives from stale widget wiring after a process death).+ // A play tap must never be a silent no-op, so toggle rather than assume+ // the MediaSession broadcast handled it.if (player.hasBook) {- // On iOS, widget links always come through here (no MediaSession shortcut).- if (Platform.isIOS) {- if (player.isPlaying) {- debugPrint('[WidgetDebug] -> pause()');- player.pause();- } else {- debugPrint('[WidgetDebug] -> play()');- player.play();- }+ if (player.isPlaying) {+ debugPrint('[WidgetDebug] -> pause()');+ player.pause();+ } else {+ debugPrint('[WidgetDebug] -> play()');+ player.play();}return;}