Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MyKSuite-16): Change navigation to the UpgradeBottomSheet by deeplink #289

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() }