diff --git a/Gastrack_icon.png b/Gastrack_icon.png new file mode 100644 index 0000000..245bf27 Binary files /dev/null and b/Gastrack_icon.png differ diff --git a/Gastrack_icon.pxd b/Gastrack_icon.pxd new file mode 100644 index 0000000..1b68819 Binary files /dev/null and b/Gastrack_icon.pxd differ diff --git a/Gastrack_icon_bw.png b/Gastrack_icon_bw.png new file mode 100644 index 0000000..828318a Binary files /dev/null and b/Gastrack_icon_bw.png differ diff --git a/Gastrack_icon_transparent.png b/Gastrack_icon_transparent.png new file mode 100644 index 0000000..7260c70 Binary files /dev/null and b/Gastrack_icon_transparent.png differ diff --git a/gastrack/Assets.xcassets/AppIcon.appiconset/Contents.json b/gastrack/Assets.xcassets/AppIcon.appiconset/Contents.json index 2305880..94edb3b 100644 --- a/gastrack/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/gastrack/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,6 +1,7 @@ { "images" : [ { + "filename" : "Gastrack_icon.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" @@ -12,6 +13,7 @@ "value" : "dark" } ], + "filename" : "Gastrack_icon_transparent.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" @@ -23,6 +25,7 @@ "value" : "tinted" } ], + "filename" : "Gastrack_icon_bw.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" diff --git a/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon.png b/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon.png new file mode 100644 index 0000000..245bf27 Binary files /dev/null and b/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon.png differ diff --git a/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon_bw.png b/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon_bw.png new file mode 100644 index 0000000..828318a Binary files /dev/null and b/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon_bw.png differ diff --git a/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon_transparent.png b/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon_transparent.png new file mode 100644 index 0000000..7260c70 Binary files /dev/null and b/gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon_transparent.png differ diff --git a/gastrack/ContentView.swift b/gastrack/ContentView.swift index 1d5ddca..b87908d 100644 --- a/gastrack/ContentView.swift +++ b/gastrack/ContentView.swift @@ -16,9 +16,9 @@ struct ContentView: View { var body: some View { NavigationSplitView { - List { + ScrollView { ForEach(entries) { e in - Text("Entry: \(e.odo)") + EntryCardView(entry: e) } } .sheet(isPresented: $addEntry) { @@ -28,14 +28,16 @@ struct ContentView: View { } .toolbar { ToolbarItem(placement: .bottomBar) { - Text("") + Button(action: addItem) { + Label("Add Item", systemImage: "plus.circle.fill") + } } ToolbarItem(placement: .status) { Text("Placeholder") .frame(alignment: .center) } ToolbarItem(placement: .bottomBar) { - Button(action: addItem) { + Button(action: { addEntry.toggle() }) { Label("Add Item", systemImage: "plus") } } @@ -46,12 +48,11 @@ struct ContentView: View { } private func addItem() { - addEntry.toggle() -// withAnimation { -// let newItem = Entry(odo: 75239, cost: 92.19, quantity: 36.34, fuelType: "91") -// modelContext.insert(newItem) -// try? modelContext.save() -// } + withAnimation { + let newItem = Entry(odo: 75239, cost: 92.19, quantity: 36.34, fuelType: "91") + modelContext.insert(newItem) + try? modelContext.save() + } } private func deleteItems(offsets: IndexSet) { diff --git a/gastrack/Entry.swift b/gastrack/Entry.swift index 6aad292..d0d7f49 100644 --- a/gastrack/Entry.swift +++ b/gastrack/Entry.swift @@ -12,16 +12,22 @@ import SwiftData final class Entry { var id: UUID + var date: Date var odo: Int var cost: Double var quantity: Double var fuelType: String - public init(odo: Int, cost: Double, quantity: Double, fuelType: String) { + public init(date: Date = Date(), odo: Int, cost: Double, quantity: Double, fuelType: String) { self.id = UUID() + self.date = date self.odo = odo self.cost = cost self.quantity = quantity self.fuelType = fuelType } + + public func getFormattedDate() -> String { + return self.date.formatted(date: .numeric, time: .omitted) + } } diff --git a/gastrack/EntryCardView.swift b/gastrack/EntryCardView.swift new file mode 100644 index 0000000..744533b --- /dev/null +++ b/gastrack/EntryCardView.swift @@ -0,0 +1,34 @@ +// +// EntryCardView.swift +// gastrack +// +// Created by Pradyun Setti on 24/02/2025. +// + +import SwiftUI + +struct EntryCardView: View { + let entry: Entry + + var body: some View { + HStack { + VStack(alignment: .leading) { + Text(entry.getFormattedDate()) + .font(.system(.caption, design: .default, weight: .medium)) + Text(String(format: "$%.2f", entry.cost)) + .font(.system(.headline, design: .default, weight: .bold)) + .foregroundStyle(.green) + Text(String(format: "%.3f L", entry.quantity)) + } + Spacer() + } + .padding() + .background(Color.secondary.opacity(0.3)) + .clipShape(RoundedRectangle(cornerRadius: 12)) + .padding(.horizontal) + } +} + +//#Preview { +// EntryCardView() +//}