Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abc737eb2d | ||
|
|
3d5c999dc2 | ||
|
|
d899409b78 | ||
|
|
8bbcb0b4dc | ||
|
|
767080a983 | ||
|
|
7a84364238 |
@@ -30,7 +30,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>2</string>
|
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSLocalNetworkUsageDescription</key>
|
<key>NSLocalNetworkUsageDescription</key>
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.0.1</string>
|
<string>$(MARKETING_VERSION)</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>2</string>
|
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionPointIdentifier</key>
|
<key>NSExtensionPointIdentifier</key>
|
||||||
|
|||||||
@@ -406,7 +406,7 @@
|
|||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 2;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||||
@@ -472,7 +472,7 @@
|
|||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 2;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||||
@@ -537,7 +537,7 @@
|
|||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 2;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||||
@@ -602,7 +602,7 @@
|
|||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 2;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||||
@@ -699,7 +699,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = Config/App.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Config/App.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||||
GENERATE_INFOPLIST_FILE = NO;
|
GENERATE_INFOPLIST_FILE = NO;
|
||||||
INFOPLIST_FILE = "Config/App-Info.plist";
|
INFOPLIST_FILE = "Config/App-Info.plist";
|
||||||
@@ -707,7 +707,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0.1;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.apt.fuelboard;
|
PRODUCT_BUNDLE_IDENTIFIER = com.apt.fuelboard;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
@@ -722,7 +722,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = Config/App.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Config/App.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||||
GENERATE_INFOPLIST_FILE = NO;
|
GENERATE_INFOPLIST_FILE = NO;
|
||||||
INFOPLIST_FILE = "Config/App-Info.plist";
|
INFOPLIST_FILE = "Config/App-Info.plist";
|
||||||
@@ -730,7 +730,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0.1;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.apt.fuelboard;
|
PRODUCT_BUNDLE_IDENTIFIER = com.apt.fuelboard;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
@@ -745,7 +745,7 @@
|
|||||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||||
CODE_SIGN_ENTITLEMENTS = Config/Widget.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Config/Widget.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||||
GENERATE_INFOPLIST_FILE = NO;
|
GENERATE_INFOPLIST_FILE = NO;
|
||||||
INFOPLIST_FILE = "Config/Widget-Info.plist";
|
INFOPLIST_FILE = "Config/Widget-Info.plist";
|
||||||
@@ -754,7 +754,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
"@executable_path/../../Frameworks",
|
"@executable_path/../../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0.1;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.apt.fuelboard.widgets;
|
PRODUCT_BUNDLE_IDENTIFIER = com.apt.fuelboard.widgets;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
@@ -770,7 +770,7 @@
|
|||||||
APPLICATION_EXTENSION_API_ONLY = YES;
|
APPLICATION_EXTENSION_API_ONLY = YES;
|
||||||
CODE_SIGN_ENTITLEMENTS = Config/Widget.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Config/Widget.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
DEVELOPMENT_TEAM = F3BE6NE7U3;
|
||||||
GENERATE_INFOPLIST_FILE = NO;
|
GENERATE_INFOPLIST_FILE = NO;
|
||||||
INFOPLIST_FILE = "Config/Widget-Info.plist";
|
INFOPLIST_FILE = "Config/Widget-Info.plist";
|
||||||
@@ -779,7 +779,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
"@executable_path/../../Frameworks",
|
"@executable_path/../../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0.1;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.apt.fuelboard.widgets;
|
PRODUCT_BUNDLE_IDENTIFIER = com.apt.fuelboard.widgets;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
|
|||||||
@@ -46,9 +46,11 @@ final class WatchSyncManager: NSObject, WCSessionDelegate {
|
|||||||
if let favourites = try? JSONEncoder().encode(FuelStore.loadFavourites()) {
|
if let favourites = try? JSONEncoder().encode(FuelStore.loadFavourites()) {
|
||||||
context[FuelStore.favouritesKey] = favourites
|
context[FuelStore.favouritesKey] = favourites
|
||||||
}
|
}
|
||||||
if let stations = try? JSONEncoder().encode(FuelStore.loadStations()) {
|
// Do NOT send the full station dump to watchOS via WatchConnectivity.
|
||||||
context[FuelStore.stationsKey] = stations
|
// The UK dataset is megabytes large and exceeds application-context
|
||||||
}
|
// payload limits, which prevents any snapshot from arriving. The
|
||||||
|
// favourites payload already carries station snapshots + prices, so the
|
||||||
|
// watch can render favourites without the full list.
|
||||||
|
|
||||||
context[FuelStore.fuelKey] = FuelStore.loadSelectedFuel().rawValue
|
context[FuelStore.fuelKey] = FuelStore.loadSelectedFuel().rawValue
|
||||||
context[FuelStore.distanceUnitKey] = FuelStore.loadDistanceUnit().rawValue
|
context[FuelStore.distanceUnitKey] = FuelStore.loadDistanceUnit().rawValue
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../Shared/DataRefreshMode.swift
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import MapKit
|
||||||
|
|
||||||
private enum WatchFuelType: String, CaseIterable, Identifiable, Codable {
|
private enum WatchFuelType: String, CaseIterable, Identifiable, Codable {
|
||||||
case e10
|
case e10
|
||||||
@@ -102,6 +103,8 @@ private struct WatchFavouriteRow: Identifiable {
|
|||||||
let priceText: String
|
let priceText: String
|
||||||
let distanceText: String?
|
let distanceText: String?
|
||||||
let isCheapest: Bool
|
let isCheapest: Bool
|
||||||
|
let latitude: Double
|
||||||
|
let longitude: Double
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum WatchRefreshState {
|
private enum WatchRefreshState {
|
||||||
@@ -109,6 +112,7 @@ private enum WatchRefreshState {
|
|||||||
case stale(lastUpdated: String)
|
case stale(lastUpdated: String)
|
||||||
case checking
|
case checking
|
||||||
case requested(lastUpdated: String)
|
case requested(lastUpdated: String)
|
||||||
|
case checkedNoNewData(lastUpdated: String)
|
||||||
case needsPhone
|
case needsPhone
|
||||||
case noData
|
case noData
|
||||||
|
|
||||||
@@ -117,7 +121,8 @@ private enum WatchRefreshState {
|
|||||||
case .idle(let lastUpdated): return "Updated \(lastUpdated)"
|
case .idle(let lastUpdated): return "Updated \(lastUpdated)"
|
||||||
case .stale(let lastUpdated): return "Cache from \(lastUpdated)"
|
case .stale(let lastUpdated): return "Cache from \(lastUpdated)"
|
||||||
case .checking: return "Checking…"
|
case .checking: return "Checking…"
|
||||||
case .requested(let lastUpdated): return "Requested · \(lastUpdated)"
|
case .requested(let lastUpdated): return "Updated · \(lastUpdated)"
|
||||||
|
case .checkedNoNewData(let lastUpdated): return "No newer data · \(lastUpdated)"
|
||||||
case .needsPhone: return "Refresh on iPhone"
|
case .needsPhone: return "Refresh on iPhone"
|
||||||
case .noData: return "No cached prices yet"
|
case .noData: return "No cached prices yet"
|
||||||
}
|
}
|
||||||
@@ -129,6 +134,7 @@ private enum WatchRefreshState {
|
|||||||
case .stale: return .yellow
|
case .stale: return .yellow
|
||||||
case .checking: return .yellow
|
case .checking: return .yellow
|
||||||
case .requested: return .green
|
case .requested: return .green
|
||||||
|
case .checkedNoNewData: return .secondary
|
||||||
case .needsPhone: return .orange
|
case .needsPhone: return .orange
|
||||||
case .noData: return .secondary
|
case .noData: return .secondary
|
||||||
}
|
}
|
||||||
@@ -140,6 +146,7 @@ private enum WatchRefreshState {
|
|||||||
case .stale: return "exclamationmark.circle"
|
case .stale: return "exclamationmark.circle"
|
||||||
case .checking: return "arrow.triangle.2.circlepath"
|
case .checking: return "arrow.triangle.2.circlepath"
|
||||||
case .requested: return "checkmark.circle"
|
case .requested: return "checkmark.circle"
|
||||||
|
case .checkedNoNewData: return "clock.badge.exclamationmark"
|
||||||
case .needsPhone: return "iphone"
|
case .needsPhone: return "iphone"
|
||||||
case .noData: return "tray"
|
case .noData: return "tray"
|
||||||
}
|
}
|
||||||
@@ -283,14 +290,30 @@ struct ContentView: View {
|
|||||||
@State private var distanceUnit: WatchDistanceUnit = WatchFuelCache.loadDistanceUnit()
|
@State private var distanceUnit: WatchDistanceUnit = WatchFuelCache.loadDistanceUnit()
|
||||||
@State private var priceStyle: WatchPriceStyle = WatchFuelCache.loadPriceStyle()
|
@State private var priceStyle: WatchPriceStyle = WatchFuelCache.loadPriceStyle()
|
||||||
|
|
||||||
|
private var displayedFuels: [WatchFuelType] {
|
||||||
|
let fuels = Set(favourites.map(\.fuel))
|
||||||
|
let sorted = fuels.sorted { $0.sortRank < $1.sortRank }
|
||||||
|
return sorted.isEmpty ? [fuel] : sorted
|
||||||
|
}
|
||||||
|
|
||||||
|
private var hasAnyFavourites: Bool {
|
||||||
|
!favourites.isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
if hasAnyFavourites {
|
||||||
TabView(selection: $fuel) {
|
TabView(selection: $fuel) {
|
||||||
ForEach(WatchFuelType.allCases) { fuelCase in
|
ForEach(displayedFuels) { fuelCase in
|
||||||
fuelPage(for: fuelCase)
|
fuelPage(for: fuelCase)
|
||||||
.tag(fuelCase)
|
.tag(fuelCase)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.tabViewStyle(.verticalPage)
|
.tabViewStyle(.verticalPage)
|
||||||
|
} else {
|
||||||
|
emptyStateView
|
||||||
|
}
|
||||||
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
reloadFromCache()
|
reloadFromCache()
|
||||||
WatchSyncManager.shared.requestSnapshot()
|
WatchSyncManager.shared.requestSnapshot()
|
||||||
@@ -301,6 +324,7 @@ struct ContentView: View {
|
|||||||
.onChange(of: scenePhase) { _, newPhase in
|
.onChange(of: scenePhase) { _, newPhase in
|
||||||
if newPhase == .active {
|
if newPhase == .active {
|
||||||
reloadFromCache()
|
reloadFromCache()
|
||||||
|
WatchSyncManager.shared.requestSnapshot()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,8 +341,6 @@ struct ContentView: View {
|
|||||||
|
|
||||||
if let cheapest {
|
if let cheapest {
|
||||||
cheapestCard(for: fuelCase, favourite: cheapest)
|
cheapestCard(for: fuelCase, favourite: cheapest)
|
||||||
} else {
|
|
||||||
emptyCheapestCard(for: fuelCase)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
statusRow
|
statusRow
|
||||||
@@ -340,17 +362,11 @@ struct ContentView: View {
|
|||||||
Text("Favourites")
|
Text("Favourites")
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
|
||||||
if rows.isEmpty {
|
|
||||||
Text("No favourites for \(fuelCase.displayName.lowercased()) yet.")
|
|
||||||
.font(.caption)
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
} else {
|
|
||||||
ForEach(rows) { row in
|
ForEach(rows) { row in
|
||||||
favouriteRow(row, fuel: fuelCase)
|
favouriteRow(row, fuel: fuelCase)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.padding(.horizontal, 10)
|
.padding(.horizontal, 10)
|
||||||
.padding(.vertical, 12)
|
.padding(.vertical, 12)
|
||||||
}
|
}
|
||||||
@@ -372,7 +388,9 @@ struct ContentView: View {
|
|||||||
name: favourite.station.name,
|
name: favourite.station.name,
|
||||||
priceText: priceText,
|
priceText: priceText,
|
||||||
distanceText: distanceText,
|
distanceText: distanceText,
|
||||||
isCheapest: favourite.id == cheapest?.id
|
isCheapest: favourite.id == cheapest?.id,
|
||||||
|
latitude: favourite.station.lat,
|
||||||
|
longitude: favourite.station.lng
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,7 +410,52 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var emptyStateView: some View {
|
||||||
|
ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack(alignment: .center, spacing: 8) {
|
||||||
|
Image(systemName: "fuelpump.fill")
|
||||||
|
.foregroundStyle(Color(red: 48/255.0, green: 209/255.0, blue: 88/255.0))
|
||||||
|
Text("FuelBoard")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
|
||||||
|
statusRow
|
||||||
|
|
||||||
|
Button {
|
||||||
|
runCheckNow()
|
||||||
|
} label: {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: refreshState.icon)
|
||||||
|
Text("Check now")
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
.tint(Color(red: 48/255.0, green: 209/255.0, blue: 88/255.0))
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
Text("No favourites yet")
|
||||||
|
.font(.headline)
|
||||||
|
Text("Add favourites on iPhone and they’ll appear here.")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.padding(10)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.background(Color.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 14, style: .continuous))
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 10)
|
||||||
|
.padding(.vertical, 12)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func cheapestCard(for fuel: WatchFuelType, favourite: WatchFavouriteEntry) -> some View {
|
private func cheapestCard(for fuel: WatchFuelType, favourite: WatchFavouriteEntry) -> some View {
|
||||||
|
Button {
|
||||||
|
openMaps(latitude: favourite.station.lat, longitude: favourite.station.lng)
|
||||||
|
} label: {
|
||||||
VStack(alignment: .leading, spacing: 6) {
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
Text("Cheapest favourite")
|
Text("Cheapest favourite")
|
||||||
.font(.caption2)
|
.font(.caption2)
|
||||||
@@ -414,22 +477,9 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
.padding(10)
|
.padding(10)
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
.background(fuel.color.opacity(0.15), in: RoundedRectangle(cornerRadius: 14, style: .continuous))
|
.contentShape(RoundedRectangle(cornerRadius: 14, style: .continuous))
|
||||||
}
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
private func emptyCheapestCard(for fuel: WatchFuelType) -> some View {
|
|
||||||
VStack(alignment: .leading, spacing: 6) {
|
|
||||||
Text("Cheapest favourite")
|
|
||||||
.font(.caption2)
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
Text("No favourite saved")
|
|
||||||
.font(.headline)
|
|
||||||
Text("Add favourites on iPhone to see them here.")
|
|
||||||
.font(.caption)
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
}
|
|
||||||
.padding(10)
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
.background(fuel.color.opacity(0.15), in: RoundedRectangle(cornerRadius: 14, style: .continuous))
|
.background(fuel.color.opacity(0.15), in: RoundedRectangle(cornerRadius: 14, style: .continuous))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,6 +491,9 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func favouriteRow(_ favourite: WatchFavouriteRow, fuel: WatchFuelType) -> some View {
|
private func favouriteRow(_ favourite: WatchFavouriteRow, fuel: WatchFuelType) -> some View {
|
||||||
|
Button {
|
||||||
|
openMaps(latitude: favourite.latitude, longitude: favourite.longitude)
|
||||||
|
} label: {
|
||||||
HStack(spacing: 8) {
|
HStack(spacing: 8) {
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
@@ -469,6 +522,9 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
.padding(.horizontal, 10)
|
.padding(.horizontal, 10)
|
||||||
.padding(.vertical, 8)
|
.padding(.vertical, 8)
|
||||||
|
.contentShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
.background(Color.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 12, style: .continuous))
|
.background(Color.white.opacity(0.06), in: RoundedRectangle(cornerRadius: 12, style: .continuous))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,6 +555,7 @@ struct ContentView: View {
|
|||||||
|
|
||||||
private func runCheckNow() {
|
private func runCheckNow() {
|
||||||
refreshState = .checking
|
refreshState = .checking
|
||||||
|
let previousLastRefresh = WatchFuelCache.loadLastRefresh()
|
||||||
let requestDate = Date()
|
let requestDate = Date()
|
||||||
WatchFuelCache.requestRefresh(requestDate)
|
WatchFuelCache.requestRefresh(requestDate)
|
||||||
WatchSyncManager.shared.requestRefresh(at: requestDate)
|
WatchSyncManager.shared.requestRefresh(at: requestDate)
|
||||||
@@ -508,8 +565,16 @@ struct ContentView: View {
|
|||||||
if WatchFuelCache.wasRefreshHandled(since: requestDate) {
|
if WatchFuelCache.wasRefreshHandled(since: requestDate) {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
reloadFromCache()
|
reloadFromCache()
|
||||||
let label = WatchFuelCache.loadLastRefresh().map(relativeRefreshText(for:)) ?? "just now"
|
let currentLastRefresh = WatchFuelCache.loadLastRefresh()
|
||||||
refreshState = .requested(lastUpdated: label)
|
if let currentLastRefresh,
|
||||||
|
currentLastRefresh >= requestDate,
|
||||||
|
currentLastRefresh > (previousLastRefresh ?? .distantPast) {
|
||||||
|
refreshState = .requested(lastUpdated: relativeRefreshText(for: currentLastRefresh))
|
||||||
|
} else if let currentLastRefresh {
|
||||||
|
refreshState = .checkedNoNewData(lastUpdated: relativeRefreshText(for: currentLastRefresh))
|
||||||
|
} else {
|
||||||
|
refreshState = .noData
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -526,6 +591,17 @@ struct ContentView: View {
|
|||||||
formatter.unitsStyle = .short
|
formatter.unitsStyle = .short
|
||||||
return formatter.localizedString(for: date, relativeTo: Date())
|
return formatter.localizedString(for: date, relativeTo: Date())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func openMaps(latitude: Double, longitude: Double) {
|
||||||
|
let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
|
||||||
|
let destination = MKMapItem(placemark: MKPlacemark(coordinate: coordinate))
|
||||||
|
_ = MKMapItem.openMaps(
|
||||||
|
with: [MKMapItem.forCurrentLocation(), destination],
|
||||||
|
launchOptions: [
|
||||||
|
MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|||||||
@@ -59,9 +59,6 @@ final class WatchSyncManager: NSObject, WCSessionDelegate {
|
|||||||
if let favourites = payload["fuelboard.favourites"] as? Data {
|
if let favourites = payload["fuelboard.favourites"] as? Data {
|
||||||
defaults.set(favourites, forKey: "fuelboard.favourites")
|
defaults.set(favourites, forKey: "fuelboard.favourites")
|
||||||
}
|
}
|
||||||
if let stations = payload["fuelboard.stations"] as? Data {
|
|
||||||
defaults.set(stations, forKey: "fuelboard.stations")
|
|
||||||
}
|
|
||||||
if let fuel = payload["fuelboard.selectedFuel"] as? String {
|
if let fuel = payload["fuelboard.selectedFuel"] as? String {
|
||||||
defaults.set(fuel, forKey: "fuelboard.selectedFuel")
|
defaults.set(fuel, forKey: "fuelboard.selectedFuel")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,9 +147,9 @@ private struct FuelBoardLiveActivityView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Minimal strip for small space (CarPlay small / Watch smart stack):
|
/// Minimal strip for small space (CarPlay small / Watch smart stack):
|
||||||
/// fuel type + bold price on one line, station · distance below.
|
/// fuel type + distance + bold price on one line, station name below.
|
||||||
/// Deliberately no app name and no "Tap for directions" — CarPlay is
|
/// Deliberately no app name and no full address — the watch-sized slot is
|
||||||
/// display-only, and the user's asks here are just fuel + price + distance.
|
/// too tight, so the second line is reserved for the station name only.
|
||||||
private var compactBody: some View {
|
private var compactBody: some View {
|
||||||
VStack(alignment: .leading, spacing: 3) {
|
VStack(alignment: .leading, spacing: 3) {
|
||||||
HStack(spacing: 5) {
|
HStack(spacing: 5) {
|
||||||
@@ -157,16 +157,21 @@ private struct FuelBoardLiveActivityView: View {
|
|||||||
.font(.caption.bold())
|
.font(.caption.bold())
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
Spacer(minLength: 4)
|
Spacer(minLength: 4)
|
||||||
|
Text(context.state.distanceText)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
.lineLimit(1)
|
||||||
|
Spacer(minLength: 4)
|
||||||
FuelStore.priceTextAttributed(context.state.pricePence,
|
FuelStore.priceTextAttributed(context.state.pricePence,
|
||||||
style: context.state.priceDisplayStyle,
|
style: context.state.priceDisplayStyle,
|
||||||
size: 15, weight: .bold)
|
size: 15, weight: .bold)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
}
|
}
|
||||||
Text("\(context.state.stationName) · \(context.state.distanceText)")
|
Text(context.state.stationName)
|
||||||
.font(.system(size: 9))
|
.font(.system(size: 10, weight: .medium))
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
.minimumScaleFactor(0.7)
|
.minimumScaleFactor(0.75)
|
||||||
.truncationMode(.tail)
|
.truncationMode(.tail)
|
||||||
}
|
}
|
||||||
.padding(8)
|
.padding(8)
|
||||||
|
|||||||
Reference in New Issue
Block a user