-
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
8 changed files
with
191 additions
and
58 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
59 changes: 59 additions & 0 deletions
59
apps/mobile/metro-now-watch Watch App/model/MetroStopsManager.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,59 @@ | ||
// | ||
// MetroStopsManager.swift | ||
// metro-now | ||
// | ||
// Created by Kryštof Krátký on 29.09.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct Stop: Codable { | ||
var id: String | ||
var name: String | ||
var avgLatitude, avgLongitude: Double | ||
var platforms: [Platform] | ||
} | ||
|
||
struct Platform: Codable { | ||
var id: String | ||
var name: String | ||
var latitude, longitude: Double | ||
var routes: [Route] | ||
} | ||
|
||
struct Route: Codable { | ||
var id: String | ||
var name: String | ||
} | ||
|
||
class StopManager: ObservableObject { | ||
@Published var stops = [Stop]() | ||
@Published var closestStop: Stop? = nil | ||
} | ||
|
||
func getAllMetroStops() async -> [Stop] { | ||
let METRO_NOW_API = "http://localhost:3001" | ||
print("Fetching data") | ||
guard let url = URL(string: "http://localhost:3001/stop/all?metroOnly=true") else { | ||
print("Invalid URL in getAllMetroStops") | ||
return [] | ||
} | ||
print("URL created") | ||
|
||
do { | ||
let (data, _) = try await URLSession.shared.data(from: url) | ||
print("Fetched data") | ||
|
||
let decodedResponse = try? JSONDecoder().decode([Stop].self, from: data) | ||
guard let decodedResponse else { | ||
print("Error parsing data") | ||
return [] | ||
} | ||
|
||
return decodedResponse | ||
} catch { | ||
print("Invalid data") | ||
} | ||
|
||
return [] | ||
} |
24 changes: 24 additions & 0 deletions
24
apps/mobile/metro-now-watch Watch App/pages/departure-detail/DepartureDetailView.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,24 @@ | ||
import SwiftUI | ||
|
||
struct DepartureDetailView: View { | ||
let platformID: String | ||
|
||
var body: some View { | ||
VStack { | ||
Label( | ||
"Haje", | ||
systemImage: "arrowshape.right.fill" | ||
) | ||
.font(.title2) | ||
Text("1m 20s") | ||
.font(.title2) | ||
Text("Also to Kacerov in 1m 20s") | ||
.font(.footnote) | ||
} | ||
|
||
.containerBackground( | ||
.red.gradient, | ||
for: .tabView | ||
) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
apps/mobile/metro-now-watch Watch App/pages/departure-detail/DeparturesListView.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,23 @@ | ||
import SwiftUI | ||
|
||
struct DeparturesListView: View { | ||
let platformID: String | ||
|
||
var body: some View { | ||
NavigationView { | ||
List { | ||
Text("A List Item") | ||
Text("A Second List Item") | ||
Text("A Third List Item") | ||
Text("A List Item") | ||
Text("A Second List Item") | ||
Text("A Third List Item") | ||
} | ||
} | ||
|
||
.containerBackground( | ||
.red.gradient, | ||
for: .tabView | ||
) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...obile/metro-now-watch Watch App/pages/station-departures/StationDepartureDetailView.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,24 @@ | ||
import SwiftUI | ||
|
||
struct StationDepartureDetailView: View { | ||
var body: some View { | ||
TabView { | ||
TabView { | ||
DepartureDetailView(platformID: "unknown") | ||
.tag(Optional(0)) | ||
DeparturesListView(platformID: "unknown") | ||
.tag(Optional(1)) | ||
} | ||
.tabViewStyle(.verticalPage(transitionStyle: .blur)) | ||
|
||
TabView { | ||
DepartureDetailView(platformID: "unknown") | ||
.tag(Optional(0)) | ||
DeparturesListView(platformID: "unknown") | ||
.tag(Optional(1)) | ||
} | ||
.tabViewStyle(.verticalPage(transitionStyle: .blur)) | ||
} | ||
.tabViewStyle(.page) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
apps/mobile/metro-now-watch Watch App/pages/station-departures/StationDeparturesView.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,34 @@ | ||
import SwiftUI | ||
|
||
struct StationDeparturesView: View { | ||
var label: String | ||
|
||
var body: some View { | ||
NavigationStack { | ||
ScrollView { | ||
ForEach(0 ..< 2) { _ in | ||
NavigationLink(value: 2) { | ||
HStack { | ||
VStack(alignment: .leading) { | ||
Text("Háje") | ||
Text("Also to Kačerov").font(.system(size: 12)) | ||
} | ||
Spacer() | ||
Text("20s") | ||
} | ||
} | ||
.buttonStyle(.plain) | ||
.frame(maxWidth: .infinity) | ||
.padding(.vertical, 8) | ||
.padding(.horizontal, 12) | ||
.background(.red) | ||
.clipShape(.rect(cornerRadius: 12)) | ||
} | ||
} | ||
.navigationTitle(label) | ||
.navigationDestination(for: Int.self) { _ in | ||
StationDepartureDetailView() | ||
} | ||
} | ||
} | ||
} |
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
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