Skip to content

Commit

Permalink
Merge branch 'Dana' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiaanv authored Dec 16, 2024
2 parents 2b52157 + 9072f92 commit b7dd8f1
Show file tree
Hide file tree
Showing 188 changed files with 26,482 additions and 17 deletions.
91 changes: 91 additions & 0 deletions Dependencies/DanaKit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
.DS_Store

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
55 changes: 55 additions & 0 deletions Dependencies/DanaKit/Common/BackgroundTask.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// BackgroundTask.swift
// DanaKit
//
// Created by Bastiaan Verhaar on 19/02/2024.
// Copyright © 2024 Randall Knutson. All rights reserved.
//

import AVFoundation


/// A trick used to keep the app alive
class BackgroundTask {

// MARK: - Vars
var player = AVAudioPlayer()
var timer = Timer()

// MARK: - Methods
func startBackgroundTask() {
NotificationCenter.default.addObserver(self, selector: #selector(interruptedAudio), name: AVAudioSession.interruptionNotification, object: AVAudioSession.sharedInstance())
self.playAudio()
}

func stopBackgroundTask() {
NotificationCenter.default.removeObserver(self, name: AVAudioSession.interruptionNotification, object: nil)
player.stop()
}

@objc fileprivate func interruptedAudio(_ notification: Notification) {
if notification.name == AVAudioSession.interruptionNotification && notification.userInfo != nil {
let info = notification.userInfo!
var intValue = 0
(info[AVAudioSessionInterruptionTypeKey]! as AnyObject).getValue(&intValue)
if intValue == 1 { playAudio() }
}
}

fileprivate func playAudio() {
do {
let bundle = Bundle(for: DanaKitHUDProvider.self).path(forResource: "blank", ofType: "wav")
let alertSound = URL(fileURLWithPath: bundle!)
// try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .mixWithOthers)
try AVAudioSession.sharedInstance().setActive(true)
try self.player = AVAudioPlayer(contentsOf: alertSound)
// Play audio forever by setting num of loops to -1
self.player.numberOfLoops = -1
self.player.volume = 0.01
self.player.prepareToPlay()
self.player.play()
} catch { print(error)
}
}
}
15 changes: 15 additions & 0 deletions Dependencies/DanaKit/Common/Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Bundle.swift
// DanaKit
//
// Created by Darin Krauss on 1/23/21.
// Copyright © 2021 LoopKit Authors. All rights reserved.
//

import Foundation

extension Bundle {
var bundleDisplayName: String {
return object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
}
}
76 changes: 76 additions & 0 deletions Dependencies/DanaKit/Common/Data.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// Data.swift
// DanaKit
//
// Created by Bastiaan Verhaar on 10/12/2023.
// Copyright © 2023 Randall Knutson. All rights reserved.
//

extension Data {
init?(hexString: String) {
let len = hexString.count / 2
var data = Data(capacity: len)
var i = hexString.startIndex
for _ in 0..<len {
let j = hexString.index(i, offsetBy: 2)
let bytes = hexString[i..<j]
if var num = UInt8(bytes, radix: 16) {
data.append(&num, count: 1)
} else {
return nil
}
i = j
}
self = data
}

func uint16(at index: Int) -> UInt16 {
var value: UInt16 = 0
(self as NSData).getBytes(&value, range: NSRange(location: index, length: MemoryLayout<UInt16>.size))
return UInt16(littleEndian: value)
}

mutating func addDate(at index: Int, date: Date, utc: Bool = true) {
var date = date
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(identifier: "UTC")!

if !utc {
let delta = TimeInterval(TimeZone.current.secondsFromGMT(for: date) - TimeZone(identifier: "UTC")!.secondsFromGMT(for: date))
date = date.addingTimeInterval(delta)
}

self[index] = UInt8((calendar.component(.year, from: date) - 2000) & 0xff)
self[index + 1] = UInt8(calendar.component(.month, from: date) & 0xff)
self[index + 2] = UInt8(calendar.component(.day, from: date) & 0xff)
self[index + 3] = UInt8(calendar.component(.hour, from: date) & 0xff)
self[index + 4] = UInt8(calendar.component(.minute, from: date) & 0xff)
self[index + 5] = UInt8(calendar.component(.second, from: date) & 0xff)
}

func date(at index: Int, _ usingUtc: Bool) -> Date {
let year = 2000 + Int(self[index])
let month = Int(self[index + 1])
let day = Int(self[index + 2])
let hour = Int(self[index + 3])
let min = Int(self[index + 4])
let sec = Int(self[index + 5])

var components = DateComponents()
components.year = year
components.month = month
components.day = day
components.hour = hour
components.minute = min
components.second = sec

var calendar = Calendar.current
if usingUtc {
calendar.timeZone = TimeZone(identifier: "UTC")!
} else {
calendar.timeZone = TimeZone.current
}

return calendar.date(from: components)!
}
}
62 changes: 62 additions & 0 deletions Dependencies/DanaKit/Common/DoseEntry.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// DoseEntry.swift
// DanaKit
//
// Created by Bastiaan Verhaar on 21/01/2024.
// Copyright © 2024 Randall Knutson. All rights reserved.
//

import Foundation
import LoopKit

extension DoseEntry {
public static func bolus(units: Double, deliveredUnits: Double, duration: TimeInterval, activationType: BolusActivationType, insulinType: InsulinType, startDate: Date = Date.now) -> DoseEntry {
var endTime = Date.now
endTime.addTimeInterval(duration)

return DoseEntry(
type: .bolus,
startDate: startDate,
endDate: endTime,
value: units,
unit: .units,
deliveredUnits: deliveredUnits,
insulinType: insulinType,
automatic: activationType.isAutomatic,
manuallyEntered: activationType == .manualNoRecommendation,
isMutable: false
)
}

public static func tempBasal(absoluteUnit: Double, duration: TimeInterval, insulinType: InsulinType, startDate: Date = Date.now) -> DoseEntry {
return DoseEntry(
type: .tempBasal,
startDate: startDate,
endDate: startDate + duration,
value: absoluteUnit,
unit: .unitsPerHour,
insulinType: insulinType
)
}

public static func basal(rate: Double, insulinType: InsulinType, startDate: Date = Date.now) -> DoseEntry {
return DoseEntry(
type: .basal,
startDate: startDate,
value: rate,
unit: .unitsPerHour,
insulinType: insulinType
)
}

public static func resume(insulinType: InsulinType, resumeDate: Date = Date.now) -> DoseEntry {
return DoseEntry(
resumeDate: resumeDate,
insulinType: insulinType
)
}

public static func suspend(suspendDate: Date = Date.now) -> DoseEntry {
return DoseEntry(suspendDate: suspendDate)
}
}
21 changes: 21 additions & 0 deletions Dependencies/DanaKit/Common/IdentifiableClass.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// IdentifiableClass.swift
// DanaKit
//
// Created by Bastiaan Verhaar on 18/12/2023.
// Copyright © 2023 Randall Knutson. All rights reserved.
//

import Foundation


protocol IdentifiableClass: AnyObject {
static var className: String { get }
}


extension IdentifiableClass {
static var className: String {
return NSStringFromClass(self).components(separatedBy: ".").last!
}
}
21 changes: 21 additions & 0 deletions Dependencies/DanaKit/Common/LocalizedString.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// LocalizedString.swift
// DanaKit
//
// Created by Bastiaan Verhaar on 05/12/2023.
// Copyright © 2023 Randall Knutson. All rights reserved.
//

import Foundation

private class FrameworkBundle {
static let main = Bundle(for: DanaKitHUDProvider.self)
}

func LocalizedString(_ key: String, tableName: String? = nil, value: String? = nil, comment: String) -> String {
if let value = value {
return NSLocalizedString(key, tableName: tableName, bundle: FrameworkBundle.main, value: value, comment: comment)
} else {
return NSLocalizedString(key, tableName: tableName, bundle: FrameworkBundle.main, comment: comment)
}
}
18 changes: 18 additions & 0 deletions Dependencies/DanaKit/Common/NavigationLink.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// NavigationLink.swift
// DanaKit
//
// Created by Bastiaan Verhaar on 01/01/2024.
// Copyright © 2024 Randall Knutson. All rights reserved.
//

import SwiftUI

extension NavigationLink where Label == EmptyView, Destination == EmptyView {

/// Useful in cases where a `NavigationLink` is needed but there should not be
/// a destination. e.g. for programmatic navigation.
static var empty: NavigationLink {
self.init(destination: EmptyView(), label: { EmptyView() })
}
}
Loading

0 comments on commit b7dd8f1

Please sign in to comment.