Modern Apps git

← Modern-Apps.git

fooddelivery: detekt clean (104 tests)

Commit
835a88f98fe7bd4bb60bbaf7458e5be13a1d80d0
Author
Vayun Mathur <[email protected]>
When
2026-11-14 23:22 UTC (21 days ago)
Parents
1003d78
Fix all 37 detekt findings: real KDoc for 36 undocumented public classes (Route destinations, API models in Models.kt, CartStore, companions); FoodDeliveryApp (LongMethod 100) split into PendingCartDialog() and FoodDeliveryNavigation() composables, behaviour preserved.

Verified: ./gradlew :fooddelivery:detekt :fooddelivery:testDevUnitTest :fooddelivery:lint --max-workers=32 — BUILD SUCCESSFUL, 104 unit tests pass. No @Suppress added.

Diff

fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.ktindex c8c3dd0fd8..c29f943cc1 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/MainActivity.kt@@ -75,14 +75,21 @@ internal fun List<CartItem>.canAddFromSameMerchant(item: CartItem): Boolean {     return cartMerchant == 0 || item.merchantId == 0 || cartMerchant == item.merchantId } +/** Navigation destinations for browsing, checkout, order tracking, and email verification. */ sealed interface Route : NavKey {+    /** The tabbed main screen, opening on [initialTab]. */     @Serializable data class Main(val initialTab: Int = 0) : Route+    /** The menu page for the restaurant identified by [id]. */     @Serializable data class Restaurant(val id: Int) : Route+    /** The checkout flow for the current cart. */     @Serializable data object Checkout : Route+    /** Live tracking for the order identified by [orderId]. */     @Serializable data class OrderTracking(val orderId: Int) : Route+    /** Email-verification screen for [customerId] carrying its verification [token]. */     @Serializable data class EmailVerification(val customerId: String, val token: String) : Route } +/** Entry activity that initialises Stripe and app state and routes notification and deep-link intents into the UI. */ class MainActivity : MaActivity() {     // The order to open on the tracking screen, set from a notification tap. Held as     // Compose state so onNewIntent can push a new deep link into the running UI.@@ -98,6 +105,7 @@ class MainActivity : MaActivity() {     private val requestNotificationPermission =         registerForActivityResult(ActivityResultContracts.RequestPermission()) { } +        /** Holds the Stripe publishable key used to initialise payments. */     companion object {         private const val STRIPE_PUBLISHABLE_KEY =             "pk_live_51NQy7lFJFBMK4hv9KubgZcyH2Wy0MsXn9BtrtM7moEi762WE7pcmZ1JL9BrCKPRKw6ZJdGo9YJSA1pidb0KUthlJ00Wr4bcpVD"@@ -212,28 +220,15 @@ private fun FoodDeliveryApp(     // replaces the cart they already have (checkout can only order from one).     var pendingCartItem by remember { mutableStateOf<CartItem?>(null) }     pendingCartItem?.let { pending ->-        val currentName = cart.firstOrNull()?.merchantName?.ifBlank { "another restaurant" }-            ?: "another restaurant"-        val newName = pending.merchantName.ifBlank { "a different restaurant" }-        AlertDialog(-            onDismissRequest = { pendingCartItem = null },-            title = { Text("Start a new cart?") },-            text = {-                Text(-                    "Your cart has items from $currentName. Ordering is from one " +-                        "restaurant at a time, so adding from $newName will clear it."-                )-            },-            confirmButton = {-                Button(onClick = {-                    cart.clear()-                    cart.add(pending)-                    CartStore.save(context, cart)-                    pendingCartItem = null-                }) { Text("Start new cart") }-            },-            dismissButton = {-                TextButton(onClick = { pendingCartItem = null }) { Text("Keep my cart") }+        PendingCartDialog(+            cart = cart,+            pending = pending,+            onDismiss = { pendingCartItem = null },+            onConfirm = {+                cart.clear()+                cart.add(pending)+                CartStore.save(context, cart)+                pendingCartItem = null             },         )     }@@ -245,6 +240,49 @@ private fun FoodDeliveryApp(         if (addedMeanwhile) CartStore.save(context, cart)     } +    FoodDeliveryNavigation(+        backStack = backStack,+        cart = cart,+        onPendingCartItem = { pendingCartItem = it },+    )++}++@Composable+private fun PendingCartDialog(+    cart: androidx.compose.runtime.snapshots.SnapshotStateList<CartItem>,+    pending: CartItem,+    onDismiss: () -> Unit,+    onConfirm: () -> Unit,+) {+    val currentName = cart.firstOrNull()?.merchantName?.ifBlank { "another restaurant" }+        ?: "another restaurant"+    val newName = pending.merchantName.ifBlank { "a different restaurant" }+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text("Start a new cart?") },+        text = {+            Text(+                "Your cart has items from $currentName. Ordering is from one " ++                    "restaurant at a time, so adding from $newName will clear it."+            )+        },+        confirmButton = {+            Button(onClick = onConfirm) { Text("Start new cart") }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text("Keep my cart") }+        },+    )+}++@Composable+private fun FoodDeliveryNavigation(+    backStack: NavBackStack<Route>,+    cart: androidx.compose.runtime.snapshots.SnapshotStateList<CartItem>,+    onPendingCartItem: (CartItem) -> Unit,+) {+    val context = LocalContext.current     MainNavigation(backStack) {         entry<Route.Main>(metadata = ListPage()) { route ->             FoodDeliveryTabs(@@ -262,7 +300,7 @@ private fun FoodDeliveryApp(                         cart.add(item)                         CartStore.save(context, cart)                     } else {-                        pendingCartItem = item+                        onPendingCartItem(item)                     }                 }             )
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/CartStore.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/CartStore.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/CartStore.ktindex e3cae05ba5..b77940edda 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/CartStore.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/CartStore.kt@@ -11,6 +11,7 @@ import kotlinx.coroutines.withContext import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +/** Persists the single-merchant cart as JSON in SharedPreferences, with writes serialised on one dispatcher. */ @OptIn(ExperimentalCoroutinesApi::class) object CartStore { 
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/Models.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/Models.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/Models.ktindex 4d7b2372d8..49cb464c2b 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/Models.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/Models.kt@@ -4,17 +4,20 @@ import kotlin.math.max import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +/** Generic backend envelope carrying a [message] and an optional [data] payload. */ @Serializable data class ApiResponse<T>(     val message: String = "",     val data: T? = null, ) +/** Backend response wrapping the list of available merchants. */ @Serializable data class MerchantsWrapper(     val merchants: List<Merchant> = emptyList(), ) +/** A restaurant listing with its address, opening state, ratings, and fulfilment options. */ @Serializable data class Merchant(     val id: Int = 0,@@ -59,6 +62,7 @@ data class Merchant(     val displayRewardsPercentage: Double get() = rewardsPercentage ?: 0.0 } +/** Brand artwork and visibility for a merchant. */ @Serializable data class Brand(     val logoUrl: String? = null,@@ -66,6 +70,7 @@ data class Brand(     val showOnApp: Boolean = false, ) +/** A summary menu item shown on a merchant listing, priced in cents. */ @Serializable data class MerchantItem(     val id: Int = 0,@@ -77,6 +82,7 @@ data class MerchantItem(     val priceDollars: Double get() = price / 100.0 } +/** A merchant's full detail, including its menu categories, items, deals, and promotions. */ @Serializable data class MerchantDetail(     val id: Int = 0,@@ -109,6 +115,7 @@ data class MerchantDetail(     val promotions: List<Promotion> = emptyList(), ) +/** A section of a merchant's menu, grouping items by [itemIds]. */ @Serializable data class MenuCategory(     val id: Int = 0,@@ -119,6 +126,7 @@ data class MenuCategory(     val merchantId: Int = 0, ) +/** A menu item with pricing, availability, imagery, and modifier groups, priced in cents. */ @Serializable data class MenuItem(     val id: Int = 0,@@ -143,6 +151,7 @@ data class MenuItem(     val doordashPriceDollars: Double? get() = doordashPrice?.let { it / 100.0 } } +/** A group of selectable modifiers for a menu item, with selection limits. */ @Serializable data class ModifierGroup(     val id: Int = 0,@@ -153,6 +162,7 @@ data class ModifierGroup(     val modifiers: List<Modifier> = emptyList(), ) +/** One selectable modifier option, priced in cents. */ @Serializable data class Modifier(     val id: Int = 0,@@ -162,6 +172,7 @@ data class Modifier(     val priceDollars: Double get() = price / 100.0 } +/** A merchant deal, with its discount and minimum-order threshold. */ @Serializable data class Deal(     val id: Int = 0,@@ -179,6 +190,7 @@ data class Deal(     val discountAmountDollars: Double get() = discountAmount / 100.0 } +/** A named promotional offer for a merchant. */ @Serializable data class Promotion(     val id: Int = 0,@@ -186,6 +198,7 @@ data class Promotion(     val description: String = "", ) +/** The merchant summary embedded in an order. */ @Serializable data class OrderMerchant(     val id: Int = 0,@@ -254,6 +267,7 @@ data class OrderRewards(     val rewardsAvailableDollars: Double get() = rewardsAvailable / 100.0 } +/** A placed order with its totals, fulfilment state, and live-tracking data. */ @Serializable data class Order(     val id: Int = 0,@@ -388,6 +402,7 @@ data class Order(         } } +/** One line of a placed order, with its chosen modifiers. */ @Serializable data class OrderItem(     val id: Int = 0,@@ -400,6 +415,7 @@ data class OrderItem(     val priceDollars: Double get() = price / 100.0 } +/** A modifier recorded on a placed order line. */ @Serializable data class OrderItemModifier(     val name: String? = null,@@ -408,6 +424,7 @@ data class OrderItemModifier(     val modifierGroupName: String? = null, ) +/** A customer's saved delivery address. */ @Serializable data class SavedAddress(     val id: String = "",@@ -442,6 +459,7 @@ data class SelectedModifier(     val priceDollars: Double get() = price / 100.0 } +/** A cart line: a menu item, its quantity, and its selected modifiers. */ @Serializable data class CartItem(     val menuItem: MenuItem,@@ -462,6 +480,7 @@ data class CartItem(         get() = (menuItem.price + selectedModifiers.sumOf { it.price * it.quantity }) * quantity / 100.0 } +/** The signed-in customer's profile and rewards summary. */ @Serializable data class Customer(     val id: Int = 0,@@ -478,6 +497,7 @@ data class Customer(     val savingsDollars: Double get() = totalCustomerSavings / 100.0 } +/** OAuth tokens returned by the backend for an authenticated session. */ @Serializable data class AuthToken(     @SerialName("access_token") val accessToken: String = "",@@ -495,6 +515,7 @@ data class FeedbackRequest(     val tips: Int = 0, ) +/** Feedback submitted for an order, with its rating and optional tip. */ @Serializable data class Feedback(     val id: Int = 0,@@ -584,6 +605,7 @@ data class MerchantRewards(     val balanceDollars: Double get() = balance / 100.0 } +/** A redeemable reward and the points it requires. */ @Serializable data class Reward(     val id: Int = 0,@@ -609,6 +631,7 @@ data class CustomerSavings(         get() = (if (customerSavings != 0) customerSavings else totalCustomerSavings) / 100.0 } +/** One cart line in the checkout request payload. */ @Serializable data class CheckoutCartItem(     val itemId: Int,@@ -617,6 +640,7 @@ data class CheckoutCartItem(     val modifiers: List<SelectedModifier> = emptyList(), ) +/** The delivery address in the checkout request payload. */ @Serializable data class CheckoutAddress(     val addressStreet: String = "",@@ -670,6 +694,7 @@ data class CheckoutRequest(     val isDriveThru: Boolean? = null, ) +/** Checkout result carrying the Stripe client secret and the created order. */ @Serializable data class CheckoutResponse(     val clientSecret: String = "",
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/intents/OrderLookupIntent.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/intents/OrderLookupIntent.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/intents/OrderLookupIntent.ktindex 67c96d3cdf..85de27543e 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/intents/OrderLookupIntent.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/intents/OrderLookupIntent.kt@@ -86,6 +86,7 @@ class OrderLookupIntent : AssistantIntent<OrderLookupRequest, OrderLookupResult>         return r * 2 * atan2(sqrt(a), sqrt(1 - a))     } +        /** Matching radius used to identify the merchant at a queried location. */     companion object {         /** How close a merchant must be to the queried point to be the same place. */         private const val MATCH_RADIUS_METERS = 800.0
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/notifications/OrderTrackingService.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/notifications/OrderTrackingService.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/notifications/OrderTrackingService.ktindex 593b02f9f5..71cdd8f869 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/notifications/OrderTrackingService.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/notifications/OrderTrackingService.kt@@ -139,6 +139,7 @@ class OrderTrackingService : Service() {         super.onDestroy()     } +        /** Polling timings, intent extras, and start/stop helpers for order tracking. */     companion object {         private const val TAG = "OrderTrackingService"