Procházet zdrojové kódy

Refactor continued WIP

Deniz Cengiz před 1 rokem
rodič
revize
367072b640

+ 4 - 0
FreeAPS/Sources/APS/Extensions/FontExtensions.swift

@@ -3,10 +3,14 @@ import SwiftUI
 extension Font.Weight {
     var displayName: String {
         switch self {
+        case .ultraLight: return "Ultra Light"
         case .light: return "Light"
         case .regular: return "Regular"
         case .medium: return "Medium"
+        case .semibold: return "Semibold"
         case .bold: return "Bold"
+        case .heavy: return "Heavy"
+        case .black: return "Black"
         default: return "Unknown"
         }
     }

+ 3 - 3
FreeAPS/Sources/APS/Storage/ContactTrickStorage.swift

@@ -33,7 +33,7 @@ final class BaseContactTrickStorage: ContactTrickStorage, Injectable {
         return fetchedContactTrickEntries.map { entry in
             ContactTrickEntry(
                 layout: ContactTrickLayout.init(rawValue: entry.layout ?? "Single") ?? .single,
-                ring1: ContactTrickLargeRing.init(rawValue: entry.ring1 ?? "DontShowRing") ?? .none,
+                ring: ContactTrickLargeRing.init(rawValue: entry.ring ?? "DontShowRing") ?? .none,
                 primary: ContactTrickValue.init(rawValue: entry.primary ?? "GlucoseContactValue") ?? .glucose,
                 top: ContactTrickValue.init(rawValue: entry.top ?? "NoneContactValue") ?? .none,
                 bottom: ContactTrickValue.init(rawValue: entry.top ?? "NoneContactValue") ?? .none,
@@ -56,11 +56,11 @@ final class BaseContactTrickStorage: ContactTrickStorage, Injectable {
             newContactTrickEntry.id = UUID()
             newContactTrickEntry.contactId = contactTrickEntry.contactId
             newContactTrickEntry.layout = contactTrickEntry.layout.rawValue
-            newContactTrickEntry.ring1 = contactTrickEntry.ring1.rawValue
+            newContactTrickEntry.ring = contactTrickEntry.ring.rawValue
             newContactTrickEntry.primary = contactTrickEntry.primary.rawValue
             newContactTrickEntry.top = contactTrickEntry.top.rawValue
             newContactTrickEntry.bottom = contactTrickEntry.bottom.rawValue
-            newContactTrickEntry.contactId = contactTrickEntry.ring1.rawValue
+            newContactTrickEntry.contactId = contactTrickEntry.ring.rawValue
             newContactTrickEntry.isDarkMode = contactTrickEntry.darkMode
             newContactTrickEntry.ringWidth = Int16(contactTrickEntry.ringWidth.rawValue)
             newContactTrickEntry.ringGap = Int16(contactTrickEntry.ringGap.rawValue)

+ 1 - 1
FreeAPS/Sources/Models/ContactTrickEntry.swift

@@ -2,7 +2,7 @@ import SwiftUI
 
 struct ContactTrickEntry: Hashable, Sendable {
     var layout: ContactTrickLayout = .single
-    var ring1: ContactTrickLargeRing = .none
+    var ring: ContactTrickLargeRing = .none
     var primary: ContactTrickValue = .glucose
     var top: ContactTrickValue = .none
     var bottom: ContactTrickValue = .none

+ 59 - 28
FreeAPS/Sources/Modules/ContactTrick/View/ContactTrickRootView.swift

@@ -162,16 +162,7 @@ extension ContactTrick {
 
         var body: some View {
             HStack {
-                Text(
-                    NSLocalizedString("Contact", comment: "") + ": " + "Trio \(index + 1)"
-                )
-                .font(.body)
-                .minimumScaleFactor(0.5)
-                .lineLimit(1)
-
-                Spacer()
-
-                VStack {
+                VStack(alignment: .leading) {
                     GeometryReader { geometry in
                         ZStack {
                             Circle()
@@ -191,6 +182,25 @@ extension ContactTrick {
                 }
                 .fixedSize(horizontal: true, vertical: false)
                 .padding(.horizontal, 30)
+
+                Spacer()
+
+                VStack {
+                    Text("Contact: Trio \(index + 1)").bold()
+//                    HStack {
+//                        Text("Layout: \(entry.layout.displayName)")
+//                        Text("\(entry.ring.displayName)")
+//                        if entry.layout == .single {
+//                            Text("\(entry.primary.displayName)")
+//                        }
+//                        Text("\(entry.top.displayName), \(entry.bottom.displayName)")
+//                    }.foregroundStyle(.secondary)
+//                    HStack {
+//                        Text("Font Size \(entry.fontSize.displayName)")
+//                        Text("Font Width \(entry.fontWidth.displayName)")
+//                        Text("Font Weight \(entry.fontWeight.displayName)")
+//                    }.foregroundStyle(.secondary)
+                }
             }
             .frame(maxWidth: .infinity)
         }
@@ -240,27 +250,48 @@ extension ContactTrick {
 
                     Section(header: Text("Ring")) {
                         Picker(
-                            selection: $entry.ring1,
+                            selection: $entry.ring,
                             label: Text("Outer")
                         ) {
                             ForEach(ContactTrickLargeRing.allCases, id: \.self) { ring in
                                 Text(ring.displayName).tag(ring)
                             }
                         }
-                        Picker(
-                            selection: $entry.ringWidth,
-                            label: Text("Width")
-                        ) {
-                            ForEach(ringWidths, id: \.self) { width in
-                                Text("\(width)").tag(width)
+
+                        if entry.ring != .none {
+                            Picker(
+                                selection: $entry.ringWidth,
+                                label: Text("Width")
+                            ) {
+                                ForEach(
+                                    [
+                                        ContactTrickEntry.RingWidth.tiny,
+                                        ContactTrickEntry.RingWidth.small,
+                                        ContactTrickEntry.RingWidth.regular,
+                                        ContactTrickEntry.RingWidth.medium,
+                                        ContactTrickEntry.RingWidth.large
+                                    ],
+                                    id: \.self
+                                ) { width in
+                                    Text(width.displayName).tag(width)
+                                }
                             }
-                        }
-                        Picker(
-                            selection: $entry.ringGap,
-                            label: Text("Gap")
-                        ) {
-                            ForEach(ringGaps, id: \.self) { gap in
-                                Text("\(gap)").tag(gap)
+                            Picker(
+                                selection: $entry.ringGap,
+                                label: Text("Gap")
+                            ) {
+                                ForEach(
+                                    [
+                                        ContactTrickEntry.RingGap.tiny,
+                                        ContactTrickEntry.RingGap.small,
+                                        ContactTrickEntry.RingGap.regular,
+                                        ContactTrickEntry.RingGap.medium,
+                                        ContactTrickEntry.RingGap.large
+                                    ],
+                                    id: \.self
+                                ) { gap in
+                                    Text(gap.displayName).tag(gap)
+                                }
                             }
                         }
                     }
@@ -279,7 +310,7 @@ extension ContactTrick {
                                 ],
                                 id: \.self
                             ) { size in
-                                Text("\(size)").tag(size)
+                                Text(size.displayName).tag(size)
                             }
                         }
                         Picker(
@@ -295,12 +326,12 @@ extension ContactTrick {
                                 ],
                                 id: \.self
                             ) { size in
-                                Text("\(size)").tag(size)
+                                Text(size.displayName).tag(size)
                             }
                         }
                         Picker(
                             selection: $entry.fontWidth,
-                            label: Text("Tracking")
+                            label: Text("Width")
                         ) {
                             ForEach(
                                 [Font.Width.standard, Font.Width.condensed, Font.Width.expanded],
@@ -314,7 +345,7 @@ extension ContactTrick {
                             label: Text("Weight")
                         ) {
                             ForEach(
-                                [Font.Weight.regular, Font.Weight.bold, Font.Weight.black],
+                                [Font.Weight.light, Font.Weight.regular, Font.Weight.medium, Font.Weight.bold, Font.Weight.black],
                                 id: \.self
                             ) { weight in
                                 Text(weight.displayName).tag(weight)

+ 18 - 18
FreeAPS/Sources/Services/ContactTrick/ContactPicture.swift

@@ -40,7 +40,7 @@ struct ContactPicture: View {
         let ringGap = Double(contact.ringGap.rawValue) / 100.0
         let outerGap = 0.03
 
-        if contact.ring1 != .none {
+        if contact.ring != .none {
             rect = CGRect(
                 x: rect.minX + width * outerGap,
                 y: rect.minY + height * outerGap,
@@ -55,7 +55,7 @@ struct ContactPicture: View {
                 height: rect.height - height * ringWidth
             )
 
-            drawRing(ring: contact.ring1, contact: contact, state: state, rect: ringRect, strokeWidth: width * ringWidth)
+            drawRing(ring: contact.ring, contact: contact, state: state, rect: ringRect, strokeWidth: width * ringWidth)
 
             rect = CGRect(
                 x: rect.minX + width * (ringWidth + ringGap),
@@ -98,12 +98,12 @@ struct ContactPicture: View {
 
             if contact.bottom != .none, contact.top == .none {
                 // move things around a little bit to give more space to the bottom area
-                if contact.ring1 == .iob || contact.ring1 == .cob || contact.ring1 == .iobcob ||
-                    (contact.bottom == .trend && contact.ring1 == .loop)
+                if contact.ring == .iob || contact.ring == .cob || contact.ring == .iobcob ||
+                    (contact.bottom == .trend && contact.ring == .loop)
                 {
                     bottomHeight = bottomHeight + height * ringWidth * 2
                     bottomWidth = bottomWidth + width * ringWidth * 2
-                } else if contact.ring1 == .loop {
+                } else if contact.ring == .loop {
                     primaryHeight = primaryHeight - height * ringWidth
                     bottomY = primaryY + primaryHeight
                     bottomHeight = bottomHeight + height * ringWidth * 2
@@ -646,7 +646,7 @@ struct ContactPicture_Previews: PreviewProvider {
             ContactPicturePreview(
                 contact: .constant(
                     ContactTrickEntry(
-                        ring1: .iob,
+                        ring: .iob,
                         primary: .glucose,
                         bottom: .trend,
                         fontSize: fontSize,
@@ -683,7 +683,7 @@ struct ContactPicture_Previews: PreviewProvider {
             ContactPicturePreview(
                 contact: .constant(
                     ContactTrickEntry(
-                        ring1: .loop,
+                        ring: .loop,
                         primary: .glucose,
                         top: .none,
                         bottom: .trend,
@@ -696,12 +696,12 @@ struct ContactPicture_Previews: PreviewProvider {
                     trend: "→",
                     lastLoopDate: .now
                 ))
-            ).previewDisplayName("bg + trend + ring1")
+            ).previewDisplayName("bg + trend + ring")
 
             ContactPicturePreview(
                 contact: .constant(
                     ContactTrickEntry(
-                        ring1: .loop,
+                        ring: .loop,
                         primary: .glucose,
                         top: .none,
                         bottom: .eventualBG,
@@ -714,12 +714,12 @@ struct ContactPicture_Previews: PreviewProvider {
                     lastLoopDate: .now - 7.minutes,
                     eventualBG: "6.2"
                 ))
-            ).previewDisplayName("bg + eventual + ring1")
+            ).previewDisplayName("bg + eventual + ring")
 
             ContactPicturePreview(
                 contact: .constant(
                     ContactTrickEntry(
-                        ring1: .loop,
+                        ring: .loop,
                         primary: .lastLoopDate,
                         top: .none,
                         bottom: .none,
@@ -732,12 +732,12 @@ struct ContactPicture_Previews: PreviewProvider {
                     trend: "↗︎",
                     lastLoopDate: .now - 2.minutes
                 ))
-            ).previewDisplayName("lastLoopDate + ring1")
+            ).previewDisplayName("lastLoopDate + ring")
 
             ContactPicturePreview(
                 contact: .constant(
                     ContactTrickEntry(
-                        ring1: .loop,
+                        ring: .loop,
                         primary: .glucose,
                         top: .none,
                         bottom: .none,
@@ -752,7 +752,7 @@ struct ContactPicture_Previews: PreviewProvider {
                     iobText: "6.1",
                     maxIOB: 8.0
                 ))
-            ).previewDisplayName("bg + ring1 + ring2")
+            ).previewDisplayName("bg + ring + ring2")
 
             ContactPicturePreview(
                 contact: .constant(
@@ -776,7 +776,7 @@ struct ContactPicture_Previews: PreviewProvider {
                 contact: .constant(
                     ContactTrickEntry(
                         layout: .single,
-                        ring1: .iobcob,
+                        ring: .iobcob,
                         primary: .none,
                         ringWidth: .regular,
                         ringGap: .regular,
@@ -798,7 +798,7 @@ struct ContactPicture_Previews: PreviewProvider {
                 contact: .constant(
                     ContactTrickEntry(
                         layout: .single,
-                        ring1: .iobcob,
+                        ring: .iobcob,
                         primary: .none,
                         fontSize: fontSize,
                         fontWeight: .medium
@@ -818,7 +818,7 @@ struct ContactPicture_Previews: PreviewProvider {
                 contact: .constant(
                     ContactTrickEntry(
                         layout: .single,
-                        ring1: .iobcob,
+                        ring: .iobcob,
                         primary: .none,
                         fontSize: fontSize,
                         fontWeight: .medium
@@ -838,7 +838,7 @@ struct ContactPicture_Previews: PreviewProvider {
                 contact: .constant(
                     ContactTrickEntry(
                         layout: .single,
-                        ring1: .iobcob,
+                        ring: .iobcob,
                         primary: .glucose,
                         bottom: .trend,
                         fontSize: fontSize,

+ 7 - 6
FreeAPS/Sources/Services/ContactTrick/ContactTrickManager.swift

@@ -233,12 +233,13 @@ final class BaseContactTrickManager: NSObject, ContactTrickManager, Injectable {
                     }
 
                     // When we create new contacts we store the IDs, in that case we need to write into the settings storage
-                    // Save the new entries into Core Data
-                    for newEntry in newEntries {
-                        Task {
-                            await self.contactTrickStorage.storeContactTrickEntry(newEntry)
-                        }
-                    }
+                    // TODO: We actually need to UPDATE the respective entry in CD, so rather RETURN the contactId here and UPDATE the respective entry in CD.
+//                    // Save the new entries into Core Data
+//                    for newEntry in newEntries {
+//                        Task {
+//                            await self.contactTrickStorage.storeContactTrickEntry(newEntry)
+//                        }
+//                    }
 
                     contacts = newContacts
                 }

+ 1 - 1
Model/Classes+Properties/ContactTrickEntryStored+CoreDataProperties.swift

@@ -7,7 +7,7 @@ public extension ContactTrickEntryStored {
     }
 
     @NSManaged var layout: String?
-    @NSManaged var ring1: String?
+    @NSManaged var ring: String?
     @NSManaged var primary: String?
     @NSManaged var top: String?
     @NSManaged var bottom: String?

+ 1 - 1
Model/TrioCoreDataPersistentContainer.xcdatamodeld/TrioCoreDataPersistentContainer.xcdatamodel/contents

@@ -36,7 +36,7 @@
         <attribute name="isDarkMode" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
         <attribute name="layout" optional="YES" attributeType="String"/>
         <attribute name="primary" optional="YES" attributeType="String"/>
-        <attribute name="ring1" optional="YES" attributeType="String"/>
+        <attribute name="ring" optional="YES" attributeType="String"/>
         <attribute name="ringGap" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
         <attribute name="ringWidth" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
         <attribute name="top" optional="YES" attributeType="String"/>