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
12 changes: 12 additions & 0 deletions CoffeeTracker/CoffeeTracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
371E297127C40FB300C8ACBF /* BeanFixtures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371E297027C40FB300C8ACBF /* BeanFixtures.swift */; };
371E297327C40FEF00C8ACBF /* BeansCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371E297227C40FEF00C8ACBF /* BeansCollectionView.swift */; };
371E297527C4100900C8ACBF /* NewBeansView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371E297427C4100900C8ACBF /* NewBeansView.swift */; };
376A5E5327D844D60038BDA0 /* PhotoPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 376A5E5227D844D60038BDA0 /* PhotoPickerView.swift */; };
3782E03527C4AA81000F0404 /* BeansCollectionViewOO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3782E03427C4AA81000F0404 /* BeansCollectionViewOO.swift */; };
3797E1C427D6A52F000FE457 /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3797E1C327D6A52F000FE457 /* View+Extensions.swift */; };
3797E1C627D6A6F3000FE457 /* Color+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3797E1C527D6A6F3000FE457 /* Color+Extension.swift */; };
Expand All @@ -43,6 +44,7 @@
371E297027C40FB300C8ACBF /* BeanFixtures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeanFixtures.swift; sourceTree = "<group>"; };
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>"; };
376A5E5227D844D60038BDA0 /* PhotoPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoPickerView.swift; sourceTree = "<group>"; };
3782E03427C4AA81000F0404 /* BeansCollectionViewOO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeansCollectionViewOO.swift; sourceTree = "<group>"; };
3797E1C327D6A52F000FE457 /* View+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extensions.swift"; sourceTree = "<group>"; };
3797E1C527D6A6F3000FE457 /* Color+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -83,6 +85,7 @@
371E294D27C40D2100C8ACBF /* CoffeeTracker */ = {
isa = PBXGroup;
children = (
376A5E5127D844BF0038BDA0 /* PhotoPicker */,
37B776A727C67A7800EFD566 /* Info.plist */,
37B776A327C67A6B00EFD566 /* CoffeeTracker.entitlements */,
371E296F27C40FA600C8ACBF /* Fixtures */,
Expand Down Expand Up @@ -138,6 +141,14 @@
path = Fixtures;
sourceTree = "<group>";
};
376A5E5127D844BF0038BDA0 /* PhotoPicker */ = {
isa = PBXGroup;
children = (
376A5E5227D844D60038BDA0 /* PhotoPickerView.swift */,
);
path = PhotoPicker;
sourceTree = "<group>";
};
37B776A427C67A6F00EFD566 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -219,6 +230,7 @@
371E296727C40EF100C8ACBF /* BeanRowView.swift in Sources */,
3797E1C627D6A6F3000FE457 /* Color+Extension.swift in Sources */,
371E295827C40D2200C8ACBF /* Persistence.swift in Sources */,
376A5E5327D844D60038BDA0 /* PhotoPickerView.swift in Sources */,
3782E03527C4AA81000F0404 /* BeansCollectionViewOO.swift in Sources */,
371E296227C40E8800C8ACBF /* CoffeeTrackerMain.swift in Sources */,
371E295127C40D2100C8ACBF /* ContentView.swift in Sources */,
Expand Down
14 changes: 7 additions & 7 deletions CoffeeTracker/CoffeeTracker/Beans/BeanDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ struct BeanDetailView: View {
}
}

struct BeanDetailView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
BeanDetailView(bean: testRoast)
}
}
}
//struct BeanDetailView_Previews: PreviewProvider {
// static var previews: some View {
// NavigationView {
// BeanDetailView(bean: testRoast)
// }
// }
//}
4 changes: 4 additions & 0 deletions CoffeeTracker/CoffeeTracker/Beans/BeanModel.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import CoreData
import UIKit

struct BeanModel: Identifiable, Hashable {
var id: UUID = UUID()
Expand All @@ -11,6 +12,7 @@ struct BeanModel: Identifiable, Hashable {
var boughtOn: Date
var notes: String
var objectID: NSManagedObjectID?
var image: UIImage

mutating func updateNotes(_ note: String) {
notes = note
Expand All @@ -26,6 +28,7 @@ struct BeanModel: Identifiable, Hashable {
newBean.roastedOn = roastedOn
newBean.boughtOn = boughtOn
newBean.notes = notes
newBean.beanPhoto = image.pngData()

self.objectID = newBean.objectID

Expand Down Expand Up @@ -55,6 +58,7 @@ struct BeanModel: Identifiable, Hashable {
object.roastedOn = roastedOn
object.boughtOn = boughtOn
object.notes = notes
object.beanPhoto = image.pngData()
try context.save()
}
} catch {
Expand Down
6 changes: 4 additions & 2 deletions CoffeeTracker/CoffeeTracker/Beans/BeanRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ struct BeanRowView: View {
var body: some View {
VStack{
HStack(spacing: 20) {
Image(systemName: SFSymbols.bag)
.font(.title)
Image(uiImage: bean.image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 100, height: 100, alignment: .center)
VStack(alignment: .leading, spacing: 5) {
HStack(alignment: .top) {
VStack(alignment: .leading) {
Expand Down
15 changes: 13 additions & 2 deletions CoffeeTracker/CoffeeTracker/Beans/BeansCollectionViewOO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import CoreData
import UIKit

class BeansCollectionViewOO: NSObject, ObservableObject {
@Published var beans: [BeanModel] = []
Expand All @@ -31,6 +32,15 @@ class BeansCollectionViewOO: NSObject, ObservableObject {
do {
try fetchedBeanResultsController.performFetch()
beans = (fetchedBeanResultsController.fetchedObjects ?? []).map({ foundBean -> BeanModel in

let image = UIImage(data: foundBean.beanPhoto ?? Data())

var savedImage = UIImage(systemName: SFSymbols.photo)!

if let image = image {
savedImage = image
}

return BeanModel(id: foundBean.id ?? UUID(),
name: foundBean.name ?? "",
style: foundBean.style ?? "",
Expand All @@ -39,7 +49,8 @@ class BeansCollectionViewOO: NSObject, ObservableObject {
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "",
objectID: foundBean.objectID)
objectID: foundBean.objectID,
image: savedImage)
})
} catch {
print("Error")
Expand All @@ -58,7 +69,7 @@ extension BeansCollectionViewOO: NSFetchedResultsControllerDelegate {
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "",
objectID: foundBean.objectID)
objectID: foundBean.objectID, image: UIImage())
})
}
}
60 changes: 50 additions & 10 deletions CoffeeTracker/CoffeeTracker/Beans/NewBeansView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import Photos

struct NewBeansView: View {
enum Field {
Expand All @@ -14,6 +15,7 @@ struct NewBeansView: View {
case roaster
case notes
}

@Environment(\.managedObjectContext) private var viewContext
@Binding var showForm: Bool

Expand All @@ -23,21 +25,55 @@ struct NewBeansView: View {
roaster: "",
roastedOn: Date(),
boughtOn: Date(),
notes: "")
notes: "", image: UIImage())

@State private var isImageSelected = false
@State var selectedImage = UIImage()
@State private var showingPhotoPicker = false
@FocusState private var focusedField: Field?

var isEdit = false

var body: some View {
ScrollView {
VStack {
VStack(alignment: .leading, spacing: 20) {
Section("Bean Information") {
TextField("Name", text: $beans.name)
.textFieldStyle(.roundedBorder)
.focused($focusedField, equals: .name)
TextField("Style", text: $beans.style)
.textFieldStyle(.roundedBorder)
.focused($focusedField, equals: .style)
HStack(spacing: 10) {
Button {
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
switch status {
case .notDetermined:
print("Not determined")
case .authorized:
showingPhotoPicker.toggle()
case .restricted:
print("Restricted")
case .denied:
print("DENIED")
default:
print("IDK WHAT HAPPENED")
}
}
} label: {
if isImageSelected {
Image(uiImage: beans.image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 100, height: 100, alignment: .center)
} else {
Image(systemName: SFSymbols.photo)
.font(.system(size: 75))
}
}
VStack {
TextField("Name", text: $beans.name)
.textFieldStyle(.roundedBorder)
.focused($focusedField, equals: .name)
TextField("Style", text: $beans.style)
.textFieldStyle(.roundedBorder)
.focused($focusedField, equals: .style)
}
}
}
Section("Roaster Information") {
DatePicker("Roasted On",
Expand Down Expand Up @@ -83,7 +119,8 @@ struct NewBeansView: View {
roaster: "",
roastedOn: Date(),
boughtOn: Date(),
notes: "")
notes: "",
image: UIImage())
}
focusedField = nil
showForm = false
Expand All @@ -97,7 +134,10 @@ struct NewBeansView: View {
}

}.padding()
}.background(.ultraThickMaterial)
Spacer()
}.background(.ultraThickMaterial).sheet(isPresented: $showingPhotoPicker) {
ImagePicker(selectedImage: $beans.image, isImageSelected: $isImageSelected)
}
.onDisappear {
focusedField = nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="19574" systemVersion="21C52" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="19574" systemVersion="21D62" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
<entity name="Bean" representedClassName="Bean" syncable="YES" codeGenerationType="class">
<attribute name="beanPhoto" optional="YES" attributeType="Binary"/>
<attribute name="boughtAt" optional="YES" attributeType="String"/>
<attribute name="boughtOn" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="buyAgain" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
Expand All @@ -15,7 +16,7 @@
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
</entity>
<elements>
<element name="Bean" positionX="-63" positionY="0" width="128" height="164"/>
<element name="Bean" positionX="-63" positionY="0" width="128" height="179"/>
<element name="Item" positionX="-63" positionY="-18" width="128" height="44"/>
</elements>
</model>
7 changes: 4 additions & 3 deletions CoffeeTracker/CoffeeTracker/Fixtures/BeanFixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@
//

import Foundation
import UIKit

var lightRoast = BeanModel(name: "Verona Blend",
style: "Light",
buyAgain: true,
roaster: "Starbucks",
roastedOn: Date.now,
boughtOn: Date.now,
notes: "")
notes: "", image: UIImage())

var mediumRoast = BeanModel(name: "20th Anniversary Blend",
style: "Medium",
buyAgain: false,
roaster: "Summermoon",
roastedOn: Date.now,
boughtOn: Date.now,
notes: "I like it a lot")
notes: "I like it a lot", image: UIImage())

var testRoast = BeanModel(name: "Swiftly Brewed",
style: "Light",
buyAgain: true,
roaster: "Apple Inc",
roastedOn: Date.now,
boughtOn: Date.now,
notes: "Sold in Maegan's hopes and dreams")
notes: "Sold in Maegan's hopes and dreams", image: UIImage())

let allRoasts = [lightRoast, mediumRoast, testRoast]
15 changes: 8 additions & 7 deletions CoffeeTracker/CoffeeTracker/Helpers/SFSymbolHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import Foundation

enum SFSymbols {
static var bag = "bag"
static var thumbsup = "hand.thumbsup.fill"
static var thumbsdown = "hand.thumbsdown.fill"
static var trash = "trash"
static var pencil = "pencil.and.outline"
static var plus = "plus"
static var share = "square.and.arrow.up"
static let bag = "bag"
static let thumbsup = "hand.thumbsup.fill"
static let thumbsdown = "hand.thumbsdown.fill"
static let trash = "trash"
static let pencil = "pencil.and.outline"
static let plus = "plus"
static let share = "square.and.arrow.up"
static let photo = "photo"
}
2 changes: 2 additions & 0 deletions CoffeeTracker/CoffeeTracker/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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>NSPhotoLibraryUsageDescription</key>
<string>To be able to add photos of your beans.</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>UIBackgroundModes</key>
Expand Down
Loading