Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve SwiftUI and UIKit integration #127

Merged
merged 5 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions OCKSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1200;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 1620;
ORGANIZATIONNAME = "Network Reconnaissance Lab";
TargetAttributes = {
5173CB8623C3A846007655A0 = {
Expand Down Expand Up @@ -1040,7 +1040,6 @@
91AD924D24A4C42E00925D4D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
Expand Down Expand Up @@ -1069,7 +1068,6 @@
91AD924E24A4C42E00925D4D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
Expand Down Expand Up @@ -1237,15 +1235,15 @@
repositoryURL = "https://github.com/netreconlab/CareKitEssentials";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = "1.0.0-alpha.16";
minimumVersion = "1.0.0-alpha.31";
};
};
70202EBF2807333900CF73FB /* XCRemoteSwiftPackageReference "CareKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/cbaker6/CareKit.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = "3.0.0-beta.14";
minimumVersion = "3.0.0-beta.31";
};
};
918FDEAD271B3F8F0045A0EF /* XCRemoteSwiftPackageReference "ParseCareKit" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/cbaker6/CareKit.git",
"state" : {
"revision" : "482e0b34b4116158178cd8f368aeedcb1c8c2b81",
"version" : "3.0.0-beta.15"
"revision" : "989454a4a5f0c8f23fd3344c6bb5aa8e3db185a7",
"version" : "3.0.0-beta.31"
}
},
{
"identity" : "carekitessentials",
"kind" : "remoteSourceControl",
"location" : "https://github.com/netreconlab/CareKitEssentials",
"state" : {
"revision" : "02ea2bb43ae076f647c80d8045da7ea698749649",
"version" : "1.0.0-alpha.19"
"revision" : "8df6c52a65d7881611acb23178b39d08c44ebd21",
"version" : "1.0.0-alpha.32"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1620"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1620"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
128 changes: 78 additions & 50 deletions OCKSample/Extensions/OCKStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,67 +79,95 @@ extension OCKStore {
let beforeBreakfast = Calendar.current.date(byAdding: .hour, value: 8, to: aFewDaysAgo)!
let afterLunch = Calendar.current.date(byAdding: .hour, value: 14, to: aFewDaysAgo)!

let schedule = OCKSchedule(composing: [
OCKScheduleElement(start: beforeBreakfast,
end: nil,
interval: DateComponents(day: 1)),

OCKScheduleElement(start: afterLunch,
end: nil,
interval: DateComponents(day: 2))
])

var doxylamine = OCKTask(id: TaskID.doxylamine,
title: "Take Doxylamine",
carePlanUUID: nil,
schedule: schedule)
doxylamine.instructions = "Take 25mg of doxylamine when you experience nausea."
let schedule = OCKSchedule(
composing: [
OCKScheduleElement(
start: beforeBreakfast,
end: nil,
interval: DateComponents(day: 1)
),
OCKScheduleElement(
start: afterLunch,
end: nil,
interval: DateComponents(day: 2)
)
]
)

var doxylamine = OCKTask(
id: TaskID.doxylamine,
title: String(localized: "TAKE DOXYLAMINE"),
carePlanUUID: nil,
schedule: schedule
)
doxylamine.instructions = String(localized: "DOXYLAMINE_INSTRUCTIONS")
doxylamine.asset = "pills.fill"

let nauseaSchedule = OCKSchedule(composing: [
OCKScheduleElement(start: beforeBreakfast,
end: nil,
interval: DateComponents(day: 1),
text: "Anytime throughout the day",
targetValues: [], duration: .allDay)
])

var nausea = OCKTask(id: TaskID.nausea,
title: "Track your nausea",
carePlanUUID: nil,
schedule: nauseaSchedule)
let nauseaSchedule = OCKSchedule(
composing: [
OCKScheduleElement(
start: beforeBreakfast,
end: nil,
interval: DateComponents(day: 1),
text: String(localized: "ANYTIME_DURING_DAY"),
targetValues: [],
duration: .allDay
)
]
)

var nausea = OCKTask(
id: TaskID.nausea,
title: String(localized: "TRACK NAUSEA"),
carePlanUUID: nil,
schedule: nauseaSchedule
)
nausea.impactsAdherence = false
nausea.instructions = "Tap the button below anytime you experience nausea."
nausea.instructions = String(localized: "NAUSEA_INSTRUCTIONS")
nausea.asset = "bed.double"

let kegelElement = OCKScheduleElement(start: beforeBreakfast,
end: nil,
interval: DateComponents(day: 2))
let kegelSchedule = OCKSchedule(composing: [kegelElement])
var kegels = OCKTask(id: TaskID.kegels,
title: "Kegel Exercises",
carePlanUUID: nil,
schedule: kegelSchedule)
let kegelElement = OCKScheduleElement(
start: beforeBreakfast,
end: nil,
interval: DateComponents(day: 2)
)
let kegelSchedule = OCKSchedule(
composing: [kegelElement]
)
var kegels = OCKTask(
id: TaskID.kegels,
title: String(localized: "KEGEL_EXERCISES"),
carePlanUUID: nil,
schedule: kegelSchedule
)
kegels.impactsAdherence = true
kegels.instructions = "Perform kegel exercies"

let stretchElement = OCKScheduleElement(start: beforeBreakfast,
end: nil,
interval: DateComponents(day: 1))
let stretchSchedule = OCKSchedule(composing: [stretchElement])
var stretch = OCKTask(id: TaskID.stretch,
title: "Stretch",
carePlanUUID: nil,
schedule: stretchSchedule)
kegels.instructions = String(localized: "KEGEL_INSTRUCTIONS")

let stretchElement = OCKScheduleElement(
start: beforeBreakfast,
end: nil,
interval: DateComponents(day: 1)
)
let stretchSchedule = OCKSchedule(
composing: [stretchElement]
)
var stretch = OCKTask(
id: TaskID.stretch,
title: String(localized: "STRETCH"),
carePlanUUID: nil,
schedule: stretchSchedule
)
stretch.impactsAdherence = true
stretch.asset = "figure.walk"

try await addTasksIfNotPresent([nausea, doxylamine, kegels, stretch])

var contact1 = OCKContact(id: "jane",
givenName: "Jane",
familyName: "Daniels",
carePlanUUID: nil)
var contact1 = OCKContact(
id: "jane",
givenName: "Jane",
familyName: "Daniels",
carePlanUUID: nil
)
contact1.asset = "JaneDaniels"
contact1.title = "Family Practice Doctor"
contact1.role = "Dr. Daniels is a family practice doctor with 8 years of experience."
Expand Down
18 changes: 6 additions & 12 deletions OCKSample/Main/Care/CareView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct CareView: UIViewControllerRepresentable {

@Environment(\.appDelegate) private var appDelegate
@Environment(\.careStore) private var careStore
@CareStoreFetchRequest(query: query()) private var events

func makeUIViewController(context: Context) -> some UIViewController {
let viewController = createViewController()
Expand All @@ -38,25 +37,20 @@ struct CareView: UIViewControllerRepresentable {
}
guard careViewController.store !== careStore ||
appDelegate?.isFirstTimeLogin == true else {
// No need to replace view
careViewController.events = events
return
}
navigationController.setViewControllers([createViewController()], animated: false)
let newCareViewController = createViewController()
navigationController.setViewControllers(
[newCareViewController],
animated: false
)
}

func createViewController() -> UIViewController {
CareViewController(
store: careStore,
events: events
store: careStore
)
}

static func query() -> OCKEventQuery {
var query = OCKEventQuery(for: Date())
query.taskIDs = [TaskID.steps]
return query
}
}

struct CareView_Previews: PreviewProvider {
Expand Down
Loading
Loading