Skip to content

Commit

Permalink
refactor(app): settings file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
krystxf committed Dec 3, 2024
1 parent 44c97aa commit be0726d
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ struct SettingsAboutPageView: View {
.frame(maxWidth: .infinity, alignment: .center)
Text("""
The app is still in development. Stay tuned to see what's next!
""")
.font(.caption)
""")
.multilineTextAlignment(.center)
}

}

if let appStoreUrl {
Expand Down
179 changes: 154 additions & 25 deletions apps/mobile/metro-now/widgets/widgets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct Provider: TimelineProvider {
func getTimeline(in _: Context, completion: @escaping (Timeline<Entry>) -> Void) {
var entries: [SimpleEntry] = []

// 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)!
Expand All @@ -34,23 +33,157 @@ struct SimpleEntry: TimelineEntry {
let date: Date
}





struct LargeWidgetListItemView: View {
let routeName: String

let headsign: String
let departure: Date

let nextHeadsing: String?
let nextDeparture: Date?

var body: some View {
HStack{
RouteNameIconView(
label: routeName,
background: getRouteColor(routeName)
)

VStack{
HStack{
Text(headsign)
Spacer()
Text(departure,style: .offset)
.fontDesign(.monospaced)
.multilineTextAlignment(.trailing)
}


if let nextHeadsing, let nextDeparture {

HStack{
Text(headsign == nextHeadsing ? "Also in" : nextHeadsing)
Spacer()
Text(nextDeparture,style: .offset)
.fontDesign(.monospaced)
.multilineTextAlignment(.trailing)

}
.font(.caption)
}
}
}
}
}

struct WidgetsEntryPlaceholderView : View {
var entry: Provider.Entry

var body: some View {
Text("Muzeum")
.font(.headline)

VStack{
LargeWidgetListItemView(
routeName: "a",
headsign: "D. Hostivar",
departure: .now,
nextHeadsing: "Skalka",
nextDeparture: .now
)
Divider()
LargeWidgetListItemView(
routeName: "a",
headsign: "N. Motol",departure: .now,
nextHeadsing: "N. Motol",
nextDeparture: .now
)
Divider()
LargeWidgetListItemView(
routeName: "c",
headsign: "Letnany",departure: .now,
nextHeadsing: "Letnany",
nextDeparture: .now
)
Divider()
LargeWidgetListItemView(
routeName: "c",
headsign: "Haje",departure: .now,
nextHeadsing: "Kacerov",
nextDeparture: .now
)
Divider()
Spacer()

Text("Last refreshed: \(entry.date, style: .time)")
.foregroundStyle(.tertiary)
.font(.footnote)
}


}
}

struct LargeWidgetView : View {
var entry: Provider.Entry

var body: some View {
Text("Muzeum")
.font(.headline)

VStack{
LargeWidgetListItemView(
routeName: "a",
headsign: "D. Hostivar",
departure: .now,
nextHeadsing: "Skalka",
nextDeparture: .now
)
Divider()
LargeWidgetListItemView(
routeName: "a",
headsign: "N. Motol",departure: .now,
nextHeadsing: "N. Motol",
nextDeparture: .now
)
Divider()
LargeWidgetListItemView(
routeName: "c",
headsign: "Letnany",departure: .now,
nextHeadsing: "Letnany",
nextDeparture: .now
)
Divider()
LargeWidgetListItemView(
routeName: "c",
headsign: "Haje",departure: .now,
nextHeadsing: "Kacerov",
nextDeparture: .now
)
Divider()
Spacer()

Text("Last refreshed: \(entry.date, style: .time)")
.foregroundStyle(.tertiary)
.font(.footnote)
}
}
}

struct widgetsEntryView: View {
var entry: Provider.Entry
@Environment(\.widgetFamily) var widgetFamily

var body: some View {
VStack {
Text("🚇 metro-now")
.font(.headline)
Text("coming soon")
.font(.subheadline)

Spacer()
VStack {
Text(widgetFamily.description.lowercased())
Text("Last update: ") + Text(entry.date, style: .time)
}
.font(.footnote)
switch widgetFamily {
case .systemLarge, .systemExtraLarge:
LargeWidgetView(entry: entry)
default:
LargeWidgetView(entry: entry)
}
}
}
Expand All @@ -69,35 +202,31 @@ struct widgets: Widget {
.background()
}
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
.configurationDisplayName("Metro Departures")
.description("Show metro departures from selected stop.")
.supportedFamilies([
.systemSmall,
.systemMedium,
.systemLarge,
.systemExtraLarge
])
}
}

#Preview("small", as: .systemSmall) {
widgets()
} timeline: {
SimpleEntry(date: .now)
SimpleEntry(date: .now)
}

#Preview("medium", as: .systemMedium) {
widgets()
} timeline: {
SimpleEntry(date: .now)
SimpleEntry(date: .now)
}

#Preview("large", as: .systemLarge) {
widgets()
} timeline: {
SimpleEntry(date: .now)
SimpleEntry(date: .now)
}

#Preview("extra large", as: .systemExtraLarge) {
widgets()
} timeline: {
SimpleEntry(date: .now)
SimpleEntry(date: .now)
}

0 comments on commit be0726d

Please sign in to comment.