Procházet zdrojové kódy

Trigger refresh after toggling contact settings

Jonas Björkert před 1 rokem
rodič
revize
129794fc43

+ 1 - 1
LoopFollow/Contact/Settings/ContactSettingsView.swift

@@ -21,7 +21,7 @@ struct ContactSettingsView: View {
         NavigationView {
             Form {
                 Section(header: Text("Contact Integration")) {
-                    Text("Add the contact named \(viewModel.contactName) to your watch face to show the current BG value in real time. Make sure to give the app full access to Contacts when prompted.")
+                    Text("Add the contact named '\(viewModel.contactName)' to your watch face to show the current BG value in real time. Make sure to give the app full access to Contacts when prompted.")
                         .font(.footnote)
                         .foregroundColor(.secondary)
                         .padding(.vertical, 4)

+ 8 - 3
LoopFollow/Contact/Settings/ContactSettingsViewModel.swift

@@ -9,8 +9,6 @@
 import Foundation
 import Combine
 
-import Foundation
-
 extension Bundle {
     var displayName: String {
         return object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ?? "LoopFollow"
@@ -19,12 +17,13 @@ extension Bundle {
 
 class ContactSettingsViewModel: ObservableObject {
     var contactName: String {
-        "'\(Bundle.main.displayName) - BG'"
+        "\(Bundle.main.displayName) - BG"
     }
 
     @Published var contactEnabled: Bool {
         didSet {
             storage.contactEnabled.value = contactEnabled
+            triggerRefresh()
         }
     }
 
@@ -34,6 +33,7 @@ class ContactSettingsViewModel: ObservableObject {
                 contactDelta = false
             }
             storage.contactTrend.value = contactTrend
+            triggerRefresh()
         }
     }
 
@@ -43,6 +43,7 @@ class ContactSettingsViewModel: ObservableObject {
                 contactTrend = false
             }
             storage.contactDelta.value = contactDelta
+            triggerRefresh()
         }
     }
 
@@ -63,4 +64,8 @@ class ContactSettingsViewModel: ObservableObject {
         storage.contactDelta.$value
             .assign(to: &$contactDelta)
     }
+
+    private func triggerRefresh() {
+        NotificationCenter.default.post(name: NSNotification.Name("refresh"), object: nil)
+    }
 }