Skip to content

Commit

Permalink
fix(MyKSuite-16): Change navigation to the UpgradeBottomSheet by deep…
Browse files Browse the repository at this point in the history
…link (#289)
  • Loading branch information
FabianDevel authored Feb 20, 2025
2 parents 7b5ce3e + 2e71e21 commit 0aaac2f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion MykSuite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<KSuiteApp>(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`
}
}
5 changes: 2 additions & 3 deletions MykSuite/src/main/res/navigation/my_ksuite_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
android:id="@+id/myKSuiteUpgradeBottomSheet"
android:name="com.infomaniak.core.myksuite.ui.views.MyKSuiteUpgradeBottomSheetDialog"
android:label="MyKSuiteUpgradeBottomSheet">
<argument
android:name="kSuiteApp"
app:argType="com.infomaniak.core.myksuite.ui.screens.KSuiteApp" />

<deepLink app:uri="android-app://com.infomaniak.core.myksuite/myKSuiteUpgradeBottomSheet/{kSuiteApp}" />
</dialog>

</navigation>
20 changes: 20 additions & 0 deletions src/main/kotlin/com/infomaniak/core/extensions/StringExt.kt
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.core.extensions

fun String.capitalizeFirstChar(): String = replaceFirstChar { char -> char.titlecase() }

0 comments on commit 0aaac2f

Please sign in to comment.