diff --git a/Gas Man.xcodeproj/project.pbxproj b/Gas Man.xcodeproj/project.pbxproj
index eacb89c..1b1ed6d 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 = 202503190946;
+ CURRENT_PROJECT_VERSION = 202503191007;
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 = 202503190946;
+ CURRENT_PROJECT_VERSION = 202503191007;
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 070d653..810c8ad 100644
--- a/Gas Man/AddFuelLogView.swift
+++ b/Gas Man/AddFuelLogView.swift
@@ -8,6 +8,35 @@
import SwiftUI
import CoreData
+// Helper function to check if a string is properly formatted (e.g., "18.526")
+func isProperlyFormatted(_ input: String) -> Bool {
+ let pattern = #"^\d+\.\d{3}$"#
+ return input.range(of: pattern, options: .regularExpression) != nil
+}
+
+// helper function to format input.
+func formatInput(_ input: String) -> String {
+ // Extract only numeric characters.
+ let digitsOnly = input.filter { $0.isNumber }
+ // If no digits, return empty.
+ guard !digitsOnly.isEmpty else { return "" }
+ // Convert to an integer to remove any leading zeros.
+ let numberValue = Int(digitsOnly) ?? 0
+ // Convert back to a string.
+ let digits = String(numberValue)
+
+ if digits.count > 3 {
+ // Insert decimal point so that the last 3 digits are decimals.
+ let integerPart = digits.dropLast(3)
+ let decimalPart = digits.suffix(3)
+ return "\(integerPart).\(decimalPart)"
+ } else {
+ // If fewer than 4 digits, pad with zeros on the left to 3 digits.
+ let padded = String(repeating: "0", count: 3 - digits.count) + digits
+ return "0." + padded
+ }
+}
+
struct AddFuelLogView: View {
@Environment(\.managedObjectContext) private var viewContext
@Environment(\.dismiss) var dismiss
@@ -59,26 +88,53 @@ struct AddFuelLogView: View {
Text("Odometer:")
TextField("", text: $odometer)
.keyboardType(.decimalPad)
+ .multilineTextAlignment(.trailing)
}
HStack {
Text("Gallons:")
TextField("", text: $fuelVolume)
.keyboardType(.decimalPad)
- .onChange(of: fuelVolume) { _ in updateCalculatedValues() }
+ .multilineTextAlignment(.trailing)
+ .onChange(of: fuelVolume) { newValue in
+ // Only reformat if the input is not already in the proper format.
+// if newValue.contains(".") { return }
+ let pattern = #"^\d+\.\d{3}$"#
+ if newValue.range(of: pattern, options: .regularExpression) != nil {
+ return
+ }
+ let formatted = formatInput(newValue)
+ if formatted != newValue {
+ fuelVolume = formatted
+ }
+ updateCalculatedValues()
+ }
}
HStack {
Text("Price/Gal:")
TextField("", text: $pricePerGalon)
.keyboardType(.decimalPad)
- .onChange(of: pricePerGalon) { _ in updateCalculatedValues() }
+ .multilineTextAlignment(.trailing)
+ .onChange(of: pricePerGalon) { newValue in
+// if newValue.contains(".") { return }
+ let pattern = #"^\d+\.\d{3}$"#
+ if newValue.range(of: pattern, options: .regularExpression) != nil {
+ return
+ }
+ let formatted = formatInput(newValue)
+ if formatted != newValue {
+ pricePerGalon = formatted
+ }
+ updateCalculatedValues()
+ }
}
HStack {
Text("Cost:")
TextField("", text: $cost)
.keyboardType(.decimalPad)
+ .multilineTextAlignment(.trailing)
.onChange(of: cost) { _ in updateCalculatedValues() }
}
@@ -94,8 +150,8 @@ struct AddFuelLogView: View {
Text("Coordinates: \(locationCoordinates)")
}
- TextField("Location Coordinates", text: $locationCoordinates)
TextField("Location Name", text: $locationName)
+ .multilineTextAlignment(.trailing)
Picker("Octane", selection: $selectedOctane) {
ForEach(octaneOptions, id: \.self) { option in
@@ -108,7 +164,7 @@ struct AddFuelLogView: View {
Section(header: Text("Vehicle")) {
Picker("Select Vehicle", selection: $selectedVehicleID) {
ForEach(vehicles, id: \.id) { vehicle in
- Text("\(vehicle.year) \(vehicle.make ?? "") \(vehicle.model ?? "")")
+ Text("\(vehicle.year ?? "") \(vehicle.make ?? "") \(vehicle.model ?? "")")
.tag(vehicle.id)
}
}
diff --git a/Gas Man/AddVehicleView.swift b/Gas Man/AddVehicleView.swift
index 23d937f..289c299 100644
--- a/Gas Man/AddVehicleView.swift
+++ b/Gas Man/AddVehicleView.swift
@@ -139,7 +139,7 @@ struct AddVehicleView: View {
private func saveVehicle() {
let newVehicle = Vehicle(context: viewContext)
newVehicle.id = UUID()
- newVehicle.year = Int16(year) ?? 0
+ newVehicle.year = year
newVehicle.make = make
newVehicle.model = model
newVehicle.color = color
diff --git a/Gas Man/EditVehicleView.swift b/Gas Man/EditVehicleView.swift
index 2c96b0d..a2cb2ee 100644
--- a/Gas Man/EditVehicleView.swift
+++ b/Gas Man/EditVehicleView.swift
@@ -136,7 +136,7 @@ struct EditVehicleView: View {
private func loadVehicleData() {
// Basic Information
- year = "\(vehicle.year)"
+ year = vehicle.year ?? ""
make = vehicle.make ?? ""
model = vehicle.model ?? ""
color = vehicle.color ?? ""
@@ -218,7 +218,7 @@ struct EditVehicleView: View {
}
private func saveChanges() {
- vehicle.year = Int16(year) ?? 0
+ vehicle.year = year
vehicle.make = make
vehicle.model = model
vehicle.color = color
diff --git a/Gas Man/FuelLogDetailView.swift b/Gas Man/FuelLogDetailView.swift
index f9456b9..377c362 100644
--- a/Gas Man/FuelLogDetailView.swift
+++ b/Gas Man/FuelLogDetailView.swift
@@ -22,7 +22,7 @@ struct FuelLogDetailView: View {
// Vehicle header section
if let vehicle = fuelLog.vehicle {
Section {
- Text("\(vehicle.year) \(vehicle.model ?? "")")
+ Text("\(vehicle.year ?? "") \(vehicle.model ?? "")")
.font(.headline)
.frame(maxWidth: .infinity, alignment: .center)
}
diff --git a/Gas Man/FuelLogListView.swift b/Gas Man/FuelLogListView.swift
index d5e3629..5f21378 100644
--- a/Gas Man/FuelLogListView.swift
+++ b/Gas Man/FuelLogListView.swift
@@ -70,7 +70,7 @@ struct FuelLogListView: View {
Section {
Picker("Vehicle", selection: $selectedVehicleID) {
ForEach(vehicles, id: \.id) { vehicle in
- Text("\(vehicle.year) \(vehicle.make ?? "") \(vehicle.model ?? "")")
+ Text("\(vehicle.year ?? "") \(vehicle.make ?? "") \(vehicle.model ?? "")")
.tag(vehicle.id)
}
}
diff --git a/Gas Man/Gas_Man.xcdatamodeld/Gas_Man.xcdatamodel/contents b/Gas Man/Gas_Man.xcdatamodeld/Gas_Man.xcdatamodel/contents
index dbb6761..bf0faf0 100644
--- a/Gas Man/Gas_Man.xcdatamodeld/Gas_Man.xcdatamodel/contents
+++ b/Gas Man/Gas_Man.xcdatamodeld/Gas_Man.xcdatamodel/contents
@@ -48,7 +48,7 @@
-
+
\ No newline at end of file
diff --git a/Gas Man/Persistence.swift b/Gas Man/Persistence.swift
index 535289a..f029a24 100644
--- a/Gas Man/Persistence.swift
+++ b/Gas Man/Persistence.swift
@@ -15,6 +15,7 @@ struct PersistenceController {
init(inMemory: Bool = false) {
// "GasMan" must match the name of your .xcdatamodeld file.
container = NSPersistentCloudKitContainer(name: "Gas_Man")
+
if inMemory {
container.persistentStoreDescriptions.first?.url = URL(fileURLWithPath: "/dev/null")
diff --git a/Gas Man/Vehicle.swift b/Gas Man/Vehicle.swift
index 9994c50..5d2249c 100644
--- a/Gas Man/Vehicle.swift
+++ b/Gas Man/Vehicle.swift
@@ -25,7 +25,7 @@ extension Vehicle: Identifiable {
id ?? UUID()
}
- @NSManaged public var year: Int16
+ @NSManaged public var year: String?
@NSManaged public var make: String?
@NSManaged public var model: String?
@NSManaged public var color: String?
diff --git a/Gas Man/VehicleDetailView.swift b/Gas Man/VehicleDetailView.swift
index 68f90c3..74259a2 100644
--- a/Gas Man/VehicleDetailView.swift
+++ b/Gas Man/VehicleDetailView.swift
@@ -26,7 +26,7 @@ struct VehicleDetailView: View {
HStack {
Text("Year:")
Spacer()
- Text("\(vehicle.year)")
+ Text(vehicle.year ?? "")
}
HStack {
Text("Make:")
diff --git a/Gas Man/VehicleRowView.swift b/Gas Man/VehicleRowView.swift
index f6c70f2..edae2c8 100644
--- a/Gas Man/VehicleRowView.swift
+++ b/Gas Man/VehicleRowView.swift
@@ -13,7 +13,7 @@ struct VehicleRowView: View {
var body: some View {
VStack(alignment: .leading) {
- Text("\(vehicle.year) \(vehicle.make ?? "") \(vehicle.model ?? "")")
+ Text("\(vehicle.year ?? "") \(vehicle.make ?? "") \(vehicle.model ?? "")")
.font(.headline)
Text(vehicle.color ?? "")
.font(.subheadline)