A cross platform Audiobookshelf client for Android and iOS
Dart
Stop Absorb starting playback by itself when it's opened from the widget cover or right after an update
Barnabas6ba92f9e0749
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt b/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.ktindex e1774c0b..8eaf9593 100644--- a/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt+++ b/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt@@ -14,6 +14,7 @@ import android.media.audiofx.Equalizerimport android.media.audiofx.LoudnessEnhancerimport android.media.audiofx.Virtualizerimport android.os.Build+import android.os.Bundleimport android.os.Environmentimport android.os.Handlerimport android.os.Looper@@ -26,6 +27,7 @@ import com.ryanheise.audioservice.AudioServiceimport com.ryanheise.audioservice.AudioServiceActivityimport com.ryanheise.audioservice.AudioServicePluginimport com.ryanheise.just_audio.MonoController+import es.antonborri.home_widget.HomeWidgetLaunchIntentimport io.flutter.embedding.engine.FlutterEngineimport io.flutter.embedding.engine.FlutterEngineCacheimport io.flutter.plugin.common.MethodCall@@ -53,6 +55,22 @@ class MainActivity : AudioServiceActivity() {// init proves the engine is unavailable, skip attaching native effects.private var effectsAvailable: Boolean = true+ // Android brings a task back from a dead process by recreating its root+ // activity with the intent that first created it. When that was the+ // widget's play button, every later plain open (the widget cover, the+ // installer's Open button, Recents) replayed the play deep link and the+ // app started playing on its own. A real tap always creates the activity+ // fresh, so only a recreated one can be carrying a replay.+ override fun onCreate(savedInstanceState: Bundle?) {+ if (savedInstanceState != null &&+ intent?.action == HomeWidgetLaunchIntent.HOME_WIDGET_LAUNCH_ACTION) {+ Log.d(TAG, "Dropping replayed widget launch ${intent.data}")+ intent.action = Intent.ACTION_MAIN+ intent.data = null+ }+ super.onCreate(savedInstanceState)+ }+override fun provideFlutterEngine(context: Context): FlutterEngine? {// Headless service starts (Android Auto binds, media buttons on a// dead process) boot the engine with no activity so the browse tree@@ -547,6 +565,12 @@ class MainActivity : AudioServiceActivity() {Log.d(TAG, "Discarding search intent: $action")return}+ // FlutterActivity never adopts a new intent, so the widget's "launched+ // from" query kept answering with whatever intent created the activity.+ // On a task restored from a dead process that lost a fresh play-button+ // tap and replayed an old one. Keep the latest so the query sees the+ // tap that actually opened the app this time.+ setIntent(intent)super.onNewIntent(intent)}diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetTiny.kt b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetTiny.ktindex 5ce9e47c..a33204aa 100644--- a/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetTiny.kt+++ b/android/app/src/main/kotlin/com/barnabas/absorb/NowPlayingWidgetTiny.kt@@ -394,12 +394,14 @@ class NowPlayingWidgetTiny : AppWidgetProvider() {views.setViewVisibility(R.id.widget_play_pending_tile, View.GONE)}+ // With the app dead the tile shows no play icon, so a tap reads+ // as "open", not "play" - wired to play it opened the app and+ // started playback on its own. The larger widgets keep+ // open-and-play on their actual play button.val tapIntent = if (canControl) {togglePendingIntent(context)} else {- HomeWidgetLaunchIntent.getActivity(- context, MainActivity::class.java, Uri.parse("absorb://widget/play_pause")- )+ openAppPendingIntent(context)}views.setOnClickPendingIntent(R.id.widget_root, tapIntent)}