Skip to content

Commit

Permalink
Merge pull request #425 from erik-apple/stable-candidate
Browse files Browse the repository at this point in the history
Stable candidate
  • Loading branch information
erik-apple authored May 4, 2020
2 parents 0ac0e5b + 754a107 commit 51cef0b
Show file tree
Hide file tree
Showing 71 changed files with 1,187 additions and 759 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: swift
osx_image: xcode11
osx_image: xcode11.4
xcode_workspace: CKWorkspace.xcworkspace
xcode_scheme: CareKit
xcode_destination: platform=iOS Simulator,OS=13.0,name=iPhone 11 Pro Max
xcode_destination: platform=iOS Simulator,OS=13.4,name=iPhone 11 Pro Max
87 changes: 85 additions & 2 deletions CareKit.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,93 @@
"configurations" : [
{
"id" : "28C2AC89-B957-4FB0-9242-53AEB9E6D4B0",
"name" : "Configuration 1",
"name" : "Default",
"options" : {

}
},
{
"id" : "42D7C666-B3E1-4F36-88FB-E0B87436BB05",
"name" : "Germany",
"options" : {
"language" : "de",
"locationScenario" : {
"identifier" : "London, England",
"referenceType" : "built-in"
},
"region" : "DE"
}
},
{
"id" : "76269B8E-AEA1-4864-AA9A-F583B2F54AF1",
"name" : "Africa",
"options" : {
"locationScenario" : {
"identifier" : "Johannesburg, South Africa",
"referenceType" : "built-in"
},
"region" : "EG"
}
},
{
"id" : "34F9B126-5A5C-4F0A-A861-84C9B2376FA2",
"name" : "Australia",
"options" : {
"language" : "en-AU",
"locationScenario" : {
"identifier" : "Sydney, Australia",
"referenceType" : "built-in"
},
"region" : "AU"
}
},
{
"id" : "05B1E279-40AF-49C6-8BAC-86779932468D",
"name" : "England",
"options" : {
"language" : "en-GB",
"locationScenario" : {
"identifier" : "London, England",
"referenceType" : "built-in"
},
"region" : "GB"
}
},
{
"id" : "F4D2A746-C1E8-4D5A-BCD7-EEEC3D73CEC5",
"name" : "Japan",
"options" : {
"language" : "ja",
"locationScenario" : {
"identifier" : "Tokyo, Japan",
"referenceType" : "built-in"
},
"region" : "JP"
}
},
{
"id" : "4DB57CAB-36AB-4D1A-8259-C918197191CE",
"name" : "Hong Kong",
"options" : {
"language" : "zh-HK",
"locationScenario" : {
"identifier" : "Hong Kong, China",
"referenceType" : "built-in"
},
"region" : "HK"
}
},
{
"id" : "2DEE87AE-1E91-4B64-BA06-8B37298B2A16",
"name" : "Mexico",
"options" : {
"language" : "es-419",
"locationScenario" : {
"identifier" : "Mexico City, Mexico",
"referenceType" : "built-in"
},
"region" : "MX"
}
}
],
"defaultOptions" : {
Expand All @@ -19,7 +102,7 @@
{
"containerPath" : "container:CareKitCarePlanStore\/CareKitCarePlanStore.xcodeproj",
"identifier" : "E784B8F72232EED600736CA5",
"name" : "CareKitCarePlanStore"
"name" : "CareKitStore"
}
]
},
Expand Down
22 changes: 4 additions & 18 deletions CareKit/CareKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

/* Begin PBXBuildFile section */
032C86F02326B68D00D0A0EA /* Calendar+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032C86EF2326B68D00D0A0EA /* Calendar+Extensions.swift */; };
1409474C22B020C4005C1D16 /* CareKitStore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1409474A22B020C4005C1D16 /* CareKitStore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1409474E22B020CA005C1D16 /* CareKitUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1409474D22B020CA005C1D16 /* CareKitUI.framework */; };
1409474F22B020CA005C1D16 /* CareKitUI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1409474D22B020CA005C1D16 /* CareKitUI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1409475122B02153005C1D16 /* CareKitStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1409475022B02153005C1D16 /* CareKitStore.framework */; };
5101E6CB23733F3B0023B8A6 /* TestCustomCalendarViewSynchronizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5101E6CA23733F3B0023B8A6 /* TestCustomCalendarViewSynchronizer.swift */; };
51094D94234F8E3E00B4BFFB /* OCKTaskController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51094D93234F8E3E00B4BFFB /* OCKTaskController.swift */; };
Expand Down Expand Up @@ -84,6 +82,7 @@
51B714862367849100590A5A /* OCKButtonLogTaskView+Updatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51B714852367849100590A5A /* OCKButtonLogTaskView+Updatable.swift */; };
51BEAD5A237E00C600B32D55 /* TestDailyTasksPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51BEAD59237E00C600B32D55 /* TestDailyTasksPageViewController.swift */; };
51CF0A00235528EC00A343F9 /* OCKTaskControllerProtocol+Methods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51CF09FF235528EC00A343F9 /* OCKTaskControllerProtocol+Methods.swift */; };
51D8E27F24115D7D0026C716 /* TestListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51D8E27E24115D7D0026C716 /* TestListView.swift */; };
51E88828234CE61300763B97 /* OCKContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E88827234CE61300763B97 /* OCKContactViewController.swift */; };
51EF7E46234FAAB700B28C0A /* OCKSimpleTaskViewSynchronizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EF7E45234FAAB700B28C0A /* OCKSimpleTaskViewSynchronizer.swift */; };
51EF7E48234FAB7A00B28C0A /* OCKInstructionsTaskViewSynchronizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EF7E47234FAB7A00B28C0A /* OCKInstructionsTaskViewSynchronizer.swift */; };
Expand Down Expand Up @@ -141,21 +140,6 @@
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
1409474722B020A2005C1D16 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
1409474F22B020CA005C1D16 /* CareKitUI.framework in Embed Frameworks */,
1409474C22B020C4005C1D16 /* CareKitStore.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
032C86EF2326B68D00D0A0EA /* Calendar+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Calendar+Extensions.swift"; sourceTree = "<group>"; };
03A2F774237F51C200A13638 /* CareKitStore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = CareKitStore.xcodeproj; path = ../CareKitStore/CareKitStore.xcodeproj; sourceTree = "<group>"; };
Expand Down Expand Up @@ -232,6 +216,7 @@
51B714852367849100590A5A /* OCKButtonLogTaskView+Updatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OCKButtonLogTaskView+Updatable.swift"; sourceTree = "<group>"; };
51BEAD59237E00C600B32D55 /* TestDailyTasksPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDailyTasksPageViewController.swift; sourceTree = "<group>"; };
51CF09FF235528EC00A343F9 /* OCKTaskControllerProtocol+Methods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OCKTaskControllerProtocol+Methods.swift"; sourceTree = "<group>"; };
51D8E27E24115D7D0026C716 /* TestListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestListView.swift; sourceTree = "<group>"; };
51E88827234CE61300763B97 /* OCKContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKContactViewController.swift; sourceTree = "<group>"; };
51EF7E45234FAAB700B28C0A /* OCKSimpleTaskViewSynchronizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKSimpleTaskViewSynchronizer.swift; sourceTree = "<group>"; };
51EF7E47234FAB7A00B28C0A /* OCKInstructionsTaskViewSynchronizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKInstructionsTaskViewSynchronizer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -484,6 +469,7 @@
51FF9B8C2373374200BAEDB2 /* Calendar */,
511372452374DFBD00831191 /* TestSynchronizedContext.swift */,
51BEAD59237E00C600B32D55 /* TestDailyTasksPageViewController.swift */,
51D8E27E24115D7D0026C716 /* TestListView.swift */,
5196C7FD226F8F8F00F1C2A2 /* Info.plist */,
);
path = CareKitTests;
Expand Down Expand Up @@ -747,7 +733,6 @@
8605A5B71C4F04EC00DD65FF /* Headers */,
8605A5B61C4F04EC00DD65FF /* Frameworks */,
8605A5B81C4F04EC00DD65FF /* Resources */,
1409474722B020A2005C1D16 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -871,6 +856,7 @@
511372442374CA2B00831191 /* TestCustomChartViewController.swift in Sources */,
511372422374CA1900831191 /* TestCartesianChartViewSynchronizer.swift in Sources */,
51FF9B8E2373377500BAEDB2 /* TestWeekCalendarViewSynchronizer.swift in Sources */,
51D8E27F24115D7D0026C716 /* TestListView.swift in Sources */,
511372462374DFBD00831191 /* TestSynchronizedContext.swift in Sources */,
51BEAD5A237E00C600B32D55 /* TestDailyTasksPageViewController.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ UIPageViewControllerDataSource, UIPageViewControllerDelegate {

// MARK: - Properties

open func selectDate(_ date: Date, animated: Bool) {
let previousDate = selectedDate
guard !Calendar.current.isDate(previousDate, inSameDayAs: date) else { return }
calendarWeekPageViewController.selectDate(date, animated: animated)
weekCalendarPageViewController(calendarWeekPageViewController, didSelectDate: date, previousDate: previousDate)
}

override open func viewSafeAreaInsetsDidChange() {
updateScrollViewInsets()
}
Expand Down Expand Up @@ -145,11 +152,7 @@ UIPageViewControllerDataSource, UIPageViewControllerDelegate {

@objc
private func pressedToday(sender: UIBarButtonItem) {
let previousDate = selectedDate
let currentDate = Date()
guard !Calendar.current.isDate(previousDate, inSameDayAs: currentDate) else { return }
calendarWeekPageViewController.selectDate(currentDate, animated: true)
weekCalendarPageViewController(calendarWeekPageViewController, didSelectDate: currentDate, previousDate: previousDate)
selectDate(Date(), animated: true)
}

private func updateScrollViewInsets() {
Expand Down
11 changes: 8 additions & 3 deletions CareKit/CareKit/Lists/View/OCKListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ import UIKit
/// A view enclosing a scrollable stack view.
internal class OCKListView: OCKView {

override var backgroundColor: UIColor? {
didSet {
contentView.backgroundColor = backgroundColor
scrollView.backgroundColor = backgroundColor
}
}

// MARK: Properties

/// The stack view embedded inside the scroll view.
Expand All @@ -45,7 +52,7 @@ internal class OCKListView: OCKView {
/// The scroll view that contains the stack view.
let scrollView = UIScrollView()

private let contentView = UIView()
let contentView = UIView()

// MARK: - Life Cycle

Expand All @@ -68,7 +75,6 @@ internal class OCKListView: OCKView {
}

private func styleSubviews() {
scrollView.backgroundColor = contentView.backgroundColor
scrollView.alwaysBounceVertical = true
}

Expand Down Expand Up @@ -97,7 +103,6 @@ internal class OCKListView: OCKView {
let cachedStyle = style()
contentView.directionalLayoutMargins = cachedStyle.dimension.directionalInsets1
backgroundColor = cachedStyle.color.customGroupedBackground
contentView.backgroundColor = cachedStyle.color.customGroupedBackground
stackView.spacing = cachedStyle.dimension.directionalInsets1.top
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ UIViewController, OCKCalendarViewDelegate {
viewModelSubscription?.cancel()
viewModelSubscription = controller.objectWillChange
.context()
.sink { [view] context in
guard let typedView = view as? ViewSynchronizer.View else { fatalError("View should be of type \(ViewSynchronizer.View.self)") }
self.viewSynchronizer.updateView(typedView, context: context)
.sink { [weak self] context in
guard let typedView = self?.view as? ViewSynchronizer.View else { fatalError("View should be of type \(ViewSynchronizer.View.self)") }
self?.viewSynchronizer.updateView(typedView, context: context)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ open class OCKChartController: OCKChartControllerProtocol, ObservableObject {

// MARK: Properties

private let weekOfDate: Date
private var subscription: AnyCancellable?
private let eventQuery: OCKEventQuery
private var cancellables: Set<AnyCancellable> = Set()

// MARK: - Life Cycle

/// Initialize the controller.
/// - Parameter weekOfDate: A date in the week of the insights range.
/// - Parameter storeManager: Wraps the store that contains the insight data.
public required init(weekOfDate: Date, storeManager: OCKSynchronizedStoreManager) {
self.weekOfDate = weekOfDate
self.eventQuery = OCKEventQuery(dateInterval: Calendar.current.dateIntervalOfWeek(for: weekOfDate))
self.storeManager = storeManager
self.objectWillChange = .init([])
}
Expand All @@ -67,44 +67,31 @@ open class OCKChartController: OCKChartControllerProtocol, ObservableObject {
/// - configurations: An array of configurations to be plotted.
open func fetchAndObserveInsights(forConfigurations configurations: [OCKDataSeriesConfiguration],
errorHandler: ((Error) -> Void)? = nil) {

// Fetch tasks, then fetch events for the tasks and set the view model
let eventQuery = OCKEventQuery(dateInterval: Calendar.current.dateIntervalOfWeek(for: weekOfDate))
fetchTasks(eventQuery: eventQuery, configurations: configurations, errorHandler: errorHandler)
}

private func fetchTasks(eventQuery: OCKEventQuery, configurations: [OCKDataSeriesConfiguration],
errorHandler: ((Error) -> Void)? = nil) {

// Build up the task query
var taskQuery = OCKTaskQuery(for: Date())
taskQuery.ids = configurations.map { $0.taskID }

storeManager.store.fetchAnyTasks(query: taskQuery, callbackQueue: .main) { [weak self] result in
guard let self = self else { return }
switch result {
case .success(let tasks):

// Fetch events and set the view model. Also set the view model when the events change
self.refetchEvents(eventQuery: eventQuery, configurations: configurations) { result in
if case let .failure(error) = result {
errorHandler?(error)
}
}

self.subscribeTo(tasks: tasks, eventQuery: eventQuery, configurations: configurations) { result in
if case let .failure(error) = result {
errorHandler?(error)
cancellables = Set()
configurations.forEach { config in
store.fetchAnyEvents(taskID: config.taskID, query: eventQuery, callbackQueue: .main) { result in
switch result {
case let .failure(error): errorHandler?(error)
case let .success(events):
self.refetchEvents(configurations: configurations, completion: nil)
events.forEach { event in
self.storeManager
.publisher(forEvent: event, categories: [.add, .update, .delete])
.sink(receiveValue: { _ in
self.refetchEvents(configurations: configurations) { result in
if case let .failure(error) = result {
errorHandler?(error)
}
}
})
.store(in: &self.cancellables)
}
}

case .failure(let error):
errorHandler?(error)
}
}
}

private func refetchEvents(eventQuery: OCKEventQuery, configurations: [OCKDataSeriesConfiguration],
private func refetchEvents(configurations: [OCKDataSeriesConfiguration],
completion: OCKResultClosure<[OCKDataSeries]>?) {
var allDataSeries = [OCKDataSeries]()
let group = DispatchGroup()
Expand Down Expand Up @@ -138,25 +125,4 @@ open class OCKChartController: OCKChartControllerProtocol, ObservableObject {
completion?(.success(allDataSeries))
}
}

private func subscribeTo(tasks: [OCKAnyTask],
eventQuery: OCKEventQuery, configurations: [OCKDataSeriesConfiguration],
completion: OCKResultClosure<[OCKDataSeries]>?) {
// Set the view model when the tasks change
let taskSubscriptions = tasks.map { task in
return storeManager.publisher(forTask: task, categories: [.update, .delete], fetchImmediately: false)
.sink { _ in self.refetchEvents(eventQuery: eventQuery, configurations: configurations, completion: completion) }
}

// Set the view model when the events for the tasks change
let eventSubscriptions = tasks.map { task in
return self.storeManager.publisher(forEventsBelongingToTask: task, categories: [.update, .add, .delete])
.sink { _ in self.refetchEvents(eventQuery: eventQuery, configurations: configurations, completion: completion) }
}

subscription = AnyCancellable {
taskSubscriptions.forEach { $0.cancel() }
eventSubscriptions.forEach { $0.cancel() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ open class OCKCartesianChartViewSynchronizer: OCKChartViewSynchronizerProtocol {

open func makeView() -> OCKCartesianChartView {
let chartView = OCKCartesianChartView(type: plotType)
chartView.graphView.selectedIndex = Calendar.current.component(.weekday, from: selectedDate) - Calendar.current.firstWeekday
let currentWeekday = Calendar.current.component(.weekday, from: selectedDate)
let firstWeekday = Calendar.current.firstWeekday
var offset = (currentWeekday - 1) - (firstWeekday - 1)
if offset < 0 {
offset += 7
}
chartView.graphView.selectedIndex = offset
chartView.graphView.horizontalAxisMarkers = Calendar.current.orderedWeekdaySymbolsVeryShort()
return chartView
}
Expand Down
Loading

0 comments on commit 51cef0b

Please sign in to comment.