Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.shopify.checkoutkit.androiddemo.common.navigation

import androidx.compose.runtime.Composable
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand All @@ -18,59 +17,6 @@ import com.shopify.checkoutkit.androiddemo.settings.SettingsView
import com.shopify.checkoutkit.androiddemo.settings.SettingsViewModel
import com.shopify.checkoutkit.androiddemo.settings.account.AccountView
import com.shopify.checkoutkit.androiddemo.settings.authentication.LoginView
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

sealed class Screen(val route: String) {
data object Home : Screen("home")
data object Product : Screen("product/{productId}") {
fun productIdRouteVariable(backStackEntry: NavBackStackEntry): String {
return backStackEntry.arguments?.getString("productId") ?: ""
}

fun route(productId: String): String {
return route.replace("{productId}", URLEncoder.encode(productId, StandardCharsets.UTF_8.name()))
}
}

data object Products : Screen("product")
data object ProductCollection : Screen("collection/{collectionHandle}") {
fun collectionHandleRouteVariable(backStackEntry: NavBackStackEntry): String {
return backStackEntry.arguments?.getString("collectionHandle") ?: ""
}

fun route(collectionHandle: String): String {
return route.replace(
"{collectionHandle}",
URLEncoder.encode(collectionHandle, StandardCharsets.UTF_8.name())
)
}
}

data object Cart : Screen("cart")
data object Settings : Screen("settings")
data object Logs : Screen("logs")
data object Login : Screen("login")
data object Account : Screen("account")

companion object {
fun fromRoute(route: String): Screen {
return when (route) {
Home.route -> Home
ProductCollection.route -> ProductCollection
Product.route -> Product
Products.route -> Products
Cart.route -> Cart
Settings.route -> Settings
Logs.route -> Logs
Login.route -> Login
Account.route -> Account
else -> throw RuntimeException("Unknown route")
}
}
}
}

@Composable
fun CheckoutKitNavHost(
navController: NavHostController = rememberNavController(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.shopify.checkoutkit.androiddemo.common.navigation

import androidx.navigation.NavBackStackEntry
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

sealed class Screen(val route: String) {
data object Home : Screen("home")
data object Product : Screen("product/{productId}") {
fun productIdRouteVariable(backStackEntry: NavBackStackEntry): String {
return backStackEntry.arguments?.getString("productId") ?: ""
}

fun route(productId: String): String {
return route.replace("{productId}", URLEncoder.encode(productId, StandardCharsets.UTF_8.name()))
}
}

data object Products : Screen("product")
data object ProductCollection : Screen("collection/{collectionHandle}") {
fun collectionHandleRouteVariable(backStackEntry: NavBackStackEntry): String {
return backStackEntry.arguments?.getString("collectionHandle") ?: ""
}

fun route(collectionHandle: String): String {
return route.replace(
"{collectionHandle}",
URLEncoder.encode(collectionHandle, StandardCharsets.UTF_8.name())
)
}
}

data object Cart : Screen("cart")
data object Settings : Screen("settings")
data object Logs : Screen("logs")
data object Login : Screen("login")
data object Account : Screen("account")

companion object {
fun fromRoute(route: String): Screen {
return when (route) {
Home.route -> Home
ProductCollection.route -> ProductCollection
Product.route -> Product
Products.route -> Products
Cart.route -> Cart
Settings.route -> Settings
Logs.route -> Logs
Login.route -> Login
Account.route -> Account
else -> throw RuntimeException("Unknown route")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ naming:
FunctionNaming:
ignoreAnnotated: [ 'Composable', 'Test' ]
MatchingDeclarationName:
active: false
active: true

style:
MagicNumber:
Expand All @@ -40,7 +40,7 @@ style:
formatting:
active: true
Filename:
active: false
active: true
autoCorrect: true
MaximumLineLength:
active: true
Expand Down
Loading