forked from Artificial-Pancreas/iAPS
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,896 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
struct ContactTrickEntry: JSON, Equatable { | ||
var enabled: Bool = false | ||
var layout: ContactTrickLayout = .single | ||
var ring1: ContactTrickLargeRing = .none | ||
var primary: ContactTrickValue = .glucose | ||
var top: ContactTrickValue = .none | ||
var bottom: ContactTrickValue = .none | ||
var contactId: String? = nil | ||
var displayName: String? = nil | ||
var darkMode: Bool = true | ||
var ringWidth: Int = 7 | ||
var ringGap: Int = 2 | ||
var fontSize: Int = 100 | ||
var fontName: String = "Default Font" | ||
var fontWeight: FontWeight = .medium | ||
var fontTracking: FontTracking = .normal | ||
|
||
func isDefaultFont() -> Bool { | ||
fontName == "Default Font" | ||
} | ||
} | ||
|
||
protocol ContactTrickObserver { | ||
func basalProfileDidChange(_ entry: [ContactTrickEntry]) | ||
} | ||
|
||
extension ContactTrickEntry { | ||
private enum CodingKeys: String, CodingKey { | ||
case enabled | ||
case layout | ||
case ring1 | ||
case primary | ||
case top | ||
case bottom | ||
case contactId | ||
case displayName | ||
case darkMode | ||
case ringWidth | ||
case ringGap | ||
case fontSize | ||
case fontName | ||
case fontWeight | ||
case fontTracking | ||
} | ||
|
||
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
let enabled = try container.decodeIfPresent(Bool.self, forKey: .enabled) ?? false | ||
let layout = try container.decodeIfPresent(ContactTrickLayout.self, forKey: .layout) ?? .single | ||
let ring1 = try container.decodeIfPresent(ContactTrickLargeRing.self, forKey: .ring1) ?? .none | ||
let primary = try container.decodeIfPresent(ContactTrickValue.self, forKey: .primary) ?? .glucose | ||
let top = try container.decodeIfPresent(ContactTrickValue.self, forKey: .top) ?? .none | ||
let bottom = try container.decodeIfPresent(ContactTrickValue.self, forKey: .bottom) ?? .none | ||
let contactId = try container.decodeIfPresent(String.self, forKey: .contactId) | ||
let displayName = try container.decodeIfPresent(String.self, forKey: .displayName) | ||
let darkMode = try container.decodeIfPresent(Bool.self, forKey: .darkMode) ?? true | ||
let ringWidth = try container.decodeIfPresent(Int.self, forKey: .ringWidth) ?? 7 | ||
let ringGap = try container.decodeIfPresent(Int.self, forKey: .ringGap) ?? 2 | ||
let fontSize = try container.decodeIfPresent(Int.self, forKey: .fontSize) ?? 100 | ||
let fontName = try container.decodeIfPresent(String.self, forKey: .fontName) ?? "Default Font" | ||
let fontWeight = try container.decodeIfPresent(FontWeight.self, forKey: .fontWeight) ?? .regular | ||
let fontTracking = try container.decodeIfPresent(FontTracking.self, forKey: .fontTracking) ?? .normal | ||
|
||
self = ContactTrickEntry( | ||
enabled: enabled, | ||
layout: layout, | ||
ring1: ring1, | ||
primary: primary, | ||
top: top, | ||
bottom: bottom, | ||
contactId: contactId, | ||
displayName: displayName, | ||
darkMode: darkMode, | ||
ringWidth: ringWidth, | ||
ringGap: ringGap, | ||
fontSize: fontSize, | ||
fontName: fontName, | ||
fontWeight: fontWeight, | ||
fontTracking: fontTracking | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Foundation | ||
|
||
enum FontTracking: String, JSON, Identifiable, CaseIterable, Codable { | ||
var id: String { rawValue } | ||
|
||
case tighter | ||
case tight | ||
case normal | ||
case wide | ||
|
||
var displayName: String { | ||
switch self { | ||
case .tighter: | ||
NSLocalizedString("Tighter", comment: "") | ||
case .tight: | ||
NSLocalizedString("Tight", comment: "") | ||
case .normal: | ||
NSLocalizedString("Normal", comment: "") | ||
case .wide: | ||
NSLocalizedString("Wide", comment: "") | ||
} | ||
} | ||
|
||
var value: Double { | ||
switch self { | ||
case .tighter: -0.05 | ||
case .tight: -0.025 | ||
case .normal: 0 | ||
case .wide: 0.05 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Foundation | ||
|
||
enum FontWeight: String, JSON, Identifiable, CaseIterable, Codable { | ||
var id: String { rawValue } | ||
|
||
case light | ||
case regular | ||
case medium | ||
case semibold | ||
case bold | ||
case black | ||
|
||
var displayName: String { | ||
switch self { | ||
case .light: | ||
return NSLocalizedString("Light", comment: "") | ||
case .regular: | ||
return NSLocalizedString("Regular", comment: "") | ||
case .medium: | ||
return NSLocalizedString("Medium", comment: "") | ||
case .semibold: | ||
return NSLocalizedString("Semibold", comment: "") | ||
case .bold: | ||
return NSLocalizedString("Bold", comment: "") | ||
case .black: | ||
return NSLocalizedString("Black", comment: "") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
FreeAPS/Sources/Modules/ContactTrick/ContactTrickDataFlow.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Combine | ||
import Foundation | ||
|
||
enum ContactTrick { | ||
enum Config {} | ||
|
||
class Item: Identifiable, Hashable, Equatable { | ||
let id = UUID() | ||
var index: Int = 0 | ||
var entry: ContactTrickEntry | ||
|
||
init(index: Int, entry: ContactTrickEntry) { | ||
self.index = index | ||
self.entry = entry | ||
} | ||
|
||
static func == (lhs: Item, rhs: Item) -> Bool { | ||
lhs.index == rhs.index | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(index) | ||
} | ||
} | ||
} | ||
|
||
protocol ContactTrickProvider: Provider { | ||
var contacts: [ContactTrickEntry] { get } | ||
func saveContacts(_ contacts: [ContactTrickEntry]) -> AnyPublisher<Void, Error> | ||
} |
Oops, something went wrong.