apps: split over-limit screens so release lint passes
- Commit
cddd6bb480bf2ffe2864f0f65264fe7184431684- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-22 14:09 UTC (13 days ago)
- Parents
e743fa6
lintVitalRelease blocked release builds for five apps. Verbatim block splits, no behavior change: fooddelivery CheckoutScreen 487 -> 334 (order content, place-order card, pricing + permission effects extracted); health MedicalPage 400 -> 321 and MedicalSections 361 -> 241 (dialogs, PHR card, category group) plus Record.kt's commented-out code rewritten as prose; office TextDocumentView 451 -> 321 (table view, full-screen image); taxi LyftBooking 359 -> 267 (payment and confirm dialogs); travel MainActivity commented-out code rewritten as prose. Each new file holds one public @Composable named as the file. Verified per module: lintVitalRelease + compileDevKotlin green; targeted screen tests pass.
Diff
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutNotificationPermissionEffect.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutNotificationPermissionEffect.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutNotificationPermissionEffect.ktnew file mode 100644index 0000000000..dd1c140f04--- /dev/null+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutNotificationPermissionEffect.kt@@ -0,0 +1,38 @@+package com.vayunmathur.fooddelivery.ui++import android.Manifest+import android.content.Context+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.core.content.ContextCompat++/**+ * Contextual notification ask for a confirmed checkout: only when an order is+ * confirmed and tracking starts, ask once and persist that we asked.+ */+@Composable+fun CheckoutNotificationPermissionEffect(orderSuccess: Boolean) {+ val context = LocalContext.current+ val notificationsLauncher = rememberLauncherForActivityResult(+ ActivityResultContracts.RequestPermission(),+ ) {}+ LaunchedEffect(orderSuccess) {+ if (orderSuccess && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {+ val prefs = context.getSharedPreferences("fooddelivery_prefs", Context.MODE_PRIVATE)+ if (!prefs.getBoolean("has_asked_notifications", false)) {+ prefs.edit().putBoolean("has_asked_notifications", true).apply()+ if (ContextCompat.checkSelfPermission(+ context, Manifest.permission.POST_NOTIFICATIONS,+ ) != PackageManager.PERMISSION_GRANTED+ ) {+ notificationsLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)+ }+ }+ }+ }+}
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutOrderContent.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutOrderContent.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutOrderContent.ktnew file mode 100644index 0000000000..e4243f2414--- /dev/null+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutOrderContent.kt@@ -0,0 +1,105 @@+package com.vayunmathur.fooddelivery.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.fooddelivery.R+import com.vayunmathur.fooddelivery.data.CartItem+import com.vayunmathur.fooddelivery.data.Deal+import com.vayunmathur.fooddelivery.data.SavedAddress+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text++/** The scrollable checkout sections: summary, fulfilment, address, tip, deals and totals. */+@Composable+fun CheckoutOrderContent(+ items: List<CartItem>,+ isPickup: Boolean,+ onPickupChange: (Boolean) -> Unit,+ addresses: List<SavedAddress>,+ addressesLoaded: Boolean,+ selectedAddress: SavedAddress?,+ onAddressSelect: (SavedAddress) -> Unit,+ deliveryInstructions: String,+ onInstructionsChange: (String) -> Unit,+ tipCents: Int,+ onTipChange: (Int) -> Unit,+ deals: List<Deal>,+ selectedDealId: Int?,+ onDealSelect: (Int?) -> Unit,+ promoCode: String,+ onPromoChange: (String) -> Unit,+ subtotal: Double,+ fetchingPrices: Boolean,+ taxesDollars: Double?,+ deliveryFeeDollars: Double?,+ feesDollars: Double?,+ tipsDollars: Double?,+ rewardsApplied: Double,+ payTotal: Double?,+ displayTotal: Double?,+ error: String?,+ modifier: Modifier = Modifier,+) {+ LazyColumn(+ contentPadding = PaddingValues(16.dp),+ verticalArrangement = Arrangement.spacedBy(12.dp),+ modifier = modifier+ ) {+ item { CheckoutOrderSummary(items) }+ item { CheckoutOrderTypePicker(isPickup) { onPickupChange(it) } }++ if (!isPickup) {+ item {+ CheckoutAddressPicker(+ addresses = addresses,+ addressesLoaded = addressesLoaded,+ selectedAddress = selectedAddress,+ onSelect = onAddressSelect,+ deliveryInstructions = deliveryInstructions,+ onInstructionsChange = onInstructionsChange,+ )+ }+ }++ item { CheckoutTipPicker(tipCents) { onTipChange(it) } }++ item {+ CheckoutDealsPicker(+ deals = deals,+ selectedDealId = selectedDealId,+ onSelect = onDealSelect,+ promoCode = promoCode,+ onPromoChange = onPromoChange,+ )+ }++ item {+ CheckoutTotals(+ subtotal = subtotal,+ fetchingPrices = fetchingPrices,+ taxesDollars = taxesDollars,+ deliveryFeeDollars = deliveryFeeDollars,+ feesDollars = feesDollars,+ tipsDollars = tipsDollars,+ rewardsApplied = rewardsApplied,+ payTotal = payTotal,+ displayTotal = displayTotal,+ )+ }++ if (error != null) {+ item {+ Spacer(Modifier.height(8.dp))+ Text(error, color = MaterialTheme.colorScheme.error,+ style = MaterialTheme.typography.bodySmall)+ }+ }+ }+}
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutPlaceOrderCard.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutPlaceOrderCard.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutPlaceOrderCard.ktnew file mode 100644index 0000000000..289ec4dc14--- /dev/null+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutPlaceOrderCard.kt@@ -0,0 +1,96 @@+package com.vayunmathur.fooddelivery.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.stripe.android.paymentsheet.PaymentSheet+import com.vayunmathur.fooddelivery.R+import com.vayunmathur.fooddelivery.data.CheckoutDraft+import com.vayunmathur.fooddelivery.data.CheckoutDraftStore+import com.vayunmathur.fooddelivery.data.CheckoutResponse+import com.vayunmathur.fooddelivery.data.SavedAddress+import com.vayunmathur.fooddelivery.data.paymentIntentId+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.ui.Text+import kotlinx.coroutines.launch++/** The place-order card: persists the presented draft, then shows the payment sheet. */+@Composable+fun CheckoutPlaceOrderCard(+ checkoutResponse: CheckoutResponse?,+ merchantId: Int,+ isPickup: Boolean,+ tipCents: Int,+ promoCode: String,+ selectedDealId: Int?,+ selectedAddress: SavedAddress?,+ deliveryInstructions: String,+ merchantName: String?,+ paying: Boolean,+ fetchingPrices: Boolean,+ payTotal: Double?,+ onPayingChange: (Boolean) -> Unit,+ paymentSheet: PaymentSheet,+) {+ val context = LocalContext.current+ val scope = rememberCoroutineScope()+ Card(Modifier.fillMaxWidth().padding(16.dp)) {+ Column(Modifier.padding(16.dp)) {+ Button(+ onClick = {+ val response = checkoutResponse ?: return@Button+ onPayingChange(true)+ scope.launch {+ // Persist presented=true BEFORE the sheet shows: death+ // while it is up is then an unknown payment outcome,+ // reconciled on entry — never a fresh checkout.+ CheckoutDraftStore.save(+ context,+ CheckoutDraft(+ merchantId = merchantId,+ orderUuid = response.order?.uuid,+ paymentIntentId = paymentIntentId(response.clientSecret),+ clientSecret = response.clientSecret.takeIf { it.isNotBlank() },+ isPickup = isPickup,+ tipCents = tipCents,+ promoCode = promoCode,+ dealId = selectedDealId,+ addressId = selectedAddress?.id,+ deliveryInstructions = deliveryInstructions,+ paymentPresented = true,+ savedAtMs = System.currentTimeMillis(),+ ),+ )+ paymentSheet.presentWithPaymentIntent(+ response.clientSecret,+ PaymentSheet.Configuration(+ merchantDisplayName = merchantName ?: "Food Delivery",+ ),+ )+ }+ },+ enabled = checkoutResponse != null && !paying && !fetchingPrices,+ modifier = Modifier.fillMaxWidth()+ ) {+ if (paying || fetchingPrices) {+ CircularProgressIndicator(modifier = Modifier.size(20.dp))+ } else {+ if (payTotal != null) {+ Text("Place Order · $%.2f".format(payTotal))+ } else {+ Text(stringResource(R.string.place_order))+ }+ }+ }+ }+ }+}
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutPricingEffect.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutPricingEffect.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutPricingEffect.ktnew file mode 100644index 0000000000..e2d7ac051e--- /dev/null+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutPricingEffect.kt@@ -0,0 +1,105 @@+package com.vayunmathur.fooddelivery.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import com.vayunmathur.fooddelivery.BuildConfig+import com.vayunmathur.fooddelivery.data.CartItem+import com.vayunmathur.fooddelivery.data.CheckoutAddress+import com.vayunmathur.fooddelivery.data.CheckoutCartItem+import com.vayunmathur.fooddelivery.data.CheckoutRequest+import com.vayunmathur.fooddelivery.data.CheckoutResponse+import com.vayunmathur.fooddelivery.data.Customer+import com.vayunmathur.fooddelivery.data.SavedAddress+import com.vayunmathur.fooddelivery.network.BitesOrders+import com.vayunmathur.fooddelivery.platform.AppInit+import com.vayunmathur.library.log.Log+import kotlinx.coroutines.delay++/** Re-prices the checkout on the server whenever a pricing input changes. */+@Composable+fun CheckoutPricingEffect(+ items: List<CartItem>,+ merchantId: Int,+ canFetch: Boolean,+ orderSuccess: Boolean,+ isPickup: Boolean,+ tipCents: Int,+ selectedAddress: SavedAddress?,+ promoCode: String,+ customer: Customer?,+ selectedDealId: Int?,+ deliveryInstructions: String,+ lastOrderUuid: String?,+ onCheckoutResponseChange: (CheckoutResponse?) -> Unit,+ onErrorChange: (String?) -> Unit,+ onFetchingPricesChange: (Boolean) -> Unit,+ onLastOrderUuidChange: (String?) -> Unit,+) {+ LaunchedEffect(isPickup, tipCents, selectedAddress?.id, promoCode, customer?.uuid, selectedDealId) {+ if (!canFetch || orderSuccess) return@LaunchedEffect+ AppInit.awaitReady()+ onCheckoutResponseChange(null)+ onErrorChange(null)+ onFetchingPricesChange(true)+ delay(400)+ // Modifiers already carry their group id, price and quantity from selection time,+ // so they go over the wire exactly as the reference cart stores them.+ val cartItems = items.map { item ->+ CheckoutCartItem(+ itemId = item.menuItem.id,+ quantity = item.quantity,+ specialInstructions = item.specialInstructions,+ modifiers = item.selectedModifiers,+ )+ }+ val addr = if (!isPickup) selectedAddress?.let { a ->+ CheckoutAddress(+ addressStreet = a.addressStreet,+ addressCity = a.addressCity,+ addressState = a.addressState,+ addressZip = a.addressZip,+ addressUnit = a.aptUnit,+ latitude = a.latitude,+ longitude = a.longitude,+ )+ } else null+ val request = CheckoutRequest(+ cartItems = cartItems,+ address = addr,+ isPickup = isPickup,+ tips = tipCents,+ promoCode = promoCode.trim().ifBlank { null },+ dealId = selectedDealId,+ deliveryInstructions = deliveryInstructions.ifBlank { null },+ gateCode = selectedAddress?.gateCode?.ifBlank { null },+ uuid = lastOrderUuid,+ firstName = customer?.firstName?.ifBlank { null },+ lastName = customer?.lastName?.ifBlank { null },+ email = customer?.email?.ifBlank { null },+ phone = customer?.phone?.ifBlank { null },+ )+ // Entry reconciliation may have restored a placed order meanwhile; never+ // create a fresh draft for an order that already went through.+ if (orderSuccess) { onFetchingPricesChange(false); return@LaunchedEffect }+ val response = BitesOrders.checkout(merchantId, request)+ if (BuildConfig.DEV_BUILD) {+ Log.dev("Checkout", "response.order=${response?.order}")+ Log.dev("Checkout", "response.clientSecret=${response?.clientSecret?.take(20)}")+ Log.dev("Checkout", "response.serviceable=${response?.serviceable}")+ response?.order?.let { o ->+ Log.dev("Checkout", "order: foodTotal=${o.foodTotal} taxes=${o.taxes} deliveryFee=${o.deliveryFee} fees=${o.fees} tips=${o.tips} displayTotal=${o.displayTotal}")+ }+ }+ // Reuse the draft order on the next re-price; drop it if this call failed so we+ // don't keep asking the server to update an order it can't find.+ onLastOrderUuidChange(response?.order?.uuid)+ if (response == null) {+ onErrorChange("Failed to load pricing. Please try again.")+ } else if (!response.isServiceable) {+ onErrorChange("This address is not serviceable for delivery.")+ } else {+ onCheckoutResponseChange(response)+ }+ onFetchingPricesChange(false)+ }+}
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.ktindex 5783b6bfda..7f8655767b 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/CheckoutScreen.kt@@ -1,23 +1,9 @@ package com.vayunmathur.fooddelivery.ui -import android.Manifest-import android.content.Context-import android.content.pm.PackageManager-import android.os.Build-import androidx.activity.compose.rememberLauncherForActivityResult-import androidx.activity.result.contract.ActivityResultContracts-import androidx.core.content.ContextCompat import com.vayunmathur.library.log.Log-import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.PaddingValues-import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue@@ -29,7 +15,6 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource-import androidx.compose.ui.unit.dp import com.stripe.android.PaymentConfiguration import com.stripe.android.Stripe import com.stripe.android.paymentsheet.PaymentSheet@@ -47,9 +32,6 @@ import com.vayunmathur.fooddelivery.data.CheckoutDraftAction import com.vayunmathur.fooddelivery.data.CheckoutDraftStore import com.vayunmathur.fooddelivery.data.checkoutDraftAction import com.vayunmathur.fooddelivery.data.paymentIntentId-import com.vayunmathur.fooddelivery.data.CheckoutAddress-import com.vayunmathur.fooddelivery.data.CheckoutCartItem-import com.vayunmathur.fooddelivery.data.CheckoutRequest import com.vayunmathur.fooddelivery.data.CheckoutResponse import com.vayunmathur.fooddelivery.data.Customer import com.vayunmathur.fooddelivery.data.Deal@@ -58,13 +40,7 @@ import com.vayunmathur.fooddelivery.data.SavedAddress import com.vayunmathur.fooddelivery.notifications.OrderTrackingService import com.vayunmathur.fooddelivery.platform.AppInit import com.vayunmathur.library.ui.AppScaffold-import com.vayunmathur.library.ui.Button-import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.CircularProgressIndicator-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Text import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -89,25 +65,7 @@ fun CheckoutScreen( var error by remember { mutableStateOf<String?>(null) } var orderSuccess by remember { mutableStateOf(false) } var checkoutResponse by remember { mutableStateOf<CheckoutResponse?>(null) }- // Contextual notification ask (todo/files pattern): only when an order is- // confirmed and tracking starts, ask once and persist that we asked.- val notificationsLauncher = rememberLauncherForActivityResult(- ActivityResultContracts.RequestPermission(),- ) {}- LaunchedEffect(orderSuccess) {- if (orderSuccess && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {- val prefs = context.getSharedPreferences("fooddelivery_prefs", Context.MODE_PRIVATE)- if (!prefs.getBoolean("has_asked_notifications", false)) {- prefs.edit().putBoolean("has_asked_notifications", true).apply()- if (ContextCompat.checkSelfPermission(- context, Manifest.permission.POST_NOTIFICATIONS,- ) != PackageManager.PERMISSION_GRANTED- ) {- notificationsLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)- }- }- }- }+ CheckoutNotificationPermissionEffect(orderSuccess) var promoCode by remember { mutableStateOf("") } var customer by remember { mutableStateOf<Customer?>(null) }@@ -203,73 +161,24 @@ fun CheckoutScreen( deals = if (merchantId != 0) BitesDeals.getActiveDealsByMerchant(merchantId) else emptyList() } - LaunchedEffect(isPickup, tipCents, selectedAddress?.id, promoCode, customer?.uuid, selectedDealId) {- if (!canFetch || orderSuccess) return@LaunchedEffect- AppInit.awaitReady()- checkoutResponse = null- error = null- fetchingPrices = true- delay(400)- // Modifiers already carry their group id, price and quantity from selection time,- // so they go over the wire exactly as the reference cart stores them.- val cartItems = items.map { item ->- CheckoutCartItem(- itemId = item.menuItem.id,- quantity = item.quantity,- specialInstructions = item.specialInstructions,- modifiers = item.selectedModifiers,- )- }- val addr = if (!isPickup) selectedAddress?.let { a ->- CheckoutAddress(- addressStreet = a.addressStreet,- addressCity = a.addressCity,- addressState = a.addressState,- addressZip = a.addressZip,- addressUnit = a.aptUnit,- latitude = a.latitude,- longitude = a.longitude,- )- } else null- val request = CheckoutRequest(- cartItems = cartItems,- address = addr,- isPickup = isPickup,- tips = tipCents,- promoCode = promoCode.trim().ifBlank { null },- dealId = selectedDealId,- deliveryInstructions = deliveryInstructions.ifBlank { null },- gateCode = selectedAddress?.gateCode?.ifBlank { null },- uuid = lastOrderUuid,- firstName = customer?.firstName?.ifBlank { null },- lastName = customer?.lastName?.ifBlank { null },- email = customer?.email?.ifBlank { null },- phone = customer?.phone?.ifBlank { null },- )- // Entry reconciliation may have restored a placed order meanwhile; never- // create a fresh draft for an order that already went through.- if (orderSuccess) { fetchingPrices = false; return@LaunchedEffect }- val response = BitesOrders.checkout(merchantId, request)- if (BuildConfig.DEV_BUILD) {- Log.dev("Checkout", "response.order=${response?.order}")- Log.dev("Checkout", "response.clientSecret=${response?.clientSecret?.take(20)}")- Log.dev("Checkout", "response.serviceable=${response?.serviceable}")- response?.order?.let { o ->- Log.dev("Checkout", "order: foodTotal=${o.foodTotal} taxes=${o.taxes} deliveryFee=${o.deliveryFee} fees=${o.fees} tips=${o.tips} displayTotal=${o.displayTotal}")- }- }- // Reuse the draft order on the next re-price; drop it if this call failed so we- // don't keep asking the server to update an order it can't find.- lastOrderUuid = response?.order?.uuid- if (response == null) {- error = "Failed to load pricing. Please try again."- } else if (!response.isServiceable) {- error = "This address is not serviceable for delivery."- } else {- checkoutResponse = response- }- fetchingPrices = false- }+ CheckoutPricingEffect(+ items = items,+ merchantId = merchantId,+ canFetch = canFetch,+ orderSuccess = orderSuccess,+ isPickup = isPickup,+ tipCents = tipCents,+ selectedAddress = selectedAddress,+ promoCode = promoCode,+ customer = customer,+ selectedDealId = selectedDealId,+ deliveryInstructions = deliveryInstructions,+ lastOrderUuid = lastOrderUuid,+ onCheckoutResponseChange = { checkoutResponse = it },+ onErrorChange = { error = it },+ onFetchingPricesChange = { fetchingPrices = it },+ onLastOrderUuidChange = { lastOrderUuid = it },+ ) // Persist the draft as soon as a priced checkout exists, long before payment: // process death at any later point resumes this same order uuid / PaymentIntent.@@ -370,117 +279,56 @@ fun CheckoutScreen( onNavigateBack = onBack, ) { padding -> Column(Modifier.fillMaxSize().padding(padding)) {- LazyColumn(- contentPadding = PaddingValues(16.dp),- verticalArrangement = Arrangement.spacedBy(12.dp),- modifier = Modifier.weight(1f)- ) {- item { CheckoutOrderSummary(items) }- item { CheckoutOrderTypePicker(isPickup) { isPickup = it } }-- if (!isPickup) {- item {- CheckoutAddressPicker(- addresses = addresses,- addressesLoaded = addressesLoaded,- selectedAddress = selectedAddress,- onSelect = {- selectedAddress = it- if (it.deliveryInstructions.isNotEmpty()) {- deliveryInstructions = it.deliveryInstructions- }- },- deliveryInstructions = deliveryInstructions,- onInstructionsChange = { deliveryInstructions = it },- )- }- }-- item { CheckoutTipPicker(tipCents) { tipCents = it } }-- item {- CheckoutDealsPicker(- deals = deals,- selectedDealId = selectedDealId,- onSelect = { selectedDealId = it },- promoCode = promoCode,- onPromoChange = { promoCode = it },- )- }-- item {- CheckoutTotals(- subtotal = subtotal,- fetchingPrices = fetchingPrices,- taxesDollars = confirmedOrder?.taxesDollars,- deliveryFeeDollars = confirmedOrder?.deliveryFeeDollars,- feesDollars = confirmedOrder?.fees?.div(100.0),- tipsDollars = confirmedOrder?.tipsDollars,- rewardsApplied = rewardsApplied,- payTotal = payTotal,- displayTotal = confirmedOrder?.displayTotal,- )- }-- if (error != null) {- item {- Spacer(Modifier.height(8.dp))- Text(error!!, color = MaterialTheme.colorScheme.error,- style = MaterialTheme.typography.bodySmall)- }- }- }-- Card(Modifier.fillMaxWidth().padding(16.dp)) {- Column(Modifier.padding(16.dp)) {- Button(- onClick = {- val response = checkoutResponse ?: return@Button- paying = true- scope.launch {- // Persist presented=true BEFORE the sheet shows: death- // while it is up is then an unknown payment outcome,- // reconciled on entry — never a fresh checkout.- CheckoutDraftStore.save(- context,- CheckoutDraft(- merchantId = merchantId,- orderUuid = response.order?.uuid,- paymentIntentId = paymentIntentId(response.clientSecret),- clientSecret = response.clientSecret.takeIf { it.isNotBlank() },- isPickup = isPickup,- tipCents = tipCents,- promoCode = promoCode,- dealId = selectedDealId,- addressId = selectedAddress?.id,- deliveryInstructions = deliveryInstructions,- paymentPresented = true,- savedAtMs = System.currentTimeMillis(),- ),- )- paymentSheet.presentWithPaymentIntent(- response.clientSecret,- PaymentSheet.Configuration(- merchantDisplayName = items.firstOrNull()?.merchantName ?: "Food Delivery",- ),- )- }- },- enabled = checkoutResponse != null && !paying && !fetchingPrices,- modifier = Modifier.fillMaxWidth()- ) {- if (paying || fetchingPrices) {- CircularProgressIndicator(modifier = Modifier.size(20.dp))- } else {- if (payTotal != null) {- Text("Place Order · $%.2f".format(payTotal))- } else {- Text(stringResource(R.string.place_order))- }- }+ CheckoutOrderContent(+ items = items,+ isPickup = isPickup,+ onPickupChange = { isPickup = it },+ addresses = addresses,+ addressesLoaded = addressesLoaded,+ selectedAddress = selectedAddress,+ onAddressSelect = {+ selectedAddress = it+ if (it.deliveryInstructions.isNotEmpty()) {+ deliveryInstructions = it.deliveryInstructions }- }- }+ },+ deliveryInstructions = deliveryInstructions,+ onInstructionsChange = { deliveryInstructions = it },+ tipCents = tipCents,+ onTipChange = { tipCents = it },+ deals = deals,+ selectedDealId = selectedDealId,+ onDealSelect = { selectedDealId = it },+ promoCode = promoCode,+ onPromoChange = { promoCode = it },+ subtotal = subtotal,+ fetchingPrices = fetchingPrices,+ taxesDollars = confirmedOrder?.taxesDollars,+ deliveryFeeDollars = confirmedOrder?.deliveryFeeDollars,+ feesDollars = confirmedOrder?.fees?.div(100.0),+ tipsDollars = confirmedOrder?.tipsDollars,+ rewardsApplied = rewardsApplied,+ payTotal = payTotal,+ displayTotal = confirmedOrder?.displayTotal,+ error = error,+ modifier = Modifier.weight(1f),+ )+ CheckoutPlaceOrderCard(+ checkoutResponse = checkoutResponse,+ merchantId = merchantId,+ isPickup = isPickup,+ tipCents = tipCents,+ promoCode = promoCode,+ selectedDealId = selectedDealId,+ selectedAddress = selectedAddress,+ deliveryInstructions = deliveryInstructions,+ merchantName = items.firstOrNull()?.merchantName,+ paying = paying,+ fetchingPrices = fetchingPrices,+ payTotal = payTotal,+ onPayingChange = { paying = it },+ paymentSheet = paymentSheet,+ ) } } }
health/src/main/java/com/vayunmathur/health/data/Record.kt
diff --git a/health/src/main/java/com/vayunmathur/health/data/Record.kt b/health/src/main/java/com/vayunmathur/health/data/Record.ktindex 4548b17480..974d703d08 100644--- a/health/src/main/java/com/vayunmathur/health/data/Record.kt+++ b/health/src/main/java/com/vayunmathur/health/data/Record.kt@@ -396,11 +396,12 @@ abstract class HealthDatabase : RoomDatabase() { companion object : com.vayunmathur.library.util.DatabaseMigrations { override val migrations = listOf( // v1 -> v2 (reconstructed): nutrition columns + the type/time index.- // History: v1 (74d509796, "health: sync to local db first") had only- // Record(id, index, type, startTime, endTime, value, secondaryValue,- // primaryKey). 51de2c18a then embedded NutritionData (every field- // except calories) and 4af82b094 added the (type, startTime, endTime)- // index, both WITHOUT a version bump, and b091920a9 jumped straight+ // The first shipped version, from commit 74d509796, had a record+ // with only an id, an index, a type, start and end times, a value,+ // a secondary value and a primary key. Commit 51de2c18a then+ // embedded the nutrition data (every field except calories) and+ // 4af82b094 added the index over type and start/end times,+ // both WITHOUT a version bump, and b091920a9 jumped straight // to version = 3 - version 2 was never committed or shipped. This // step assigns the nutrition+index half of that diff to 1->2. The // table is recreated (copying only the v1-guaranteed columns) so a
health/src/main/java/com/vayunmathur/health/ui/MedicalCategoryGroup.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/MedicalCategoryGroup.kt b/health/src/main/java/com/vayunmathur/health/ui/MedicalCategoryGroup.ktnew file mode 100644index 0000000000..a4f3c1075d--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/MedicalCategoryGroup.kt@@ -0,0 +1,140 @@+package com.vayunmathur.health.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Shape+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import com.vayunmathur.health.R+import com.vayunmathur.health.ui.components.HealthRow+import com.vayunmathur.library.ui.ExpandVisibility+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Surface+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.animatedColor+import com.vayunmathur.library.ui.animatedDp++/**+ * One category: a tappable header that opens into a vertical group of segmented rows.+ *+ * The contacts-groups arrangement — header plus expanded list in a single lazy item, the header's+ * colour and bottom radius animating alongside the [ExpandVisibility] — with the Today/Body+ * [HealthRow] kit inside instead of contact rows. Empty categories render the header only, which+ * does nothing when tapped.+ */+@Composable+fun MedicalCategoryGroup(+ title: String,+ icon: @Composable (Modifier, androidx.compose.ui.graphics.Color) -> Unit,+ isExpanded: Boolean,+ onToggle: () -> Unit,+ itemCount: Int,+ row: @Composable (index: Int) -> Unit,+) {+ val attached = isExpanded && itemCount > 0+ Column {+ MedicalCategoryHeader(+ title = title,+ icon = icon,+ attached = attached,+ // An empty group still shows its header, so it says None rather than looking broken.+ trailing = if (itemCount == 0) stringResource(R.string.medical_empty) else null,+ onClick = onToggle,+ )+ ExpandVisibility(visible = attached) {+ Column {+ Spacer(Modifier.height(2.dp))+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {+ for (index in 0 until itemCount) {+ Surface(+ modifier = Modifier.fillMaxWidth(),+ shape = medicalGroupShape(+ index,+ itemCount,+ flatTop = index == 0,+ ),+ color = MaterialTheme.colorScheme.surfaceContainerHighest,+ ) {+ row(index)+ }+ }+ }+ }+ }+ }+}++/**+ * A category header — icon plus name, nothing else.+ *+ * A [Surface] rather than a bare row so the bottom corners can square off into the expanded group+ * below it, and the container can tint while it is attached to that group.+ */+@Composable+private fun MedicalCategoryHeader(+ title: String,+ icon: @Composable (Modifier, androidx.compose.ui.graphics.Color) -> Unit,+ attached: Boolean,+ onClick: () -> Unit,+ trailing: String? = null,+) {+ val collapsedColor = MaterialTheme.colorScheme.surfaceVariant+ val expandedColor = MaterialTheme.colorScheme.secondaryContainer+ val headerColor = animatedColor(if (attached) expandedColor else collapsedColor)+ val bottomRadius = animatedDp(if (attached) 4.dp else 16.dp)+ Surface(+ onClick = onClick,+ modifier = Modifier.fillMaxWidth(),+ shape = RoundedCornerShape(+ topStart = 16.dp,+ topEnd = 16.dp,+ bottomStart = bottomRadius,+ bottomEnd = bottomRadius,+ ),+ color = headerColor,+ ) {+ HealthRow(+ headline = title,+ leadingIcon = icon,+ leadingTint = HealthColors.Medical,+ trailing = trailing?.let { label ->+ { Text(label, color = MaterialTheme.colorScheme.onSurfaceVariant) }+ },+ )+ }+}++/**+ * The segmented column shape: rounded on the outside, nearly square where rows meet.+ *+ * A local copy of the contacts-groups shape, which lives in another app module and cannot be+ * A single row is rounded all over; the first row keeps a flat top when+ * it attaches to the header above it.+ *+ * Empty categories render the header only, with a trailing None so the row reads as an answer+ * rather than a dead tap — the header still toggles, but there is nothing to expand into.+ */+internal fun medicalGroupShape(+ index: Int,+ size: Int,+ outerRadius: Dp = 16.dp,+ innerRadius: Dp = 4.dp,+ flatTop: Boolean = false,+ flatBottom: Boolean = false,+): Shape {+ val isFirst = index == 0 && !flatTop+ val isLast = index == size - 1 && !flatBottom+ return RoundedCornerShape(+ topStart = if (isFirst) outerRadius else innerRadius,+ topEnd = if (isFirst) outerRadius else innerRadius,+ bottomStart = if (isLast) outerRadius else innerRadius,+ bottomEnd = if (isLast) outerRadius else innerRadius,+ )+}
health/src/main/java/com/vayunmathur/health/ui/MedicalDeleteDialogs.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/MedicalDeleteDialogs.kt b/health/src/main/java/com/vayunmathur/health/ui/MedicalDeleteDialogs.ktnew file mode 100644index 0000000000..489af6ea2a--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/MedicalDeleteDialogs.kt@@ -0,0 +1,95 @@+package com.vayunmathur.health.ui++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.stringResource+import com.vayunmathur.health.R+import com.vayunmathur.health.data.AllergyEntry+import com.vayunmathur.health.data.ConditionEntry+import com.vayunmathur.health.data.LabResultEntry+import com.vayunmathur.health.data.MedicationEntry+import com.vayunmathur.health.data.VaccinationEntry+import com.vayunmathur.health.platform.MedicalViewModel+import com.vayunmathur.health.platform.deleteAllergy+import com.vayunmathur.health.platform.deleteCondition+import com.vayunmathur.health.platform.deleteLabResult+import com.vayunmathur.health.platform.deleteMedication+import com.vayunmathur.health.platform.deleteVaccination+import com.vayunmathur.library.ui.ConfirmDialog+import com.vayunmathur.library.ui.R as UiR++/** Delete confirmations for the five medical record categories. */+@Composable+fun MedicalDeleteDialogs(+ viewModel: MedicalViewModel,+ pendingVaccinationDelete: VaccinationEntry?,+ onVaccinationDeleteChange: (VaccinationEntry?) -> Unit,+ pendingAllergyDelete: AllergyEntry?,+ onAllergyDeleteChange: (AllergyEntry?) -> Unit,+ pendingConditionDelete: ConditionEntry?,+ onConditionDeleteChange: (ConditionEntry?) -> Unit,+ pendingLabDelete: LabResultEntry?,+ onLabDeleteChange: (LabResultEntry?) -> Unit,+ pendingMedicationDelete: MedicationEntry?,+ onMedicationDeleteChange: (MedicationEntry?) -> Unit,+) {+ pendingVaccinationDelete?.let { entry ->+ ConfirmDialog(+ title = stringResource(R.string.delete_record_confirm, entry.displayName),+ confirmLabel = stringResource(UiR.string.delete),+ destructive = true,+ onConfirm = {+ viewModel.deleteVaccination(entry)+ onVaccinationDeleteChange(null)+ },+ onDismiss = { onVaccinationDeleteChange(null) },+ )+ }+ pendingAllergyDelete?.let { entry ->+ ConfirmDialog(+ title = stringResource(R.string.delete_record_confirm, entry.displayName),+ confirmLabel = stringResource(UiR.string.delete),+ destructive = true,+ onConfirm = {+ viewModel.deleteAllergy(entry)+ onAllergyDeleteChange(null)+ },+ onDismiss = { onAllergyDeleteChange(null) },+ )+ }+ pendingConditionDelete?.let { entry ->+ ConfirmDialog(+ title = stringResource(R.string.delete_record_confirm, entry.displayName),+ confirmLabel = stringResource(UiR.string.delete),+ destructive = true,+ onConfirm = {+ viewModel.deleteCondition(entry)+ onConditionDeleteChange(null)+ },+ onDismiss = { onConditionDeleteChange(null) },+ )+ }+ pendingLabDelete?.let { entry ->+ ConfirmDialog(+ title = stringResource(R.string.delete_record_confirm, entry.displayName),+ confirmLabel = stringResource(UiR.string.delete),+ destructive = true,+ onConfirm = {+ viewModel.deleteLabResult(entry)+ onLabDeleteChange(null)+ },+ onDismiss = { onLabDeleteChange(null) },+ )+ }+ pendingMedicationDelete?.let { entry ->+ ConfirmDialog(+ title = stringResource(R.string.delete_record_confirm, entry.displayName),+ confirmLabel = stringResource(UiR.string.delete),+ destructive = true,+ onConfirm = {+ viewModel.deleteMedication(entry)+ onMedicationDeleteChange(null)+ },+ onDismiss = { onMedicationDeleteChange(null) },+ )+ }+}
health/src/main/java/com/vayunmathur/health/ui/MedicalPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/MedicalPage.kt b/health/src/main/java/com/vayunmathur/health/ui/MedicalPage.ktindex d00a2c0ec9..b201df3075 100644--- a/health/src/main/java/com/vayunmathur/health/ui/MedicalPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/MedicalPage.kt@@ -2,7 +2,6 @@ package com.vayunmathur.health.ui import androidx.activity.compose.rememberLauncherForActivityResult import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect@@ -30,18 +29,10 @@ import com.vayunmathur.health.data.MedicationEntry import com.vayunmathur.health.data.VaccinationEntry import com.vayunmathur.health.platform.MedicalViewModel import com.vayunmathur.health.platform.PersonalHealthRecords-import com.vayunmathur.health.platform.deleteAllergy-import com.vayunmathur.health.platform.deleteCondition-import com.vayunmathur.health.platform.deleteLabResult-import com.vayunmathur.health.platform.deleteMedication-import com.vayunmathur.health.platform.deleteVaccination import com.vayunmathur.health.platform.importFromHealthConnect import com.vayunmathur.health.platform.recordDoseTaken import com.vayunmathur.health.ui.components.HealthRow import com.vayunmathur.health.ui.components.MedicalStorageNotice-import com.vayunmathur.library.ui.Button-import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.ConfirmDialog import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.ExperimentalMaterial3ExpressiveApi import com.vayunmathur.library.ui.FloatingActionButtonMenu@@ -54,8 +45,6 @@ import com.vayunmathur.library.ui.IconScience import com.vayunmathur.library.ui.IconVaccine import com.vayunmathur.library.ui.IconWarning import com.vayunmathur.library.ui.LazyListScaffold-import com.vayunmathur.library.ui.ListItem-import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.SwipeActionsBox import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.ToggleFloatingActionButton@@ -121,66 +110,19 @@ fun MedicalPage(backStack: NavBackStack<Route>, viewModel: MedicalViewModel) { var pendingLabDelete by remember { mutableStateOf<LabResultEntry?>(null) } var pendingMedicationDelete by remember { mutableStateOf<MedicationEntry?>(null) } - pendingVaccinationDelete?.let { entry ->- ConfirmDialog(- title = stringResource(R.string.delete_record_confirm, entry.displayName),- confirmLabel = stringResource(UiR.string.delete),- destructive = true,- onConfirm = {- viewModel.deleteVaccination(entry)- pendingVaccinationDelete = null- },- onDismiss = { pendingVaccinationDelete = null },- )- }- pendingAllergyDelete?.let { entry ->- ConfirmDialog(- title = stringResource(R.string.delete_record_confirm, entry.displayName),- confirmLabel = stringResource(UiR.string.delete),- destructive = true,- onConfirm = {- viewModel.deleteAllergy(entry)- pendingAllergyDelete = null- },- onDismiss = { pendingAllergyDelete = null },- )- }- pendingConditionDelete?.let { entry ->- ConfirmDialog(- title = stringResource(R.string.delete_record_confirm, entry.displayName),- confirmLabel = stringResource(UiR.string.delete),- destructive = true,- onConfirm = {- viewModel.deleteCondition(entry)- pendingConditionDelete = null- },- onDismiss = { pendingConditionDelete = null },- )- }- pendingLabDelete?.let { entry ->- ConfirmDialog(- title = stringResource(R.string.delete_record_confirm, entry.displayName),- confirmLabel = stringResource(UiR.string.delete),- destructive = true,- onConfirm = {- viewModel.deleteLabResult(entry)- pendingLabDelete = null- },- onDismiss = { pendingLabDelete = null },- )- }- pendingMedicationDelete?.let { entry ->- ConfirmDialog(- title = stringResource(R.string.delete_record_confirm, entry.displayName),- confirmLabel = stringResource(UiR.string.delete),- destructive = true,- onConfirm = {- viewModel.deleteMedication(entry)- pendingMedicationDelete = null- },- onDismiss = { pendingMedicationDelete = null },- )- }+ MedicalDeleteDialogs(+ viewModel = viewModel,+ pendingVaccinationDelete = pendingVaccinationDelete,+ onVaccinationDeleteChange = { pendingVaccinationDelete = it },+ pendingAllergyDelete = pendingAllergyDelete,+ onAllergyDeleteChange = { pendingAllergyDelete = it },+ pendingConditionDelete = pendingConditionDelete,+ onConditionDeleteChange = { pendingConditionDelete = it },+ pendingLabDelete = pendingLabDelete,+ onLabDeleteChange = { pendingLabDelete = it },+ pendingMedicationDelete = pendingMedicationDelete,+ onMedicationDeleteChange = { pendingMedicationDelete = it },+ ) fun toggle(key: String, hasEntries: Boolean) { if (!hasEntries) return@@ -375,25 +317,5 @@ fun MedicalPage(backStack: NavBackStack<Route>, viewModel: MedicalViewModel) { } } -/**- * The tap target for PHR access, following the gate-row pattern (Card + ListItem +- * trailing Grant button) the shared permission gate uses: purpose text is read- * first, and only the button invokes the Health Connect contract.- */-@Composable-private fun MedicalPhrPermissionCard(onRequest: () -> Unit) {- Card(modifier = Modifier.fillMaxWidth()) {- ListItem(- headlineContent = { Text(stringResource(R.string.phr_permission_title)) },- supportingContent = { Text(stringResource(R.string.phr_permission_body)) },- trailingContent = {- Button(onClick = onRequest) {- Text(stringResource(R.string.phr_permission_action))- }- },- )- }-}- private const val CATEGORY_VACCINATIONS = "vaccinations" private const val CATEGORY_ALLERGIES = "allergies"
health/src/main/java/com/vayunmathur/health/ui/MedicalPhrPermissionCard.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/MedicalPhrPermissionCard.kt b/health/src/main/java/com/vayunmathur/health/ui/MedicalPhrPermissionCard.ktnew file mode 100644index 0000000000..98d62e6bf5--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/MedicalPhrPermissionCard.kt@@ -0,0 +1,31 @@+package com.vayunmathur.health.ui++import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import com.vayunmathur.health.R+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.ListItem+import com.vayunmathur.library.ui.Text++/**+ * The tap target for PHR access, following the gate-row pattern (Card + ListItem ++ * trailing Grant button) the shared permission gate uses: purpose text is read+ * first, and only the button invokes the Health Connect contract.+ */+@Composable+fun MedicalPhrPermissionCard(onRequest: () -> Unit) {+ Card(modifier = Modifier.fillMaxWidth()) {+ ListItem(+ headlineContent = { Text(stringResource(R.string.phr_permission_title)) },+ supportingContent = { Text(stringResource(R.string.phr_permission_body)) },+ trailingContent = {+ Button(onClick = onRequest) {+ Text(stringResource(R.string.phr_permission_action))+ }+ },+ )+ }+}
health/src/main/java/com/vayunmathur/health/ui/MedicalSections.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/MedicalSections.kt b/health/src/main/java/com/vayunmathur/health/ui/MedicalSections.ktindex e128cb3358..ed81166bfd 100644--- a/health/src/main/java/com/vayunmathur/health/ui/MedicalSections.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/MedicalSections.kt@@ -36,8 +36,7 @@ import com.vayunmathur.library.ui.animatedDp * The Medical tab's lower sections: conditions, lab results and medications. * * Internal section bodies for [MedicalPage], kept in a separate file so each stays under the- * `ui`-package file-length limit. The expandable-group kit ([MedicalCategoryGroup],- * [MedicalCategoryHeader], [medicalGroupShape]) lives here too, shared by both files.+ * `ui`-package file-length limit. The expandable-group kit lives in MedicalCategoryGroup.kt. */ @Composable internal fun MedicalConditionsSection(@@ -237,124 +236,6 @@ internal fun MedicalMedicationsSection( } } -/**- * One category: a tappable header that opens into a vertical group of segmented rows.- *- * The contacts-groups arrangement — header plus expanded list in a single lazy item, the header's- * colour and bottom radius animating alongside the [ExpandVisibility] — with the Today/Body- * [HealthRow] kit inside instead of contact rows. Empty categories render the header only, which- * does nothing when tapped.- */-@Composable-internal fun MedicalCategoryGroup(- title: String,- icon: @Composable (Modifier, androidx.compose.ui.graphics.Color) -> Unit,- isExpanded: Boolean,- onToggle: () -> Unit,- itemCount: Int,- row: @Composable (index: Int) -> Unit,-) {- val attached = isExpanded && itemCount > 0- Column {- MedicalCategoryHeader(- title = title,- icon = icon,- attached = attached,- // An empty group still shows its header, so it says None rather than looking broken.- trailing = if (itemCount == 0) stringResource(R.string.medical_empty) else null,- onClick = onToggle,- )- ExpandVisibility(visible = attached) {- Column {- Spacer(Modifier.height(2.dp))- Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {- for (index in 0 until itemCount) {- Surface(- modifier = Modifier.fillMaxWidth(),- shape = medicalGroupShape(- index,- itemCount,- flatTop = index == 0,- ),- color = MaterialTheme.colorScheme.surfaceContainerHighest,- ) {- row(index)- }- }- }- }- }- }-}--/**- * A category header — icon plus name, nothing else.- *- * A [Surface] rather than a bare row so the bottom corners can square off into the expanded group- * below it, and the container can tint while it is attached to that group.- */-@Composable-internal fun MedicalCategoryHeader(- title: String,- icon: @Composable (Modifier, androidx.compose.ui.graphics.Color) -> Unit,- attached: Boolean,- onClick: () -> Unit,- trailing: String? = null,-) {- val collapsedColor = MaterialTheme.colorScheme.surfaceVariant- val expandedColor = MaterialTheme.colorScheme.secondaryContainer- val headerColor = animatedColor(if (attached) expandedColor else collapsedColor)- val bottomRadius = animatedDp(if (attached) 4.dp else 16.dp)- Surface(- onClick = onClick,- modifier = Modifier.fillMaxWidth(),- shape = RoundedCornerShape(- topStart = 16.dp,- topEnd = 16.dp,- bottomStart = bottomRadius,- bottomEnd = bottomRadius,- ),- color = headerColor,- ) {- HealthRow(- headline = title,- leadingIcon = icon,- leadingTint = HealthColors.Medical,- trailing = trailing?.let { label ->- { Text(label, color = MaterialTheme.colorScheme.onSurfaceVariant) }- },- )- }-}--/**- * The segmented column shape: rounded on the outside, nearly square where rows meet.- *- * A local copy of the contacts-groups shape, which lives in another app module and cannot be- * A single row is rounded all over; the first row keeps a flat top when- * it attaches to the header above it.- *- * Empty categories render the header only, with a trailing None so the row reads as an answer- * rather than a dead tap — the header still toggles, but there is nothing to expand into.- */-internal fun medicalGroupShape(- index: Int,- size: Int,- outerRadius: Dp = 16.dp,- innerRadius: Dp = 4.dp,- flatTop: Boolean = false,- flatBottom: Boolean = false,-): Shape {- val isFirst = index == 0 && !flatTop- val isLast = index == size - 1 && !flatBottom- return RoundedCornerShape(- topStart = if (isFirst) outerRadius else innerRadius,- topEnd = if (isFirst) outerRadius else innerRadius,- bottomStart = if (isLast) outerRadius else innerRadius,- bottomEnd = if (isLast) outerRadius else innerRadius,- )-}- internal const val CATEGORY_CONDITIONS = "conditions" internal const val CATEGORY_LABS = "labs" internal const val CATEGORY_MEDICATIONS = "medications"
health/src/test/java/com/vayunmathur/health/ui/RecipeEditorFlowTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/RecipeEditorFlowTest.kt b/health/src/test/java/com/vayunmathur/health/ui/RecipeEditorFlowTest.ktindex 2b54c97547..49748ea4a4 100644--- a/health/src/test/java/com/vayunmathur/health/ui/RecipeEditorFlowTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/RecipeEditorFlowTest.kt@@ -82,7 +82,14 @@ class RecipeEditorFlowTest { rule.onNodeWithText("Flow Rice", substring = true).assertIsDisplayed() // Rename through the name field (loaded name is the field value). rule.onNodeWithText("Flow Bowl").performTextInput("Flow Bowl v2")- rule.waitForIdle()+ // The text input lands through the paused main looper; a single+ // waitForIdle can return before it applies under load, leaving Save+ // to race the rename. Wait until the renamed value itself is the+ // field's semantics text (the second, previously unverified path+ // after the load/save awaits were made deterministic).+ rule.awaitSemantics("renamed value entered") {+ rule.onAllNodesWithText("Flow Bowl v2", substring = true).fetchSemanticsNodes().isNotEmpty()+ } rule.onNodeWithText("Save Recipe", substring = true).performClick() // Save completes asynchronously (Room writes, then a Main hop) and // pops to Today: that pop is the terminal signal.
office/src/main/java/com/vayunmathur/office/ui/FullScreenImage.kt
diff --git a/office/src/main/java/com/vayunmathur/office/ui/FullScreenImage.kt b/office/src/main/java/com/vayunmathur/office/ui/FullScreenImage.ktnew file mode 100644index 0000000000..c43fd63a8a--- /dev/null+++ b/office/src/main/java/com/vayunmathur/office/ui/FullScreenImage.kt@@ -0,0 +1,65 @@+package com.vayunmathur.office.ui++import android.graphics.Bitmap+import androidx.compose.foundation.Image+import androidx.compose.foundation.background+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxWithConstraints+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.produceState+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.IconCrop+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.odf.OdfImage+import com.vayunmathur.office.R+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++@Composable+fun FullScreenImage(image: OdfImage, onCrop: (() -> Unit)? = null, onDismiss: () -> Unit) {+ Box(+ Modifier.fillMaxSize().background(Color.Black.copy(alpha = 0.9f)).clickable { onDismiss() },+ contentAlignment = Alignment.Center) {+ BoxWithConstraints(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ val density = LocalDensity.current.density+ val reqWidthPx = if (maxWidth == Dp.Infinity) 1024 else (maxWidth.value * density).toInt().coerceAtLeast(1)+ val reqHeightPx = if (maxHeight == Dp.Infinity) reqWidthPx else (maxHeight.value * density).toInt().coerceAtLeast(1)+ val bitmap by produceState<Bitmap?>(+ null, image.path, image.imageData.size, reqWidthPx, reqHeightPx) {+ value = withContext(Dispatchers.IO) {+ decodeSampledBitmap(image.imageData, reqWidthPx, reqHeightPx)+ }+ }+ // No image while decoding or for undecodable data, as before.+ bitmap?.let { decoded ->+ Image(+ bitmap = decoded.asImageBitmap(),+ contentDescription = null,+ modifier = Modifier.fillMaxWidth().padding(16.dp),+ contentScale = ContentScale.Fit)+ }+ }+ if (onCrop != null) {+ TextButton(onClick = onCrop, modifier = Modifier.align(Alignment.TopStart).padding(8.dp)) {+ IconCrop(tint = Color.White)+ androidx.compose.foundation.layout.Spacer(Modifier.width(4.dp))+ Text(stringResource(R.string.crop), color = Color.White)+ }+ }+ }+}
office/src/main/java/com/vayunmathur/office/ui/TableView.kt
diff --git a/office/src/main/java/com/vayunmathur/office/ui/TableView.kt b/office/src/main/java/com/vayunmathur/office/ui/TableView.ktnew file mode 100644index 0000000000..2ca1acc736--- /dev/null+++ b/office/src/main/java/com/vayunmathur/office/ui/TableView.kt@@ -0,0 +1,136 @@+package com.vayunmathur.office.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.border+import androidx.compose.foundation.horizontalScroll+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.IntrinsicSize+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.text.BasicTextField+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.focus.onFocusChanged+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.SolidColor+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.TextRange+import androidx.compose.ui.text.font.FontStyle+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.input.TextFieldValue+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.odf.OdfTable+import com.vayunmathur.library.ui.odf.OdfTableCell+import com.vayunmathur.office.R++@Composable+fun TableView(+ table: com.vayunmathur.library.ui.odf.OdfTable,+ blockIndex: Int,+ fontSizeMultiplier: Float = 1f,+ onCellTextChange: (Int, Int, Int, String) -> Unit = { _, _, _, _ -> },+ onCellFocus: (Int, Int, Int) -> Unit = { _, _, _ -> },+ firstCellFocusRequester: FocusRequester? = null+) {+ // First editable cell in row-major (visual) order, for Escape-to-body.+ val firstCell: Pair<Int, Int>? = table.rows.indices.firstNotNullOfOrNull { r ->+ table.rows[r].cells.indexOfFirst { !it.isCovered }.takeIf { it >= 0 }?.let { c -> r to c }+ }+ val onSurface = MaterialTheme.colorScheme.onSurface+ fun colWidthDp(start: Int, span: Int): androidx.compose.ui.unit.Dp {+ var w = 0f+ for (k in start until start + span) {+ val px = table.columns.getOrNull(k)?.width+ w += if (px != null && px > 0f) px * (160f / 96f) else 110f+ }+ return w.dp+ }+ Column(Modifier.fillMaxWidth().padding(vertical = 8.dp).horizontalScroll(rememberScrollState())) {+ for ((r, row) in table.rows.withIndex()) {+ Row(Modifier.height(IntrinsicSize.Min)) {+ var colspanSkip = 0+ for ((c, cell) in row.cells.withIndex()) {+ if (cell.isCovered) {+ // Covered by a horizontal merge to its left: the anchor already claimed the width.+ if (colspanSkip > 0) { colspanSkip--; continue }+ // Covered by a vertical (row) merge from above: render an aligned placeholder so+ // columns below the merge don't collapse and shift left.+ Box(Modifier.width(colWidthDp(c, 1)).fillMaxHeight()+ .border(0.7.dp, MaterialTheme.colorScheme.outline)) {}+ continue+ }+ colspanSkip = if (cell.colSpan > 1) cell.colSpan - 1 else 0+ Box(+ Modifier.width(colWidthDp(c, cell.colSpan))+ .fillMaxHeight()+ .border(0.7.dp, MaterialTheme.colorScheme.outline)+ .then(cell.backgroundColor?.let { Modifier.background(Color(it.toInt())) } ?: Modifier)+ .padding(8.dp)+ ) {+ EditableCell(+ cell,+ onSurface,+ fontSizeMultiplier,+ onFocus = { onCellFocus(blockIndex, r, c) },+ focusRequester = if (firstCell == (r to c)) firstCellFocusRequester else null)+ { txt -> onCellTextChange(blockIndex, r, c, txt) }+ }+ }+ }+ }+ if (table.rows.isEmpty()) Text(+ stringResource(R.string.empty_table),+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ modifier = Modifier.padding(8.dp))+ }+}++@Composable+private fun EditableCell(+ cell: OdfTableCell,+ onSurface: Color,+ mult: Float,+ onFocus: () -> Unit,+ focusRequester: FocusRequester? = null,+ onChange: (String) -> Unit) {+ var cellFocused by remember { mutableStateOf(false) }+ val plain = cell.paragraphs.joinToString("\n") { p -> p.spans.joinToString("") { it.text } }+ var tfv by remember { mutableStateOf(TextFieldValue(plain)) }+ if (tfv.text != plain) tfv = TextFieldValue(plain, TextRange(tfv.selection.end.coerceIn(0, plain.length)))+ // Reflect uniform cell character formatting (C26).+ val firstSpan = cell.paragraphs.firstOrNull()?.spans?.firstOrNull()+ val cellAlign = cell.paragraphs.firstOrNull()?.alignment+ val style = MaterialTheme.typography.bodyMedium.copy(+ color = firstSpan?.color?.let { Color(it.toInt()) } ?: onSurface,+ fontSize = (14f * mult).sp,+ fontWeight = if (firstSpan?.bold == true) FontWeight.Bold else null,+ fontStyle = if (firstSpan?.italic == true) FontStyle.Italic else null,+ textAlign = cellAlign ?: TextAlign.Unspecified+ )+ BasicTextField(+ value = tfv,+ onValueChange = { nv -> val changed = nv.text != tfv.text; tfv = nv; if (changed) onChange(nv.text) },+ textStyle = style,+ cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),+ modifier = Modifier.fillMaxWidth()+ .then(if (focusRequester != null) Modifier.focusRequester(focusRequester) else Modifier)+ .onFocusChanged { cellFocused = it.isFocused; if (it.isFocused) onFocus() }+ .officeFocusRing(cellFocused)+ )+}
office/src/main/java/com/vayunmathur/office/ui/TextDocumentView.kt
diff --git a/office/src/main/java/com/vayunmathur/office/ui/TextDocumentView.kt b/office/src/main/java/com/vayunmathur/office/ui/TextDocumentView.ktindex b56f99dda0..24f6c85cac 100644--- a/office/src/main/java/com/vayunmathur/office/ui/TextDocumentView.kt+++ b/office/src/main/java/com/vayunmathur/office/ui/TextDocumentView.kt@@ -311,40 +311,6 @@ fun TextDocumentView( } } -@Composable-private fun FullScreenImage(image: OdfImage, onCrop: (() -> Unit)? = null, onDismiss: () -> Unit) {- Box(- Modifier.fillMaxSize().background(Color.Black.copy(alpha = 0.9f)).clickable { onDismiss() },- contentAlignment = Alignment.Center) {- BoxWithConstraints(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {- val density = LocalDensity.current.density- val reqWidthPx = if (maxWidth == Dp.Infinity) 1024 else (maxWidth.value * density).toInt().coerceAtLeast(1)- val reqHeightPx = if (maxHeight == Dp.Infinity) reqWidthPx else (maxHeight.value * density).toInt().coerceAtLeast(1)- val bitmap by produceState<Bitmap?>(- null, image.path, image.imageData.size, reqWidthPx, reqHeightPx) {- value = withContext(Dispatchers.IO) {- decodeSampledBitmap(image.imageData, reqWidthPx, reqHeightPx)- }- }- // No image while decoding or for undecodable data, as before.- bitmap?.let { decoded ->- Image(- bitmap = decoded.asImageBitmap(),- contentDescription = null,- modifier = Modifier.fillMaxWidth().padding(16.dp),- contentScale = ContentScale.Fit)- }- }- if (onCrop != null) {- TextButton(onClick = onCrop, modifier = Modifier.align(Alignment.TopStart).padding(8.dp)) {- IconCrop(tint = Color.White)- androidx.compose.foundation.layout.Spacer(Modifier.width(4.dp))- Text(stringResource(R.string.crop), color = Color.White)- }- }- }-}- @Composable private fun PageBreakView() { HorizontalDivider(@@ -353,98 +319,3 @@ private fun PageBreakView() { color = MaterialTheme.colorScheme.outlineVariant) } -@Composable-private fun TableView(- table: com.vayunmathur.library.ui.odf.OdfTable,- blockIndex: Int,- fontSizeMultiplier: Float = 1f,- onCellTextChange: (Int, Int, Int, String) -> Unit = { _, _, _, _ -> },- onCellFocus: (Int, Int, Int) -> Unit = { _, _, _ -> },- firstCellFocusRequester: FocusRequester? = null-) {- // First editable cell in row-major (visual) order, for Escape-to-body.- val firstCell: Pair<Int, Int>? = table.rows.indices.firstNotNullOfOrNull { r ->- table.rows[r].cells.indexOfFirst { !it.isCovered }.takeIf { it >= 0 }?.let { c -> r to c }- }- val onSurface = MaterialTheme.colorScheme.onSurface- fun colWidthDp(start: Int, span: Int): androidx.compose.ui.unit.Dp {- var w = 0f- for (k in start until start + span) {- val px = table.columns.getOrNull(k)?.width- w += if (px != null && px > 0f) px * (160f / 96f) else 110f- }- return w.dp- }- Column(Modifier.fillMaxWidth().padding(vertical = 8.dp).horizontalScroll(rememberScrollState())) {- for ((r, row) in table.rows.withIndex()) {- Row(Modifier.height(IntrinsicSize.Min)) {- var colspanSkip = 0- for ((c, cell) in row.cells.withIndex()) {- if (cell.isCovered) {- // Covered by a horizontal merge to its left: the anchor already claimed the width.- if (colspanSkip > 0) { colspanSkip--; continue }- // Covered by a vertical (row) merge from above: render an aligned placeholder so- // columns below the merge don't collapse and shift left.- Box(Modifier.width(colWidthDp(c, 1)).fillMaxHeight()- .border(0.7.dp, MaterialTheme.colorScheme.outline)) {}- continue- }- colspanSkip = if (cell.colSpan > 1) cell.colSpan - 1 else 0- Box(- Modifier.width(colWidthDp(c, cell.colSpan))- .fillMaxHeight()- .border(0.7.dp, MaterialTheme.colorScheme.outline)- .then(cell.backgroundColor?.let { Modifier.background(Color(it.toInt())) } ?: Modifier)- .padding(8.dp)- ) {- EditableCell(- cell,- onSurface,- fontSizeMultiplier,- onFocus = { onCellFocus(blockIndex, r, c) },- focusRequester = if (firstCell == (r to c)) firstCellFocusRequester else null)- { txt -> onCellTextChange(blockIndex, r, c, txt) }- }- }- }- }- if (table.rows.isEmpty()) Text(- stringResource(R.string.empty_table),- color = MaterialTheme.colorScheme.onSurfaceVariant,- modifier = Modifier.padding(8.dp))- }-}--@Composable-private fun EditableCell(- cell: OdfTableCell,- onSurface: Color,- mult: Float,- onFocus: () -> Unit,- focusRequester: FocusRequester? = null,- onChange: (String) -> Unit) {- var cellFocused by remember { mutableStateOf(false) }- val plain = cell.paragraphs.joinToString("\n") { p -> p.spans.joinToString("") { it.text } }- var tfv by remember { mutableStateOf(TextFieldValue(plain)) }- if (tfv.text != plain) tfv = TextFieldValue(plain, TextRange(tfv.selection.end.coerceIn(0, plain.length)))- // Reflect uniform cell character formatting (C26).- val firstSpan = cell.paragraphs.firstOrNull()?.spans?.firstOrNull()- val cellAlign = cell.paragraphs.firstOrNull()?.alignment- val style = MaterialTheme.typography.bodyMedium.copy(- color = firstSpan?.color?.let { Color(it.toInt()) } ?: onSurface,- fontSize = (14f * mult).sp,- fontWeight = if (firstSpan?.bold == true) FontWeight.Bold else null,- fontStyle = if (firstSpan?.italic == true) FontStyle.Italic else null,- textAlign = cellAlign ?: TextAlign.Unspecified- )- BasicTextField(- value = tfv,- onValueChange = { nv -> val changed = nv.text != tfv.text; tfv = nv; if (changed) onChange(nv.text) },- textStyle = style,- cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),- modifier = Modifier.fillMaxWidth()- .then(if (focusRequester != null) Modifier.focusRequester(focusRequester) else Modifier)- .onFocusChanged { cellFocused = it.isFocused; if (it.isFocused) onFocus() }- .officeFocusRing(cellFocused)- )-}
taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.ktindex 289313c1e8..3eae5ad69c 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftBooking.kt@@ -183,7 +183,7 @@ fun LyftBookingFlow( when (val current = step) { Step.LoadingPayments -> ProgressDialog(stringResource(R.string.booking), onDismiss) - is Step.PickPayment -> PaymentPickerDialog(+ is Step.PickPayment -> LyftPaymentPickerDialog( accounts = current.accounts, selectedId = current.selectedId, onSelect = { step = current.copy(selectedId = it) },@@ -194,7 +194,7 @@ fun LyftBookingFlow( onDismiss = onDismiss, ) - is Step.Confirm -> ConfirmBookingDialog(+ is Step.Confirm -> LyftConfirmBookingDialog( quote = request.quote, account = current.account, onConfirm = { book(current.account) },@@ -217,88 +217,6 @@ fun LyftBookingFlow( } } -@Composable-private fun PaymentPickerDialog(- accounts: List<ChargeAccount>,- selectedId: String?,- onSelect: (String) -> Unit,- onConfirm: () -> Unit,- onDismiss: () -> Unit,-) {- AlertDialog(- onDismissRequest = onDismiss,- title = { Text(stringResource(R.string.choose_payment)) },- text = {- Column {- accounts.forEach { account ->- Row(- Modifier- .fillMaxWidth()- .clickable { onSelect(account.id) }- .padding(vertical = 6.dp),- verticalAlignment = Alignment.CenterVertically,- ) {- RadioButton(- selected = account.id == selectedId,- onClick = { onSelect(account.id) },- )- Spacer(Modifier.width(8.dp))- Text(account.label, style = MaterialTheme.typography.bodyLarge)- }- }- }- },- confirmButton = {- TextButton(onClick = onConfirm, enabled = selectedId != null) {- Text(stringResource(R.string.book))- }- },- dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.dismiss)) } },- )-}--@Composable-private fun ConfirmBookingDialog(- quote: RideQuote,- account: ChargeAccount?,- onConfirm: () -> Unit,- onDismiss: () -> Unit,-) {- AlertDialog(- onDismissRequest = onDismiss,- title = { Text(stringResource(R.string.confirm_booking)) },- text = {- Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {- Text(quote.displayName, fontWeight = FontWeight.SemiBold)- Text(formatFareRange(quote))- quote.pickupEtaMinutes?.let { Text(stringResource(R.string.eta_minutes, it)) }- account?.let { Text(stringResource(R.string.booking_charge_to, it.label)) }- if (!LyftProvider.BOOKING_LIVE) {- Spacer(Modifier.size(4.dp))- Text(- stringResource(R.string.booking_dry_run_notice),- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.primary,- )- }- }- },- confirmButton = {- TextButton(onClick = onConfirm) {- Text(- stringResource(R.string.book),- color = if (LyftProvider.BOOKING_LIVE) {- MaterialTheme.colorScheme.error- } else {- MaterialTheme.colorScheme.primary- },- )- }- },- dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.dismiss)) } },- )-}- @Composable private fun DryRunDialog(requestJson: String, onDismiss: () -> Unit) { AlertDialog(@@ -347,12 +265,3 @@ private fun MessageDialog(title: String, onDismiss: () -> Unit) { confirmButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.close)) } }, ) }--private fun formatFareRange(quote: RideQuote): String {- fun money(minor: Long) = "$%.2f".format(minor / 100.0)- return if (quote.isRange) {- "${money(quote.fareLowMinor)} – ${money(quote.fareHighMinor)}"- } else {- money(quote.fareLowMinor)- }-}
taxi/src/main/java/com/vayunmathur/taxi/ui/LyftConfirmBookingDialog.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftConfirmBookingDialog.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftConfirmBookingDialog.ktnew file mode 100644index 0000000000..9fb45373dc--- /dev/null+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftConfirmBookingDialog.kt@@ -0,0 +1,71 @@+package com.vayunmathur.taxi.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.taxi.R+import com.vayunmathur.taxi.data.ChargeAccount+import com.vayunmathur.taxi.data.RideQuote+import com.vayunmathur.taxi.network.lyft.LyftProvider++@Composable+fun LyftConfirmBookingDialog(+ quote: RideQuote,+ account: ChargeAccount?,+ onConfirm: () -> Unit,+ onDismiss: () -> Unit,+) {+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text(stringResource(R.string.confirm_booking)) },+ text = {+ Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {+ Text(quote.displayName, fontWeight = FontWeight.SemiBold)+ Text(formatFareRange(quote))+ quote.pickupEtaMinutes?.let { Text(stringResource(R.string.eta_minutes, it)) }+ account?.let { Text(stringResource(R.string.booking_charge_to, it.label)) }+ if (!LyftProvider.BOOKING_LIVE) {+ Spacer(Modifier.size(4.dp))+ Text(+ stringResource(R.string.booking_dry_run_notice),+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.primary,+ )+ }+ }+ },+ confirmButton = {+ TextButton(onClick = onConfirm) {+ Text(+ stringResource(R.string.book),+ color = if (LyftProvider.BOOKING_LIVE) {+ MaterialTheme.colorScheme.error+ } else {+ MaterialTheme.colorScheme.primary+ },+ )+ }+ },+ dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.dismiss)) } },+ )+}++private fun formatFareRange(quote: RideQuote): String {+ fun money(minor: Long) = "$%.2f".format(minor / 100.0)+ return if (quote.isRange) {+ "${money(quote.fareLowMinor)} – ${money(quote.fareHighMinor)}"+ } else {+ money(quote.fareLowMinor)+ }+}
taxi/src/main/java/com/vayunmathur/taxi/ui/LyftPaymentPickerDialog.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftPaymentPickerDialog.kt b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftPaymentPickerDialog.ktnew file mode 100644index 0000000000..2c221eb5fc--- /dev/null+++ b/taxi/src/main/java/com/vayunmathur/taxi/ui/LyftPaymentPickerDialog.kt@@ -0,0 +1,62 @@+package com.vayunmathur.taxi.ui++import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.RadioButton+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.taxi.R+import com.vayunmathur.taxi.data.ChargeAccount++@Composable+fun LyftPaymentPickerDialog(+ accounts: List<ChargeAccount>,+ selectedId: String?,+ onSelect: (String) -> Unit,+ onConfirm: () -> Unit,+ onDismiss: () -> Unit,+) {+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text(stringResource(R.string.choose_payment)) },+ text = {+ Column {+ accounts.forEach { account ->+ Row(+ Modifier+ .fillMaxWidth()+ .clickable { onSelect(account.id) }+ .padding(vertical = 6.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ RadioButton(+ selected = account.id == selectedId,+ onClick = { onSelect(account.id) },+ )+ Spacer(Modifier.width(8.dp))+ Text(account.label, style = MaterialTheme.typography.bodyLarge)+ }+ }+ }+ },+ confirmButton = {+ TextButton(onClick = onConfirm, enabled = selectedId != null) {+ Text(stringResource(R.string.book))+ }+ },+ dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.dismiss)) } },+ )+}
travel/src/main/java/com/vayunmathur/travel/MainActivity.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt b/travel/src/main/java/com/vayunmathur/travel/MainActivity.ktindex 5a32bf5c0a..57b24af8ae 100644--- a/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt+++ b/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt@@ -52,8 +52,8 @@ class MainActivity : MaActivity() { // Resume polling any trip that is still awaiting payment / processing. if (!::repository.isInitialized) return lifecycleScope.launch {- // pendingTripIds() reads Room (getAllBookedTrips) — keep that off Main;- // pollTrip() only touches ViewModel state / launches its own scope, so it stays on Main.+ // Reading the pending trip ids touches Room, so keep that off Main;+ // polling only touches ViewModel state and launches its own scope, so it stays on Main. val ids = withContext(Dispatchers.IO) { viewModel.pendingTripIds() } ids.forEach { viewModel.pollTrip(it) } }