Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions CoffeeTracker/CoffeeTracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
371E297327C40FEF00C8ACBF /* BeansCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371E297227C40FEF00C8ACBF /* BeansCollectionView.swift */; };
371E297527C4100900C8ACBF /* NewBeansView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371E297427C4100900C8ACBF /* NewBeansView.swift */; };
3782E03527C4AA81000F0404 /* BeansCollectionViewOO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3782E03427C4AA81000F0404 /* BeansCollectionViewOO.swift */; };
37B776A627C67A6F00EFD566 /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 37B776A527C67A6F00EFD566 /* CloudKit.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
371E294B27C40D2100C8ACBF /* Coffee+.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Coffee+.app"; sourceTree = BUILT_PRODUCTS_DIR; };
371E294B27C40D2100C8ACBF /* Coffee_.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Coffee_.app; sourceTree = BUILT_PRODUCTS_DIR; };
371E294E27C40D2100C8ACBF /* CoffeeTrackerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoffeeTrackerApp.swift; sourceTree = "<group>"; };
371E295027C40D2100C8ACBF /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
371E295227C40D2200C8ACBF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -41,13 +42,17 @@
371E297227C40FEF00C8ACBF /* BeansCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeansCollectionView.swift; sourceTree = "<group>"; };
371E297427C4100900C8ACBF /* NewBeansView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewBeansView.swift; sourceTree = "<group>"; };
3782E03427C4AA81000F0404 /* BeansCollectionViewOO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeansCollectionViewOO.swift; sourceTree = "<group>"; };
37B776A327C67A6B00EFD566 /* CoffeeTracker.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CoffeeTracker.entitlements; sourceTree = "<group>"; };
37B776A527C67A6F00EFD566 /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
37B776A727C67A7800EFD566 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
371E294827C40D2100C8ACBF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
37B776A627C67A6F00EFD566 /* CloudKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -59,20 +64,23 @@
children = (
371E294D27C40D2100C8ACBF /* CoffeeTracker */,
371E294C27C40D2100C8ACBF /* Products */,
37B776A427C67A6F00EFD566 /* Frameworks */,
);
sourceTree = "<group>";
};
371E294C27C40D2100C8ACBF /* Products */ = {
isa = PBXGroup;
children = (
371E294B27C40D2100C8ACBF /* Coffee+.app */,
371E294B27C40D2100C8ACBF /* Coffee_.app */,
);
name = Products;
sourceTree = "<group>";
};
371E294D27C40D2100C8ACBF /* CoffeeTracker */ = {
isa = PBXGroup;
children = (
37B776A727C67A7800EFD566 /* Info.plist */,
37B776A327C67A6B00EFD566 /* CoffeeTracker.entitlements */,
371E296F27C40FA600C8ACBF /* Fixtures */,
371E296A27C40F5400C8ACBF /* Helpers */,
371E296327C40EA500C8ACBF /* Beans */,
Expand Down Expand Up @@ -124,6 +132,14 @@
path = Fixtures;
sourceTree = "<group>";
};
37B776A427C67A6F00EFD566 /* Frameworks */ = {
isa = PBXGroup;
children = (
37B776A527C67A6F00EFD566 /* CloudKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -141,7 +157,7 @@
);
name = CoffeeTracker;
productName = CoffeeTracker;
productReference = 371E294B27C40D2100C8ACBF /* Coffee+.app */;
productReference = 371E294B27C40D2100C8ACBF /* Coffee_.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand Down Expand Up @@ -334,12 +350,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = CoffeeTracker/CoffeeTracker.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"CoffeeTracker/Preview Content\"";
DEVELOPMENT_TEAM = ZDK82FGR3Z;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = CoffeeTracker/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand All @@ -352,7 +370,7 @@
);
MARKETING_VERSION = 0.1;
PRODUCT_BUNDLE_IDENTIFIER = dev.cctplus.CoffeeTracker;
PRODUCT_NAME = "Coffee+";
PRODUCT_NAME = Coffee_;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand All @@ -364,12 +382,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = CoffeeTracker/CoffeeTracker.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"CoffeeTracker/Preview Content\"";
DEVELOPMENT_TEAM = ZDK82FGR3Z;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = CoffeeTracker/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand All @@ -382,7 +402,7 @@
);
MARKETING_VERSION = 0.1;
PRODUCT_BUNDLE_IDENTIFIER = dev.cctplus.CoffeeTracker;
PRODUCT_NAME = "Coffee+";
PRODUCT_NAME = Coffee_;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand Down
22 changes: 20 additions & 2 deletions CoffeeTracker/CoffeeTracker/Beans/BeanDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import SwiftUI

struct BeanDetailView: View {
@State private var showEditView = false

var bean: BeanModel
var body: some View {
VStack(alignment: .leading) {
Expand Down Expand Up @@ -71,6 +73,12 @@ struct BeanDetailView: View {
.cornerRadius(10)
}
}
.sheet(isPresented: $showEditView) {
showEditView = false
} content: {
NewBeansView(showForm: $showEditView, beans: bean, isEdit: true)
}

// HStack {
// Button {
// print("EDIT")
Expand All @@ -96,6 +104,14 @@ struct BeanDetailView: View {
// .padding(.bottom)
// }
}.padding(.horizontal)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {showEditView.toggle()}) {
Image(systemName: SFSymbols.pencil)
}
}
}
.navigationBarTitleDisplayMode(.inline)
}

func formatDate(_ date: Date) -> String {
Expand All @@ -108,7 +124,9 @@ struct BeanDetailView: View {

struct BeanDetailView_Previews: PreviewProvider {
static var previews: some View {
BeanDetailView(bean: testRoast)
.preferredColorScheme(.dark)
NavigationView {
BeanDetailView(bean: testRoast)
.preferredColorScheme(.dark)
}
}
}
22 changes: 22 additions & 0 deletions CoffeeTracker/CoffeeTracker/Beans/BeanModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct BeanModel: Identifiable, Hashable {
var roastedOn: Date
var boughtOn: Date
var notes: String
var objectID: NSManagedObjectID?

mutating func updateNotes(_ note: String) {
notes = note
Expand All @@ -33,4 +34,25 @@ struct BeanModel: Identifiable, Hashable {
print("Failed: \(error)")
}
}

func updateBean(context: NSManagedObjectContext) {
guard let objectID = objectID else {
print("❌ No object ID for update")
return
}

do {
let object: Bean = try context.existingObject(with: objectID) as! Bean
object.name = name
object.style = style
object.buyAgain = buyAgain
object.roaster = roaster
object.roastedOn = roastedOn
object.boughtOn = boughtOn
object.notes = notes
try context.save()
} catch {
print("❌ Error")
}
}
}
30 changes: 16 additions & 14 deletions CoffeeTracker/CoffeeTracker/Beans/BeansCollectionViewOO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ class BeansCollectionViewOO: NSObject, ObservableObject {
try fetchedBeanResultsController.performFetch()
beans = (fetchedBeanResultsController.fetchedObjects ?? []).map({ foundBean -> BeanModel in
return BeanModel(id: foundBean.id ?? UUID(),
name: foundBean.name ?? "",
style: foundBean.style ?? "",
buyAgain: foundBean.buyAgain,
roaster: foundBean.roaster ?? "",
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "")
name: foundBean.name ?? "",
style: foundBean.style ?? "",
buyAgain: foundBean.buyAgain,
roaster: foundBean.roaster ?? "",
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "",
objectID: foundBean.objectID)
})
} catch {
print("Error")
Expand All @@ -50,13 +51,14 @@ extension BeansCollectionViewOO: NSFetchedResultsControllerDelegate {
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
beans = (controller.fetchedObjects as? [Bean] ?? []).map({ foundBean -> BeanModel in
return BeanModel(id: foundBean.id ?? UUID(),
name: foundBean.name ?? "",
style: foundBean.style ?? "",
buyAgain: foundBean.buyAgain,
roaster: foundBean.roaster ?? "",
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "")
name: foundBean.name ?? "",
style: foundBean.style ?? "",
buyAgain: foundBean.buyAgain,
roaster: foundBean.roaster ?? "",
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "",
objectID: foundBean.objectID)
})
}
}
25 changes: 16 additions & 9 deletions CoffeeTracker/CoffeeTracker/Beans/NewBeansView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ struct NewBeansView: View {
roaster: "",
roastedOn: Date(),
boughtOn: Date(),
notes: "")
notes: "")

var isEdit = false

var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 20) {
Expand Down Expand Up @@ -60,15 +63,19 @@ struct NewBeansView: View {
HStack{
Spacer()
Button {
beans.addBeansToData(context: viewContext)
if isEdit {
beans.updateBean(context: viewContext)
} else {
beans.addBeansToData(context: viewContext)
beans = BeanModel(name: "",
style: "",
buyAgain: false,
roaster: "",
roastedOn: Date(),
boughtOn: Date(),
notes: "")
}
showForm = false
beans = BeanModel(name: "",
style: "",
buyAgain: false,
roaster: "",
roastedOn: Date(),
boughtOn: Date(),
notes: "")
} label: {
Text("Save").padding(.horizontal, 30)
}.buttonStyle(BorderedButtonStyle())
Expand Down
16 changes: 16 additions & 0 deletions CoffeeTracker/CoffeeTracker/CoffeeTracker.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.CoffeeTracker</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudKit</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion CoffeeTracker/CoffeeTracker/Helpers/SFSymbolHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ enum SFSymbols {
static var thumbsup = "hand.thumbsup.fill"
static var thumbsdown = "hand.thumbsdown.fill"
static var trash = "trash"
static var pencil = "pencil"
static var pencil = "pencil.and.outline"
static var plus = "plus"
}
12 changes: 12 additions & 0 deletions CoffeeTracker/CoffeeTracker/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
</dict>
</plist>