1
1
package com.bff.wespot
2
2
3
+ import android.Manifest
4
+ import android.content.pm.PackageManager
5
+ import android.os.Build
3
6
import android.os.Bundle
4
7
import androidx.activity.ComponentActivity
5
8
import androidx.activity.compose.setContent
@@ -32,14 +35,23 @@ import androidx.compose.ui.graphics.painter.Painter
32
35
import androidx.compose.ui.res.painterResource
33
36
import androidx.compose.ui.res.stringResource
34
37
import androidx.compose.ui.unit.dp
38
+ import androidx.core.app.ActivityCompat
39
+ import androidx.core.content.ContextCompat
35
40
import androidx.navigation.NavController
36
41
import androidx.navigation.NavGraph.Companion.findStartDestination
37
42
import androidx.navigation.compose.rememberNavController
43
+ import com.ramcosta.composedestinations.dynamic.within
38
44
import com.bff.wespot.designsystem.R
39
45
import com.bff.wespot.designsystem.component.header.WSTopBar
40
46
import com.bff.wespot.designsystem.theme.StaticTypeScale
41
47
import com.bff.wespot.designsystem.theme.WeSpotTheme
42
48
import com.bff.wespot.designsystem.theme.WeSpotThemeManager
49
+ import com.bff.wespot.message.screen.MessageScreenArgs
50
+ import com.bff.wespot.message.screen.destinations.MessageScreenDestination
51
+ import com.bff.wespot.message.screen.destinations.ReceiverSelectionScreenDestination
52
+ import com.bff.wespot.message.screen.send.ReceiverSelectionScreenArgs
53
+ import com.bff.wespot.model.notification.NotificationType
54
+ import com.bff.wespot.model.notification.convertNotificationType
43
55
import com.bff.wespot.navigation.Navigator
44
56
import com.ramcosta.composedestinations.navigation.navigate
45
57
import com.ramcosta.composedestinations.spec.NavGraphSpec
@@ -54,18 +66,57 @@ class MainActivity : ComponentActivity() {
54
66
55
67
override fun onCreate (savedInstanceState : Bundle ? ) {
56
68
super .onCreate(savedInstanceState)
69
+ requestNotificationPermission()
57
70
58
71
setContent {
59
72
WeSpotTheme {
60
- MainScreen (navigator)
73
+ MainScreen (
74
+ navigator = navigator,
75
+ navArgs = getMainScreenArgsFromIntent(),
76
+ )
77
+ }
78
+ }
79
+ }
80
+
81
+ private fun requestNotificationPermission () {
82
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
83
+ val hasPermission = ContextCompat .checkSelfPermission(
84
+ this ,
85
+ Manifest .permission.POST_NOTIFICATIONS
86
+ ) == PackageManager .PERMISSION_GRANTED
87
+
88
+ if (! hasPermission) {
89
+ ActivityCompat .requestPermissions(
90
+ this ,
91
+ arrayOf(Manifest .permission.POST_NOTIFICATIONS ),
92
+ 0
93
+ )
61
94
}
62
95
}
63
96
}
97
+
98
+ private fun getMainScreenArgsFromIntent (): MainScreenNavArgs {
99
+ val targetId = intent.getStringExtra(" targetId" )?.toInt() ? : - 1
100
+ val date = intent.getStringExtra(" date" ) ? : " "
101
+ val type = intent.getStringExtra(" type" ) ? : " "
102
+
103
+ return MainScreenNavArgs (
104
+ targetId = targetId,
105
+ date = date,
106
+ type = convertNotificationType(type),
107
+ )
108
+ }
64
109
}
65
110
111
+ data class MainScreenNavArgs (
112
+ val type : NotificationType ,
113
+ val date : String ,
114
+ val targetId : Int ,
115
+ )
116
+
66
117
@OptIn(ExperimentalMaterial3Api ::class )
67
118
@Composable
68
- private fun MainScreen (navigator : Navigator ) {
119
+ private fun MainScreen (navigator : Navigator , navArgs : MainScreenNavArgs ) {
69
120
val navController = rememberNavController()
70
121
71
122
val checkScreen by navController.checkCurrentScreen()
@@ -123,6 +174,8 @@ private fun MainScreen(navigator: Navigator) {
123
174
modifier = Modifier .padding(it),
124
175
navigator = navigator
125
176
)
177
+
178
+ navigateScreenFromNavArgs(navArgs, navController)
126
179
}
127
180
}
128
181
@@ -235,6 +288,38 @@ private fun TabItem(
235
288
}
236
289
}
237
290
291
+ private fun navigateScreenFromNavArgs (navArgs : MainScreenNavArgs , navController : NavController ) {
292
+ when (navArgs.type) {
293
+ NotificationType .MESSAGE -> {
294
+ navController.navigate(
295
+ ReceiverSelectionScreenDestination (
296
+ ReceiverSelectionScreenArgs (false ),
297
+ ) within AppNavGraphs .message
298
+ )
299
+ }
300
+
301
+ NotificationType .MESSAGE_SENT , NotificationType .MESSAGE_RECEIVED -> {
302
+ navController.navigate(
303
+ MessageScreenDestination (
304
+ MessageScreenArgs (
305
+ type = navArgs.type,
306
+ messageId = navArgs.targetId,
307
+ ),
308
+ ) within AppNavGraphs .message
309
+ )
310
+ }
311
+
312
+ NotificationType .VOTE -> {
313
+ }
314
+ NotificationType .VOTE_RESULT -> {
315
+ }
316
+ NotificationType .VOTE_RECEIVED -> {
317
+ }
318
+ NotificationType .IDLE -> {
319
+ }
320
+ }
321
+ }
322
+
238
323
private fun NavController.navigateToNavGraph (navGraph : NavGraphSpec ) {
239
324
this .navigate(navGraph) {
240
325
launchSingleTop = true
0 commit comments