Skip to content

Commit

Permalink
moved UIKit-dependant functions out of TreatmentEntry+CoreDataClass a…
Browse files Browse the repository at this point in the history
…nd into TreatmentTableViewCell
  • Loading branch information
paulplant committed May 30, 2022
1 parent 1ef321f commit dc43dac
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 145 deletions.
88 changes: 0 additions & 88 deletions xdrip/Core Data/classes/TreatmentEntry+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import CoreData
import UIKit


// @objc and Int16 allows enums to work with CoreData
Expand Down Expand Up @@ -113,56 +112,6 @@ import UIKit
}

}

/// Returns the displayUnit: the .unit as required by the treatment type and the user settings
public func iconColor() -> UIColor {

switch self {

case .Insulin:
return ConstantsGlucoseChart.bolusTreatmentColor

case .Carbs:
return ConstantsGlucoseChart.carbsTreatmentColor

case .Exercise:
return UIColor.magenta

case .BgCheck:
return ConstantsGlucoseChart.bgCheckTreatmentColorInner

}

}

/// Returns the displayUnit: the .unit as required by the treatment type and the user settings
public func iconImage() -> UIImage? {

if #available(iOS 13.0, *) {

switch self {

case .Insulin:
return UIImage(systemName: "arrowtriangle.down.fill")!

case .Carbs:
return UIImage(systemName: "circle.fill")!

case .Exercise:
return UIImage(systemName: "heart.fill")!

case .BgCheck:
return UIImage(systemName: "drop.fill")!

}

} else {

return nil

}

}

}

Expand Down Expand Up @@ -214,43 +163,6 @@ public class TreatmentEntry: NSManagedObject, Comparable {
super.init(entity: entity, insertInto: context)
}

/// Returns the displayValue: the .value in the correct value if any changes are required
public func displayValue() -> String {

// if the treatmentType is a BG Check then convert the value to mmol/l if that is what the user is using. All BG checks are stored in coredata as mg/dl
if self.treatmentType == .BgCheck {

// save typing
let isMgDl: Bool = UserDefaults.standard.bloodGlucoseUnitIsMgDl

// convert to mmol/l if needed, round accordingly and add the correct units
return self.value.mgdlToMmol(mgdl: isMgDl).bgValueRounded(mgdl: isMgDl).stringWithoutTrailingZeroes

} else {

return self.value.stringWithoutTrailingZeroes

}

}

/// Returns the displayUnit: the .unit as required by the treatment type and the user settings
public func displayUnit() -> String {

// if the treatmentType is a BG Check then convert the value to mmol/l if that is what the user is using. All BG checks are stored in coredata as mg/dl
if self.treatmentType == .BgCheck {

// convert to mmol/l if needed, round accordingly and add the correct units
return String(UserDefaults.standard.bloodGlucoseUnitIsMgDl ? Texts_Common.mgdl : Texts_Common.mmol)

} else {

return self.treatmentType.unit()

}

}

/// - get the dictionary representation required for creating a new treatment @ NighScout using POST or updating an existing treatment @ NightScout using PUT
/// - splits of "-carbs" "-insulin" or "-exercise" from the id
public func dictionaryRepresentationForNightScoutUpload() -> [String: Any] {
Expand Down
Loading

0 comments on commit dc43dac

Please sign in to comment.