From 73331b3d1e4daf8683ae5635994c71848d129ea1 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 8 May 2022 12:49:16 +0100 Subject: [PATCH] launching the app when tapping the summary notification --- app/src/main/kotlin/app/dapk/st/graph/AppModule.kt | 10 ++++++---- .../main/kotlin/app/dapk/st/navigator/Navigator.kt | 8 ++++---- features/notifications/build.gradle | 1 + .../app/dapk/st/notifications/NotificationFactory.kt | 11 +++++++++++ .../app/dapk/st/notifications/NotificationsModule.kt | 4 +++- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/app/dapk/st/graph/AppModule.kt b/app/src/main/kotlin/app/dapk/st/graph/AppModule.kt index e77cb3e..2edcad5 100644 --- a/app/src/main/kotlin/app/dapk/st/graph/AppModule.kt +++ b/app/src/main/kotlin/app/dapk/st/graph/AppModule.kt @@ -1,6 +1,5 @@ package app.dapk.st.graph -import android.app.Activity import android.app.Application import android.content.Context import android.content.Intent @@ -90,9 +89,9 @@ internal class AppModule(context: Application, logger: MatrixLogger) { val domainModules = DomainModules(matrixModules, trackingModule.errorTracker) val coreAndroidModule = CoreAndroidModule(intentFactory = object : IntentFactory { - override fun home(activity: Activity) = Intent(activity, MainActivity::class.java) - override fun messenger(activity: Activity, roomId: RoomId) = MessengerActivity.newInstance(activity, roomId) - override fun messengerShortcut(activity: Activity, roomId: RoomId) = MessengerActivity.newShortcutInstance(activity, roomId) + override fun home(context: Context) = Intent(context, MainActivity::class.java) + override fun messenger(context: Context, roomId: RoomId) = MessengerActivity.newInstance(context, roomId) + override fun messengerShortcut(context: Context, roomId: RoomId) = MessengerActivity.newShortcutInstance(context, roomId) }) val featureModules = FeatureModules( @@ -101,6 +100,7 @@ internal class AppModule(context: Application, logger: MatrixLogger) { domainModules, trackingModule, workModule, + coreAndroidModule, imageLoaderModule, context, buildMeta, @@ -115,6 +115,7 @@ internal class FeatureModules internal constructor( private val domainModules: DomainModules, private val trackingModule: TrackingModule, private val workModule: WorkModule, + private val coreAndroidModule: CoreAndroidModule, imageLoaderModule: ImageLoaderModule, context: Context, buildMeta: BuildMeta, @@ -172,6 +173,7 @@ internal class FeatureModules internal constructor( storeModule.value.roomStore(), context, workModule.workScheduler(), + intentFactory = coreAndroidModule.intentFactory(), ) } diff --git a/features/navigator/src/main/kotlin/app/dapk/st/navigator/Navigator.kt b/features/navigator/src/main/kotlin/app/dapk/st/navigator/Navigator.kt index 28f7287..cb3ae02 100644 --- a/features/navigator/src/main/kotlin/app/dapk/st/navigator/Navigator.kt +++ b/features/navigator/src/main/kotlin/app/dapk/st/navigator/Navigator.kt @@ -1,6 +1,7 @@ package app.dapk.st.navigator import android.app.Activity +import android.content.Context import android.content.Intent import app.dapk.st.matrix.common.RoomId import kotlin.properties.ReadOnlyProperty @@ -39,10 +40,9 @@ interface Navigator { interface IntentFactory { - fun home(activity: Activity): Intent - fun messenger(activity: Activity, roomId: RoomId): Intent - fun messengerShortcut(activity: Activity, roomId: RoomId): Intent - + fun home(context: Context): Intent + fun messenger(context: Context, roomId: RoomId): Intent + fun messengerShortcut(context: Context, roomId: RoomId): Intent } diff --git a/features/notifications/build.gradle b/features/notifications/build.gradle index 21b4bf9..5dd0cdf 100644 --- a/features/notifications/build.gradle +++ b/features/notifications/build.gradle @@ -10,6 +10,7 @@ dependencies { implementation project(":core") implementation project(":domains:android:imageloader") implementation project(":features:messenger") + implementation project(":features:navigator") implementation platform('com.google.firebase:firebase-bom:29.0.3') implementation 'com.google.firebase:firebase-messaging' diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt index 61594f4..515a285 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt @@ -11,6 +11,7 @@ import app.dapk.st.imageloader.IconLoader import app.dapk.st.matrix.sync.RoomEvent import app.dapk.st.matrix.sync.RoomOverview import app.dapk.st.messenger.MessengerActivity +import app.dapk.st.navigator.IntentFactory private const val GROUP_ID = "st" private const val channelId = "message" @@ -18,6 +19,7 @@ private const val channelId = "message" class NotificationFactory( private val iconLoader: IconLoader, private val context: Context, + private val intentFactory: IntentFactory, ) { suspend fun createNotifications(events: Map>, onlyContainsRemovals: Boolean): Notifications { @@ -53,6 +55,14 @@ class NotificationFactory( summaryInboxStyle.setSummaryText("${notifications.countMessages()} messages from ${notifications.size} chats") } + val openAppIntent = PendingIntent.getActivity( + context, + 1000, + intentFactory.home(context) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK), + PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE + ) + return builder() .setStyle(summaryInboxStyle) .setOnlyAlertOnce(onlyContainsRemovals) @@ -60,6 +70,7 @@ class NotificationFactory( .setCategory(Notification.CATEGORY_MESSAGE) .setGroupSummary(true) .setGroup(GROUP_ID) + .setContentIntent(openAppIntent) .build() } diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationsModule.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationsModule.kt index e2d166a..24a55bf 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationsModule.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationsModule.kt @@ -8,6 +8,7 @@ import app.dapk.st.matrix.common.CredentialsStore import app.dapk.st.matrix.push.PushService import app.dapk.st.matrix.sync.RoomStore import app.dapk.st.matrix.sync.SyncService +import app.dapk.st.navigator.IntentFactory import app.dapk.st.push.RegisterFirebasePushTokenUseCase import app.dapk.st.work.WorkScheduler @@ -20,6 +21,7 @@ class NotificationsModule( private val roomStore: RoomStore, private val context: Context, private val workScheduler: WorkScheduler, + private val intentFactory: IntentFactory, ) : ProvidableModule { fun pushUseCase() = pushService @@ -28,7 +30,7 @@ class NotificationsModule( fun firebasePushTokenUseCase() = firebasePushTokenUseCase fun notificationsUseCase() = NotificationsUseCase( roomStore, - NotificationRenderer(notificationManager(), NotificationFactory(iconLoader, context)), + NotificationRenderer(notificationManager(), NotificationFactory(iconLoader, context, intentFactory)), NotificationChannels(notificationManager()), )