-
-
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
19 changed files
with
566 additions
and
49 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
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 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import Foundation | ||
|
||
struct ApiDeparture: Codable { | ||
let departureTimestamp: DepartureTimestamp | ||
let route: Route | ||
let trip: Trip | ||
} | ||
|
||
struct DepartureTimestamp: Codable { | ||
let predicted: Date | ||
} | ||
|
||
struct Route: Codable { | ||
let shortName: String | ||
} | ||
|
||
struct Trip: Codable { | ||
let headsign: String | ||
} |
This file was deleted.
Oops, something went wrong.
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
11 changes: 11 additions & 0 deletions
11
app/metro-now-widgets/Assets.xcassets/AccentColor.colorset/Contents.json
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,11 @@ | ||
{ | ||
"colors": [ | ||
{ | ||
"idiom": "universal" | ||
} | ||
], | ||
"info": { | ||
"author": "xcode", | ||
"version": 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/metro-now-widgets/Assets.xcassets/AppIcon.appiconset/Contents.json
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,13 @@ | ||
{ | ||
"images": [ | ||
{ | ||
"idiom": "universal", | ||
"platform": "ios", | ||
"size": "1024x1024" | ||
} | ||
], | ||
"info": { | ||
"author": "xcode", | ||
"version": 1 | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"info": { | ||
"author": "xcode", | ||
"version": 1 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/metro-now-widgets/Assets.xcassets/WidgetBackground.colorset/Contents.json
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,11 @@ | ||
{ | ||
"colors": [ | ||
{ | ||
"idiom": "universal" | ||
} | ||
], | ||
"info": { | ||
"author": "xcode", | ||
"version": 1 | ||
} | ||
} |
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,74 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import SwiftUI | ||
import WidgetKit | ||
|
||
import CoreLocation | ||
|
||
class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { | ||
private let locationManager = CLLocationManager() | ||
@Published var location: CLLocation? | ||
|
||
override init() { | ||
super.init() | ||
locationManager.delegate = self | ||
locationManager.requestWhenInUseAuthorization() | ||
locationManager.startUpdatingLocation() | ||
} | ||
|
||
func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | ||
if let location = locations.last { | ||
self.location = location | ||
locationManager.stopUpdatingLocation() | ||
} | ||
} | ||
|
||
func locationManager(_: CLLocationManager, didFailWithError error: Error) { | ||
print("Failed to find user's location: \(error.localizedDescription)") | ||
} | ||
} | ||
|
||
struct Provider: TimelineProvider { | ||
let locationManager = LocationManager() | ||
|
||
func placeholder(in _: Context) -> WidgetEntry { | ||
WidgetEntry(date: Date(), stationName: "Loading...", departures: []) | ||
} | ||
|
||
func getSnapshot(in _: Context, completion: @escaping (WidgetEntry) -> Void) { | ||
let entry = WidgetEntry(date: Date(), stationName: "Kacerov", departures: []) | ||
completion(entry) | ||
} | ||
|
||
func getTimeline(in _: Context, completion: @escaping (Timeline<Entry>) -> Void) { | ||
Task { | ||
let departures = [] | ||
} | ||
|
||
var entries: [WidgetEntry] = [] | ||
|
||
// Generate a timeline consisting of five entries an hour apart, starting from the current date. | ||
let currentDate = Date() | ||
for hourOffset in 0 ..< 5 { | ||
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! | ||
let entry = WidgetEntry(date: Date(), stationName: "Kacerov", departures: []) | ||
entries.append(entry) | ||
} | ||
|
||
let timeline = Timeline(entries: entries, policy: .atEnd) | ||
completion(timeline) | ||
} | ||
|
||
private func fetchNearestMetroStation(completion: @escaping (String) -> Void) { | ||
guard let location = locationManager.location else { | ||
completion("Location not available") | ||
return | ||
} | ||
|
||
// Replace with actual API call to fetch nearest metro station using location.coordinate | ||
let nearestStation = "Mock Metro Station" | ||
completion(nearestStation) | ||
} | ||
} |
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,18 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import WidgetKit | ||
|
||
struct WidgetEntryDeparture { | ||
var departureDate: Date | ||
var direction: String | ||
var metroLine: String | ||
} | ||
|
||
struct WidgetEntry: TimelineEntry { | ||
var date: Date | ||
|
||
let stationName: String | ||
let departures: [WidgetEntryDeparture] | ||
} |
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,29 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct Departure: View { | ||
let direction: String | ||
let departureDate: Date | ||
let metroLine: String | ||
|
||
var body: some View { | ||
HStack { | ||
Text(direction) | ||
.frame(alignment: .leading) | ||
.font(.caption) | ||
.fontWeight(.bold) | ||
Spacer() | ||
Text(departureDate.formatted(.dateTime.hour().minute())) | ||
.frame(alignment: .leading) | ||
.font(.caption) | ||
.fontWeight(.bold) | ||
} | ||
.padding(.vertical, 10) | ||
.padding(.horizontal, 5) | ||
.background(getMetroLineColor(metroLine)) | ||
.clipShape(.rect(cornerRadius: 10)) | ||
} | ||
} |
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,13 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PlaceholderView: View { | ||
var entry: Provider.Entry | ||
|
||
var body: some View { | ||
Text("Widget is waiting for data to be fetched") | ||
} | ||
} |
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,25 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SmallWidgetView: View { | ||
var entry: Provider.Entry | ||
|
||
var body: some View { | ||
VStack { | ||
WidgetHeading(stationName: "Kacerov") | ||
Departure( | ||
direction: "Haje", | ||
departureDate: Date(), | ||
metroLine: "C" | ||
) | ||
Departure( | ||
direction: "Letnany", | ||
departureDate: Date(), | ||
metroLine: "C" | ||
) | ||
} | ||
} | ||
} |
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,18 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct WidgetHeading: View { | ||
let stationName: String | ||
|
||
var body: some View { | ||
HStack { | ||
Text(stationName) | ||
.font(.headline) | ||
.frame(alignment: .topLeading) | ||
Spacer() | ||
} | ||
} | ||
} |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NSWidgetWantsLocation</key> | ||
<true/> | ||
<key>NSLocationUsageDescription</key> | ||
<string>Location is needed to determine nearest metro station</string> | ||
<key>NSLocationWhenInUseUsageDescription</key> | ||
<string>Location is needed to determine nearest metro station</string> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.widgetkit-extension</string> | ||
</dict> | ||
</dict> | ||
</plist> |
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,27 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import MapKit | ||
import SwiftUI | ||
import WidgetKit | ||
|
||
struct metro_now_widgets: Widget { | ||
let kind: String = "metro_now_widgets" | ||
|
||
var body: some WidgetConfiguration { | ||
StaticConfiguration(kind: kind, provider: Provider()) { | ||
entry in | ||
SmallWidgetView(entry: entry) | ||
.containerBackground(.fill.tertiary, for: .widget) | ||
} | ||
.configurationDisplayName("Departures") | ||
.description("Metro departures from nearest station") | ||
} | ||
} | ||
|
||
#Preview(as: .systemSmall) { | ||
metro_now_widgets() | ||
} timeline: { | ||
WidgetEntry(date: .now, stationName: "Dejvicka", departures: []) | ||
} |
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,13 @@ | ||
// | ||
// Author: Kryštof Krátký | ||
// | ||
|
||
import SwiftUI | ||
import WidgetKit | ||
|
||
@main | ||
struct metro_now_widgetsBundle: WidgetBundle { | ||
var body: some Widget { | ||
metro_now_widgets() | ||
} | ||
} |
Oops, something went wrong.