🚧 First draw of Calandar month navigation
This commit is contained in:
20
AboTracker/PersistenceController.swift
Normal file
20
AboTracker/PersistenceController.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
import CoreData
|
||||
|
||||
struct PersistenceController {
|
||||
static let shared = PersistenceController()
|
||||
|
||||
let container: NSPersistentContainer
|
||||
|
||||
init() {
|
||||
container = NSPersistentContainer(name: "SubscriptionModel")
|
||||
container.loadPersistentStores { (storeDescription, error) in
|
||||
if let error = error as NSError? {
|
||||
fatalError("Unresolved error \(error), \(error.userInfo)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var context: NSManagedObjectContext {
|
||||
return container.viewContext
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22758" systemVersion="23F79" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
|
||||
<entity name="Payment" representedClassName="Payment" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="amount" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
|
||||
<attribute name="interval" optional="YES" attributeType="String"/>
|
||||
<attribute name="startDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<relationship name="subscription" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Subscription"/>
|
||||
</entity>
|
||||
<entity name="Subscription" representedClassName="Subscription" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="color" optional="YES" attributeType="Transformable"/>
|
||||
<attribute name="name" optional="YES" attributeType="String"/>
|
||||
<relationship name="payments" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Payment"/>
|
||||
</entity>
|
||||
</model>
|
||||
10
AboTracker/data/Payment+CoreDataClass.swift
Normal file
10
AboTracker/data/Payment+CoreDataClass.swift
Normal file
@@ -0,0 +1,10 @@
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
@objc(Payment)
|
||||
public class Payment: NSManagedObject {
|
||||
@NSManaged public var amount: Double
|
||||
@NSManaged public var interval: String
|
||||
@NSManaged public var startDate: Date
|
||||
@NSManaged public var subscription: Subscription
|
||||
}
|
||||
28
AboTracker/data/Payment+CoreDataProperties.swift
Normal file
28
AboTracker/data/Payment+CoreDataProperties.swift
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Payment+CoreDataProperties.swift
|
||||
// AboTracker
|
||||
//
|
||||
// Created by Keyvan Atashfaraz on 02.07.24.
|
||||
//
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
extension Payment {
|
||||
|
||||
@nonobjc public class func fetchRequest() -> NSFetchRequest<Payment> {
|
||||
return NSFetchRequest<Payment>(entityName: "Payment")
|
||||
}
|
||||
|
||||
@NSManaged public var amount: Double
|
||||
@NSManaged public var interval: String?
|
||||
@NSManaged public var startDate: Date?
|
||||
@NSManaged public var subscription: Subscription?
|
||||
|
||||
}
|
||||
|
||||
extension Payment : Identifiable {
|
||||
|
||||
}
|
||||
10
AboTracker/data/Subscription+CoreDataClass.swift
Normal file
10
AboTracker/data/Subscription+CoreDataClass.swift
Normal file
@@ -0,0 +1,10 @@
|
||||
import Foundation
|
||||
import CoreData
|
||||
import SwiftUI
|
||||
|
||||
@objc(Subscription)
|
||||
public class Subscription: NSManagedObject {
|
||||
@NSManaged public var name: String
|
||||
@NSManaged public var color: UIColor
|
||||
@NSManaged public var payments: Set<Payment>
|
||||
}
|
||||
27
AboTracker/data/Subscription+CoreDataProperties.swift
Normal file
27
AboTracker/data/Subscription+CoreDataProperties.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Subscription+CoreDataProperties.swift
|
||||
// AboTracker
|
||||
//
|
||||
// Created by Keyvan Atashfaraz on 02.07.24.
|
||||
//
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
extension Subscription {
|
||||
|
||||
@nonobjc public class func fetchRequest() -> NSFetchRequest<Subscription> {
|
||||
return NSFetchRequest<Subscription>(entityName: "Subscription")
|
||||
}
|
||||
|
||||
@NSManaged public var name: String?
|
||||
@NSManaged public var color: NSObject?
|
||||
@NSManaged public var payments: Payment?
|
||||
|
||||
}
|
||||
|
||||
extension Subscription : Identifiable {
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ struct PaymentCalendarView: View {
|
||||
let dateFormatter = DateFormatter()
|
||||
|
||||
@State private var currentDate = Date()
|
||||
private let initialDate = Date()
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@@ -13,11 +14,43 @@ struct PaymentCalendarView: View {
|
||||
.font(.title)
|
||||
.padding()
|
||||
|
||||
Text(currentMonthYear())
|
||||
.font(.headline)
|
||||
.padding()
|
||||
HStack {
|
||||
Button(action: {
|
||||
self.currentDate = self.calendar.date(byAdding: .month, value: -1, to: self.currentDate)!
|
||||
}) {
|
||||
Image(systemName: "chevron.left.circle.fill")
|
||||
.font(.title)
|
||||
}
|
||||
|
||||
Button(action: {
|
||||
self.currentDate = self.initialDate
|
||||
}) {
|
||||
Text("Current Month")
|
||||
.font(.headline)
|
||||
}
|
||||
|
||||
Button(action: {
|
||||
self.currentDate = self.calendar.date(byAdding: .month, value: 1, to: self.currentDate)!
|
||||
}) {
|
||||
Image(systemName: "chevron.right.circle.fill")
|
||||
.font(.title)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
calendarView()
|
||||
.gesture(
|
||||
DragGesture()
|
||||
.onEnded { gesture in
|
||||
if gesture.translation.width < 0 {
|
||||
// Swipe left -> move to next month
|
||||
self.currentDate = self.calendar.date(byAdding: .month, value: 1, to: self.currentDate)!
|
||||
} else {
|
||||
// Swipe right -> move to previous month
|
||||
self.currentDate = self.calendar.date(byAdding: .month, value: -1, to: self.currentDate)!
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
@@ -77,7 +110,6 @@ struct PaymentCalendarView: View {
|
||||
return date >= startOfWeek && date <= endOfWeek && calendar.component(.weekday, from: payment.startDate) == calendar.component(.weekday, from: date)
|
||||
|
||||
case .monthly:
|
||||
// ToDo: Payment not visible if Payment is at example at 31th of month, but month only has 30 days
|
||||
return calendar.component(.day, from: payment.startDate) == calendar.component(.day, from: date)
|
||||
|
||||
case .quarter:
|
||||
|
||||
Reference in New Issue
Block a user