Skip to content

Commit

Permalink
fix #74 Chart shows a gap after changing bloodglucose unit
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanDegraeve committed Feb 2, 2020
1 parent 548b0d2 commit 04c2901
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion xdrip/Managers/Charts/GlucoseChartManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftCharts
import os.log
import UIKit

public final class GlucoseChartManager {
public final class GlucoseChartManager: NSObject {

// MARK: - public properties

Expand Down Expand Up @@ -136,6 +136,12 @@ public final class GlucoseChartManager {
// operationQueue will be queue of blocks that gets readings and updates glucoseChartPoints, startDate and endDate. To avoid race condition, the operations should be one after the other
operationQueue.maxConcurrentOperationCount = 1

super.init()

// update of unit requires glucoseChartPoints to be set to 0
UserDefaults.standard.addObserver(self, forKeyPath: UserDefaults.Key.bloodGlucoseUnitIsMgDl.rawValue, options: .new, context: nil)


}

// MARK: - public functions
Expand Down Expand Up @@ -230,6 +236,7 @@ public final class GlucoseChartManager {
self.startDate = startDateToUse
self.glucoseChartPoints = newGlucoseChartPointsToPrepend + (reUseExistingChartPointList ? self.glucoseChartPoints : [ChartPoint]()) + newGlucoseChartPointsToAppend


// update the chart outlet
chartOutlet.reloadChart()

Expand Down Expand Up @@ -290,6 +297,28 @@ public final class GlucoseChartManager {
}

}

// MARK:- observe function

override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

if let keyPath = keyPath {

if let keyPathEnum = UserDefaults.Key(rawValue: keyPath) {

switch keyPathEnum {

case UserDefaults.Key.multipleAppBadgeValueWith10, UserDefaults.Key.showReadingInAppBadge, UserDefaults.Key.bloodGlucoseUnitIsMgDl:
glucoseChartPoints = []

default:
break

}
}

}
}

// MARK: - private functions

Expand Down

0 comments on commit 04c2901

Please sign in to comment.