diff --git a/MykSuite/build.gradle.kts b/MykSuite/build.gradle.kts index eacd22c2..a8f3bcbb 100644 --- a/MykSuite/build.gradle.kts +++ b/MykSuite/build.gradle.kts @@ -67,6 +67,6 @@ dependencies { implementation(core.compose.runtime) debugImplementation(core.compose.ui.tooling) implementation(core.compose.material3) - api(core.compose.ui) + implementation(core.compose.ui) implementation(core.compose.ui.tooling.preview) } diff --git a/MykSuite/src/main/java/com/infomaniak/core/myksuite/ui/views/MyKSuiteUpgradeBottomSheetDialog.kt b/MykSuite/src/main/java/com/infomaniak/core/myksuite/ui/views/MyKSuiteUpgradeBottomSheetDialog.kt index eaeba00b..70181c07 100644 --- a/MykSuite/src/main/java/com/infomaniak/core/myksuite/ui/views/MyKSuiteUpgradeBottomSheetDialog.kt +++ b/MykSuite/src/main/java/com/infomaniak/core/myksuite/ui/views/MyKSuiteUpgradeBottomSheetDialog.kt @@ -25,24 +25,36 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.infomaniak.core.enumValueOfOrNull +import com.infomaniak.core.extensions.capitalizeFirstChar +import com.infomaniak.core.myksuite.ui.screens.KSuiteApp import com.infomaniak.core.myksuite.ui.screens.MyKSuiteUpgradeBottomSheet @OptIn(ExperimentalMaterial3Api::class) class MyKSuiteUpgradeBottomSheetDialog : BottomSheetDialogFragment() { - private val navigationArgs: MyKSuiteUpgradeBottomSheetDialogArgs by navArgs() + private val kSuiteApp by lazy { + arguments?.getString(K_SUITE_APP_KEY)?.let { app -> enumValueOfOrNull(app.lowercase().capitalizeFirstChar()) } + } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + if (kSuiteApp == null) findNavController().popBackStack() + return ComposeView(requireContext()).apply { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - setContent { - MyKSuiteUpgradeBottomSheet( - onDismissRequest = this@MyKSuiteUpgradeBottomSheetDialog.findNavController()::popBackStack, - app = navigationArgs.kSuiteApp, - ) + kSuiteApp?.let { + setContent { + MyKSuiteUpgradeBottomSheet( + onDismissRequest = this@MyKSuiteUpgradeBottomSheetDialog.findNavController()::popBackStack, + app = it, + ) + } } } } + + companion object { + private const val K_SUITE_APP_KEY = "kSuiteApp" // Must kept the same value as the deepLink's in `my_ksuite_navigation` + } } diff --git a/MykSuite/src/main/res/navigation/my_ksuite_navigation.xml b/MykSuite/src/main/res/navigation/my_ksuite_navigation.xml index 56e8da83..3d77317d 100644 --- a/MykSuite/src/main/res/navigation/my_ksuite_navigation.xml +++ b/MykSuite/src/main/res/navigation/my_ksuite_navigation.xml @@ -33,9 +33,8 @@ android:id="@+id/myKSuiteUpgradeBottomSheet" android:name="com.infomaniak.core.myksuite.ui.views.MyKSuiteUpgradeBottomSheetDialog" android:label="MyKSuiteUpgradeBottomSheet"> - + + diff --git a/src/main/kotlin/com/infomaniak/core/extensions/StringExt.kt b/src/main/kotlin/com/infomaniak/core/extensions/StringExt.kt new file mode 100644 index 00000000..8a271adb --- /dev/null +++ b/src/main/kotlin/com/infomaniak/core/extensions/StringExt.kt @@ -0,0 +1,20 @@ +/* + * Infomaniak Core - Android + * Copyright (C) 2025 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.infomaniak.core.extensions + +fun String.capitalizeFirstChar(): String = replaceFirstChar { char -> char.titlecase() }