Compare commits
2 Commits
953a064de6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7c99b5ac5
|
||
|
|
63eacbb378
|
BIN
Gastrack_icon.png
Normal file
BIN
Gastrack_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
BIN
Gastrack_icon.pxd
Normal file
BIN
Gastrack_icon.pxd
Normal file
Binary file not shown.
BIN
Gastrack_icon_bw.png
Normal file
BIN
Gastrack_icon_bw.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
BIN
Gastrack_icon_transparent.png
Normal file
BIN
Gastrack_icon_transparent.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
@@ -8,6 +8,9 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct AddEntryView: View {
|
struct AddEntryView: View {
|
||||||
|
@Environment(\.presentationMode) var presentationMode
|
||||||
|
@Environment(\.modelContext) var ctx
|
||||||
|
|
||||||
@State private var t1: String = ""
|
@State private var t1: String = ""
|
||||||
@State private var t2: String = ""
|
@State private var t2: String = ""
|
||||||
|
|
||||||
@@ -42,16 +45,30 @@ struct AddEntryView: View {
|
|||||||
.navigationTitle("New Entry")
|
.navigationTitle("New Entry")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .cancellationAction) {
|
ToolbarItem(placement: .cancellationAction) {
|
||||||
Button("Cancel") {}
|
Button(action: { presentationMode.wrappedValue.dismiss() }) {
|
||||||
|
Text("Cancel")
|
||||||
|
.foregroundStyle(.red)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ToolbarItem(placement: .confirmationAction) {
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
Button("Confirm") {
|
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 {
|
#Preview {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
|
"filename" : "Gastrack_icon.png",
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"platform" : "ios",
|
"platform" : "ios",
|
||||||
"size" : "1024x1024"
|
"size" : "1024x1024"
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
"value" : "dark"
|
"value" : "dark"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"filename" : "Gastrack_icon_transparent.png",
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"platform" : "ios",
|
"platform" : "ios",
|
||||||
"size" : "1024x1024"
|
"size" : "1024x1024"
|
||||||
@@ -23,6 +25,7 @@
|
|||||||
"value" : "tinted"
|
"value" : "tinted"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"filename" : "Gastrack_icon_bw.png",
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"platform" : "ios",
|
"platform" : "ios",
|
||||||
"size" : "1024x1024"
|
"size" : "1024x1024"
|
||||||
|
|||||||
BIN
gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon.png
Normal file
BIN
gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
BIN
gastrack/Assets.xcassets/AppIcon.appiconset/Gastrack_icon_bw.png
Normal file
BIN
gastrack/Assets.xcassets/AppIcon.appiconset/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 |
@@ -16,9 +16,9 @@ struct ContentView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
List {
|
ScrollView {
|
||||||
ForEach(entries) { e in
|
ForEach(entries) { e in
|
||||||
Text("Entry: \(e.odo)")
|
EntryCardView(entry: e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $addEntry) {
|
.sheet(isPresented: $addEntry) {
|
||||||
@@ -28,14 +28,16 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .bottomBar) {
|
ToolbarItem(placement: .bottomBar) {
|
||||||
Text("")
|
Button(action: addItem) {
|
||||||
|
Label("Add Item", systemImage: "plus.circle.fill")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ToolbarItem(placement: .status) {
|
ToolbarItem(placement: .status) {
|
||||||
Text("Placeholder")
|
Text("Placeholder")
|
||||||
.frame(alignment: .center)
|
.frame(alignment: .center)
|
||||||
}
|
}
|
||||||
ToolbarItem(placement: .bottomBar) {
|
ToolbarItem(placement: .bottomBar) {
|
||||||
Button(action: addItem) {
|
Button(action: { addEntry.toggle() }) {
|
||||||
Label("Add Item", systemImage: "plus")
|
Label("Add Item", systemImage: "plus")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,12 +48,11 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func addItem() {
|
private func addItem() {
|
||||||
addEntry.toggle()
|
withAnimation {
|
||||||
// withAnimation {
|
let newItem = Entry(odo: 75239, cost: 92.19, quantity: 36.34, fuelType: "91")
|
||||||
// let newItem = Entry(odo: 75239, cost: 92.19, quantity: 36.34, fuelType: "91")
|
modelContext.insert(newItem)
|
||||||
// modelContext.insert(newItem)
|
try? modelContext.save()
|
||||||
// try? modelContext.save()
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func deleteItems(offsets: IndexSet) {
|
private func deleteItems(offsets: IndexSet) {
|
||||||
|
|||||||
@@ -12,16 +12,22 @@ import SwiftData
|
|||||||
final class Entry {
|
final class Entry {
|
||||||
var id: UUID
|
var id: UUID
|
||||||
|
|
||||||
|
var date: Date
|
||||||
var odo: Int
|
var odo: Int
|
||||||
var cost: Double
|
var cost: Double
|
||||||
var quantity: Double
|
var quantity: Double
|
||||||
var fuelType: String
|
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.id = UUID()
|
||||||
|
self.date = date
|
||||||
self.odo = odo
|
self.odo = odo
|
||||||
self.cost = cost
|
self.cost = cost
|
||||||
self.quantity = quantity
|
self.quantity = quantity
|
||||||
self.fuelType = fuelType
|
self.fuelType = fuelType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func getFormattedDate() -> String {
|
||||||
|
return self.date.formatted(date: .numeric, time: .omitted)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
gastrack/EntryCardView.swift
Normal file
34
gastrack/EntryCardView.swift
Normal 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()
|
||||||
|
//}
|
||||||
Reference in New Issue
Block a user