From 07e8581ee2e1465e6c53ed90aa0730127794e234 Mon Sep 17 00:00:00 2001 From: Kameron Kenny Date: Wed, 19 Mar 2025 10:06:32 -0400 Subject: [PATCH] add full tank indicator --- Gas Man.xcodeproj/project.pbxproj | 4 ++-- Gas Man/AddFuelLogView.swift | 11 ++++++++--- Gas Man/FuelLogDetailView.swift | 16 ++++++++++++++++ Gas Man/FuelLogListView.swift | 19 +++++-------------- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Gas Man.xcodeproj/project.pbxproj b/Gas Man.xcodeproj/project.pbxproj index 1451144..eacb89c 100644 --- a/Gas Man.xcodeproj/project.pbxproj +++ b/Gas Man.xcodeproj/project.pbxproj @@ -289,7 +289,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = "Gas Man/Gas_Man.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 202503181111; + CURRENT_PROJECT_VERSION = 202503190946; DEVELOPMENT_ASSET_PATHS = "\"Gas Man/Preview Content\""; DEVELOPMENT_TEAM = Z734T5CD6B; ENABLE_HARDENED_RUNTIME = YES; @@ -332,7 +332,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = "Gas Man/Gas_Man.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 202503181111; + CURRENT_PROJECT_VERSION = 202503190946; DEVELOPMENT_ASSET_PATHS = "\"Gas Man/Preview Content\""; DEVELOPMENT_TEAM = Z734T5CD6B; ENABLE_HARDENED_RUNTIME = YES; diff --git a/Gas Man/AddFuelLogView.swift b/Gas Man/AddFuelLogView.swift index 1c39a59..070d653 100644 --- a/Gas Man/AddFuelLogView.swift +++ b/Gas Man/AddFuelLogView.swift @@ -21,6 +21,8 @@ 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 // Allowed octane options let octaneOptions = [87, 89, 91, 92, 93, 95] @@ -80,6 +82,10 @@ struct AddFuelLogView: View { .onChange(of: cost) { _ in updateCalculatedValues() } } + // New Full Tank toggle + Toggle("Full Tank", isOn: $fullTank) + .toggleStyle(SwitchToggleStyle(tint: .blue)) + Button("Get Current Location") { locationManager.requestLocation() } @@ -204,7 +210,6 @@ struct AddFuelLogView: View { fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] fetchRequest.fetchLimit = 1 if let lastFuelLog = try? viewContext.fetch(fetchRequest).first { - // Compare against the latest fuel log's odometer. if newOdometer <= lastFuelLog.odometer { showOdometerAlert = true return @@ -221,8 +226,9 @@ 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 - // Set the vehicle relationship if a vehicle was selected: if let vehicleID = selectedVehicleID, let selectedVehicle = vehicles.first(where: { $0.id == vehicleID }) { newLog.vehicle = selectedVehicle @@ -237,5 +243,4 @@ struct AddFuelLogView: View { fatalError("Unresolved error \(nsError), \(nsError.userInfo)") } } - } diff --git a/Gas Man/FuelLogDetailView.swift b/Gas Man/FuelLogDetailView.swift index cca6550..f9456b9 100644 --- a/Gas Man/FuelLogDetailView.swift +++ b/Gas Man/FuelLogDetailView.swift @@ -57,6 +57,22 @@ struct FuelLogDetailView: View { 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")) { HStack { Text("Coordinates:") diff --git a/Gas Man/FuelLogListView.swift b/Gas Man/FuelLogListView.swift index ba88bac..d5e3629 100644 --- a/Gas Man/FuelLogListView.swift +++ b/Gas Man/FuelLogListView.swift @@ -47,7 +47,6 @@ struct FuelLogListView: View { var body: some View { NavigationView { if vehicles.isEmpty { - // Empty state: no vehicles exist. VStack(spacing: 20) { Text("No vehicles found.") .font(.headline) @@ -68,25 +67,16 @@ struct FuelLogListView: View { } } else { List { - // Vehicle Picker Section Section { Picker("Vehicle", selection: $selectedVehicleID) { - ForEach(vehicles, id: \.objectID) { vehicle in - // Only tag if vehicle.id is not nil. - if let vid = vehicle.id { - Text("\(vehicle.year) \(vehicle.make ?? "") \(vehicle.model ?? "")") - .tag(vid as UUID?) - } 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?) - } + ForEach(vehicles, id: \.id) { vehicle in + Text("\(vehicle.year) \(vehicle.make ?? "") \(vehicle.model ?? "")") + .tag(vehicle.id) } } .pickerStyle(MenuPickerStyle()) } - // Fuel Logs Section (filtered by selected vehicle) ForEach(filteredFuelLogs.indices, id: \.self) { index in let log = filteredFuelLogs[index] let distance: Double? = { @@ -96,6 +86,8 @@ struct FuelLogListView: View { return milesDriven > 0 ? milesDriven : nil }() let mpg: Double? = { + // Only calculate MPG if fullTank is true. + guard log.fullTank else { return nil } guard index < filteredFuelLogs.count - 1 else { return nil } let previousLog = filteredFuelLogs[index + 1] let milesDriven = log.odometer - previousLog.odometer @@ -139,7 +131,6 @@ struct FuelLogListView: View { } } - // Set default vehicle selection on appear. private func setDefaultVehicle() { if selectedVehicleID == nil { if let lastFuelLog = fuelLogs.first, let vehicle = lastFuelLog.vehicle {