launching the app when tapping the summary notification
This commit is contained in:
parent
995377343b
commit
73331b3d1e
|
@ -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(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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<RoomOverview, List<RoomEvent>>, 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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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()),
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue