-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
324 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
apps/mobile/metro-now/metro-now Watch App/pages/departure-placeholder.swift
This file was deleted.
Oops, something went wrong.
78 changes: 0 additions & 78 deletions
78
apps/mobile/metro-now/metro-now Watch App/pages/main-page.swift
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
apps/mobile/metro-now/metro-now Watch App/pages/platform/next-departure.view.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// metro-now | ||
// https://github.com/krystxf/metro-now | ||
|
||
import SwiftUI | ||
|
||
struct PlatformDetailNextDepartureView: View { | ||
let headsign: String | ||
let departure: Date | ||
let nextHeadsign: String? | ||
let nextDeparture: Date? | ||
|
||
var body: some View { | ||
VStack(spacing: 40) { | ||
VStack { | ||
Spacer() | ||
Label( | ||
shortenStopName(headsign), | ||
systemImage: "arrowshape.forward" | ||
).font(.title2) | ||
.fontWeight(.semibold) | ||
.symbolVariant(.fill) | ||
.imageScale(.small) | ||
.foregroundStyle(.secondary) | ||
|
||
CountdownView( | ||
targetDate: departure | ||
) | ||
.font(.largeTitle) | ||
.foregroundStyle(.primary) | ||
} | ||
|
||
if let nextHeadsign, let nextDeparture { | ||
if headsign == nextHeadsign { | ||
CountdownView( | ||
targetDate: nextDeparture | ||
) { | ||
"Also in \($0)" | ||
}.foregroundStyle(.tertiary) | ||
} else { | ||
VStack { | ||
Text( | ||
shortenStopName(nextHeadsign) | ||
) | ||
|
||
CountdownView( | ||
targetDate: nextDeparture | ||
) | ||
}.foregroundStyle(.secondary) | ||
} | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
apps/mobile/metro-now/metro-now Watch App/pages/platform/platform-departures-list.view.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// metro-now | ||
// https://github.com/krystxf/metro-now | ||
|
||
import SwiftUI | ||
|
||
struct PlatformDetailDeparturesListView: View { | ||
let departures: [ApiDeparture] | ||
|
||
var body: some View { List(departures, id: \.departure.predicted) { departure in | ||
HStack { | ||
Text(departure.headsign) | ||
Spacer() | ||
CountdownView(targetDate: departure.departure.predicted) | ||
} | ||
}} | ||
} |
98 changes: 98 additions & 0 deletions
98
apps/mobile/metro-now/metro-now Watch App/pages/platform/platform-detail.view.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// metro-now | ||
// https://github.com/krystxf/metro-now | ||
|
||
import SwiftUI | ||
|
||
struct PlatformDetailView: View { | ||
let platformId: String | ||
let metroLine: MetroLine? | ||
@State var departures: [ApiDeparture]? = nil | ||
private let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect() | ||
|
||
init( | ||
platformId: String, | ||
metroLine: MetroLine? = nil, | ||
departures: [ApiDeparture]? = nil | ||
|
||
) { | ||
self.platformId = platformId | ||
self.departures = departures | ||
self.metroLine = metroLine | ||
} | ||
|
||
var body: some View { | ||
TabView { | ||
if let departures, departures.count > 0 { | ||
let backgroundColor = getMetroLineColor( | ||
metroLine ?? MetroLine(rawValue: departures[0].route) | ||
) ?? .clear | ||
|
||
PlatformDetailNextDepartureView( | ||
headsign: departures[0].headsign, | ||
departure: departures[0].departure.scheduled, | ||
nextHeadsign: departures[1].headsign, | ||
nextDeparture: departures[1].departure.predicted | ||
) | ||
.containerBackground(backgroundColor.gradient, for: .tabView) | ||
|
||
PlatformDetailDeparturesListView(departures: departures) | ||
.containerBackground(backgroundColor.gradient, for: .tabView) | ||
|
||
} else { | ||
ProgressView() | ||
} | ||
} | ||
|
||
.toolbar { | ||
if let metroLineName = metroLine?.rawValue { | ||
ToolbarItem( | ||
placement: .confirmationAction) | ||
{ | ||
Text(metroLineName) | ||
.overlay( | ||
Circle() | ||
.size(width: 32, height: 32, anchor: .center) | ||
.stroke(.white.opacity(0.6), lineWidth: 3) | ||
) | ||
.fontWeight(.semibold) | ||
.foregroundStyle(.white.opacity(0.6)) | ||
} | ||
|
||
} | ||
} | ||
|
||
.tabViewStyle(.verticalPage(transitionStyle: .identity)) | ||
.onAppear { | ||
getDepartures() | ||
} | ||
.onReceive(timer) { _ in | ||
getDepartures() | ||
} | ||
} | ||
|
||
func getDepartures() { | ||
NetworkManager.shared | ||
.getDepartures(stopIds: [], platformIds: [platformId]) { result in | ||
DispatchQueue.main.async { | ||
switch result { | ||
case let .success(departures): | ||
|
||
self.departures = departures | ||
print(departures) | ||
|
||
case let .failure(error): | ||
print(error.localizedDescription) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
NavigationStack { | ||
PlatformDetailView( | ||
platformId: "U1040Z101P", | ||
metroLine: MetroLine.B | ||
) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
apps/mobile/metro-now/metro-now Watch App/pages/stop/list-item-placeholder.view.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// metro-now | ||
// https://github.com/krystxf/metro-now | ||
|
||
import SwiftUI | ||
|
||
struct StopDepartureListItemPlaceholderView: View { | ||
let color: Color | ||
|
||
init(color: Color? | ||
) { | ||
self.color = color ?? Color.gray.opacity(0.3) | ||
} | ||
|
||
var body: some View { | ||
StopDepartureListItemView( | ||
color: color, | ||
headsign: "Loading", | ||
departure: .now, | ||
nextHeadsign: "Loading", | ||
nextDeparture: .now | ||
) | ||
.redacted(reason: .placeholder) | ||
} | ||
} | ||
|
||
#Preview { | ||
ScrollView { | ||
StopDepartureListItemPlaceholderView( | ||
color: .red | ||
) | ||
StopDepartureListItemPlaceholderView( | ||
color: .red | ||
) | ||
StopDepartureListItemPlaceholderView( | ||
color: .green | ||
) | ||
StopDepartureListItemPlaceholderView( | ||
color: .green | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.