globalesim: tabs, serial names, guarded refresh
- Commit
0a44e9a1e0de0e49b8d1bd9e31ac07b57bcfd95b- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-24 18:53 UTC (1 month ago)
- Parents
562c6d6
Diff
globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.ktindex c5902cef50..ebc6ce5abe 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt@@ -40,9 +40,11 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { viewModelScope.launch { // Mint the anonymous id only. Provisioning happens on explicit // user action (createEsim) — never on launch, since each- // provision is a real $1.75 vendor charge.+ // provision is a real $1.75 vendor charge. Rates are public, so+ // they load immediately; status/budget wait until an eSIM exists+ // (refreshAll guards on profile presence). idStore.getOrCreate()- refreshAll()+ refreshRates() } } @@ -58,7 +60,10 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { viewModelScope.launch { state = state.copy(loading = true, error = null) runCatching { EsimApi.register(accountId()) }- .onSuccess { refreshAll() }+ .onSuccess {+ state = state.copy(profile = it.profile)+ refreshAll()+ } .onFailure { state = state.copy(loading = false, error = it.message) } } }@@ -68,8 +73,12 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { } fun refreshAll() {- refreshStatus() refreshRates()+ // No eSIM yet (fresh install, pre-create): status/budget would hit+ // a nonexistent account, so skip them. createEsim/transferIn call+ // refreshAll again once the account exists.+ if (state.profile == null) return+ refreshStatus() refreshBudget() } @@ -233,7 +242,14 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { runCatching { EsimApi.transferIn(oldAccountId, code.trim(), fresh) } .onSuccess { idStore.replace(fresh)- state = state.copy(loading = false, transferCode = null)+ // Claimed account owns the moved eSIM — status/budget are+ // valid now. Set a non-null profile first so refreshAll+ // doesn't skip them, then overwrite with live data.+ state = state.copy(+ loading = false,+ transferCode = null,+ profile = state.profile ?: ProfileDto(iccid = "", status = "active"),+ ) refreshAll() onDone() }
globalesim/src/main/java/com/vayunmathur/globalesim/ui/PricingScreen.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/PricingScreen.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/PricingScreen.ktindex 4bb2041f19..b93af0f581 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/PricingScreen.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/PricingScreen.kt@@ -3,6 +3,7 @@ package com.vayunmathur.globalesim.ui import androidx.compose.foundation.clickable 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.fillMaxWidth import androidx.compose.foundation.layout.height@@ -32,14 +33,16 @@ import com.vayunmathur.library.ui.LoadingIndicator import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.ui.animatedColor import com.vayunmathur.library.ui.animatedDp import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.library.ui.rememberMessenger /**- * Pricing: searchable per-country rate list. Tapping a country expands it- * to show every carrier and its per-GB price (cheapest first), in the same+ * Pricing: searchable per-country rate list with the search field in the+ * app bar (no title text). Tapping a country expands it to show every+ * carrier and its per-GB price (cheapest first), in the same * expandable-group style as the contacts groups page. Display-only — * the wallet is charged the local rate automatically as you use data. */@@ -67,18 +70,22 @@ fun PricingScreen( } LazyListScaffold(- title = "Pricing",+ topBar = {+ TopAppBar(+ title = {+ CommonSearchBar(+ value = query,+ onValueChange = { query = it },+ placeholder = "Search countries",+ padding = PaddingValues(bottom = 8.dp),+ )+ },+ )+ }, horizontalPadding = 8.dp, verticalArrangement = Arrangement.spacedBy(4.dp), scrollBehavior = appBarScrollBehavior(), ) {- item(key = "pricing-search") {- CommonSearchBar(- value = query,- onValueChange = { query = it },- placeholder = "Search countries",- )- } if (filtered.isEmpty()) { item(key = "pricing-empty") { if (state.loading) {@@ -95,12 +102,13 @@ fun PricingScreen( } filtered.forEach { rate -> val isExpanded = rate.countryCode in expanded- val showNetworks = isExpanded && rate.networks.isNotEmpty()+ // Expand whenever tapped; the body shows carriers, or a fallback+ // line when the server didn't send a breakdown. item(key = "country-${rate.countryCode}") { val collapsedColor = MaterialTheme.colorScheme.surfaceVariant val expandedColor = MaterialTheme.colorScheme.secondaryContainer- val headerColor = animatedColor(if (showNetworks) expandedColor else collapsedColor)- val bottomRadius = animatedDp(if (showNetworks) 4.dp else 16.dp)+ val headerColor = animatedColor(if (isExpanded) expandedColor else collapsedColor)+ val bottomRadius = animatedDp(if (isExpanded) 4.dp else 16.dp) Column { Surface( onClick = {@@ -128,7 +136,7 @@ fun PricingScreen( colors = ListItemDefaults.colors(containerColor = Color.Transparent), ) }- ExpandVisibility(visible = showNetworks) {+ ExpandVisibility(visible = isExpanded) { Column { Spacer(Modifier.height(2.dp)) Surface(@@ -137,15 +145,27 @@ fun PricingScreen( color = MaterialTheme.colorScheme.surfaceContainerHighest, ) { Column(Modifier.padding(vertical = 4.dp)) {- rate.networks.forEach { net ->+ if (rate.networks.isEmpty()) { ListItem(- modifier = Modifier.clickable {},- content = { Text(net.operator) },- supportingContent = {- Text(QuoteMath.formatCents(net.pricePerGbUsdCents) + " / GB")+ content = {+ Text(+ "Carrier breakdown unavailable — " ++ "charged at ${QuoteMath.formatCents(rate.pricePerGbUsdCents)} / GB.",+ ) }, colors = ListItemDefaults.colors(containerColor = Color.Transparent), )+ } else {+ rate.networks.forEach { net ->+ ListItem(+ modifier = Modifier.clickable {},+ content = { Text(net.operator) },+ supportingContent = {+ Text(QuoteMath.formatCents(net.pricePerGbUsdCents) + " / GB")+ },+ colors = ListItemDefaults.colors(containerColor = Color.Transparent),+ )+ } } } }