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

Minor Contact Trick Adjustments
* Rename single to default
* Change order of element pickers: 1. top, 2. primary (if layout is default), 3. bottom
* Hide secondary font size picker when layout is split (has no effect in default layout)
* Remove condensed font width (letter spacing) to avoid letter stacking / unreadable strings

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

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

@@ -40,7 +40,7 @@ final class BaseContactTrickStorage: ContactTrickStorage, Injectable {
             return fetchedContactTrickEntries.compactMap { entry in
                 ContactTrickEntry(
                     name: entry.name ?? "No name provided",
-                    layout: ContactTrickLayout(rawValue: entry.layout ?? "Single") ?? .single,
+                    layout: ContactTrickLayout(rawValue: entry.layout ?? "Default") ?? .default,
                     ring: ContactTrickLargeRing(rawValue: entry.ring ?? "Hidden") ?? .none,
                     primary: ContactTrickValue(rawValue: entry.primary ?? "Glucose Reading") ?? .glucose,
                     top: ContactTrickValue(rawValue: entry.top ?? "None") ?? .none,

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

@@ -4,7 +4,7 @@ import SwiftUI
 struct ContactTrickEntry: Hashable, Equatable, Sendable {
     var id = UUID()
     var name: String = ""
-    var layout: ContactTrickLayout = .single
+    var layout: ContactTrickLayout = .default
     var ring: ContactTrickLargeRing = .none
     var primary: ContactTrickValue = .glucose
     var top: ContactTrickValue = .none
@@ -153,13 +153,13 @@ enum ContactTrickValue: String, JSON, CaseIterable, Identifiable, Codable {
 
 enum ContactTrickLayout: String, JSON, CaseIterable, Identifiable, Codable {
     var id: String { rawValue }
-    case single
+    case `default`
     case split
 
     var displayName: String {
         switch self {
-        case .single:
-            return NSLocalizedString("Single", comment: "")
+        case .default:
+            return NSLocalizedString("Default", comment: "")
         case .split:
             return NSLocalizedString("Split", comment: "")
         }

+ 18 - 11
FreeAPS/Sources/Modules/ContactTrick/View/AddContactTrickSheet.swift

@@ -10,7 +10,7 @@ struct AddContactTrickSheet: View {
     @State private var hasHighContrast: Bool = true
     @State private var ringWidth: ContactTrickEntry.RingWidth = .regular
     @State private var ringGap: ContactTrickEntry.RingGap = .small
-    @State private var layout: ContactTrickLayout = .single
+    @State private var layout: ContactTrickLayout = .default
     @State private var primary: ContactTrickValue = .glucose
     @State private var top: ContactTrickValue = .none
     @State private var bottom: ContactTrickValue = .trend
@@ -72,25 +72,30 @@ struct AddContactTrickSheet: View {
                             ForEach(ContactTrickLayout.allCases, id: \.id) { layout in
                                 Text(layout.displayName).tag(layout)
                             }
-                        }
+                        }.onChange(of: layout, { oldLayout, newLayout in
+                            if oldLayout != newLayout, newLayout == .split {
+                                top = .glucose
+                            } else {
+                                top = .none
+                            }
+                        })
                         Toggle("High Contrast Mode", isOn: $hasHighContrast)
                     }.listRowBackground(Color.chart)
 
                     // Primary Value Section
                     Section(header: Text("Display Values")) {
-                        if layout == .single {
+                        Picker("Top Value", selection: $top) {
+                            ForEach(ContactTrickValue.allCases, id: \.id) { value in
+                                Text(value.displayName).tag(value)
+                            }
+                        }
+                        if layout == .default {
                             Picker("Primary", selection: $primary) {
                                 ForEach(ContactTrickValue.allCases, id: \.id) { value in
                                     Text(value.displayName).tag(value)
                                 }
                             }
                         }
-
-                        Picker("Top Value", selection: $top) {
-                            ForEach(ContactTrickValue.allCases, id: \.id) { value in
-                                Text(value.displayName).tag(value)
-                            }
-                        }
                         Picker("Bottom Value", selection: $bottom) {
                             ForEach(ContactTrickValue.allCases, id: \.id) { value in
                                 Text(value.displayName).tag(value)
@@ -124,7 +129,9 @@ struct AddContactTrickSheet: View {
                     // Font Settings Section
                     Section(header: Text("Font Settings")) {
                         fontSizePicker
-                        secondaryFontSizePicker
+                        if layout == .split {
+                            secondaryFontSizePicker
+                        }
                         fontWeightPicker
                         fontWidthPicker
                     }.listRowBackground(Color.chart)
@@ -230,7 +237,7 @@ struct AddContactTrickSheet: View {
     private var fontWidthPicker: some View {
         Picker("Font Width", selection: $fontWidth) {
             ForEach(
-                [Font.Width.standard, Font.Width.condensed, Font.Width.expanded],
+                [Font.Width.standard, Font.Width.expanded],
                 id: \.self
             ) { width in
                 Text("\(width.displayName)".capitalized).tag(width)

+ 19 - 10
FreeAPS/Sources/Modules/ContactTrick/View/ContactTrickDetailView.swift

@@ -46,12 +46,25 @@ struct ContactTrickDetailView: View {
                         ForEach(ContactTrickLayout.allCases, id: \.id) { layout in
                             Text(layout.displayName).tag(layout)
                         }
-                    }
+                    }.onChange(of: contactTrickEntry.layout, { oldLayout, newLayout in
+                        if oldLayout != newLayout, newLayout == .split {
+                            contactTrickEntry.top = .glucose
+                        } else {
+                            contactTrickEntry.top = .none
+                        }
+                    })
+
                     Toggle("High Contrast Mode", isOn: $contactTrickEntry.hasHighContrast)
                 }.listRowBackground(Color.chart)
 
                 Section(header: Text("Display Values")) {
-                    if contactTrickEntry.layout == .single {
+                    Picker("Top Value", selection: $contactTrickEntry.top) {
+                        ForEach(ContactTrickValue.allCases, id: \.id) { value in
+                            Text(value.displayName).tag(value)
+                        }
+                    }
+
+                    if contactTrickEntry.layout == .default {
                         Picker("Primary", selection: $contactTrickEntry.primary) {
                             ForEach(ContactTrickValue.allCases, id: \.id) { value in
                                 Text(value.displayName).tag(value)
@@ -59,12 +72,6 @@ struct ContactTrickDetailView: View {
                         }
                     }
 
-                    Picker("Top Value", selection: $contactTrickEntry.top) {
-                        ForEach(ContactTrickValue.allCases, id: \.id) { value in
-                            Text(value.displayName).tag(value)
-                        }
-                    }
-
                     Picker("Bottom Value", selection: $contactTrickEntry.bottom) {
                         ForEach(ContactTrickValue.allCases, id: \.id) { value in
                             Text(value.displayName).tag(value)
@@ -97,7 +104,9 @@ struct ContactTrickDetailView: View {
                 // Font Settings Section
                 Section(header: Text("Font Settings")) {
                     fontSizePicker
-                    secondaryFontSizePicker
+                    if contactTrickEntry.layout == .split {
+                        secondaryFontSizePicker
+                    }
                     fontWeightPicker
                     fontWidthPicker
                 }.listRowBackground(Color.chart)
@@ -206,7 +215,7 @@ struct ContactTrickDetailView: View {
     private var fontWidthPicker: some View {
         Picker("Font Width", selection: $contactTrickEntry.fontWidth) {
             ForEach(
-                [Font.Width.standard, Font.Width.condensed, Font.Width.expanded],
+                [Font.Width.standard, Font.Width.expanded],
                 id: \.self
             ) { width in
                 Text("\(width.displayName)".capitalized).tag(width)

+ 1 - 15
FreeAPS/Sources/Services/ContactTrick/ContactTrickManager.swift

@@ -75,21 +75,7 @@ final class BaseContactTrickManager: NSObject, ContactTrickManager, Injectable {
     // MARK: - Core Data observation
 
     private func registerHandlers() {
-        /*
-         TODO: - Do we really need to update in both cases, i.e. when OrefDetermination entity AND GlucoseStored entity have received updates ?
-         The main use case is showing glucose values and both updates happen ~ at the same time and if a new glucose value arrives the latest Determination gets fetched with that as well. Moreover, we don't need to update on Determination updates at all if the user hasn't chosen to display anything Determination related
-         */
-//
-//        coreDataPublisher?.filterByEntityName("OrefDetermination").sink { [weak self] _ in
-//            guard let self = self else { return }
-//            Task {
-//                await self.updateContactTrickState()
-//                await self.updateContactImages()
-//            }
-//        }.store(in: &subscriptions)
-
-        // Only needed for manual glucose entries
-        coreDataPublisher?.filterByEntityName("GlucoseStored").sink { [weak self] _ in
+        coreDataPublisher?.filterByEntityName("OrefDetermination").sink { [weak self] _ in
             guard let self = self else { return }
             Task {
                 await self.updateContactTrickState()

+ 7 - 5
FreeAPS/Sources/Services/ContactTrick/ContactTrickPicture.swift

@@ -66,7 +66,7 @@ struct ContactPicture: View {
         }
 
         switch contact.layout {
-        case .single:
+        case .default:
             let showTop = contact.top != .none
             let showBottom = contact.bottom != .none
 
@@ -277,6 +277,8 @@ struct ContactPicture: View {
         let textColor: Color = switch value {
         case .cob:
             .loopYellow
+        case .iob:
+            .insulin
         case .glucose:
             dynamicColor
         default:
@@ -792,7 +794,7 @@ struct ContactPicture_Previews: PreviewProvider {
 //            ContactPicturePreview(
 //                contact: .constant(
 //                    ContactTrickEntry(
-//                        layout: .single,
+//                        layout: .default,
 //                        ring: .iobcob,
 //                        primary: .none,
 //                        ringWidth: .regular,
@@ -814,7 +816,7 @@ struct ContactPicture_Previews: PreviewProvider {
 //            ContactPicturePreview(
 //                contact: .constant(
 //                    ContactTrickEntry(
-//                        layout: .single,
+//                        layout: .default,
 //                        ring: .iobcob,
 //                        primary: .none,
 //                        fontSize: fontSize,
@@ -834,7 +836,7 @@ struct ContactPicture_Previews: PreviewProvider {
 //            ContactPicturePreview(
 //                contact: .constant(
 //                    ContactTrickEntry(
-//                        layout: .single,
+//                        layout: .default,
 //                        ring: .iobcob,
 //                        primary: .none,
 //                        fontSize: fontSize,
@@ -854,7 +856,7 @@ struct ContactPicture_Previews: PreviewProvider {
 //            ContactPicturePreview(
 //                contact: .constant(
 //                    ContactTrickEntry(
-//                        layout: .single,
+//                        layout: .default,
 //                        ring: .iobcob,
 //                        primary: .glucose,
 //                        bottom: .trend,