add keep alive icon to iOS widgets for follower modes (#520)

This commit is contained in:
Paul Plant 2024-04-01 13:08:15 +02:00 committed by GitHub
parent 338a9c2886
commit 1f274188b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 46 additions and 25 deletions

View File

@ -37,7 +37,14 @@ extension XDripWidget.EntryView {
GlucoseChartView(glucoseChartType: .widgetSystemLarge, bgReadingValues: entry.widgetState.bgReadingValues, bgReadingDates: entry.widgetState.bgReadingDates, isMgDl: entry.widgetState.isMgDl, urgentLowLimitInMgDl: entry.widgetState.urgentLowLimitInMgDl, lowLimitInMgDl: entry.widgetState.lowLimitInMgDl, highLimitInMgDl: entry.widgetState.highLimitInMgDl, urgentHighLimitInMgDl: entry.widgetState.urgentHighLimitInMgDl, liveActivitySize: nil, hoursToShowScalingHours: nil, glucoseCircleDiameterScalingHours: nil, overrideChartHeight: nil, overrideChartWidth: nil)
HStack {
HStack(alignment: .center) {
if let keepAliveImageString = entry.widgetState.keepAliveImageString {
Image(systemName: keepAliveImageString)
.font(.caption)
.foregroundStyle(Color(white: 0.6))
.padding(.trailing, -4)
}
Text(entry.widgetState.dataSourceDescription)
.font(.caption).bold()
.foregroundStyle(Color(white: 0.8))

View File

@ -38,7 +38,14 @@ extension XDripWidget.EntryView {
GlucoseChartView(glucoseChartType: .widgetSystemMedium, bgReadingValues: entry.widgetState.bgReadingValues, bgReadingDates: entry.widgetState.bgReadingDates, isMgDl: entry.widgetState.isMgDl, urgentLowLimitInMgDl: entry.widgetState.urgentLowLimitInMgDl, lowLimitInMgDl: entry.widgetState.lowLimitInMgDl, highLimitInMgDl: entry.widgetState.highLimitInMgDl, urgentHighLimitInMgDl: entry.widgetState.urgentHighLimitInMgDl, liveActivitySize: nil, hoursToShowScalingHours: nil, glucoseCircleDiameterScalingHours: nil, overrideChartHeight: nil, overrideChartWidth: nil)
HStack {
HStack(alignment: .center) {
if let keepAliveImageString = entry.widgetState.keepAliveImageString {
Image(systemName: keepAliveImageString)
.font(.caption)
.foregroundStyle(Color(white: 0.6))
.padding(.trailing, -4)
}
Text(entry.widgetState.dataSourceDescription)
.font(.caption).bold()
.foregroundStyle(Color(white: 0.8))

View File

@ -32,7 +32,14 @@ extension XDripWidget.EntryView {
GlucoseChartView(glucoseChartType: .widgetSystemSmall, bgReadingValues: entry.widgetState.bgReadingValues, bgReadingDates: entry.widgetState.bgReadingDates, isMgDl: entry.widgetState.isMgDl, urgentLowLimitInMgDl: entry.widgetState.urgentLowLimitInMgDl, lowLimitInMgDl: entry.widgetState.lowLimitInMgDl, highLimitInMgDl: entry.widgetState.highLimitInMgDl, urgentHighLimitInMgDl: entry.widgetState.urgentHighLimitInMgDl, liveActivitySize: nil, hoursToShowScalingHours: nil, glucoseCircleDiameterScalingHours: nil, overrideChartHeight: nil, overrideChartWidth: nil)
HStack {
HStack(alignment: .center) {
if let keepAliveImageString = entry.widgetState.keepAliveImageString {
Image(systemName: keepAliveImageString)
.font(.caption)
.foregroundStyle(Color(white: 0.6))
.padding(.trailing, -4)
}
Text(entry.widgetState.dataSourceDescription)
.font(.system(size: 11)).bold()
.foregroundStyle(Color(white: 0.8))

View File

@ -34,13 +34,14 @@ extension XDripWidget.Entry {
var highLimitInMgDl: Double
var urgentHighLimitInMgDl: Double
var dataSourceDescription: String
var keepAliveImageString: String?
var bgUnitString: String
var bgValueInMgDl: Double?
var bgReadingDate: Date?
var bgValueStringInUserChosenUnit: String
init(bgReadingValues: [Double]? = nil, bgReadingDates: [Date]? = nil, isMgDl: Bool? = true, slopeOrdinal: Int? = 0, deltaChangeInMgDl: Double? = nil, urgentLowLimitInMgDl: Double? = 60, lowLimitInMgDl: Double? = 80, highLimitInMgDl: Double? = 180, urgentHighLimitInMgDl: Double? = 250, dataSourceDescription: String? = "") {
init(bgReadingValues: [Double]? = nil, bgReadingDates: [Date]? = nil, isMgDl: Bool? = true, slopeOrdinal: Int? = 0, deltaChangeInMgDl: Double? = nil, urgentLowLimitInMgDl: Double? = 60, lowLimitInMgDl: Double? = 80, highLimitInMgDl: Double? = 180, urgentHighLimitInMgDl: Double? = 250, dataSourceDescription: String? = "", keepAliveImageString: String?) {
self.bgReadingValues = bgReadingValues
self.bgReadingDates = bgReadingDates
self.isMgDl = isMgDl ?? true
@ -51,6 +52,8 @@ extension XDripWidget.Entry {
self.highLimitInMgDl = highLimitInMgDl ?? 180
self.urgentHighLimitInMgDl = urgentHighLimitInMgDl ?? 250
self.dataSourceDescription = dataSourceDescription ?? ""
self.keepAliveImageString = keepAliveImageString
self.bgValueInMgDl = (bgReadingValues?.count ?? 0) > 0 ? bgReadingValues?[0] : nil
self.bgReadingDate = (bgReadingDates?.count ?? 0) > 0 ? bgReadingDates?[0] : nil
@ -159,6 +162,6 @@ extension XDripWidget.Entry {
extension XDripWidget.Entry {
static var placeholder: Self {
.init(date: .now, widgetState: WidgetState(bgReadingValues: [100], bgReadingDates: [Date()], isMgDl: true, slopeOrdinal: 4, deltaChangeInMgDl: 0, urgentLowLimitInMgDl: 60, lowLimitInMgDl: 80, highLimitInMgDl: 140, urgentHighLimitInMgDl: 180, dataSourceDescription: "Dexcom G6"))
.init(date: .now, widgetState: WidgetState(bgReadingValues: [100], bgReadingDates: [Date()], isMgDl: true, slopeOrdinal: 4, deltaChangeInMgDl: 0, urgentLowLimitInMgDl: 60, lowLimitInMgDl: 80, highLimitInMgDl: 140, urgentHighLimitInMgDl: 180, dataSourceDescription: "Dexcom G6", keepAliveImageString: "circle"))
}
}

View File

@ -52,7 +52,7 @@ extension XDripWidget.Provider {
Date(timeIntervalSince1970: date)
}
return Entry.WidgetState(bgReadingValues: data.bgReadingValues, bgReadingDates: bgReadingDates, isMgDl: data.isMgDl, slopeOrdinal: data.slopeOrdinal, deltaChangeInMgDl: data.deltaChangeInMgDl, urgentLowLimitInMgDl: data.urgentLowLimitInMgDl, lowLimitInMgDl: data.lowLimitInMgDl, highLimitInMgDl: data.highLimitInMgDl, urgentHighLimitInMgDl: data.urgentHighLimitInMgDl, dataSourceDescription: data.dataSourceDescription)
return Entry.WidgetState(bgReadingValues: data.bgReadingValues, bgReadingDates: bgReadingDates, isMgDl: data.isMgDl, slopeOrdinal: data.slopeOrdinal, deltaChangeInMgDl: data.deltaChangeInMgDl, urgentLowLimitInMgDl: data.urgentLowLimitInMgDl, lowLimitInMgDl: data.lowLimitInMgDl, highLimitInMgDl: data.highLimitInMgDl, urgentHighLimitInMgDl: data.urgentHighLimitInMgDl, dataSourceDescription: data.dataSourceDescription, keepAliveImageString: data.keepAliveImageString)
} catch {
print(error.localizedDescription)
}
@ -98,7 +98,7 @@ extension XDripWidget.Provider {
return bgValueArray
}
return Entry.WidgetState(bgReadingValues: bgValueArray(), bgReadingDates: bgDateArray(), isMgDl: true, slopeOrdinal: 1, deltaChangeInMgDl: 0, urgentLowLimitInMgDl: ConstantsBGGraphBuilder.defaultUrgentLowMarkInMgdl, lowLimitInMgDl: ConstantsBGGraphBuilder.defaultLowMarkInMgdl, highLimitInMgDl: ConstantsBGGraphBuilder.defaultHighMarkInMgdl, urgentHighLimitInMgDl: ConstantsBGGraphBuilder.defaultUrgentHighMarkInMgdl, dataSourceDescription: "Dexcom G6")
return Entry.WidgetState(bgReadingValues: bgValueArray(), bgReadingDates: bgDateArray(), isMgDl: true, slopeOrdinal: 1, deltaChangeInMgDl: 0, urgentLowLimitInMgDl: ConstantsBGGraphBuilder.defaultUrgentLowMarkInMgdl, lowLimitInMgDl: ConstantsBGGraphBuilder.defaultLowMarkInMgdl, highLimitInMgDl: ConstantsBGGraphBuilder.defaultHighMarkInMgdl, urgentHighLimitInMgDl: ConstantsBGGraphBuilder.defaultUrgentHighMarkInMgdl, dataSourceDescription: "Dexcom G6", keepAliveImageString: nil)
}
}

View File

@ -59,32 +59,28 @@ public enum FollowerBackgroundKeepAliveType: Int, CaseIterable {
}
}
// return the keep-alive image for UIKit views
var keepAliveUIImage: UIImage {
// return the keep-alive image for SwiftUI views
var keepAliveImageString: String {
switch self {
case .disabled:
return UIImage(systemName: "d.circle") ?? UIImage()
return "d.circle"
case .normal:
return UIImage(systemName: "n.circle") ?? UIImage()
return "n.circle"
case .aggressive:
return UIImage(systemName: "a.circle") ?? UIImage()
return "a.circle"
case .heartbeat:
return UIImage(systemName: "heart.circle") ?? UIImage()
return "heart.circle"
}
}
// return the keep-alive image for UIKit views
var keepAliveUIImage: UIImage {
return UIImage(systemName: keepAliveImageString) ?? UIImage()
}
// return the keep-alive image for SwiftUI views
var keepAliveImage: Image {
switch self {
case .disabled:
return Image(systemName: "d.circle")
case .normal:
return Image(systemName: "n.circle")
case .aggressive:
return Image(systemName: "a.circle")
case .heartbeat:
return Image(systemName: "heart.circle")
}
return Image(systemName: keepAliveImageString)
}
}

View File

@ -20,4 +20,5 @@ struct WidgetSharedUserDefaultsModel: Codable {
var highLimitInMgDl: Double
var urgentHighLimitInMgDl: Double
var dataSourceDescription: String
var keepAliveImageString: String?
}

View File

@ -3227,7 +3227,7 @@ final class RootViewController: UIViewController, ObservableObject {
setFollowerConnectionAndHeartbeatStatus()
// set the keep-alive image, then make it visible if in follower mode
dataSourceKeepAliveImageOutlet.image = UserDefaults.standard.followerBackgroundKeepAliveType.keepAliveUIImage
dataSourceKeepAliveImageOutlet.image = UIImage(systemName: UserDefaults.standard.followerBackgroundKeepAliveType.keepAliveImageString)
dataSourceKeepAliveImageOutlet.isHidden = isMaster
// let's go through the specific cases for follower modes
@ -3557,7 +3557,7 @@ final class RootViewController: UIViewController, ObservableObject {
date.timeIntervalSince1970
}
let widgetSharedUserDefaultsModel = WidgetSharedUserDefaultsModel(bgReadingValues: bgReadingValues, bgReadingDatesAsDouble: bgReadingDatesAsDouble, isMgDl: UserDefaults.standard.bloodGlucoseUnitIsMgDl, slopeOrdinal: slopeOrdinal, deltaChangeInMgDl: deltaChangeInMgDl, urgentLowLimitInMgDl: UserDefaults.standard.urgentLowMarkValue, lowLimitInMgDl: UserDefaults.standard.lowMarkValue, highLimitInMgDl: UserDefaults.standard.highMarkValue, urgentHighLimitInMgDl: UserDefaults.standard.urgentHighMarkValue, dataSourceDescription: dataSourceDescription)
let widgetSharedUserDefaultsModel = WidgetSharedUserDefaultsModel(bgReadingValues: bgReadingValues, bgReadingDatesAsDouble: bgReadingDatesAsDouble, isMgDl: UserDefaults.standard.bloodGlucoseUnitIsMgDl, slopeOrdinal: slopeOrdinal, deltaChangeInMgDl: deltaChangeInMgDl, urgentLowLimitInMgDl: UserDefaults.standard.urgentLowMarkValue, lowLimitInMgDl: UserDefaults.standard.lowMarkValue, highLimitInMgDl: UserDefaults.standard.highMarkValue, urgentHighLimitInMgDl: UserDefaults.standard.urgentHighMarkValue, dataSourceDescription: dataSourceDescription, keepAliveImageString: !UserDefaults.standard.isMaster ? UserDefaults.standard.followerBackgroundKeepAliveType.keepAliveImageString : nil)
// store the model in the shared user defaults using a name that is uniquely specific to this copy of the app as installed on
// the user's device - this allows several copies of the app to be installed without cross-contamination of widget data