Skip to content

Commit

Permalink
initial commit - bg readings swiftui view
Browse files Browse the repository at this point in the history
  • Loading branch information
paulplant committed Jul 30, 2023
1 parent 001c58f commit 1aba802
Show file tree
Hide file tree
Showing 9 changed files with 619 additions and 24 deletions.
18 changes: 12 additions & 6 deletions xdrip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
47046EA22A69ACCE00A6F736 /* BgReadingsDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47046EA12A69ACCE00A6F736 /* BgReadingsDetailView.swift */; };
470824D2297484B500C52317 /* SwiftCharts in Frameworks */ = {isa = PBXBuildFile; productRef = 470824D1297484B500C52317 /* SwiftCharts */; };
470824D3297484B500C52317 /* SwiftCharts in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 470824D1297484B500C52317 /* SwiftCharts */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
470B618A270C448000561E56 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 470B6188270C448000561E56 /* Interface.storyboard */; };
Expand All @@ -20,6 +21,7 @@
470CE1FC246802EB00D5CB74 /* BluetoothPeripheralsView.strings in Resources */ = {isa = PBXBuildFile; fileRef = 470CE1FE246802EB00D5CB74 /* BluetoothPeripheralsView.strings */; };
470F021326DD515300C5D626 /* SettingsViewSensorCountdownSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470F021226DD515300C5D626 /* SettingsViewSensorCountdownSettingsViewModel.swift */; };
47150A4027F6211C00DB2994 /* SettingsViewTreatmentsSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47150A3F27F6211C00DB2994 /* SettingsViewTreatmentsSettingsViewModel.swift */; };
47228B152996BDD2008725DB /* BgReadingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47228B142996BDD2008725DB /* BgReadingsView.swift */; };
4749EB9B25B36E010072DF8B /* LibreNFC.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4749EB9D25B36E010072DF8B /* LibreNFC.strings */; };
47503382247420A200D2260B /* BluetoothPeripheralView.strings in Resources */ = {isa = PBXBuildFile; fileRef = 47503384247420A200D2260B /* BluetoothPeripheralView.strings */; };
4752B400263570DA0081D551 /* ConstantsStatistics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4752B3FF263570DA0081D551 /* ConstantsStatistics.swift */; };
Expand Down Expand Up @@ -699,6 +701,7 @@
4166BFCB28C3501500199980 /* el */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = el; path = el.lproj/LibreStates.strings; sourceTree = "<group>"; };
4166BFCC28C3501500199980 /* el */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = el; path = el.lproj/Snooze.strings; sourceTree = "<group>"; };
4166BFCD28C3501500199980 /* el */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = el; path = el.lproj/LibreNFC.strings; sourceTree = "<group>"; };
47046EA12A69ACCE00A6F736 /* BgReadingsDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BgReadingsDetailView.swift; path = /Users/paulplant/Documents/GitHub/xdripswift/xdrip/SwiftUIViews/BgReadingsDetailView.swift; sourceTree = "<absolute>"; };
470B6186270C448000561E56 /* xDrip4iO5.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = xDrip4iO5.app; sourceTree = BUILT_PRODUCTS_DIR; };
470B6189270C448000561E56 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Interface.storyboard; sourceTree = "<group>"; };
470B618B270C448100561E56 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -711,6 +714,7 @@
470CE1FF246802F400D5CB74 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/BluetoothPeripheralsView.strings; sourceTree = "<group>"; };
470F021226DD515300C5D626 /* SettingsViewSensorCountdownSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewSensorCountdownSettingsViewModel.swift; sourceTree = "<group>"; };
47150A3F27F6211C00DB2994 /* SettingsViewTreatmentsSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewTreatmentsSettingsViewModel.swift; sourceTree = "<group>"; };
47228B142996BDD2008725DB /* BgReadingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BgReadingsView.swift; sourceTree = "<group>"; };
4749EB9C25B36E010072DF8B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LibreNFC.strings; sourceTree = "<group>"; };
47503383247420A200D2260B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/BluetoothPeripheralView.strings; sourceTree = "<group>"; };
4752B3FF263570DA0081D551 /* ConstantsStatistics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsStatistics.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2158,6 +2162,8 @@
isa = PBXGroup;
children = (
F866974E2867A97000025441 /* Settings */,
47228B142996BDD2008725DB /* BgReadingsView.swift */,
47046EA12A69ACCE00A6F736 /* BgReadingsDetailView.swift */,
);
path = SwiftUIViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -3575,6 +3581,7 @@
F8E3A2A523D78FBD00E5E98A /* SettingsViewAppleWatchSettingsViewModel.swift in Sources */,
D400F8032778BD8000B57648 /* TextsTreatmentsView.swift in Sources */,
47ADD2E127FB05EB0025E2F4 /* ChartPointsScatterDownTrianglesWithDropdownLineLayer.swift in Sources */,
47228B152996BDD2008725DB /* BgReadingsView.swift in Sources */,
F81FA006228E09D40028C70F /* TextsCalibration.swift in Sources */,
F816E0F724367137009EE65B /* GNSEntry+CoreDataClass.swift in Sources */,
F8F9721923A5915900C3F17D /* CGMGNSEntryTransmitter.swift in Sources */,
Expand Down Expand Up @@ -3825,6 +3832,7 @@
F81FA0002289E4990028C70F /* AlertSettingsViewControllerData.swift in Sources */,
F80D916024F45EB3006840B5 /* LibreError.swift in Sources */,
F856CE5B22EDC8E50083E436 /* ConstantsBluetoothPairing.swift in Sources */,
47046EA22A69ACCE00A6F736 /* BgReadingsDetailView.swift in Sources */,
F8F971B823A5914D00C3F17D /* BluetoothPeripheral.swift in Sources */,
F8F9721723A5915900C3F17D /* CGMDroplet1Transmitter.swift in Sources */,
F8A2BC2E25DB0D6D001D1E78 /* BluetoothPeripheralManager+CGMDropletTransmitterDelegate.swift in Sources */,
Expand Down Expand Up @@ -4797,7 +4805,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
OBJROOT = "";
Expand Down Expand Up @@ -4859,7 +4866,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OBJROOT = "";
Expand All @@ -4883,8 +4889,8 @@
CODE_SIGN_STYLE = "$(XDRIP_CODE_SIGN_STYLE)";
CURRENT_PROJECT_VERSION = "$(CURRENT_PROJECT_VERSION)";
DEVELOPMENT_TEAM = "$(XDRIP_DEVELOPMENT_TEAM)";
INFOPLIST_FILE = "xdrip/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
INFOPLIST_FILE = "$(SRCROOT)/xdrip/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -4911,8 +4917,8 @@
CODE_SIGN_STYLE = "$(XDRIP_CODE_SIGN_STYLE)";
CURRENT_PROJECT_VERSION = "$(CURRENT_PROJECT_VERSION)";
DEVELOPMENT_TEAM = "$(XDRIP_DEVELOPMENT_TEAM)";
INFOPLIST_FILE = "xdrip/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
INFOPLIST_FILE = "$(SRCROOT)/xdrip/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
3 changes: 3 additions & 0 deletions xdrip/Constants/ConstantsLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,8 @@ enum ConstantsLog {
// for use in LoopManager
static let categoryLoopManager = "LoopManager "

/// for use in Bg Readings view
static let categoryBgReadingsView = "BgReadingsView "

}

1 change: 1 addition & 0 deletions xdrip/Constants/ConstantsUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ConstantsUI {

/// List background color
static let listBackGroundUIColor = UIColor.black

/// List background color
static let listBackGroundColor = Color(listBackGroundUIColor)

Expand Down
30 changes: 29 additions & 1 deletion xdrip/Core Data/accessors/BgReadingsAccessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import CoreData
import os

class BgReadingsAccessor {
class BgReadingsAccessor: ObservableObject {

// MARK: - Properties

Expand Down Expand Up @@ -192,6 +192,33 @@ class BgReadingsAccessor {

try managedObjectContext.save()

print("coredata saved")

} catch {

trace("in delete bgReading, Unable to Save Changes, error.localizedDescription = %{public}@", log: self.log, category: ConstantsLog.categoryApplicationDataBgReadings, type: .error, error.localizedDescription)

print("coredata save error")
}

}

}


/// deletes bgReading
/// - bgReading : bgReading to delete
func delete(bgReading: BgReading) {

coreDataManager.mainManagedObjectContext.performAndWait {

coreDataManager.mainManagedObjectContext.delete(bgReading)

// save changes to coredata
do {

try coreDataManager.mainManagedObjectContext.save()

} catch {

trace("in delete bgReading, Unable to Save Changes, error.localizedDescription = %{public}@", log: self.log, category: ConstantsLog.categoryApplicationDataBgReadings, type: .error, error.localizedDescription)
Expand All @@ -202,6 +229,7 @@ class BgReadingsAccessor {

}


// MARK: - private helper functions

/// returnvalue can be empty array
Expand Down
23 changes: 22 additions & 1 deletion xdrip/Managers/NightScout/NightScoutUploadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os
import UIKit
import xDrip4iOS_Widget

public class NightScoutUploadManager: NSObject {
public class NightScoutUploadManager: NSObject, ObservableObject {

// MARK: - properties

Expand Down Expand Up @@ -349,6 +349,27 @@ public class NightScoutUploadManager: NSObject {

}


/// tries to delete any entries from Nightscout that are within 1 second either side of the timestamp that is passed (this should normally just be a single entry/reading)
/// - parameters:
/// - timeStampOfBgReadingToDelete : the timestamp of the BG reading that we want to try and remove
public func deleteBgReadingFromNightscout(timeStampOfBgReadingToDelete: Date) {

// create a query that finds entries between 1 second before, and 1 second after, the timestamp
let queries = [URLQueryItem(name: "find[dateString][$gte]", value: String(timeStampOfBgReadingToDelete.addingTimeInterval(-1).ISOStringFromDate())), URLQueryItem(name: "find[dateString][$lte]", value: String(timeStampOfBgReadingToDelete.addingTimeInterval(+1).ISOStringFromDate()))]

// send a DELETE http request with the queryItems
getOrDeleteRequest(path: nightScoutEntriesPath, queries: queries, httpMethod: "DELETE", completionHandler: { (data: Data?, nightScoutResult: NightScoutResult) in

// this is maybe redundant as Nightscout returns a successful result even if no entries were actually found/deleted
if nightScoutResult.successFull() {
trace("deleting BG reading/entry with timestamp %{public}@ from Nightscout", log: self.oslog, category: ConstantsLog.categoryNightScoutUploadManager, type: .info, timeStampOfBgReadingToDelete.description)
}

})

}

// MARK: - overriden functions

/// when one of the observed settings get changed, possible actions to take
Expand Down
Loading

0 comments on commit 1aba802

Please sign in to comment.