mirror of
https://github.com/tonytins/amtkstat.git
synced 2026-10-24 05:32:54 -04:00
Train status is now coloured coded for your convenience
- Introduced TrainLateness enum to represent on-time, early, late (with minutes), and unknown states, including description text, color, and formatting logic. - Replaced TrainStatusRow.status String with TrainLateness and update ContentView to render a colored status pill and to return TrainLateness from isOnTime.
This commit is contained in:
parent
3533e5d4b8
commit
915d0ec2dc
3 changed files with 60 additions and 10 deletions
45
Sources/AmtrakStatus/TrainLateness.swift
Normal file
45
Sources/AmtrakStatus/TrainLateness.swift
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import Foundation
|
||||
import SwiftCrossUI
|
||||
|
||||
enum TrainLateness {
|
||||
case onTime
|
||||
case early(minutes: Int)
|
||||
case late(minutes: Int)
|
||||
case unknown
|
||||
|
||||
var descrption: String {
|
||||
switch self {
|
||||
case .onTime:
|
||||
return "On Time"
|
||||
case .early(minutes: let minutes):
|
||||
return "\(Self.formatted(minutes)) early"
|
||||
case .late(minutes: let minutes):
|
||||
return "\(Self.formatted(minutes)) late"
|
||||
case .unknown:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
var color: Color {
|
||||
switch self {
|
||||
case .onTime:
|
||||
return .green
|
||||
case .early:
|
||||
return .blue
|
||||
case .late:
|
||||
return .red
|
||||
case .unknown:
|
||||
return .gray
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static func formatted(_ minutes: Int) -> String {
|
||||
let hours = minutes / 60
|
||||
let remainder = minutes % 60
|
||||
guard hours > 0 else {
|
||||
return "\(minutes) mins"
|
||||
}
|
||||
return "\(hours) hr late"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue