Просмотр исходного кода

Fix coding keys; fix button enablement; add missign setting options

Deniz Cengiz 1 год назад
Родитель
Сommit
4a2d4bbac8

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

@@ -41,10 +41,10 @@ final class BaseContactTrickStorage: ContactTrickStorage, Injectable {
                 ContactTrickEntry(
                     name: entry.name ?? "No name provided",
                     layout: ContactTrickLayout(rawValue: entry.layout ?? "Single") ?? .single,
-                    ring: ContactTrickLargeRing(rawValue: entry.ring ?? "DontShowRing") ?? .none,
-                    primary: ContactTrickValue(rawValue: entry.primary ?? "GlucoseContactValue") ?? .glucose,
-                    top: ContactTrickValue(rawValue: entry.top ?? "NoneContactValue") ?? .none,
-                    bottom: ContactTrickValue(rawValue: entry.bottom ?? "NoneContactValue") ?? .none,
+                    ring: ContactTrickLargeRing(rawValue: entry.ring ?? "Hidden") ?? .none,
+                    primary: ContactTrickValue(rawValue: entry.primary ?? "Glucose Reading") ?? .glucose,
+                    top: ContactTrickValue(rawValue: entry.top ?? "None") ?? .none,
+                    bottom: ContactTrickValue(rawValue: entry.bottom ?? "None") ?? .none,
                     contactId: entry.contactId?.string,
                     darkMode: entry.isDarkMode,
                     ringWidth: ContactTrickEntry.RingWidth(rawValue: Int(entry.ringWidth)) ?? .regular,

+ 33 - 15
FreeAPS/Sources/Models/ContactTrickEntry.swift

@@ -1,7 +1,7 @@
 import CoreData
 import SwiftUI
 
-struct ContactTrickEntry: Hashable, Sendable {
+struct ContactTrickEntry: Hashable, Equatable, Sendable {
     var id = UUID()
     var name: String = ""
     var layout: ContactTrickLayout = .single
@@ -19,6 +19,24 @@ struct ContactTrickEntry: Hashable, Sendable {
     var fontWidth: Font.Width = .standard
     var managedObjectID: NSManagedObjectID?
 
+    static func == (lhs: ContactTrickEntry, rhs: ContactTrickEntry) -> Bool {
+        lhs.id == rhs.id &&
+            lhs.name == rhs.name &&
+            lhs.layout == rhs.layout &&
+            lhs.ring == rhs.ring &&
+            lhs.primary == rhs.primary &&
+            lhs.top == rhs.top &&
+            lhs.bottom == rhs.bottom &&
+            lhs.contactId == rhs.contactId &&
+            lhs.darkMode == rhs.darkMode &&
+            lhs.ringWidth == rhs.ringWidth &&
+            lhs.ringGap == rhs.ringGap &&
+            lhs.fontSize == rhs.fontSize &&
+            lhs.secondaryFontSize == rhs.secondaryFontSize &&
+            lhs.fontWeight == rhs.fontWeight &&
+            lhs.fontWidth == rhs.fontWidth
+    }
+
     // Convert `fontWeight` to a String for Core Data storage
     var fontWeightString: String {
         fontWeight.asString
@@ -112,23 +130,23 @@ enum ContactTrickValue: String, JSON, CaseIterable, Identifiable, Codable {
     var displayName: String {
         switch self {
         case .none:
-            return NSLocalizedString("NoneContactValue", comment: "")
+            return NSLocalizedString("None", comment: "")
         case .glucose:
-            return NSLocalizedString("GlucoseContactValue", comment: "")
+            return NSLocalizedString("Glucose Reading", comment: "")
         case .eventualBG:
-            return NSLocalizedString("EventualBGContactValue", comment: "")
+            return NSLocalizedString("Eventual Glucose", comment: "")
         case .delta:
-            return NSLocalizedString("DeltaContactValue", comment: "")
+            return NSLocalizedString("Glucose Delta", comment: "")
         case .trend:
-            return NSLocalizedString("TrendContactValue", comment: "")
+            return NSLocalizedString("Glucose Trend", comment: "")
         case .lastLoopDate:
-            return NSLocalizedString("LastLoopTimeContactValue", comment: "")
+            return NSLocalizedString("Last Loop Time", comment: "")
         case .cob:
-            return NSLocalizedString("COBContactValue", comment: "")
+            return NSLocalizedString("COB", comment: "")
         case .iob:
-            return NSLocalizedString("IOBContactValue", comment: "")
+            return NSLocalizedString("IOB", comment: "")
         case .ring:
-            return NSLocalizedString("LoopStatusContactValue", comment: "")
+            return NSLocalizedString("Loop Status", comment: "")
         }
     }
 }
@@ -159,15 +177,15 @@ enum ContactTrickLargeRing: String, JSON, CaseIterable, Identifiable, Codable {
     var displayName: String {
         switch self {
         case .none:
-            return NSLocalizedString("DontShowRing", comment: "")
+            return NSLocalizedString("Hidden", comment: "")
         case .loop:
-            return NSLocalizedString("LoopStatusRing", comment: "")
+            return NSLocalizedString("Loop Status", comment: "")
         case .iob:
-            return NSLocalizedString("IOBRing", comment: "")
+            return NSLocalizedString("Insulin on Board (IOB)", comment: "")
         case .cob:
-            return NSLocalizedString("COBRing", comment: "")
+            return NSLocalizedString("Carbs on Board (COB)", comment: "")
         case .iobcob:
-            return NSLocalizedString("IOB+COBRing", comment: "")
+            return NSLocalizedString("IOB + COB", comment: "")
         }
     }
 }

+ 20 - 11
FreeAPS/Sources/Modules/ContactTrick/View/ContactTrickDetailView.swift

@@ -8,10 +8,12 @@ struct ContactTrickDetailView: View {
     @ObservedObject var state: ContactTrick.StateModel
 
     @State private var contactTrickEntry: ContactTrickEntry
+    @State private var initialContactTrickEntry: ContactTrickEntry
 
     init(entry: ContactTrickEntry, state: ContactTrick.StateModel) {
         self.state = state
         _contactTrickEntry = State(initialValue: entry)
+        _initialContactTrickEntry = State(initialValue: entry)
     }
 
     var body: some View {
@@ -70,23 +72,27 @@ struct ContactTrickDetailView: View {
                     }
                 }.listRowBackground(Color.chart)
 
-                if contactTrickEntry.ring != .none {
-                    Section(header: Text("Ring Settings")) {
+                // Ring Settings Section
+                Section(header: Text("Ring Settings")) {
+                    Picker("Ring Type", selection: $contactTrickEntry.ring) {
+                        ForEach(ContactTrickLargeRing.allCases, id: \.self) { ring in
+                            Text(ring.displayName).tag(ring)
+                        }
+                    }
+
+                    if contactTrickEntry.ring != .none {
                         Picker("Ring Width", selection: $contactTrickEntry.ringWidth) {
                             ForEach(ContactTrickEntry.RingWidth.allCases, id: \.self) { width in
-                                Text(width.displayName)
-                                    .tag(width)
+                                Text(width.displayName).tag(width)
                             }
                         }
-
                         Picker("Ring Gap", selection: $contactTrickEntry.ringGap) {
                             ForEach(ContactTrickEntry.RingGap.allCases, id: \.self) { gap in
-                                Text(gap.displayName)
-                                    .tag(gap)
+                                Text(gap.displayName).tag(gap)
                             }
                         }
-                    }.listRowBackground(Color.chart)
-                }
+                    }
+                }.listRowBackground(Color.chart)
 
                 // Font Settings Section
                 Section(header: Text("Font Settings")) {
@@ -146,7 +152,9 @@ struct ContactTrickDetailView: View {
     }
 
     var stickySaveButton: some View {
-        ZStack {
+        var isUnchanged: Bool { initialContactTrickEntry == contactTrickEntry }
+
+        return ZStack {
             Rectangle()
                 .frame(width: UIScreen.main.bounds.width, height: 65)
                 .foregroundStyle(colorScheme == .dark ? Color.bgDarkerDarkBlue : Color.white)
@@ -160,7 +168,8 @@ struct ContactTrickDetailView: View {
                 Text("Save").padding(10)
             })
                 .frame(width: UIScreen.main.bounds.width * 0.9, alignment: .center)
-                .background(Color(.systemBlue))
+                .background(isUnchanged ? Color(.systemGray4) : Color(.systemBlue))
+                .disabled(isUnchanged)
                 .tint(.white)
                 .clipShape(RoundedRectangle(cornerRadius: 8))
                 .padding(5)