@@ -26,6 +26,7 @@ import androidx.navigation.navDeepLink
26
26
import androidx.navigation.toRoute
27
27
import com.infomaniak.core.sentry.SentryLog
28
28
import com.infomaniak.swisstransfer.BuildConfig
29
+ import com.infomaniak.swisstransfer.ui.MatomoSwissTransfer
29
30
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation.SettingsDestination.getDeeplinkDirection
30
31
import com.infomaniak.swisstransfer.ui.screen.main.DeeplinkViewModel.Companion.SENT_DEEPLINK_SUFFIX
31
32
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi
@@ -35,7 +36,7 @@ import kotlinx.serialization.Serializable
35
36
* Sealed class representing the navigation arguments for the main navigation flow.
36
37
*/
37
38
@Serializable
38
- sealed class MainNavigation : NavigationDestination () {
39
+ sealed class MainNavigation ( override val matomoValue : String ) : NavigationDestination() {
39
40
40
41
protected inline fun <reified T : MainNavigation > NavGraphBuilder.getDeeplinkDirection (
41
42
noinline content : @Composable (AnimatedContentScope .(NavBackStackEntry ) -> Unit ),
@@ -50,7 +51,7 @@ sealed class MainNavigation : NavigationDestination() {
50
51
51
52
// If it has to be renamed, don't forget to rename `*DestinationName` in the companion object too.
52
53
@Serializable
53
- data class SentDestination (val transferUuid : String? = null ) : MainNavigation() {
54
+ data class SentDestination (val transferUuid : String? = null ) : MainNavigation(" SentScreen " ) {
54
55
55
56
companion object {
56
57
fun NavGraphBuilder.sentDestination (content : @Composable (AnimatedContentScope .(NavBackStackEntry ) -> Unit )) {
@@ -61,7 +62,7 @@ sealed class MainNavigation : NavigationDestination() {
61
62
62
63
// If it has to be renamed, don't forget to rename `*DestinationName` in the companion object too.
63
64
@Serializable
64
- data class ReceivedDestination (val transferUuid : String? = null ) : MainNavigation() {
65
+ data class ReceivedDestination (val transferUuid : String? = null ) : MainNavigation(" ReceivedScreen " ) {
65
66
66
67
companion object {
67
68
fun NavGraphBuilder.receivedDestination (content : @Composable (AnimatedContentScope .(NavBackStackEntry ) -> Unit )) {
@@ -71,7 +72,7 @@ sealed class MainNavigation : NavigationDestination() {
71
72
}
72
73
73
74
@Serializable
74
- data object SettingsDestination : MainNavigation ()
75
+ data object SettingsDestination : MainNavigation (" SettingsScreen " )
75
76
76
77
companion object {
77
78
private val TAG = MainNavigation ::class .java.simpleName
@@ -110,48 +111,93 @@ sealed class MainNavigation : NavigationDestination() {
110
111
* Sealed class representing the navigation arguments for the new transfer flow.
111
112
*/
112
113
@Serializable
113
- sealed class NewTransferNavigation : NavigationDestination () {
114
+ sealed class NewTransferNavigation ( override val matomoValue : String ) : NavigationDestination() {
114
115
115
116
@Serializable
116
- data object ImportFilesDestination : NewTransferNavigation ()
117
+ data object ImportFilesDestination : NewTransferNavigation (" ImportFileScreen " )
117
118
118
119
@Serializable
119
- data class ValidateUserEmailDestination (val authorEmail : String ) : NewTransferNavigation()
120
+ data class ValidateUserEmailDestination (val authorEmail : String ) : NewTransferNavigation(" ValidateUserEmailScreen " )
120
121
121
122
@Serializable
122
123
data class UploadProgressDestination (
123
124
val transferType : TransferTypeUi ,
124
125
val totalSize : Long ,
125
126
val authorEmail : String? ,
126
- ) : NewTransferNavigation()
127
+ ) : NewTransferNavigation(" UploadProgressScreen " )
127
128
128
129
@Serializable
129
130
data class UploadSuccessDestination (
130
131
val transferType : TransferTypeUi ,
131
132
val transferUuid : String ,
132
133
val transferUrl : String ,
133
- ) : NewTransferNavigation()
134
+ ) : NewTransferNavigation(" UploadSuccessScreen " )
134
135
135
136
@Serializable
136
137
data class UploadErrorDestination (
137
138
val transferType : TransferTypeUi ,
138
139
val totalSize : Long ,
139
140
val authorEmail : String? ,
140
- ) : NewTransferNavigation()
141
+ ) : NewTransferNavigation(" UploadErrorScreen " )
141
142
142
143
@Serializable
143
- data object UploadIntegrityErrorDestination : NewTransferNavigation ()
144
+ data object UploadIntegrityErrorDestination : NewTransferNavigation (" UploadIntegrityErrorScreen " )
144
145
145
146
@Serializable
146
- data object NewTransferFilesDetailsDestination : NewTransferNavigation ()
147
+ data object NewTransferFilesDetailsDestination : NewTransferNavigation (" NewTransferFilesDetailsScreen " )
147
148
148
149
companion object {
149
150
val startDestination = ImportFilesDestination
151
+
152
+ private val TAG = NewTransferNavigation ::class .java.simpleName
153
+
154
+ private const val importFilesDestinationName = " ImportFilesDestination"
155
+ private const val ValidateUserEmailDestinationName = " ValidateUserEmailDestination"
156
+ private const val UploadProgressDestinationName = " UploadProgressDestination"
157
+ private const val UploadSuccessDestinationName = " UploadSuccessDestination"
158
+ private const val UploadErrorDestinationName = " UploadErrorDestination"
159
+ private const val UploadIntegrityErrorDestinationName = " UploadIntegrityErrorDestination"
160
+ private const val NewTransferFilesDetailsDestinationName = " NewTransferFilesDetailsDestination"
161
+ val newTransferDestinationsNames = listOf (
162
+ importFilesDestinationName,
163
+ ValidateUserEmailDestinationName ,
164
+ UploadProgressDestinationName ,
165
+ UploadSuccessDestinationName ,
166
+ UploadErrorDestinationName ,
167
+ UploadIntegrityErrorDestinationName ,
168
+ NewTransferFilesDetailsDestinationName ,
169
+ )
170
+
171
+ fun NavBackStackEntry.toNewTransferDestination (): NewTransferNavigation ? {
172
+ return runCatching {
173
+ val destinationRoute = destination.route ? : error(" Destination route cannot be empty" )
174
+ when (newTransferDestinationsNames.firstOrNull(destinationRoute::contains)) {
175
+ importFilesDestinationName -> this .toRoute<ImportFilesDestination >()
176
+ ValidateUserEmailDestinationName -> this .toRoute<ValidateUserEmailDestination >()
177
+ UploadProgressDestinationName -> this .toRoute<UploadProgressDestination >()
178
+ UploadSuccessDestinationName -> this .toRoute<UploadSuccessDestination >()
179
+ UploadErrorDestinationName -> this .toRoute<UploadErrorDestination >()
180
+ UploadIntegrityErrorDestinationName -> this .toRoute<UploadIntegrityErrorDestination >()
181
+ NewTransferFilesDetailsDestinationName -> this .toRoute<NewTransferFilesDetailsDestination >()
182
+ else -> error(" Destination $destinationRoute is not handled" )
183
+ }
184
+ }.getOrElse { exception ->
185
+ SentryLog .e(TAG , " toNewTransferDestination: Failure" , exception)
186
+ null
187
+ }
188
+ }
150
189
}
151
190
}
152
191
153
192
/* *
154
193
* Sealed class representing navigation arguments with a title resource.
155
194
*/
156
195
@Serializable
157
- sealed class NavigationDestination
196
+ sealed class NavigationDestination {
197
+
198
+ abstract val matomoValue: String
199
+
200
+ fun trackScreen () {
201
+ MatomoSwissTransfer .trackScreen(path = " /$matomoValue " , title = matomoValue)
202
+ }
203
+ }
0 commit comments