Modern Apps git

← Modern-Apps.git

shop: keep Navigation.kt to the Navigation composable

Commit
35c474211ed582a43b3f260502e3fffc514d5498
Author
Vayun Mathur <[email protected]>
When
2026-11-19 03:27 UTC (17 days ago)
Parents
1931ccc
PackageStructure lint now requires the app-root Navigation.kt
to contain only the top-level @Composable fun Navigation(...).
This module parked its link and notification-permission effects
in the same file, so the module failed lint.

Move the two extra top-level declarations, ShopLinkEffect and
ShopNotificationPermissionEffect, unchanged in name, signature,
and behavior, into a new file ui/NavigationEffects.kt in the
same module. They change from private to internal so the root
Navigation composable (a different package) can still call
them, consistent with the existing ui/NavigationEntries.kt
builders. Navigation.kt keeps only fun Navigation(...) and
imports the moved effects; no screen, route, or navigation
behavior changes.

Verified: ./gradlew :shop:lintDev :shop:testDevUnitTest -
both pass.

Diff

shop/src/main/java/com/vayunmathur/shop/Navigation.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/Navigation.kt b/shop/src/main/java/com/vayunmathur/shop/Navigation.ktindex 135be7cd8a..cb3e82ee40 100644--- a/shop/src/main/java/com/vayunmathur/shop/Navigation.kt+++ b/shop/src/main/java/com/vayunmathur/shop/Navigation.kt@@ -1,15 +1,9 @@ package com.vayunmathur.shop -import android.Manifest-import android.content.pm.PackageManager-import android.os.Build-import androidx.activity.compose.rememberLauncherForActivityResult-import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource-import androidx.core.content.ContextCompat import com.vayunmathur.library.ui.IconPerson import com.vayunmathur.library.ui.IconReceipt import com.vayunmathur.library.ui.IconSearch@@ -19,9 +13,10 @@ import com.vayunmathur.library.ui.TabbedPagerScaffold import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.shop.platform.ShopViewModel-import com.vayunmathur.shop.ui.applyShopPendingRoute import com.vayunmathur.shop.ui.applyShopProfileGate import com.vayunmathur.shop.ui.shopEntries+import com.vayunmathur.shop.ui.ShopLinkEffect+import com.vayunmathur.shop.ui.ShopNotificationPermissionEffect import com.vayunmathur.shop.ui.shopStartRoute  @Composable@@ -89,37 +84,3 @@ fun Navigation(     } } -/** Merchant links resolve in the ViewModel; a gated link stays unconsumed. */-@Composable-private fun ShopLinkEffect(-    viewModel: ShopViewModel,-    backStack: com.vayunmathur.library.util.NavBackStack<Route>,-    linkRequest: Pair<Int, String>?,-) {-    LaunchedEffect(linkRequest, backStack.backStack.lastOrNull()) {-        val url = linkRequest?.second ?: return@LaunchedEffect-        if (backStack.backStack.lastOrNull() == Route.ProfileSetup) return@LaunchedEffect-        viewModel.openLink(url) { route ->-            if (route is Route.ProductDetail || route == Route.Search) {-                applyShopPendingRoute(backStack, route, profileComplete = true)-            } else {-                backStack.reset(route)-            }-        }-    }-}--/** Asks for the notification permission when the ViewModel requests it. */-@Composable-private fun ShopNotificationPermissionEffect(viewModel: ShopViewModel, context: android.content.Context) {-    val notificationPermission = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {}-    LaunchedEffect(viewModel.notificationPermissionRequest) {-        if (viewModel.notificationPermissionRequest > 0 &&-            Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&-            ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) !=-            PackageManager.PERMISSION_GRANTED-        ) {-            notificationPermission.launch(Manifest.permission.POST_NOTIFICATIONS)-        }-    }-}
shop/src/main/java/com/vayunmathur/shop/ui/NavigationEffects.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/NavigationEffects.kt b/shop/src/main/java/com/vayunmathur/shop/ui/NavigationEffects.ktnew file mode 100644index 0000000000..be2b2cc16a--- /dev/null+++ b/shop/src/main/java/com/vayunmathur/shop/ui/NavigationEffects.kt@@ -0,0 +1,48 @@+package com.vayunmathur.shop.ui++import android.Manifest+import android.content.pm.PackageManager+import android.os.Build+import androidx.activity.compose.rememberLauncherForActivityResult+import androidx.activity.result.contract.ActivityResultContracts+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.core.content.ContextCompat+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.shop.Route+import com.vayunmathur.shop.platform.ShopViewModel++/** Merchant links resolve in the ViewModel; a gated link stays unconsumed. */+@Composable+internal fun ShopLinkEffect(+    viewModel: ShopViewModel,+    backStack: NavBackStack<Route>,+    linkRequest: Pair<Int, String>?,+) {+    LaunchedEffect(linkRequest, backStack.backStack.lastOrNull()) {+        val url = linkRequest?.second ?: return@LaunchedEffect+        if (backStack.backStack.lastOrNull() == Route.ProfileSetup) return@LaunchedEffect+        viewModel.openLink(url) { route ->+            if (route is Route.ProductDetail || route == Route.Search) {+                applyShopPendingRoute(backStack, route, profileComplete = true)+            } else {+                backStack.reset(route)+            }+        }+    }+}++/** Asks for the notification permission when the ViewModel requests it. */+@Composable+internal fun ShopNotificationPermissionEffect(viewModel: ShopViewModel, context: android.content.Context) {+    val notificationPermission = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {}+    LaunchedEffect(viewModel.notificationPermissionRequest) {+        if (viewModel.notificationPermissionRequest > 0 &&+            Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&+            ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) !=+            PackageManager.PERMISSION_GRANTED+        ) {+            notificationPermission.launch(Manifest.permission.POST_NOTIFICATIONS)+        }+    }+}