diff --git a/Gas Man/FuelLogs/AddFuelLogView.swift b/Gas Man/FuelLogs/AddFuelLogView.swift index cc1f8c6..99506a6 100644 --- a/Gas Man/FuelLogs/AddFuelLogView.swift +++ b/Gas Man/FuelLogs/AddFuelLogView.swift @@ -23,9 +23,9 @@ struct AddFuelLogView: View { @State private var locationName = "" @State private var selectedOctane: Int = 87 // Default or from previous record @State private var pricePerGalon = "" - // New Full Tank toggle; default is on (true) @State private var fullTank: Bool = true - + @State private var missedPrevious: Bool = false + // Allowed octane options let octaneOptions = [87, 89, 91, 92, 93, 95] @@ -115,6 +115,9 @@ struct AddFuelLogView: View { Toggle("Full Tank", isOn: $fullTank) .toggleStyle(SwitchToggleStyle(tint: .blue)) + Toggle("Missed Previous Fill-up", isOn: $missedPrevious) + .toggleStyle(SwitchToggleStyle(tint: .blue)) + Button("Get Current Location") { locationManager.requestLocation() } @@ -255,8 +258,8 @@ struct AddFuelLogView: View { newLog.locationName = locationName newLog.octane = Int16(selectedOctane) newLog.pricePerGalon = Double(pricePerGalon) ?? 0 - // Set the fullTank property from the toggle: newLog.fullTank = fullTank + newLog.missedPrevious = missedPrevious if let vehicleID = selectedVehicleID, let selectedVehicle = vehicles.first(where: { $0.id == vehicleID }) { diff --git a/Gas Man/FuelLogs/EditFuelLogView.swift b/Gas Man/FuelLogs/EditFuelLogView.swift index 571a3ea..71d28ed 100644 --- a/Gas Man/FuelLogs/EditFuelLogView.swift +++ b/Gas Man/FuelLogs/EditFuelLogView.swift @@ -24,8 +24,8 @@ struct EditFuelLogView: View { @State private var locationName = "" @State private var selectedOctane: Int = 87 @State private var pricePerGalon = "" - // Full Tank toggle @State private var fullTank: Bool = true + @State private var missedPrevious: Bool = false // Allowed octane options let octaneOptions = [87, 89, 91, 92, 93, 95] @@ -89,6 +89,9 @@ struct EditFuelLogView: View { Toggle("Full Tank", isOn: $fullTank) .toggleStyle(SwitchToggleStyle(tint: .blue)) + Toggle("Missed Previous Fill-up", isOn: $missedPrevious) + .toggleStyle(SwitchToggleStyle(tint: .blue)) + Button("Get Current Location") { // Optionally trigger location update } @@ -130,6 +133,7 @@ struct EditFuelLogView: View { cost = String(format: "%.2f", fuelLog.cost) pricePerGalon = String(format: "%.3f", fuelLog.pricePerGalon) fullTank = fuelLog.fullTank + missedPrevious = fuelLog.missedPrevious locationCoordinates = fuelLog.locationCoordinates ?? "" locationName = fuelLog.locationName ?? "" selectedOctane = Int(fuelLog.octane) @@ -187,6 +191,7 @@ struct EditFuelLogView: View { fuelLog.octane = Int16(selectedOctane) fuelLog.pricePerGalon = Double(pricePerGalon) ?? 0 fuelLog.fullTank = fullTank + fuelLog.missedPrevious = missedPrevious do { try viewContext.save() diff --git a/Gas Man/FuelLogs/FuelLogDetailView.swift b/Gas Man/FuelLogs/FuelLogDetailView.swift index ad5bd64..d2d58c0 100644 --- a/Gas Man/FuelLogs/FuelLogDetailView.swift +++ b/Gas Man/FuelLogs/FuelLogDetailView.swift @@ -73,6 +73,21 @@ struct FuelLogDetailView: View { } } } + Section { + HStack { + Text("Previous Fill-Up") + Spacer() + if fuelLog.missedPrevious { + Image(systemName: "xmark.circle.fill") + .foregroundColor(.red) + Text("Missed") + } else { + Image(systemName: "checkmark.circle.fill") + .foregroundColor(.green) + Text("Exists") + } + } + } Section(header: Text("Location")) { HStack { Text("Coordinates:") diff --git a/Gas Man/FuelLogs/FuelLogListView.swift b/Gas Man/FuelLogs/FuelLogListView.swift index 52b1ae3..890e16e 100644 --- a/Gas Man/FuelLogs/FuelLogListView.swift +++ b/Gas Man/FuelLogs/FuelLogListView.swift @@ -57,7 +57,7 @@ struct FuelLogListView: View { let current = logs[i] let next = logs[i + 1] // Only include if fullTank is true, fuelVolume is positive, and odometer difference is positive. - if current.fullTank, current.fuelVolume > 0, current.odometer > next.odometer { + if current.fullTank, !current.missedPrevious, current.fuelVolume > 0, current.odometer > next.odometer { let mpg = (current.odometer - next.odometer) / current.fuelVolume mpgValues.append(mpg) } @@ -152,6 +152,7 @@ struct FuelLogListView: View { let mpg: Double? = { // Only calculate MPG if fullTank is true. guard log.fullTank else { return nil } + guard !log.missedPrevious else { return nil } guard index < filteredFuelLogs.count - 1 else { return nil } let previousLog = filteredFuelLogs[index + 1] let milesDriven = log.odometer - previousLog.odometer diff --git a/Gas Man/Gas_Man.xcdatamodeld/Gas_Man.xcdatamodel/contents b/Gas Man/Gas_Man.xcdatamodeld/Gas_Man.xcdatamodel/contents index d184a86..d237e25 100644 --- a/Gas Man/Gas_Man.xcdatamodeld/Gas_Man.xcdatamodel/contents +++ b/Gas Man/Gas_Man.xcdatamodeld/Gas_Man.xcdatamodel/contents @@ -8,6 +8,7 @@ + diff --git a/Gas Man/Stats/MPGTrendChartView.swift b/Gas Man/Stats/MPGTrendChartView.swift index 56c2f59..b85eb3a 100644 --- a/Gas Man/Stats/MPGTrendChartView.swift +++ b/Gas Man/Stats/MPGTrendChartView.swift @@ -14,7 +14,7 @@ struct MPGTrendChartView: View { for i in 1.. previous.odometer, current.fuelVolume > 0 { let mpg = (current.odometer - previous.odometer) / current.fuelVolume diff --git a/Gas Man/Stats/StatsView.swift b/Gas Man/Stats/StatsView.swift index ab43ba6..bd5db4a 100644 --- a/Gas Man/Stats/StatsView.swift +++ b/Gas Man/Stats/StatsView.swift @@ -49,7 +49,7 @@ struct StatsView: View { for i in 0.. 0, current.odometer > next.odometer { + if current.fullTank, !current.missedPrevious, current.fuelVolume > 0, current.odometer > next.odometer { let mpg = (current.odometer - next.odometer) / current.fuelVolume mpgValues.append(mpg) }