Skip to content

Commit

Permalink
Release 6.2.2
Browse files Browse the repository at this point in the history
Quicker loops.
Override Preset View updates.
  • Loading branch information
Jon-b-m authored Feb 8, 2025
1 parent e8dc2ae commit 30c00e1
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_DISPLAY_NAME = iAPS
APP_VERSION = 6.2
APP_VERSION = 6.2.2
APP_BUILD_NUMBER = 1
COPYRIGHT_NOTICE =
DEVELOPER_TEAM = ##TEAM_ID##
Expand Down
6 changes: 4 additions & 2 deletions FreeAPS/Sources/APS/Storage/CoreDataStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ final class CoreDataStorage {
let requestInsulinDistribution = InsulinDistribution.fetchRequest() as NSFetchRequest<InsulinDistribution>
let sortInsulin = NSSortDescriptor(key: "date", ascending: false)
requestInsulinDistribution.sortDescriptors = [sortInsulin]
requestInsulinDistribution.fetchLimit = 1
try? insulinDistribution = coredataContext.fetch(requestInsulinDistribution)
}
return insulinDistribution
Expand Down Expand Up @@ -351,11 +352,12 @@ final class CoreDataStorage {
var conc = [InsulinConcentration]()
coredataContext.performAndWait {
let requestConc = InsulinConcentration.fetchRequest() as NSFetchRequest<InsulinConcentration>
let sort = NSSortDescriptor(key: "date", ascending: true)
let sort = NSSortDescriptor(key: "date", ascending: false)
requestConc.sortDescriptors = [sort]
requestConc.fetchLimit = 1
try? conc = coredataContext.fetch(requestConc)
}
let recent = conc.last
let recent = conc.first
return (recent?.concentration ?? 1.0, recent?.incrementSetting ?? 0.1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,12 @@ Enact a temp Basal or a temp target */
/* */
"Auto ISF" = "Auto ISF";

/* Is true */
" on" = " on";

/* Is false */
" off" = " off";

/* ---------------------------------------------------------------------------------------------------------------
Infotexts from openaps.docs and androidaps.docs
iAPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ extension OverrideProfilesConfig {
return formatter
}

private var dateFormatter: DateComponentsFormatter {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute]
formatter.unitsStyle = .brief
return formatter
}

var body: some View {
overridesView
.navigationBarTitle("Profiles")
Expand Down Expand Up @@ -174,21 +181,23 @@ extension OverrideProfilesConfig {
Text("Disable SMBs")
}
}
HStack {
Toggle(isOn: $state.smbIsAlwaysOff) {
Text("Schedule when SMBs are Off")
}.disabled(!state.smbIsOff)
}
if state.smbIsAlwaysOff {
if state.smbIsOff {
HStack {
Text("First Hour SMBs are Off (24 hours)")
DecimalTextField("0", value: $state.start, formatter: formatter, liveEditing: true)
Text("hour").foregroundColor(.secondary)
Toggle(isOn: $state.smbIsAlwaysOff) {
Text("Schedule when SMBs are Off")
}.disabled(!state.smbIsOff)
}
HStack {
Text("Last Hour SMBs are Off (24 hours)")
DecimalTextField("0", value: $state.end, formatter: formatter, liveEditing: true)
Text("hour").foregroundColor(.secondary)
if state.smbIsAlwaysOff {
HStack {
Text("First Hour SMBs are Off (24 hours)")
DecimalTextField("0", value: $state.start, formatter: formatter, liveEditing: true)
Text("hour").foregroundColor(.secondary)
}
HStack {
Text("Last Hour SMBs are Off (24 hours)")
DecimalTextField("0", value: $state.end, formatter: formatter, liveEditing: true)
Text("hour").foregroundColor(.secondary)
}
}
}
HStack {
Expand Down Expand Up @@ -517,16 +526,13 @@ extension OverrideProfilesConfig {
if !isEditingPreset {
Button("Start") {
showAlert.toggle()
let duration = TimeInterval(state.duration * 60)
alertSring = "\(state.percentage.formatted(.number)) %, " +
(
state.duration > 0 && !state
._indefinite ?
(
state
.duration
.formatted(.number.grouping(.never).rounded().precision(.fractionLength(0))) +
" min."
) :
state.duration > 0 && !state._indefinite ? (
dateFormatter
.string(from: duration) ?? ""
) :
NSLocalizedString(" infinite duration.", comment: "")
) +
(
Expand Down Expand Up @@ -626,77 +632,77 @@ extension OverrideProfilesConfig {
// Values as String
let targetRaw = ((preset.target ?? 0) as NSDecimalNumber) as Decimal
let target = state.units == .mmolL ? targetRaw.asMmolL : targetRaw
let duration = (preset.duration ?? 0) as Decimal
let name = ((preset.name ?? "") == "") || (preset.name?.isEmpty ?? true) ? "" : preset.name!
let percent = preset.percentage / 100
let perpetual = preset.indefinite
let durationString = perpetual ? "" : "\(formatter.string(from: duration as NSNumber)!)"
let scheduledSMBstring = (preset.smbIsOff && preset.smbIsAlwaysOff) ? "Scheduled SMBs" : ""
let smbString = (preset.smbIsOff && scheduledSMBstring == "") ? "SMBs are off" : ""
let targetString = targetRaw > 10 ? "\(glucoseFormatter.string(from: target as NSNumber)!)" : ""
let durationString = perpetual ? "" : dateFormatter
.string(from: TimeInterval(truncating: (preset.duration ?? 0) as NSNumber) * 60) ?? ""
let scheduledSMBstring = (preset.smbIsOff && preset.smbIsAlwaysOff) ? LocalizedStringKey("🕝 SMBs") : ""
let smbString = (preset.smbIsOff && scheduledSMBstring == "") ? "SMBs" : ""
let targetString = targetRaw > 10 ? "\(glucoseFormatter.string(from: target as NSNumber) ?? "")" : ""
let isfString = preset.isf ? "ISF" : ""
let crString = preset.cr ? "CR" : ""
let basalString = preset.basal ? "Basal" : ""
let dash = (crString != "" && isfString != "") ? ", " : ""
let dash2 = (basalString != "" && isfString + dash + crString != "") ? ", " : ""
let isfAndCRstring = "[" + isfString + dash + crString + dash2 + basalString + "]"
let isfAndCRstring = isfString + dash + crString + dash2 + basalString != "" ? "[" + isfString + dash + crString +
dash2 + basalString + "]" : "[None]"
let autoisfSettings = fetchedSettings.first(where: { $0.id == preset.id })

if name != "" {
VStack(alignment: .leading) {
Text(name).padding(.top, 5).padding(.bottom, 2)
HStack(spacing: 7) {
VStack(alignment: .leading, spacing: 1) {
HStack {
Text(name).padding(.vertical, 4)
Spacer()
}
HStack {
percent != 1 ?
Text(percent.formatted(.percent.grouping(.never).rounded().precision(.fractionLength(0))))
.foregroundStyle(.secondary) : nil
targetString != "" ? Text(targetString + " " + state.units.rawValue).foregroundStyle(.secondary) : nil
durationString != "" ? Text(durationString + (perpetual ? "" : "min"))
.foregroundStyle(.secondary) : nil
smbString != "" ? Text(smbString).boolTag(false).padding(.leading, 6) : nil
scheduledSMBstring != "" ? Text(scheduledSMBstring).foregroundStyle(.secondary) : nil
if let aisf = autoisfSettings, preset.overrideAutoISF, aisf.autoisf != state.currentSettings.autoisf {
Text("Auto ISF: \(aisf.autoisf)").boolTag(aisf.autoisf)
durationString != "" ? Text(durationString).foregroundStyle(.secondary) : nil
if let aisf = autoisfSettings, preset.overrideAutoISF {
bool(bool: aisf.autoisf, setting: state.currentSettings.autoisf, label: "Auto ISF")
}
Spacer()
}
.font(.caption)

if preset.advancedSettings {
HStack {
percent != 1 && !(preset.isf && preset.cr && preset.basal) ? Text("Adjust " + isfAndCRstring) :
nil
percent != 1 && !(preset.isf && preset.cr && preset.basal) ? Text("Adjust " + isfAndCRstring) : nil
if !preset.smbIsOff {
decimal(decimal: preset.smbMinutes ?? 0, setting: state.defaultSmbMinutes, label: "SMB ")
decimal(decimal: preset.uamMinutes ?? 0, setting: state.defaultUamMinutes, label: "UAM ")
}
if preset.overrideMaxIOB {
decimal(decimal: preset.maxIOB, setting: state.defaultmaxIOB, label: "Max IOB: ")
}
smbString != "" ? bool(bool: false, setting: true, label: smbString) : nil
scheduledSMBstring != "" ? Text(scheduledSMBstring) : nil
}.foregroundStyle(.secondary).font(.caption)
}

// All of the Auto ISF Settings (Bool and Decimal optionals)
if preset.overrideAutoISF, let aisf = autoisfSettings, aisf.autoisf {
let standard = state.currentSettings

LazyHStack {
HStack {
bool(
bool: aisf.enableBGacceleration,
setting: standard.enableBGacceleration,
label: "Accel: "
label: "Accel"
)
bool(bool: aisf.ketoProtect, setting: standard.ketoProtect, label: "Keto: ")
bool(bool: aisf.use_B30, setting: standard.use_B30, label: "B30: ")
bool(bool: aisf.ketoProtect, setting: standard.ketoProtect, label: "Keto")
bool(bool: aisf.use_B30, setting: standard.use_B30, label: "B30 ")

LazyHStack(spacing: 5) {
HStack {
decimal(decimal: aisf.autoisf_min, setting: standard.autoisf_min, label: "Min: ")
decimal(decimal: aisf.autoisf_max, setting: standard.autoisf_max, label: "Max: ")
}
}
.offset(y: 2)
.foregroundStyle(.secondary).font(.caption)

HStack(spacing: 5) {
HStack {
percentage(
decimal: aisf.iobThresholdPercent,
setting: standard
Expand All @@ -719,7 +725,7 @@ extension OverrideProfilesConfig {
)
}.foregroundStyle(.secondary).font(.caption)

HStack(spacing: 6) {
HStack {
decimal(
decimal: aisf.lowerISFrangeWeight,
setting: standard.lowerISFrangeWeight,
Expand Down Expand Up @@ -786,8 +792,10 @@ extension OverrideProfilesConfig {
}

private func bool(bool: Bool, setting: Bool, label: String) -> AnyView? {
let onOff = bool ? NSLocalizedString(" on", comment: "Is true") :
NSLocalizedString(" off", comment: "Is false")
if bool != setting {
return Text(label + (bool ? "on" : "off")).foregroundStyle(.white).boolTag(bool).asAny()
return Text(label + onOff).foregroundStyle(.white).boolTag(bool).asAny()
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion FreeAPS/Sources/Views/BGTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct BGTextField: View {
private var displayValue: Binding<Decimal> {
Binding(
get: { units == .mmolL ? mgdlValue.asMmolL : mgdlValue },
set: { newValue in mgdlValue = units == .mmolL ? newValue.rounded(to: 1).asMgdL : newValue.rounded(to: 0) }
set: { newValue in mgdlValue = units == .mmolL ? newValue.asMgdL : newValue }
)
}

Expand Down
2 changes: 1 addition & 1 deletion FreeAPS/Sources/Views/DecimalTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public struct DecimalTextField: UIViewRepresentable {
}

public func updateUIView(_ textField: UITextField, context: Context) {
if !context.coordinator.isEditing || context.coordinator.previousSeenValue != value {
if !context.coordinator.isEditing || abs(context.coordinator.previousSeenValue - value) > 0.0000001 {
context.coordinator.previousSeenValue = value
let newText = valueAsText()
if textField.text != newText {
Expand Down
60 changes: 4 additions & 56 deletions FreeAPS/Sources/Views/ViewModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,14 @@ struct RoundedBackground: ViewModifier {
}
}

struct CapsulaBackground: ViewModifier {
private let color: Color

init(color: Color = Color("CapsuleColor")) {
self.color = color
}

func body(content: Content) -> some View {
content
.padding()
.background(
Rectangle()
// Capsule()
.fill()
.foregroundColor(color)
)
}
}

struct BoolTag: ViewModifier {
let bool: Bool
@Environment(\.colorScheme) var colorScheme
func body(content: Content) -> some View {
content
.padding(.vertical, 4).padding(.horizontal, 6).background((bool ? Color.green : Color.red).opacity(0.4))
.clipShape(RoundedRectangle(cornerRadius: 6)).padding(.trailing, 6)
.padding(.vertical, 4).padding(.horizontal, 6)
.background((bool ? Color.green : Color.red).opacity(colorScheme == .light ? 0.8 : 0.5))
.clipShape(RoundedRectangle(cornerRadius: 6)).padding(.vertical, 3).padding(.trailing, 3)
}
}

Expand Down Expand Up @@ -147,7 +130,6 @@ struct ColouredRoundedBackground: View {
@Environment(\.colorScheme) var colorScheme
var body: some View {
Rectangle()
// RoundedRectangle(cornerRadius: 15)
.fill(
colorScheme == .dark ? .black :
Color.white
Expand Down Expand Up @@ -303,36 +285,6 @@ struct Link<T>: ViewModifier where T: View {
}
}

struct AdaptsToSoftwareKeyboard: ViewModifier {
@State var currentHeight: CGFloat = 0

func body(content: Content) -> some View {
content
.padding(.bottom, currentHeight).animation(.easeOut(duration: 0.25))
.edgesIgnoringSafeArea(currentHeight == 0 ? Edge.Set() : .bottom)
.onAppear(perform: subscribeToKeyboardChanges)
}

private let keyboardHeightOnOpening = Foundation.NotificationCenter.default
.publisher(for: UIResponder.keyboardWillShowNotification)
.map { $0.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect }
.map(\.height)

private let keyboardHeightOnHiding = Foundation.NotificationCenter.default
.publisher(for: UIResponder.keyboardWillHideNotification)
.map { _ in CGFloat(0) }

private func subscribeToKeyboardChanges() {
_ = Publishers.Merge(keyboardHeightOnOpening, keyboardHeightOnHiding)
.subscribe(on: DispatchQueue.main)
.sink { height in
if self.currentHeight == 0 || height == 0 {
self.currentHeight = height
}
}
}
}

struct ClearButton: ViewModifier {
@Binding var text: String
func body(content: Content) -> some View {
Expand Down Expand Up @@ -390,10 +342,6 @@ extension View {
modifier(Link(destination: view.state.view(for: screen), screen: screen))
}

func adaptsToSoftwareKeyboard() -> some View {
modifier(AdaptsToSoftwareKeyboard())
}

func modal<V: BaseView>(for screen: Screen?, from view: V) -> some View {
onTapGesture {
view.state.showModal(for: screen)
Expand Down

0 comments on commit 30c00e1

Please sign in to comment.