Skip to content

Commit fed1f42

Browse files
committed
Don't cache selected stop name
1 parent 8e2ace6 commit fed1f42

File tree

6 files changed

+12
-21
lines changed

6 files changed

+12
-21
lines changed

macOS/Arrivals/Settings/TflSettingsView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ private class TflSettingsViewModel: ObservableObject {
140140
}
141141

142142
func save(stopPoint: StopResult, platformFilter: String, directionFilter: String) {
143-
settings.tflStopName = stopPoint.name
144143
settings.tflStopId = stopPoint.id
145144
settings.tflPlatform = platformFilter
146145
settings.tflDirection = directionFilter

shared/src/commonMain/kotlin/com/jdamcd/arrivals/Settings.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.jdamcd.arrivals
22

33
expect class Settings() {
44
var mode: String
5-
var tflStopName: String
65
var tflStopId: String
76
var tflPlatform: String
87
var tflDirection: String
@@ -19,8 +18,6 @@ object SettingsConfig {
1918
const val MODE_TFL = "tfl"
2019
const val MODE_GTFS = "gtfs"
2120

22-
const val TFL_STOP_NAME = "selected_stop_name"
23-
const val TFL_STOP_NAME_DEFAULT = "Shoreditch High Street"
2421
const val TFL_STOP_ID = "selected_stop_id"
2522
const val TFL_STOP_ID_DEFAULT = "910GSHRDHST"
2623
const val TFL_PLATFORM = "tfl_platform"

shared/src/commonMain/kotlin/com/jdamcd/arrivals/tfl/TflArrivals.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ internal class TflArrivals(
5151
}
5252

5353
private fun formatArrivals(apiArrivals: List<ApiArrival>): ArrivalsInfo {
54+
val station = stationInfo(apiArrivals.firstOrNull()?.stationName ?: "")
5455
val arrivals =
5556
apiArrivals
5657
.asSequence()
@@ -73,14 +74,16 @@ internal class TflArrivals(
7374
}
7475
.toList()
7576
return ArrivalsInfo(
76-
station = stationInfo(),
77+
station = station,
7778
arrivals = arrivals
7879
)
7980
}
8081

81-
private fun stationInfo(): String {
82-
val station = formatStation(settings.tflStopName)
83-
return if (settings.tflPlatform.isNotEmpty()) {
82+
private fun stationInfo(name: String): String {
83+
val station = formatStation(name)
84+
return if (station.isEmpty()) {
85+
station
86+
} else if (settings.tflPlatform.isNotEmpty()) {
8487
"$station: ${settings.tflPlatform}"
8588
} else if (settings.tflDirection != SettingsConfig.TFL_DIRECTION_DEFAULT) {
8689
"$station: ${formatDirection(settings.tflDirection)}"

shared/src/jvmMain/kotlin/com/jdamcd/arrivals/Settings.jvm.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.jdamcd.arrivals
22

33
actual class Settings actual constructor() {
44
actual var mode = SettingsConfig.MODE_TFL
5-
actual var tflStopName = SettingsConfig.TFL_STOP_NAME_DEFAULT
65
actual var tflStopId = SettingsConfig.TFL_STOP_ID_DEFAULT
76
actual var tflPlatform = SettingsConfig.TFL_PLATFORM_DEFAULT
87
actual var tflDirection = SettingsConfig.TFL_DIRECTION_DEFAULT

shared/src/jvmTest/kotlin/com/jdamcd/arrivals/tfl/TflArrivalsTest.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ class TflArrivalsTest {
1919
private val arrivals = TflArrivals(api, settings)
2020

2121
private val response = listOf(
22-
ApiArrival(123, "", "Platform 2", "outbound", "New Cross", 456),
23-
ApiArrival(124, "", "Platform 2", "outbound", "Crystal Palace Rail Station", 10),
24-
ApiArrival(125, "", "Platform 1", "inbound", "Dalston Junction", 10),
25-
ApiArrival(126, "", "Platform 1", "inbound", "Highbury & Islington Underground Station", 456)
22+
ApiArrival(123, "Test Stop", "Platform 2", "outbound", "New Cross", 456),
23+
ApiArrival(124, "Test Stop", "Platform 2", "outbound", "Crystal Palace Rail Station", 10),
24+
ApiArrival(125, "Test Stop", "Platform 1", "inbound", "Dalston Junction", 10),
25+
ApiArrival(126, "Test Stop", "Platform 1", "inbound", "Highbury & Islington Underground Station", 456)
2626
)
2727

2828
@BeforeTest
2929
fun setup() {
3030
settings.tflStopId = "123"
31-
settings.tflStopName = "Test Stop"
3231
settings.tflPlatform = "Platform 2"
3332
settings.tflDirection = "all"
3433
}
@@ -78,7 +77,7 @@ class TflArrivalsTest {
7877
}
7978

8079
@Test
81-
fun `throws NoDataException if results are empty`() = runBlocking<Unit> {
80+
fun `throws NoDataException on empty results`() = runBlocking<Unit> {
8281
coEvery { api.fetchArrivals("123") } returns emptyList()
8382

8483
assertFailsWith<NoDataException> {

shared/src/macOSMain/kotlin/com/jdamcd/arrivals/Settings.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ actual class Settings actual constructor() {
1111
defaults.setObject(value, SettingsConfig.MODE)
1212
}
1313

14-
actual var tflStopName: String
15-
get() = defaults.stringForKey(SettingsConfig.TFL_STOP_NAME) ?: SettingsConfig.TFL_STOP_NAME_DEFAULT
16-
set(value) {
17-
defaults.setObject(value, SettingsConfig.TFL_STOP_NAME)
18-
}
19-
2014
actual var tflStopId: String
2115
get() = defaults.stringForKey(SettingsConfig.TFL_STOP_ID) ?: SettingsConfig.TFL_STOP_ID_DEFAULT
2216
set(value) {

0 commit comments

Comments
 (0)