Skip to content

Commit cd2a6a0

Browse files
committed
Use GCP
1 parent 0dfcf72 commit cd2a6a0

File tree

269 files changed

+29941
-609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+29941
-609
lines changed

android/app/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
}
1717

1818
android {
19-
compileSdk 36
19+
compileSdk = 36
2020

2121
defaultConfig {
2222
applicationId "ca.amandeep.path"
@@ -160,4 +160,3 @@ tasks.withType(Test) {
160160
android.sourceSets.main.res.srcDirs += 'src/test/res'
161161
maxParallelForks = 4
162162
}
163-

android/app/src/main/kotlin/DeveloperMenuTrigger.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class DeveloperMenuTrigger(
8181
activePointers[pointerId] = PointF(event.getX(pointerIndex), event.getY(pointerIndex))
8282
checkState()
8383
}
84+
8485
MotionEvent.ACTION_MOVE -> {
8586
for (i in 0 until event.pointerCount) {
8687
val id = event.getPointerId(i)
@@ -94,6 +95,7 @@ class DeveloperMenuTrigger(
9495
reset()
9596
}
9697
}
98+
9799
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> {
98100
activePointers.remove(pointerId)
99101
// If a required pointer was lifted during hold, reset
@@ -111,16 +113,20 @@ class DeveloperMenuTrigger(
111113
checkState()
112114
}
113115
}
114-
MotionEvent.ACTION_CANCEL -> reset()
116+
117+
MotionEvent.ACTION_CANCEL -> {
118+
reset()
119+
}
115120
}
116121

117122
return currentState != TriggerState.IDLE
118123
}
119124

120125
private fun getPressedCorners(): Set<Corner> =
121-
activePointers.values.mapNotNull { point ->
122-
corners.entries.find { (_, rect) -> rect.contains(point.x, point.y) }?.key
123-
}.toSet()
126+
activePointers.values
127+
.mapNotNull { point ->
128+
corners.entries.find { (_, rect) -> rect.contains(point.x, point.y) }?.key
129+
}.toSet()
124130

125131
private fun areRequiredCornersHeld(): Boolean {
126132
val pressed = getPressedCorners()
@@ -142,12 +148,14 @@ class DeveloperMenuTrigger(
142148
startFirstHold()
143149
}
144150
}
151+
145152
TriggerState.WAITING_SECOND -> {
146153
if (activePointers.size >= 2 && pressedCorners == secondComboCorners) {
147154
startSecondHold()
148155
}
149156
// Timeout job handles reset if wrong/no corners are pressed for too long
150157
}
158+
151159
TriggerState.HOLDING_FIRST, TriggerState.HOLDING_SECOND -> {
152160
// Hold validity checked in ACTION_MOVE / ACTION_UP
153161
}

android/app/src/main/kotlin/ui/main/MainScreen.kt

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import androidx.compose.material3.windowsizeclass.WindowSizeClass
4444
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
4545
import androidx.compose.runtime.Composable
4646
import androidx.compose.runtime.LaunchedEffect
47+
import androidx.compose.runtime.State as ComposeState
4748
import androidx.compose.runtime.derivedStateOf
4849
import androidx.compose.runtime.getValue
4950
import androidx.compose.runtime.mutableLongStateOf
@@ -58,7 +59,7 @@ import androidx.compose.ui.res.stringResource
5859
import androidx.compose.ui.unit.dp
5960
import androidx.lifecycle.compose.collectAsStateWithLifecycle
6061
import ca.amandeep.path.DeveloperStatus
61-
import ca.amandeep.path.data.model.State
62+
import ca.amandeep.path.data.model.State as PathState
6263
import ca.amandeep.path.main.core.ArrivalsUiModel
6364
import ca.amandeep.path.main.core.MainUiModel
6465
import ca.amandeep.path.main.core.Result
@@ -120,7 +121,7 @@ fun MainScreen(
120121

121122
val showDebugOptions by DeveloperStatus.developerModeFlow.collectAsStateWithLifecycle()
122123

123-
val store = UserPreferencesRepo(context)
124+
val store = remember(context) { UserPreferencesRepo(context) }
124125

125126
val showModelNamePref by store.showModelName.collectAsStateWithLifecycle(initialValue = false)
126127
val aiSummarizeAlertsPref by store.aiSummarizeAlerts.collectAsStateWithLifecycle(initialValue = false)
@@ -260,6 +261,7 @@ fun MainScreen(
260261
setShowHelpGuide = setShowHelpGuideWithUndo,
261262
anyLocationPermissionsGranted = anyLocationPermissionsGranted,
262263
windowSizeClass = windowSizeClass,
264+
store = store,
263265
)
264266
PullRefreshIndicator(
265267
refreshing = refreshing,
@@ -290,14 +292,14 @@ private fun setAndComputeLastGoodState(
290292
): MainUiModel {
291293
val uiModel by uiStateFlow.collectAsStateWithLifecycle(initialValue = MainUiModel())
292294

293-
val (lastGoodState, setLastGoodState) = remember { mutableStateOf(MainUiModel()) }
295+
var lastGoodState by remember { mutableStateOf(MainUiModel()) }
294296

295-
setLastGoodState(
296-
MainUiModel(
297+
LaunchedEffect(uiModel) {
298+
lastGoodState = MainUiModel(
297299
arrivals = foldWithLastGoodState(uiModel, lastGoodState) { it.arrivals },
298300
alerts = foldWithLastGoodState(uiModel, lastGoodState) { it.alerts },
299-
),
300-
)
301+
)
302+
}
301303

302304
// If all trains are empty, force a refresh, and show a loading screen
303305
val allTrainsEmpty = lastGoodState.arrivals.let {
@@ -307,14 +309,10 @@ private fun setAndComputeLastGoodState(
307309
LaunchedEffect(allTrainsEmpty, forceUpdate) {
308310
if (allTrainsEmpty) {
309311
forceUpdate()
310-
setLastGoodState(
311-
MainUiModel(alerts = lastGoodState.alerts),
312-
)
312+
lastGoodState = MainUiModel(alerts = lastGoodState.alerts)
313313
}
314314
}
315315

316-
d { "lastGoodState: $lastGoodState" }
317-
318316
return lastGoodState
319317
}
320318

@@ -348,8 +346,10 @@ private fun MainScreenContent(
348346
setShowElevatorAlerts: suspend (Boolean) -> Unit,
349347
setShowHelpGuide: suspend (Boolean) -> Unit,
350348
windowSizeClass: WindowSizeClass,
349+
store: UserPreferencesRepo,
351350
) {
352-
val connectivityState by LocalContext.current.observeConnectivity()
351+
val connectivityState by LocalContext.current
352+
.observeConnectivity()
353353
.collectAsStateWithLifecycle(initialValue = ConnectionState.Available)
354354

355355
if (uiModel.arrivals is Result.Error) {
@@ -364,7 +364,10 @@ private fun MainScreenContent(
364364
) { isLoading ->
365365
val uiModelArrivals = uiModel.arrivals
366366
when (isLoading || uiModelArrivals !is Result.Valid) {
367-
true -> LoadingScreen()
367+
true -> {
368+
LoadingScreen()
369+
}
370+
368371
false -> {
369372
val lastUpdatedState = rememberLastUpdatedState(uiModelArrivals.lastUpdated)
370373
lastUpdatedState.KeepUpdatedEffect(uiModelArrivals.lastUpdated, 1.seconds)
@@ -381,8 +384,6 @@ private fun MainScreenContent(
381384
},
382385
)
383386

384-
val context = LocalContext.current
385-
val store = UserPreferencesRepo(context)
386387
val showDirectionWarning by store.showDirectionWarning.collectAsStateWithLifecycle(initialValue = true)
387388
val setShowDirectionWarningPref = store::updateShowDirectionWarning
388389

@@ -396,7 +397,7 @@ private fun MainScreenContent(
396397
anyLocationPermissionsGranted = anyLocationPermissionsGranted,
397398
setShowingOppositeDirection = setShowingOppositeDirection,
398399
snackbarState = snackbarState,
399-
lastUpdatedState = lastUpdatedState.value,
400+
lastUpdatedState = lastUpdatedState,
400401
now = now,
401402
setShowHelpGuide = setShowHelpGuide,
402403
alertsExpanded = alertsExpanded,
@@ -422,7 +423,7 @@ fun LoadedScreen(
422423
setShowingOppositeDirection: suspend (Boolean) -> Unit,
423424
setShowElevatorAlerts: suspend (Boolean) -> Unit,
424425
snackbarState: SnackbarHostState,
425-
lastUpdatedState: LastUpdatedUiModel,
426+
lastUpdatedState: ComposeState<LastUpdatedUiModel>,
426427
now: Long,
427428
setShowHelpGuide: suspend (Boolean) -> Unit,
428429
alertsExpanded: Boolean,
@@ -469,13 +470,14 @@ fun LoadedScreen(
469470
val alertsModel = when (val uiModelAlerts = uiModel.alerts) {
470471
is Result.Valid -> uiModelAlerts.copy(
471472
data = uiModelAlerts.data.copy(
472-
alerts = uiModelAlerts.data.alerts.filter {
473-
if (userState.showElevatorAlerts) {
474-
true
475-
} else {
476-
!it.isElevator
477-
}
478-
}.toImmutableList(),
473+
alerts = uiModelAlerts.data.alerts
474+
.filter {
475+
if (userState.showElevatorAlerts) {
476+
true
477+
} else {
478+
!it.isElevator
479+
}
480+
}.toImmutableList(),
479481
),
480482
)
481483

@@ -517,13 +519,13 @@ fun LoadedScreen(
517519
else -> Unit
518520
}
519521
AnimatedVisibility(
520-
visible = !autoRefreshingNow && lastUpdatedState.secondsAgo > TOP_LAST_UPDATED_THRESHOLD_SECS,
522+
visible = !autoRefreshingNow && lastUpdatedState.value.secondsAgo > TOP_LAST_UPDATED_THRESHOLD_SECS,
521523
enter = expandVertically(),
522524
exit = shrinkVertically(),
523525
) {
524526
LastUpdatedInfoRow(
525527
modifier = spacingModifier,
526-
lastUpdatedState = lastUpdatedState,
528+
lastUpdatedState = lastUpdatedState.value,
527529
)
528530
}
529531
}
@@ -532,7 +534,7 @@ fun LoadedScreen(
532534
arrivals.data
533535
} else {
534536
arrivals.data.filter {
535-
it.first.stationName.state == (if (userState.isInNJ) State.NJ else State.NY)
537+
it.first.stationName.state == (if (userState.isInNJ) PathState.NJ else PathState.NY)
536538
}
537539
}
538540
items(
@@ -554,7 +556,7 @@ fun LoadedScreen(
554556
) {
555557
LastUpdatedInfoRow(
556558
modifier = spacingModifier,
557-
lastUpdatedState = lastUpdatedState,
559+
lastUpdatedState = lastUpdatedState.value,
558560
)
559561
}
560562
}

0 commit comments

Comments
 (0)