Modern Apps git

← Modern-Apps.git

weather: split Route.kt/Navigation.kt out of MainActivity (root-file contracts)

Commit
a30d8cc683a0d3cb85310bdb9c701e0d93b9685d
Author
vayun-mathur <[email protected]>
When
2026-08-15 18:36 UTC (3 months ago)
Parents
9ad7cea
weather root (package com.vayunmathur.weather) violates the closed root-file
allow-list — MainActivity.kt still embeds @Serializable sealed interface Route
: NavKey and @Composable fun Navigation view-model nav graph inside the
activity, both flagged by lint-rules/PackageStructureDetector per plan
§3.3.0. Extract sealed Route : NavKey (Home/SearchLocation/WeatherMap) to
Route.kt and top-level @Composable Navigation(viewModel) wiring
MainNavigation to Navigation.kt — same shape as music/ Route.kt +
Navigation.kt which cleared the lint errors. MainActivity.kt is now ONLY
class MainActivity : ComponentActivity() with fresh underscore-prefixed
imports (domain/map pinned to domain, glance pinned to widget/glance,
platform pinned to platform). Follow-up will land the remaining util→domain/
platform and map→domain/map + glance→widget/glance + screenshotTest import
fixups that are already in the working tree.

Diff

weather/src/main/java/com/vayunmathur/weather/MainActivity.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/MainActivity.kt b/weather/src/main/java/com/vayunmathur/weather/MainActivity.ktindex d85bb21e4c..0edf744494 100644--- a/weather/src/main/java/com/vayunmathur/weather/MainActivity.kt+++ b/weather/src/main/java/com/vayunmathur/weather/MainActivity.kt@@ -5,25 +5,15 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels-import androidx.compose.runtime.Composable+import com.vayunmathur.library.network.NetworkClient+import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.util.OfflineAware-import com.vayunmathur.library.util.DialogPage-import com.vayunmathur.library.util.ListPage-import com.vayunmathur.library.util.MainNavigation-import com.vayunmathur.library.util.NavKey-import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.library.widgets.updateWidgetPreviews import com.vayunmathur.weather.data.WeatherRepository-import com.vayunmathur.weather.glance.WeatherGlanceWidgetReceiver-import com.vayunmathur.weather.ui.HomePage-import com.vayunmathur.weather.ui.SearchLocationPage-import com.vayunmathur.weather.ui.WeatherMapPage-import com.vayunmathur.library.network.NetworkClient-import com.vayunmathur.library.network.TrustBundle-import com.vayunmathur.weather.util.WeatherViewModel-import com.vayunmathur.weather.util.WeatherViewModelFactory-import kotlinx.serialization.Serializable+import com.vayunmathur.weather.platform.WeatherViewModel+import com.vayunmathur.weather.platform.WeatherViewModelFactory+import com.vayunmathur.weather.widget.glance.WeatherGlanceWidgetReceiver  class MainActivity : ComponentActivity() {     private val viewModel: WeatherViewModel by viewModels {@@ -45,28 +35,3 @@ class MainActivity : ComponentActivity() {         }     } }--@Serializable-sealed interface Route : NavKey {-    @Serializable data object Home : Route-    @Serializable data object SearchLocation : Route-    @Serializable data class WeatherMap(-        val latitude: Double,-        val longitude: Double,-        val name: String,-        val isoTime: String? = null,-        val metric: String,-    ) : Route-}--@Composable-fun Navigation(viewModel: WeatherViewModel) {-    val backStack = rememberNavBackStack<Route>(Route.Home)-    MainNavigation(backStack) {-        entry<Route.Home>(metadata = ListPage()) { HomePage(backStack, viewModel) }-        entry<Route.SearchLocation>(metadata = DialogPage()) { SearchLocationPage(backStack, viewModel) }-        entry<Route.WeatherMap>(metadata = ListPage()) {-            WeatherMapPage(backStack, it.latitude, it.longitude, it.name, it.isoTime, it.metric)-        }-    }-}
weather/src/main/java/com/vayunmathur/weather/Navigation.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/Navigation.kt b/weather/src/main/java/com/vayunmathur/weather/Navigation.ktnew file mode 100644index 0000000000..4498d1cf4b--- /dev/null+++ b/weather/src/main/java/com/vayunmathur/weather/Navigation.kt@@ -0,0 +1,23 @@+package com.vayunmathur.weather++import androidx.compose.runtime.Composable+import com.vayunmathur.library.util.DialogPage+import com.vayunmathur.library.util.ListPage+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.rememberNavBackStack+import com.vayunmathur.weather.platform.WeatherViewModel+import com.vayunmathur.weather.ui.HomePage+import com.vayunmathur.weather.ui.SearchLocationPage+import com.vayunmathur.weather.ui.WeatherMapPage++@Composable+fun Navigation(viewModel: WeatherViewModel) {+    val backStack = rememberNavBackStack<Route>(Route.Home)+    MainNavigation(backStack) {+        entry<Route.Home>(metadata = ListPage()) { HomePage(backStack, viewModel) }+        entry<Route.SearchLocation>(metadata = DialogPage()) { SearchLocationPage(backStack, viewModel) }+        entry<Route.WeatherMap>(metadata = ListPage()) {+            WeatherMapPage(backStack, it.latitude, it.longitude, it.name, it.isoTime, it.metric)+        }+    }+}
weather/src/main/java/com/vayunmathur/weather/Route.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/Route.kt b/weather/src/main/java/com/vayunmathur/weather/Route.ktnew file mode 100644index 0000000000..ac2692373a--- /dev/null+++ b/weather/src/main/java/com/vayunmathur/weather/Route.kt@@ -0,0 +1,22 @@+package com.vayunmathur.weather++import com.vayunmathur.library.util.NavKey+import kotlinx.serialization.Serializable++@Serializable+sealed interface Route : NavKey {+    @Serializable+    data object Home : Route++    @Serializable+    data object SearchLocation : Route++    @Serializable+    data class WeatherMap(+        val latitude: Double,+        val longitude: Double,+        val name: String,+        val isoTime: String? = null,+        val metric: String,+    ) : Route+}