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

Merge remote-tracking branch 'ivalkou/dev' into Crowdin

Jon B.M 4 лет назад
Родитель
Сommit
50d0eb374a

+ 1 - 0
FreeAPS/Resources/Info.plist

@@ -40,6 +40,7 @@
 		<string>dexcomcgm</string>
 		<string>diabox</string>
 		<string>spikeapp</string>
+		<string>libredirect</string>
 	</array>
 	<key>LSRequiresIPhoneOS</key>
 	<true/>

+ 37 - 0
FreeAPS/Sources/APS/CGM/CGMType.swift

@@ -9,6 +9,7 @@ enum CGMType: String, JSON, CaseIterable, Identifiable {
     case dexcomG5
     case simulator
     case libreTransmitter
+    case glucoseDirect
 
     var displayName: String {
         switch self {
@@ -16,6 +17,8 @@ enum CGMType: String, JSON, CaseIterable, Identifiable {
             return "Nightscout"
         case .xdrip:
             return "xDrip"
+        case .glucoseDirect:
+            return "Glucose Direct"
         case .dexcomG6:
             return "Dexcom G6"
         case .dexcomG5:
@@ -33,6 +36,8 @@ enum CGMType: String, JSON, CaseIterable, Identifiable {
             return nil
         case .xdrip:
             return URL(string: "xdripswift://")!
+        case .glucoseDirect:
+            return URL(string: "libredirect://")!
         case .dexcomG6:
             return URL(string: "dexcomg6://")!
         case .dexcomG5:
@@ -43,4 +48,36 @@ enum CGMType: String, JSON, CaseIterable, Identifiable {
             return URL(string: "freeaps-x://libre-transmitter")!
         }
     }
+
+    var externalLink: URL? {
+        switch self {
+        case .xdrip:
+            return URL(string: "https://github.com/JohanDegraeve/xdripswift")!
+        case .glucoseDirect:
+            return URL(string: "https://github.com/creepymonster/GlucoseDirectApp")!
+        default: return nil
+        }
+    }
+
+    var subtitle: String {
+        switch self {
+        case .nightscout:
+            return NSLocalizedString("Online or internal server", comment: "Online or internal server")
+        case .xdrip:
+            return NSLocalizedString("Shared app group", comment: "Shared app group")
+        case .dexcomG6:
+            return NSLocalizedString("Native G6 app", comment: "Native G6 app")
+        case .dexcomG5:
+            return NSLocalizedString("Native G5 app", comment: "Native G5 app")
+        case .simulator:
+            return NSLocalizedString("Simple simulator", comment: "Simple simulator")
+        case .libreTransmitter:
+            return NSLocalizedString(
+                "Direct connection with Libre 1 transmitters or Libre 2",
+                comment: "Direct connection with Libre 1 transmitters or Libre 2"
+            )
+        case .glucoseDirect:
+            return NSLocalizedString("Shared app group", comment: "Shared app group")
+        }
+    }
 }

+ 2 - 0
FreeAPS/Sources/APS/FetchGlucoseManager.swift

@@ -42,6 +42,8 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
             glucoseSource = simulatorSource
         case .libreTransmitter:
             glucoseSource = libreTransmitter
+        case .glucoseDirect:
+            glucoseSource = appGroupSource
         }
 
         if settingsManager.settings.cgm != .libreTransmitter {

+ 3 - 20
FreeAPS/Sources/APS/Storage/GlucoseStorage.swift

@@ -4,8 +4,7 @@ import Swinject
 
 protocol GlucoseStorage {
     func storeGlucose(_ glucose: [BloodGlucose])
-    func removeGlucose(byID id: String)
-    func removeGlucose(byIDCollection ids: [String])
+    func removeGlucose(ids: [String])
     func recent() -> [BloodGlucose]
     func syncDate() -> Date
     func filterTooFrequentGlucose(_ glucose: [BloodGlucose], at: Date) -> [BloodGlucose]
@@ -50,29 +49,13 @@ final class BaseGlucoseStorage: GlucoseStorage, Injectable {
         }
     }
 
-    func removeGlucose(byIDCollection ids: [String]) {
+    func removeGlucose(ids: [String]) {
         processQueue.sync {
             let file = OpenAPS.Monitor.glucose
             self.storage.transaction { storage in
                 let bgInStorage = storage.retrieve(file, as: [BloodGlucose].self)
                 let filteredBG = bgInStorage?.filter { !ids.contains($0.id) } ?? []
-                storage.save(filteredBG, as: file)
-
-                DispatchQueue.main.async {
-                    self.broadcaster.notify(GlucoseObserver.self, on: .main) {
-                        $0.glucoseDidUpdate(filteredBG.reversed())
-                    }
-                }
-            }
-        }
-    }
-
-    func removeGlucose(byID id: String) {
-        processQueue.sync {
-            let file = OpenAPS.Monitor.glucose
-            self.storage.transaction { storage in
-                let bgInStorage = storage.retrieve(file, as: [BloodGlucose].self)
-                let filteredBG = bgInStorage?.filter { $0.id != id } ?? []
+                guard bgInStorage != filteredBG else { return }
                 storage.save(filteredBG, as: file)
 
                 DispatchQueue.main.async {

+ 10 - 2
FreeAPS/Sources/Modules/CGM/View/CGMRootView.swift

@@ -10,8 +10,16 @@ extension CGM {
             Form {
                 Section {
                     Picker("Type", selection: $state.cgm) {
-                        ForEach(CGMType.allCases) {
-                            Text($0.displayName).tag($0)
+                        ForEach(CGMType.allCases) { type in
+                            VStack(alignment: .leading) {
+                                Text(type.displayName)
+                                Text(type.subtitle).font(.caption).foregroundColor(.secondary)
+                            }.tag(type)
+                        }
+                    }
+                    if let link = state.cgm.externalLink {
+                        Button("About this source") {
+                            UIApplication.shared.open(link, options: [:], completionHandler: nil)
                         }
                     }
                 }

+ 1 - 1
FreeAPS/Sources/Modules/HealthKit/HealthKitStateModel.swift

@@ -23,7 +23,7 @@ extension AppleHealthKit {
                     return
                 }
 
-                self.healthKitManager.requestPermission { status, error in
+                self.healthKitManager.requestPermission { _, error in
                     guard error == nil else {
                         return
                     }

+ 1 - 1
FreeAPS/Sources/Services/HealthKit/HealthKitManager.swift

@@ -205,7 +205,7 @@ final class BaseHealthKitManager: HealthKitManager, Injectable {
                 let removingBGID = samples.map {
                     $0.metadata?["HKMetadataKeySyncIdentifier"] as? String ?? $0.uuid.uuidString
                 }
-                glucoseStorage.removeGlucose(byIDCollection: removingBGID)
+                glucoseStorage.removeGlucose(ids: removingBGID)
             }
         }
         return query