-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Infomaniak/navigation
feat: Adaptative NavigationBar for mobile and NavigationRail for Tablet
- Loading branch information
Showing
11 changed files
with
352 additions
and
121 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
app/src/main/java/com/infomaniak/swisstransfer/ui/MainScreen.kt
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationArgs.kt
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Android | ||
* Copyright (C) 2024 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.swisstransfer.ui.navigation | ||
|
||
import android.os.Bundle | ||
import androidx.navigation.NavBackStackEntry | ||
import kotlinx.serialization.Serializable | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Sealed class representing the navigation arguments for the main navigation flow. | ||
*/ | ||
@Serializable | ||
sealed class MainNavigation : NavigationDestination() { | ||
@Serializable | ||
data object SentDestination : MainNavigation() | ||
@Serializable | ||
data object ReceivedDestination : MainNavigation() | ||
@Serializable | ||
data class TransferDetailsDestination(val transferId: Int) : MainNavigation() | ||
|
||
@Serializable | ||
data object SettingsDestination : MainNavigation() | ||
} | ||
|
||
/** | ||
* Sealed class representing the navigation arguments for the new transfer flow. | ||
*/ | ||
@Serializable | ||
sealed class NewTransferNavigation : NavigationDestination() { | ||
@Serializable | ||
data object ImportFilesDestination : NewTransferNavigation() | ||
@Serializable | ||
data object TransferTypeDestination : NewTransferNavigation() | ||
@Serializable | ||
data object TransferOptionsDestination : NewTransferNavigation() | ||
@Serializable | ||
data object ValidateUserEmailDestination : NewTransferNavigation() | ||
|
||
@Serializable | ||
data object UploadProgressDestination : NewTransferNavigation() | ||
@Serializable | ||
data object UploadSuccessDestination : NewTransferNavigation() | ||
} | ||
|
||
/** | ||
* Sealed class representing navigation arguments with a title resource. | ||
*/ | ||
@Serializable | ||
sealed class NavigationDestination { | ||
|
||
companion object { | ||
|
||
inline fun <reified T : NavigationDestination> NavBackStackEntry.toDestination(): T? { | ||
return toDestination(T::class, backStackEntry = this) | ||
} | ||
|
||
fun <T : NavigationDestination> toDestination(kClass: KClass<T>, backStackEntry: NavBackStackEntry?): T? { | ||
fun kClassFromRoute(route: String) = kClass.sealedSubclasses.firstOrNull { | ||
route.contains(it.qualifiedName.toString()) | ||
} | ||
|
||
if (backStackEntry == null) return null | ||
|
||
val route = backStackEntry.destination.route ?: "" | ||
val args = backStackEntry.arguments | ||
val subclass = kClassFromRoute(route) ?: return null | ||
|
||
return createInstance(subclass, args) | ||
} | ||
|
||
private fun <T : NavigationDestination> createInstance(kClass: KClass<T>, bundle: Bundle?): T? { | ||
val primaryConstructor = kClass.constructors.firstOrNull() | ||
return primaryConstructor?.let { | ||
val args = it.parameters.associateWith { parameter -> | ||
bundle?.get(parameter.name) | ||
} | ||
it.callBy(args) | ||
} ?: kClass.objectInstance | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Android | ||
* Copyright (C) 2024 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.swisstransfer.ui.screen.main | ||
|
||
import androidx.compose.foundation.layout.safeDrawingPadding | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.toRoute | ||
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation.* | ||
|
||
@Composable | ||
fun MainNavHost(navController: NavHostController, startDestination: SentDestination) { | ||
NavHost(navController, startDestination, modifier = Modifier.safeDrawingPadding()) { | ||
composable<SentDestination> { | ||
Text("Sent") | ||
} | ||
composable<ReceivedDestination> { | ||
Text("Received") | ||
} | ||
composable<TransferDetailsDestination> { | ||
val transferDetails: TransferDetailsDestination = it.toRoute() | ||
Text("TransferDetails for transfer ${transferDetails.transferId}") | ||
} | ||
composable<SettingsDestination> { | ||
Text("Settings") | ||
} | ||
} | ||
} |
Oops, something went wrong.