add full tank indicator

This commit is contained in:
Kameron Kenny 2025-03-19 10:06:32 -04:00
parent 77fdffa619
commit 07e8581ee2
4 changed files with 31 additions and 19 deletions

View File

@ -289,7 +289,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "Gas Man/Gas_Man.entitlements"; CODE_SIGN_ENTITLEMENTS = "Gas Man/Gas_Man.entitlements";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 202503181111; CURRENT_PROJECT_VERSION = 202503190946;
DEVELOPMENT_ASSET_PATHS = "\"Gas Man/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Gas Man/Preview Content\"";
DEVELOPMENT_TEAM = Z734T5CD6B; DEVELOPMENT_TEAM = Z734T5CD6B;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
@ -332,7 +332,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "Gas Man/Gas_Man.entitlements"; CODE_SIGN_ENTITLEMENTS = "Gas Man/Gas_Man.entitlements";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 202503181111; CURRENT_PROJECT_VERSION = 202503190946;
DEVELOPMENT_ASSET_PATHS = "\"Gas Man/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Gas Man/Preview Content\"";
DEVELOPMENT_TEAM = Z734T5CD6B; DEVELOPMENT_TEAM = Z734T5CD6B;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;

View File

@ -21,6 +21,8 @@ struct AddFuelLogView: View {
@State private var locationName = "" @State private var locationName = ""
@State private var selectedOctane: Int = 87 // Default or from previous record @State private var selectedOctane: Int = 87 // Default or from previous record
@State private var pricePerGalon = "" @State private var pricePerGalon = ""
// New Full Tank toggle; default is on (true)
@State private var fullTank: Bool = true
// Allowed octane options // Allowed octane options
let octaneOptions = [87, 89, 91, 92, 93, 95] let octaneOptions = [87, 89, 91, 92, 93, 95]
@ -80,6 +82,10 @@ struct AddFuelLogView: View {
.onChange(of: cost) { _ in updateCalculatedValues() } .onChange(of: cost) { _ in updateCalculatedValues() }
} }
// New Full Tank toggle
Toggle("Full Tank", isOn: $fullTank)
.toggleStyle(SwitchToggleStyle(tint: .blue))
Button("Get Current Location") { Button("Get Current Location") {
locationManager.requestLocation() locationManager.requestLocation()
} }
@ -204,7 +210,6 @@ struct AddFuelLogView: View {
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)]
fetchRequest.fetchLimit = 1 fetchRequest.fetchLimit = 1
if let lastFuelLog = try? viewContext.fetch(fetchRequest).first { if let lastFuelLog = try? viewContext.fetch(fetchRequest).first {
// Compare against the latest fuel log's odometer.
if newOdometer <= lastFuelLog.odometer { if newOdometer <= lastFuelLog.odometer {
showOdometerAlert = true showOdometerAlert = true
return return
@ -221,8 +226,9 @@ struct AddFuelLogView: View {
newLog.locationName = locationName newLog.locationName = locationName
newLog.octane = Int16(selectedOctane) newLog.octane = Int16(selectedOctane)
newLog.pricePerGalon = Double(pricePerGalon) ?? 0 newLog.pricePerGalon = Double(pricePerGalon) ?? 0
// Set the fullTank property from the toggle:
newLog.fullTank = fullTank
// Set the vehicle relationship if a vehicle was selected:
if let vehicleID = selectedVehicleID, if let vehicleID = selectedVehicleID,
let selectedVehicle = vehicles.first(where: { $0.id == vehicleID }) { let selectedVehicle = vehicles.first(where: { $0.id == vehicleID }) {
newLog.vehicle = selectedVehicle newLog.vehicle = selectedVehicle
@ -237,5 +243,4 @@ struct AddFuelLogView: View {
fatalError("Unresolved error \(nsError), \(nsError.userInfo)") fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
} }
} }
} }

View File

@ -57,6 +57,22 @@ struct FuelLogDetailView: View {
Text("$\(fuelLog.pricePerGalon, specifier: "%.3f")") Text("$\(fuelLog.pricePerGalon, specifier: "%.3f")")
} }
} }
// New Tank Status Section
Section(header: Text("Tank Status")) {
HStack {
Text("Tank:")
Spacer()
if fuelLog.fullTank {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
Text("Full")
} else {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.red)
Text("Not Full")
}
}
}
Section(header: Text("Location")) { Section(header: Text("Location")) {
HStack { HStack {
Text("Coordinates:") Text("Coordinates:")

View File

@ -47,7 +47,6 @@ struct FuelLogListView: View {
var body: some View { var body: some View {
NavigationView { NavigationView {
if vehicles.isEmpty { if vehicles.isEmpty {
// Empty state: no vehicles exist.
VStack(spacing: 20) { VStack(spacing: 20) {
Text("No vehicles found.") Text("No vehicles found.")
.font(.headline) .font(.headline)
@ -68,25 +67,16 @@ struct FuelLogListView: View {
} }
} else { } else {
List { List {
// Vehicle Picker Section
Section { Section {
Picker("Vehicle", selection: $selectedVehicleID) { Picker("Vehicle", selection: $selectedVehicleID) {
ForEach(vehicles, id: \.objectID) { vehicle in ForEach(vehicles, id: \.id) { vehicle in
// Only tag if vehicle.id is not nil.
if let vid = vehicle.id {
Text("\(vehicle.year) \(vehicle.make ?? "") \(vehicle.model ?? "")") Text("\(vehicle.year) \(vehicle.make ?? "") \(vehicle.model ?? "")")
.tag(vid as UUID?) .tag(vehicle.id)
} else {
// If id is nil, you can still show the row but tag with nil.
Text("\(vehicle.year) \(vehicle.make ?? "") \(vehicle.model ?? "")")
.tag(nil as UUID?)
}
} }
} }
.pickerStyle(MenuPickerStyle()) .pickerStyle(MenuPickerStyle())
} }
// Fuel Logs Section (filtered by selected vehicle)
ForEach(filteredFuelLogs.indices, id: \.self) { index in ForEach(filteredFuelLogs.indices, id: \.self) { index in
let log = filteredFuelLogs[index] let log = filteredFuelLogs[index]
let distance: Double? = { let distance: Double? = {
@ -96,6 +86,8 @@ struct FuelLogListView: View {
return milesDriven > 0 ? milesDriven : nil return milesDriven > 0 ? milesDriven : nil
}() }()
let mpg: Double? = { let mpg: Double? = {
// Only calculate MPG if fullTank is true.
guard log.fullTank else { return nil }
guard index < filteredFuelLogs.count - 1 else { return nil } guard index < filteredFuelLogs.count - 1 else { return nil }
let previousLog = filteredFuelLogs[index + 1] let previousLog = filteredFuelLogs[index + 1]
let milesDriven = log.odometer - previousLog.odometer let milesDriven = log.odometer - previousLog.odometer
@ -139,7 +131,6 @@ struct FuelLogListView: View {
} }
} }
// Set default vehicle selection on appear.
private func setDefaultVehicle() { private func setDefaultVehicle() {
if selectedVehicleID == nil { if selectedVehicleID == nil {
if let lastFuelLog = fuelLogs.first, let vehicle = lastFuelLog.vehicle { if let lastFuelLog = fuelLogs.first, let vehicle = lastFuelLog.vehicle {