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

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
             return fetchedContactTrickEntries.compactMap { entry in
                 ContactTrickEntry(
                 ContactTrickEntry(
                     name: entry.name ?? "No name provided",
                     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,
                     ring: ContactTrickLargeRing(rawValue: entry.ring ?? "Hidden") ?? .none,
                     primary: ContactTrickValue(rawValue: entry.primary ?? "Glucose Reading") ?? .glucose,
                     primary: ContactTrickValue(rawValue: entry.primary ?? "Glucose Reading") ?? .glucose,
                     top: ContactTrickValue(rawValue: entry.top ?? "None") ?? .none,
                     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 {
 struct ContactTrickEntry: Hashable, Equatable, Sendable {
     var id = UUID()
     var id = UUID()
     var name: String = ""
     var name: String = ""
-    var layout: ContactTrickLayout = .single
+    var layout: ContactTrickLayout = .default
     var ring: ContactTrickLargeRing = .none
     var ring: ContactTrickLargeRing = .none
     var primary: ContactTrickValue = .glucose
     var primary: ContactTrickValue = .glucose
     var top: ContactTrickValue = .none
     var top: ContactTrickValue = .none
@@ -153,13 +153,13 @@ enum ContactTrickValue: String, JSON, CaseIterable, Identifiable, Codable {
 
 
 enum ContactTrickLayout: String, JSON, CaseIterable, Identifiable, Codable {
 enum ContactTrickLayout: String, JSON, CaseIterable, Identifiable, Codable {
     var id: String { rawValue }
     var id: String { rawValue }
-    case single
+    case `default`
     case split
     case split
 
 
     var displayName: String {
     var displayName: String {
         switch self {
         switch self {
-        case .single:
-            return NSLocalizedString("Single", comment: "")
+        case .default:
+            return NSLocalizedString("Default", comment: "")
         case .split:
         case .split:
             return NSLocalizedString("Split", comment: "")
             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 hasHighContrast: Bool = true
     @State private var ringWidth: ContactTrickEntry.RingWidth = .regular
     @State private var ringWidth: ContactTrickEntry.RingWidth = .regular
     @State private var ringGap: ContactTrickEntry.RingGap = .small
     @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 primary: ContactTrickValue = .glucose
     @State private var top: ContactTrickValue = .none
     @State private var top: ContactTrickValue = .none
     @State private var bottom: ContactTrickValue = .trend
     @State private var bottom: ContactTrickValue = .trend
@@ -72,25 +72,30 @@ struct AddContactTrickSheet: View {
                             ForEach(ContactTrickLayout.allCases, id: \.id) { layout in
                             ForEach(ContactTrickLayout.allCases, id: \.id) { layout in
                                 Text(layout.displayName).tag(layout)
                                 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)
                         Toggle("High Contrast Mode", isOn: $hasHighContrast)
                     }.listRowBackground(Color.chart)
                     }.listRowBackground(Color.chart)
 
 
                     // Primary Value Section
                     // Primary Value Section
                     Section(header: Text("Display Values")) {
                     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) {
                             Picker("Primary", selection: $primary) {
                                 ForEach(ContactTrickValue.allCases, id: \.id) { value in
                                 ForEach(ContactTrickValue.allCases, id: \.id) { value in
                                     Text(value.displayName).tag(value)
                                     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) {
                         Picker("Bottom Value", selection: $bottom) {
                             ForEach(ContactTrickValue.allCases, id: \.id) { value in
                             ForEach(ContactTrickValue.allCases, id: \.id) { value in
                                 Text(value.displayName).tag(value)
                                 Text(value.displayName).tag(value)
@@ -124,7 +129,9 @@ struct AddContactTrickSheet: View {
                     // Font Settings Section
                     // Font Settings Section
                     Section(header: Text("Font Settings")) {
                     Section(header: Text("Font Settings")) {
                         fontSizePicker
                         fontSizePicker
-                        secondaryFontSizePicker
+                        if layout == .split {
+                            secondaryFontSizePicker
+                        }
                         fontWeightPicker
                         fontWeightPicker
                         fontWidthPicker
                         fontWidthPicker
                     }.listRowBackground(Color.chart)
                     }.listRowBackground(Color.chart)
@@ -230,7 +237,7 @@ struct AddContactTrickSheet: View {
     private var fontWidthPicker: some View {
     private var fontWidthPicker: some View {
         Picker("Font Width", selection: $fontWidth) {
         Picker("Font Width", selection: $fontWidth) {
             ForEach(
             ForEach(
-                [Font.Width.standard, Font.Width.condensed, Font.Width.expanded],
+                [Font.Width.standard, Font.Width.expanded],
                 id: \.self
                 id: \.self
             ) { width in
             ) { width in
                 Text("\(width.displayName)".capitalized).tag(width)
                 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
                         ForEach(ContactTrickLayout.allCases, id: \.id) { layout in
                             Text(layout.displayName).tag(layout)
                             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)
                     Toggle("High Contrast Mode", isOn: $contactTrickEntry.hasHighContrast)
                 }.listRowBackground(Color.chart)
                 }.listRowBackground(Color.chart)
 
 
                 Section(header: Text("Display Values")) {
                 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) {
                         Picker("Primary", selection: $contactTrickEntry.primary) {
                             ForEach(ContactTrickValue.allCases, id: \.id) { value in
                             ForEach(ContactTrickValue.allCases, id: \.id) { value in
                                 Text(value.displayName).tag(value)
                                 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) {
                     Picker("Bottom Value", selection: $contactTrickEntry.bottom) {
                         ForEach(ContactTrickValue.allCases, id: \.id) { value in
                         ForEach(ContactTrickValue.allCases, id: \.id) { value in
                             Text(value.displayName).tag(value)
                             Text(value.displayName).tag(value)
@@ -97,7 +104,9 @@ struct ContactTrickDetailView: View {
                 // Font Settings Section
                 // Font Settings Section
                 Section(header: Text("Font Settings")) {
                 Section(header: Text("Font Settings")) {
                     fontSizePicker
                     fontSizePicker
-                    secondaryFontSizePicker
+                    if contactTrickEntry.layout == .split {
+                        secondaryFontSizePicker
+                    }
                     fontWeightPicker
                     fontWeightPicker
                     fontWidthPicker
                     fontWidthPicker
                 }.listRowBackground(Color.chart)
                 }.listRowBackground(Color.chart)
@@ -206,7 +215,7 @@ struct ContactTrickDetailView: View {
     private var fontWidthPicker: some View {
     private var fontWidthPicker: some View {
         Picker("Font Width", selection: $contactTrickEntry.fontWidth) {
         Picker("Font Width", selection: $contactTrickEntry.fontWidth) {
             ForEach(
             ForEach(
-                [Font.Width.standard, Font.Width.condensed, Font.Width.expanded],
+                [Font.Width.standard, Font.Width.expanded],
                 id: \.self
                 id: \.self
             ) { width in
             ) { width in
                 Text("\(width.displayName)".capitalized).tag(width)
                 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
     // MARK: - Core Data observation
 
 
     private func registerHandlers() {
     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 }
             guard let self = self else { return }
             Task {
             Task {
                 await self.updateContactTrickState()
                 await self.updateContactTrickState()

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

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