From b5dbac1e2b46bc58f60c41dc7af0971e6a3fa788 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Sat, 23 Mar 2024 19:42:14 +0100 Subject: [PATCH] #953 opening app from launcher always show home page --- CHANGELOG.md | 1 + .../aves/HomeWidgetConfigureActivity.kt | 3 +- .../deckers/thibault/aves/MainActivity.kt | 31 ++++++------------- .../aves/ScreenSaverSettingsActivity.kt | 3 +- .../thibault/aves/WallpaperActivity.kt | 5 +-- .../streams/MediaStoreChangeStreamHandler.kt | 10 +----- .../streams/SettingsChangeStreamHandler.kt | 10 +----- lib/widgets/common/behaviour/pop/scope.dart | 2 ++ 8 files changed, 21 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 969b0d010..103ad0125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ### Changed +- opening app from launcher always show home page - upgraded Flutter to stable v3.19.4 ### Fixed diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/HomeWidgetConfigureActivity.kt b/android/app/src/main/kotlin/deckers/thibault/aves/HomeWidgetConfigureActivity.kt index db22efb27..5d1518fcc 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/HomeWidgetConfigureActivity.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/HomeWidgetConfigureActivity.kt @@ -3,6 +3,7 @@ package deckers.thibault.aves import android.appwidget.AppWidgetManager import android.content.Intent import android.os.Bundle +import deckers.thibault.aves.model.FieldMap import deckers.thibault.aves.utils.FlutterUtils import deckers.thibault.aves.utils.FlutterUtils.enableSoftwareRendering import io.flutter.embedding.engine.FlutterEngine @@ -56,7 +57,7 @@ class HomeWidgetSettingsActivity : MainActivity() { finish() } - override fun extractIntentData(intent: Intent?): MutableMap { + override fun extractIntentData(intent: Intent?): FieldMap { return hashMapOf( INTENT_DATA_KEY_ACTION to INTENT_ACTION_WIDGET_SETTINGS, INTENT_DATA_KEY_WIDGET_ID to appWidgetId, diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt b/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt index 132a8041b..c54b6820c 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt @@ -175,18 +175,6 @@ open class MainActivity : FlutterFragmentActivity() { } } - override fun onResume() { - super.onResume() - mediaStoreChangeStreamHandler.onAppResume() - settingsChangeStreamHandler.onAppResume() - } - - override fun onPause() { - mediaStoreChangeStreamHandler.onAppPause() - settingsChangeStreamHandler.onAppPause() - super.onPause() - } - override fun onStop() { Log.i(LOG_TAG, "onStop") super.onStop() @@ -279,21 +267,19 @@ open class MainActivity : FlutterFragmentActivity() { } } - open fun extractIntentData(intent: Intent?): MutableMap { + open fun extractIntentData(intent: Intent?): FieldMap { when (val action = intent?.action) { Intent.ACTION_MAIN -> { - if (intent.getBooleanExtra(EXTRA_KEY_SAFE_MODE, false)) { - return hashMapOf( - INTENT_DATA_KEY_SAFE_MODE to true, - ) - } + val fields = hashMapOf( + INTENT_DATA_KEY_LAUNCHER to intent.hasCategory(Intent.CATEGORY_LAUNCHER), + INTENT_DATA_KEY_SAFE_MODE to intent.getBooleanExtra(EXTRA_KEY_SAFE_MODE, false), + ) intent.getStringExtra(EXTRA_KEY_PAGE)?.let { page -> val filters = extractFiltersFromIntent(intent) - return hashMapOf( - INTENT_DATA_KEY_PAGE to page, - INTENT_DATA_KEY_FILTERS to filters, - ) + fields[INTENT_DATA_KEY_PAGE] = page + fields[INTENT_DATA_KEY_FILTERS] = filters } + return fields } Intent.ACTION_VIEW, @@ -496,6 +482,7 @@ open class MainActivity : FlutterFragmentActivity() { const val INTENT_DATA_KEY_ACTION = "action" const val INTENT_DATA_KEY_ALLOW_MULTIPLE = "allowMultiple" const val INTENT_DATA_KEY_FILTERS = "filters" + const val INTENT_DATA_KEY_LAUNCHER = "launcher" const val INTENT_DATA_KEY_MIME_TYPE = "mimeType" const val INTENT_DATA_KEY_PAGE = "page" const val INTENT_DATA_KEY_QUERY = "query" diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/ScreenSaverSettingsActivity.kt b/android/app/src/main/kotlin/deckers/thibault/aves/ScreenSaverSettingsActivity.kt index dbc2e74f3..2d7e07077 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/ScreenSaverSettingsActivity.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/ScreenSaverSettingsActivity.kt @@ -1,9 +1,10 @@ package deckers.thibault.aves import android.content.Intent +import deckers.thibault.aves.model.FieldMap class ScreenSaverSettingsActivity : MainActivity() { - override fun extractIntentData(intent: Intent?): MutableMap { + override fun extractIntentData(intent: Intent?): FieldMap { return hashMapOf( INTENT_DATA_KEY_ACTION to INTENT_ACTION_SCREEN_SAVER_SETTINGS, ) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/WallpaperActivity.kt b/android/app/src/main/kotlin/deckers/thibault/aves/WallpaperActivity.kt index 3c0b0d1f6..c37539172 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/WallpaperActivity.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/WallpaperActivity.kt @@ -14,6 +14,7 @@ import deckers.thibault.aves.channel.calls.window.ActivityWindowHandler import deckers.thibault.aves.channel.calls.window.WindowHandler import deckers.thibault.aves.channel.streams.ImageByteStreamHandler import deckers.thibault.aves.channel.streams.MediaCommandStreamHandler +import deckers.thibault.aves.model.FieldMap import deckers.thibault.aves.utils.FlutterUtils import deckers.thibault.aves.utils.FlutterUtils.enableSoftwareRendering import deckers.thibault.aves.utils.LogUtils @@ -25,7 +26,7 @@ import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel class WallpaperActivity : FlutterFragmentActivity() { - private lateinit var intentDataMap: MutableMap + private lateinit var intentDataMap: FieldMap private lateinit var mediaSessionHandler: MediaSessionHandler override fun onCreate(savedInstanceState: Bundle?) { @@ -103,7 +104,7 @@ class WallpaperActivity : FlutterFragmentActivity() { } } - private fun extractIntentData(intent: Intent?): MutableMap { + private fun extractIntentData(intent: Intent?): FieldMap { when (intent?.action) { Intent.ACTION_ATTACH_DATA, Intent.ACTION_SET_WALLPAPER -> { (intent.data ?: intent.getParcelableExtraCompat(Intent.EXTRA_STREAM))?.let { uri -> diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/MediaStoreChangeStreamHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/MediaStoreChangeStreamHandler.kt index fd0c6eb5f..e926b5b6a 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/MediaStoreChangeStreamHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/MediaStoreChangeStreamHandler.kt @@ -30,14 +30,6 @@ class MediaStoreChangeStreamHandler(private val context: Context) : EventChannel } init { - onAppResume() - } - - fun dispose() { - onAppPause() - } - - fun onAppResume() { Log.i(LOG_TAG, "start listening to Media Store") context.contentResolver.apply { registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, contentObserver) @@ -45,7 +37,7 @@ class MediaStoreChangeStreamHandler(private val context: Context) : EventChannel } } - fun onAppPause() { + fun dispose() { Log.i(LOG_TAG, "stop listening to Media Store") context.contentResolver.unregisterContentObserver(contentObserver) } diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/SettingsChangeStreamHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/SettingsChangeStreamHandler.kt index 689cc6752..915f900c5 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/SettingsChangeStreamHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/streams/SettingsChangeStreamHandler.kt @@ -62,19 +62,11 @@ class SettingsChangeStreamHandler(private val context: Context) : EventChannel.S } init { - onAppResume() - } - - fun dispose() { - onAppPause() - } - - fun onAppResume() { Log.i(LOG_TAG, "start listening to system settings") context.contentResolver.registerContentObserver(Settings.System.CONTENT_URI, true, contentObserver) } - fun onAppPause() { + fun dispose() { Log.i(LOG_TAG, "stop listening to system settings") context.contentResolver.unregisterContentObserver(contentObserver) } diff --git a/lib/widgets/common/behaviour/pop/scope.dart b/lib/widgets/common/behaviour/pop/scope.dart index 317e59504..72bf70eef 100644 --- a/lib/widgets/common/behaviour/pop/scope.dart +++ b/lib/widgets/common/behaviour/pop/scope.dart @@ -1,3 +1,4 @@ +import 'package:aves/services/common/services.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -26,6 +27,7 @@ class AvesPopScope extends StatelessWidget { Navigator.maybeOf(context)?.pop(); } else { // exit + reportService.log('Exit by pop'); SystemNavigator.pop(); } }