Compare commits

..

4 Commits

Author SHA1 Message Date
june
d7c99b5ac5 add app icon, starting to do card views 2025-02-24 19:02:35 +13:00
june
63eacbb378 Add button to save 2025-02-23 23:33:34 +13:00
june
953a064de6 Set proper variables for text inputs 2025-02-23 23:26:00 +13:00
june
27adc0bc5a Add new entry view 2025-02-23 23:20:22 +13:00
12 changed files with 146 additions and 7 deletions

BIN
Gastrack_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
Gastrack_icon.pxd Normal file

Binary file not shown.

BIN
Gastrack_icon_bw.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -0,0 +1,83 @@
//
// AddEntryView.swift
// gastrack
//
// Created by Pradyun Setti on 23/02/2025.
//
import SwiftUI
struct AddEntryView: View {
@Environment(\.presentationMode) var presentationMode
@Environment(\.modelContext) var ctx
@State private var t1: String = ""
@State private var t2: String = ""
@State private var Odometer = ""
@State private var CostPerLitre = ""
@State private var Litres = ""
@State private var TotalCost = ""
@State private var FuelType = ""
@State private var Location = ""
var body: some View {
NavigationView {
Form {
HStack() {
Text("Last: \(72398)")
Divider()
TextField("Odometer", text: $Odometer)
}
HStack {
TextField("Cost/L", text: $CostPerLitre)
Divider()
TextField("Litres", text: $Litres)
Divider()
TextField("Total Cost", text: $TotalCost)
}
TextField("Fuel Type", text: $FuelType)
TextField("Location", text: $Location)
}
.navigationTitle("New Entry")
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button(action: { presentationMode.wrappedValue.dismiss() }) {
Text("Cancel")
.foregroundStyle(.red)
}
}
ToolbarItem(placement: .confirmationAction) {
Button(action: addItem) {
Text("Add")
}
}
}
}
}
func addItem() {
let newItem = Entry(
odo: Int(Odometer) ?? 0,
cost: Double(TotalCost) ?? 0,
quantity: Double(Litres) ?? 0,
fuelType: Location
)
ctx.insert(newItem)
try? ctx.save()
}
}
#Preview {
NavigationView {
Text("s")
.sheet(isPresented: Binding(get: {true}, set: {_ in})) {
AddEntryView()
.presentationDetents([.medium])
.presentationCornerRadius(20)
}
}
}

View File

@@ -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"

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -11,20 +11,33 @@ import SwiftData
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var entries: [Entry]
@State private var addEntry = false
var body: some View {
NavigationSplitView {
List {
ScrollView {
ForEach(entries) { e in
Text("Entry: \(e.odo)")
EntryCardView(entry: e)
}
}
.sheet(isPresented: $addEntry) {
AddEntryView()
.presentationDetents([.medium])
.presentationCornerRadius(20)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
ToolbarItem(placement: .bottomBar) {
Button(action: addItem) {
Label("Add Item", systemImage: "plus.circle.fill")
}
}
ToolbarItem(placement: .status) {
Text("Placeholder")
.frame(alignment: .center)
}
ToolbarItem(placement: .bottomBar) {
Button(action: { addEntry.toggle() }) {
Label("Add Item", systemImage: "plus")
}
}

View File

@@ -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)
}
}

View File

@@ -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()
//}