From dd25cd78e240f872b81691886689da1c73144e8d Mon Sep 17 00:00:00 2001 From: Paul Plant <37302780+paulplant@users.noreply.github.com> Date: Thu, 28 Apr 2022 20:09:23 +0200 Subject: [PATCH] Nightscout follower now syncs every 15s and sync button removed from treatments screen --- .../NightScout/NightScoutFollowManager.swift | 25 ++++--------------- xdrip/Storyboards/Base.lproj/Main.storyboard | 7 ------ .../Treatments/TreatmentsViewController.swift | 8 ------ 3 files changed, 5 insertions(+), 35 deletions(-) diff --git a/xdrip/Managers/NightScout/NightScoutFollowManager.swift b/xdrip/Managers/NightScout/NightScoutFollowManager.swift index 9ee7cc9e..1f63e4a3 100644 --- a/xdrip/Managers/NightScout/NightScoutFollowManager.swift +++ b/xdrip/Managers/NightScout/NightScoutFollowManager.swift @@ -195,7 +195,7 @@ class NightScoutFollowManager:NSObject { } // schedule new download - self.scheduleNewDownload(followGlucoseDataArray: &followGlucoseDataArray) + self.scheduleNewDownload() } @@ -208,28 +208,13 @@ class NightScoutFollowManager:NSObject { } - /// wel schedule new download with timer, when timer expires download() will be called - /// - parameters: - /// - followGlucoseDataArray : array of FollowGlucoseData, first element is the youngest, can be empty. This is the data downloaded during previous download. This parameter is just there to get the timestamp of the latest reading, in order to calculate the next download time - private func scheduleNewDownload(followGlucoseDataArray:inout [NightScoutBgReading]) { + /// schedule new download with timer, when timer expires download() will be called + private func scheduleNewDownload() { trace("in scheduleNewDownload", log: self.log, category: ConstantsLog.categoryNightScoutFollowManager, type: .info) - // start with timestamp now + 5 minutes and 10 seconds - var nextFollowDownloadTimeStamp = Date(timeIntervalSinceNow: 5 * 60 + 10) - - // followGlucoseDataArray.count > 0 then use the timestamp of the latest reading to calculate the next downloadtimestamp - if followGlucoseDataArray.count > 0 { - // use timestamp of latest stored reading + 5 minutes + 10 seconds - nextFollowDownloadTimeStamp = Date(timeInterval: 5 * 60 + 10, since: followGlucoseDataArray[0].timeStamp) - // now increase till next timestamp is bigger than now - while (nextFollowDownloadTimeStamp < Date()) { - nextFollowDownloadTimeStamp = Date(timeInterval: 5 * 60, since: nextFollowDownloadTimeStamp) - } - } - - // schedule timer and assign it to a let property - let downloadTimer = Timer.scheduledTimer(timeInterval: nextFollowDownloadTimeStamp.timeIntervalSince1970 - Date().timeIntervalSince1970, target: self, selector: #selector(self.download), userInfo: nil, repeats: false) + // schedule a timer for 15 seconds and assign it to a let property + let downloadTimer = Timer.scheduledTimer(timeInterval: 15, target: self, selector: #selector(self.download), userInfo: nil, repeats: false) // assign invalidateDownLoadTimerClosure to a closure that will invalidate the downloadTimer invalidateDownLoadTimerClosure = { diff --git a/xdrip/Storyboards/Base.lproj/Main.storyboard b/xdrip/Storyboards/Base.lproj/Main.storyboard index a88c4b8f..498e8207 100644 --- a/xdrip/Storyboards/Base.lproj/Main.storyboard +++ b/xdrip/Storyboards/Base.lproj/Main.storyboard @@ -233,12 +233,6 @@ - - - - - - @@ -1968,7 +1962,6 @@ - diff --git a/xdrip/View Controllers/Treatments/TreatmentsViewController.swift b/xdrip/View Controllers/Treatments/TreatmentsViewController.swift index 9f66b423..030d2dd1 100644 --- a/xdrip/View Controllers/Treatments/TreatmentsViewController.swift +++ b/xdrip/View Controllers/Treatments/TreatmentsViewController.swift @@ -28,14 +28,6 @@ class TreatmentsViewController : UIViewController { @IBOutlet weak var tableView: UITableView! - /// Sync button action. - @IBAction func syncButtonTapped(_ sender: UIBarButtonItem) { - - // nightscout upload manager observes this value and will initialize a sync - UserDefaults.standard.nightScoutSyncTreatmentsRequired = true - - } - // MARK: - View Life Cycle override func viewWillAppear(_ animated: Bool) {