From 5fbd7667b1949231360296ecd7ba324fbd0dd47a Mon Sep 17 00:00:00 2001 From: rhunk <101876869+rhunk@users.noreply.github.com> Date: Sat, 8 Jun 2024 15:59:19 +0200 Subject: [PATCH] fix(app): actions crash Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com> --- .../me/rhunk/snapenhance/RemoteSideContext.kt | 14 ++++++++++++++ .../ui/manager/pages/home/HomeRootSection.kt | 9 +-------- .../ui/manager/pages/home/HomeSettings.kt | 8 +------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/RemoteSideContext.kt b/app/src/main/kotlin/me/rhunk/snapenhance/RemoteSideContext.kt index f308020f0..391344145 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/RemoteSideContext.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/RemoteSideContext.kt @@ -23,6 +23,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import me.rhunk.snapenhance.bridge.BridgeService import me.rhunk.snapenhance.common.BuildConfig +import me.rhunk.snapenhance.common.Constants +import me.rhunk.snapenhance.common.action.EnumAction import me.rhunk.snapenhance.common.bridge.wrapper.LocaleWrapper import me.rhunk.snapenhance.common.bridge.wrapper.LoggerWrapper import me.rhunk.snapenhance.common.bridge.wrapper.MappingsWrapper @@ -223,4 +225,16 @@ class RemoteSideContext( return true } } + + fun launchActionIntent(action: EnumAction) { + val intent = androidContext.packageManager.getLaunchIntentForPackage( + Constants.SNAPCHAT_PACKAGE_NAME + ) + if (intent == null) { + shortToast("Can't execute action: Snapchat is not installed") + return + } + intent.putExtra(EnumAction.ACTION_PARAMETER, action.key) + androidContext.startActivity(intent) + } } diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt index ce2ce61ee..2ced13765 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt @@ -54,13 +54,6 @@ class HomeRootSection : Routes.Route() { private lateinit var activityLauncherHelper: ActivityLauncherHelper - private fun launchActionIntent(action: EnumAction) { - val intent = context.androidContext.packageManager.getLaunchIntentForPackage( - Constants.SNAPCHAT_PACKAGE_NAME - ) - intent?.putExtra(EnumAction.ACTION_PARAMETER, action.key) - context.androidContext.startActivity(intent) - } private val cards by lazy { EnumQuickActions.entries.map { @@ -70,7 +63,7 @@ class HomeRootSection : Routes.Route() { }.toMutableMap().apply { EnumAction.entries.forEach { action -> this[context.translation["actions.${action.key}.name"] to action.icon] = { - launchActionIntent(action) + context.launchActionIntent(action) } } } diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeSettings.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeSettings.kt index 584b80740..bab9d0448 100644 --- a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeSettings.kt +++ b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeSettings.kt @@ -121,12 +121,6 @@ class HomeSettings : Routes.Route() { } } - private fun launchActionIntent(action: EnumAction) { - val intent = context.androidContext.packageManager.getLaunchIntentForPackage(Constants.SNAPCHAT_PACKAGE_NAME) - intent?.putExtra(EnumAction.ACTION_PARAMETER, action.key) - context.androidContext.startActivity(intent) - } - @Composable private fun ShiftedRow( modifier: Modifier = Modifier, @@ -151,7 +145,7 @@ class HomeSettings : Routes.Route() { RowTitle(title = translation["actions_title"]) EnumAction.entries.forEach { enumAction -> RowAction(key = enumAction.key) { - launchActionIntent(enumAction) + context.launchActionIntent(enumAction) } } RowAction(key = "regen_mappings") {