Skip to content

Commit

Permalink
Merge branch 'JohanDegraeve:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
OliNix authored Jul 15, 2024
2 parents 7e6767d + fec1005 commit 5f7745b
Show file tree
Hide file tree
Showing 80 changed files with 2,188 additions and 421 deletions.
33 changes: 18 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ GEM
base64
nkf
rexml
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.922.0)
aws-sdk-core (3.194.0)
aws-partitions (1.949.0)
aws-sdk-core (3.200.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.80.0)
aws-sdk-core (~> 3, >= 3.193.0)
aws-sdk-kms (1.87.0)
aws-sdk-core (~> 3, >= 3.199.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.149.0)
aws-sdk-core (~> 3, >= 3.194.0)
aws-sdk-s3 (1.155.0)
aws-sdk-core (~> 3, >= 3.199.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.8)
aws-sigv4 (1.8.0)
Expand Down Expand Up @@ -69,7 +69,7 @@ GEM
faraday_middleware (1.2.0)
faraday (~> 1.0)
fastimage (2.3.1)
fastlane (2.220.0)
fastlane (2.221.1)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand Down Expand Up @@ -148,31 +148,32 @@ GEM
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
highline (2.0.3)
http-cookie (1.0.5)
http-cookie (1.0.6)
domain_name (~> 0.5)
httpclient (2.8.3)
jmespath (1.6.2)
json (2.7.2)
jwt (2.8.1)
jwt (2.8.2)
base64
mini_magick (4.12.0)
mini_magick (4.13.1)
mini_mime (1.1.5)
multi_json (1.15.0)
multipart-post (2.4.0)
multipart-post (2.4.1)
nanaimo (0.3.0)
naturally (2.2.1)
nkf (0.2.0)
optparse (0.5.0)
os (1.1.4)
plist (3.7.1)
public_suffix (5.0.5)
public_suffix (5.1.1)
rake (13.2.1)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.6)
rexml (3.2.8)
strscan (>= 3.0.9)
rouge (2.0.7)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand All @@ -185,6 +186,7 @@ GEM
simctl (1.6.10)
CFPropertyList
naturally
strscan (3.1.0)
terminal-notifier (2.0.0)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
Expand Down Expand Up @@ -216,6 +218,7 @@ PLATFORMS
arm64-darwin-22
arm64-darwin-23
x86_64-darwin-19
x86_64-linux

DEPENDENCIES
fastlane
Expand Down
19 changes: 16 additions & 3 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ platform :ios do
increment_build_number(
xcodeproj: "#{GITHUB_WORKSPACE}/xdrip.xcodeproj",
build_number: current_build_number
)
)

match(
type: "appstore",
Expand All @@ -58,7 +58,8 @@ platform :ios do
"com.#{TEAMID}.xdripswift",
"com.#{TEAMID}.xdripswift.xDripWidget",
"com.#{TEAMID}.xdripswift.watchkitapp",
"com.#{TEAMID}.xdripswift.watchkitapp.xDripWatchComplication"
"com.#{TEAMID}.xdripswift.watchkitapp.xDripWatchComplication",
"com.#{TEAMID}.xdripswift.xDripNotificationContextExtension"
]
)

Expand Down Expand Up @@ -106,6 +107,13 @@ platform :ios do
targets: ["xDrip Watch Complication Extension"]
)

update_code_signing_settings(
path: "#{GITHUB_WORKSPACE}/xdrip.xcodeproj",
profile_name: mapping["com.#{TEAMID}.xdripswift.xDripNotificationContextExtension"],
code_sign_identity: "iPhone Distribution",
targets: ["xDrip Notification Context Extension"]
)

gym(
export_method: "app-store",
scheme: "xdrip",
Expand Down Expand Up @@ -173,6 +181,10 @@ platform :ios do
Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS
])

configure_bundle_id("xDrip Notification Context Extension", "com.#{TEAMID}.xdripswift.xDripNotificationContextExtension", [
Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS
])


end

Expand All @@ -195,7 +207,8 @@ platform :ios do
"com.#{TEAMID}.xdripswift",
"com.#{TEAMID}.xdripswift.xDripWidget",
"com.#{TEAMID}.xdripswift.watchkitapp",
"com.#{TEAMID}.xdripswift.watchkitapp.xDripWatchComplication"
"com.#{TEAMID}.xdripswift.watchkitapp.xDripWatchComplication",
"com.#{TEAMID}.xdripswift.xDripNotificationContextExtension"
]
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Notification View Controller-->
<scene sceneID="cwh-vc-ff4">
<objects>
<viewController id="M4Y-Lb-cyx" userLabel="Notification View Controller" customClass="NotificationViewController" customModule="xDrip_Notification_Context_Extension" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" userInteractionEnabled="NO" contentMode="scaleToFill" simulatedAppContext="notificationCenter" id="S3S-Oj-5AN">
<rect key="frame" x="0.0" y="0.0" width="393" height="400"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<containerView opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="v5J-R6-SOJ">
<rect key="frame" x="16" y="59" width="361" height="307"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</containerView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="bottomMargin" secondItem="v5J-R6-SOJ" secondAttribute="bottom" id="5EB-eI-ger"/>
<constraint firstAttribute="trailingMargin" secondItem="v5J-R6-SOJ" secondAttribute="trailing" id="KhW-l2-lEL"/>
<constraint firstItem="v5J-R6-SOJ" firstAttribute="top" secondItem="S3S-Oj-5AN" secondAttribute="topMargin" id="Ml7-At-PgR"/>
<constraint firstItem="v5J-R6-SOJ" firstAttribute="leading" secondItem="S3S-Oj-5AN" secondAttribute="leadingMargin" id="ODQ-Ev-Dnu"/>
</constraints>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<size key="freeformSize" width="393" height="400"/>
<connections>
<outlet property="notificationViewContainer" destination="v5J-R6-SOJ" id="7kK-ad-IHz"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="138.1679389312977" y="4.2253521126760569"/>
</scene>
</scenes>
</document>
28 changes: 28 additions & 0 deletions xDrip Notification Context Extension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AppGroupIdentifier</key>
<string>$(APP_GROUP_IDENTIFIER)</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>UNNotificationExtensionCategory</key>
<string>snoozeCategoryIdentifier</string>
<key>UNNotificationExtensionDefaultContentHidden</key>
<true/>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<integer>1</integer>
<key>UNNotificationExtensionOverridesDefaultTitle</key>
<false/>
<key>UNNotificationExtensionUserInteractionEnabled</key>
<false/>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.content-extension</string>
</dict>
</dict>
</plist>
154 changes: 154 additions & 0 deletions xDrip Notification Context Extension/NotificationView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
//
// NotificationView.swift
// xDrip Notification Context Extension
//
// Created by Paul Plant on 8/6/24.
// Copyright © 2024 Johan Degraeve. All rights reserved.
//

import SwiftUI

struct NotificationView: View {
var alertTitle: String?
var bgReadingValues: [Double]?
var bgReadingDates: [Date]?
var isMgDl: Bool?
var slopeOrdinal: Int?
var deltaChangeInMgDl: Double?
var urgentLowLimitInMgDl: Double?
var lowLimitInMgDl: Double?
var highLimitInMgDl: Double?
var urgentHighLimitInMgDl: Double?
var alertUrgencyType: AlertUrgencyType?

var bgUnitString: String?
var bgValueInMgDl: Double?
var bgReadingDate: Date?
var bgValueStringInUserChosenUnit: String?

var body: some View {
ZStack {
Color(ConstantsAlerts.notificationBackgroundColor)
.ignoresSafeArea()

VStack(alignment: .center, spacing: 0) {
Text("\(alertTitle ?? "LOW ALARM")")
.font(.title).fontWeight(.bold)
.foregroundStyle(alertUrgencyType?.bannerTextColor ?? .white.opacity(0.85))
.lineLimit(1)
.minimumScaleFactor(0.2)
.frame(maxWidth: .infinity, maxHeight: 55)
.background(alertUrgencyType?.bannerBackgroundColor ?? .black)
.padding(.top, -15)

// this is the standard widget view
HStack(alignment: .center) {
Text("\(bgValueStringInUserChosenUnit ?? "")\(trendArrow())")
.font(.system(size: 45)).fontWeight(.bold)
.foregroundStyle(bgTextColor())
.lineLimit(1)

Spacer()

VStack(alignment: .trailing, spacing: -4) {
Text(deltaChangeStringInUserChosenUnit())
.font(.system(size: 30)).fontWeight(.bold)
.foregroundStyle(.colorPrimary)
.lineLimit(1)

Text(bgUnitString ?? "")
.font(.system(size: 15)).fontWeight(.semibold)
.foregroundStyle(.colorSecondary)
.lineLimit(1)
}
}
.padding(12)

GlucoseChartView(glucoseChartType: .notificationExpanded, bgReadingValues: bgReadingValues, bgReadingDates: bgReadingDates, isMgDl: isMgDl ?? true, urgentLowLimitInMgDl: urgentLowLimitInMgDl ?? 60, lowLimitInMgDl: lowLimitInMgDl ?? 70, highLimitInMgDl: highLimitInMgDl ?? 180, urgentHighLimitInMgDl: urgentHighLimitInMgDl ?? 250, liveActivitySize: nil, hoursToShowScalingHours: nil, glucoseCircleDiameterScalingHours: nil, overrideChartHeight: nil, overrideChartWidth: nil, highContrast: nil)
}
.background(ConstantsAlerts.notificationBackgroundColor)
}
}

func alertTitleColor() -> Color {
if let alertUrgencyType = alertUrgencyType {
switch alertUrgencyType {
case .urgent:
return .red
case .warning:
return .yellow
default:
return .colorPrimary
}
}

return .colorPrimary
}

/// Blood glucose color dependant on the user defined limit values and based upon the time since the last reading
/// - Returns: a Color either red, yellow or green
func bgTextColor() -> Color {
if let bgValueInMgDl = bgValueInMgDl, let urgentLowLimitInMgDl = urgentLowLimitInMgDl, let lowLimitInMgDl = lowLimitInMgDl, let highLimitInMgDl = highLimitInMgDl, let urgentHighLimitInMgDl = urgentHighLimitInMgDl {

if bgValueInMgDl >= urgentHighLimitInMgDl || bgValueInMgDl <= urgentLowLimitInMgDl {
return .red
} else if bgValueInMgDl >= highLimitInMgDl || bgValueInMgDl <= lowLimitInMgDl {
return .yellow
} else {
return .green
}
}
return .green
}

/// convert the optional delta change int (in mg/dL) to a formatted change value in the user chosen unit making sure all zero values are shown as a positive change to follow Nightscout convention
/// - Returns: a string holding the formatted delta change value (i.e. +0.4 or -6)
func deltaChangeStringInUserChosenUnit() -> String {
if let deltaChangeInMgDl = deltaChangeInMgDl, let isMgDl = isMgDl {
let deltaSign: String = deltaChangeInMgDl > 0 ? "+" : ""
let valueAsString = deltaChangeInMgDl.mgdlToMmolAndToString(mgdl: isMgDl)

// quickly check "value" and prevent "-0mg/dl" or "-0.0mmol/l" being displayed
// show unitized zero deltas as +0 or +0.0 as per Nightscout format
if isMgDl {
return (deltaChangeInMgDl > -1 && deltaChangeInMgDl < 1) ? "+0" : (deltaSign + valueAsString)
} else {
return (deltaChangeInMgDl > -0.1 && deltaChangeInMgDl < 0.1) ? "+0.0" : (deltaSign + valueAsString)
}
} else {
return (isMgDl ?? true) ? "-" : "-.-"
}
}


/// returns a string holding the trend arrow
/// - Returns: trend arrow string (i.e. "↑")
func trendArrow() -> String {
if let slopeOrdinal = slopeOrdinal {
switch slopeOrdinal {
case 7:
return "\u{2193}\u{2193}" // ↓↓
case 6:
return "\u{2193}" // ↓
case 5:
return "\u{2198}" // ↘
case 4:
return "\u{2192}" // →
case 3:
return "\u{2197}" // ↗
case 2:
return "\u{2191}" // ↑
case 1:
return "\u{2191}\u{2191}" // ↑↑
default:
return ""
}
} else {
return ""
}
}
}

#Preview {
NotificationView()
}
Loading

0 comments on commit 5f7745b

Please sign in to comment.