Skip to content
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
300 changes: 146 additions & 154 deletions APCAppCore/APCAppCore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions APCAppCore/APCAppCore/APCAppCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@
//

#import <UIKit/UIKit.h>
#import <BridgeSDK/BridgeSDK.h>


//! Project version number for APCAppCore.
FOUNDATION_EXPORT double APCAppCoreVersionNumber;

//! Project version string for APCAppCore.
FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];

#import <BridgeSDK/BridgeSDK.h>

//Headers
/* -------------------------------------
Headers
--------------------------------------- */
#import <APCAppCore/APCConstants.h>
#import <APCAppCore/APCAppDelegate.h>
#import <APCAppCore/APCDataMonitor.h>
Expand All @@ -59,7 +62,9 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
#import <APCAppCore/APCUtilities.h>
#import <APCAppCore/APCCorrelationsSelectorViewController.h>

// Tasks
/* -------------------------------------
Tasks
--------------------------------------- */
#import <APCAppCore/APCConsentTask.h>
#import <APCAppCore/APCConsentQuestion.h>
#import <APCAppCore/APCConsentBooleanQuestion.h>
Expand Down Expand Up @@ -94,7 +99,6 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
#import <APCAppCore/APCLog.h>
#import <APCAppCore/APCDataVerificationClient.h>

/* UI */
/* -------------------------
Onboarding ViewControllers
------------------------- */
Expand Down Expand Up @@ -162,7 +166,6 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
/* -------------------------
Medication Tracking Setup Controllers
------------------------- */

#import <APCAppCore/APCMedicationTrackerSetupViewController.h>
#import <APCAppCore/APCMedicationDosageViewController.h>
#import <APCAppCore/APCFrequencyDayTableViewCell.h>
Expand All @@ -182,7 +185,6 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
/* -------------------------
Medication Tracking App Level Components
------------------------- */

#import <APCAppCore/APCMedicationTrackerCalendarViewController.h>
#import <APCAppCore/APCMedicationTrackerCalendarDailyView.h>
#import <APCAppCore/APCMedicationDetailsTableViewCell.h>
Expand Down Expand Up @@ -214,7 +216,6 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
/* -------------------------
Views
------------------------- */

#import <APCAppCore/APCHorizontalThinLineView.h>
#import <APCAppCore/APCHorizontalBottomThinLineView.h>
#import <APCAppCore/APCVerticalThinLineView.h>
Expand Down Expand Up @@ -300,7 +301,6 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
#import <APCAppCore/HKHealthStore+APCExtensions.h>
#import <APCAppCore/UIImage+APCHelper.h>
#import <APCAppCore/APCParameters+Settings.h>
#import <APCAppCore/SBBGuidCreatedOnVersionHolder+APCAdditions.h>
#import <APCAppCore/UIView+Helper.h>
#import <APCAppCore/NSDictionary+APCAdditions.h>
#import <APCAppCore/APCDeviceHardware+APCHelper.h>
Expand All @@ -310,6 +310,7 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
#import <APCAppCore/HKWorkout+APCHelper.h>
#import <APCAppCore/CLLocation+APCAdditions.h>
#import <APCAppCore/NSDictionary+APCStringify.h>

/* -------------------------
Appearance
------------------------- */
Expand All @@ -319,7 +320,7 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
#import <APCAppCore/APCStepProgressBar+Appearance.h>

/* -------------------------
Schedule and ScheduleExpression components
Scheduler
------------------------- */
#import <APCAppCore/APCScheduler.h>
#import <APCAppCore/APCScheduleExpression.h>
Expand Down
8 changes: 5 additions & 3 deletions APCAppCore/APCAppCore/DataMonitor/APCDataMonitor+Bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@

#import "APCDataMonitor.h"

typedef void (^APCDataMonitorResponseHandler) (NSError *error);

@interface APCDataMonitor (Bridge)
- (void) refreshFromBridgeOnCompletion: (void (^)(NSError * error)) completionBlock;
- (void) batchUploadDataToBridgeOnCompletion: (void (^)(NSError * error)) completionBlock;
- (void) uploadZipFile:(NSString*) path onCompletion: (void (^)(NSError * error)) completionBlock;
- (void) refreshFromBridgeOnCompletion: (APCDataMonitorResponseHandler) completionBlock;
- (void) batchUploadDataToBridgeOnCompletion: (APCDataMonitorResponseHandler) completionBlock;
- (void) uploadZipFile: (NSString*) path onCompletion: (APCDataMonitorResponseHandler) completionBlock;
@end
60 changes: 38 additions & 22 deletions APCAppCore/APCAppCore/DataMonitor/APCDataMonitor+Bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,55 @@
//

#import "APCDataMonitor+Bridge.h"
#import "APCSchedule+Bridge.h"
#import "APCAppCore.h"

NSString *const kFirstTimeRefreshToday = @"FirstTimeRefreshToday";

@implementation APCDataMonitor (Bridge)

- (void) refreshFromBridgeOnCompletion: (void (^)(NSError * error)) completionBlock
- (void) refreshFromBridgeOnCompletion: (APCDataMonitorResponseHandler) completionBlock
{
if (self.dataSubstrate.currentUser.isConsented) {
[APCSchedule updateSchedulesOnCompletion:^(NSError *error) {
if (!error) {
[self.scheduler updateScheduledTasksIfNotUpdatingWithRange:kAPCSchedulerDateRangeToday];
[self.scheduler updateScheduledTasksIfNotUpdatingWithRange:kAPCSchedulerDateRangeTomorrow];
[APCTask refreshSurveysOnCompletion:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:APCUpdateActivityNotification object:self userInfo:NULL];
});
if (completionBlock) {
completionBlock(error);
}
}];
if (self.dataSubstrate.currentUser.isConsented)
{
__weak typeof(self) weakSelf = self;

}
else {
if (completionBlock) {
completionBlock(error);
}
}
}];
[[APCScheduler defaultScheduler] fetchTasksAndSchedulesFromServerAndThenUseThisQueue: [NSOperationQueue mainQueue]
toDoThisWhenDone: ^(NSError *errorFromServerFetch)
{
if (errorFromServerFetch)
{
[weakSelf finishRefreshCommandPassingError: errorFromServerFetch
toCompletionBlock: completionBlock];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare a weakSelf outside this block and use it here to avoid reference loop.
__weak typeof(self) weakSelf = self;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, in commit 5c46280.

else
{
[APCTask refreshSurveysOnCompletion: ^(NSError *errorFromRefreshingSurveys) {

[weakSelf finishRefreshCommandPassingError: errorFromRefreshingSurveys
toCompletionBlock: completionBlock];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, weakSelf

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, in commit 5c46280.

}];
}
}];
}
}

- (void) finishRefreshCommandPassingError: (NSError *) error
toCompletionBlock: (APCDataMonitorResponseHandler) completionBlock
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{

if (completionBlock)
{
completionBlock (error);
}

[[NSNotificationCenter defaultCenter] postNotificationName: APCUpdateActivityNotification
object: self
userInfo: nil];
}];
}

- (void) batchUploadDataToBridgeOnCompletion: (void (^)(NSError * error)) completionBlock
{
if (self.dataSubstrate.currentUser.isConsented && !self.batchUploadingInProgress) {
Expand Down
12 changes: 1 addition & 11 deletions APCAppCore/APCAppCore/DataMonitor/APCDataMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
//

#import "APCAppCore.h"
#import "APCSchedule+Bridge.h"
#import "APCDataMonitor+Bridge.h"

@interface APCDataMonitor ()
Expand All @@ -47,7 +46,6 @@ - (instancetype)initWithDataSubstrate:(APCDataSubstrate *)dataSubstrate schedul
if (self) {
self.dataSubstrate = dataSubstrate;
self.scheduler = scheduler;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateScheduledTasks) name:APCScheduleUpdatedNotification object:nil];
}
return self;
}
Expand Down Expand Up @@ -78,26 +76,18 @@ - (void) addDidEnterBackground
- (void) userConsented
{
[(APCAppDelegate*)[UIApplication sharedApplication].delegate setUpCollectors];
[self.scheduler updateScheduledTasksIfNotUpdatingWithRange:kAPCSchedulerDateRangeToday];
[self.scheduler updateScheduledTasksIfNotUpdatingWithRange:kAPCSchedulerDateRangeTomorrow];

[self refreshFromBridgeOnCompletion:^(NSError *error) {
APCLogError2 (error);
[self batchUploadDataToBridgeOnCompletion:NULL];
}];
}

- (void) updateScheduledTasks
{
[self.scheduler updateScheduledTasksIfNotUpdatingWithRange:kAPCSchedulerDateRangeToday];
[self.scheduler updateScheduledTasksIfNotUpdatingWithRange:kAPCSchedulerDateRangeTomorrow];
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)performCoreDataBlockInBackground:(void (^)(NSManagedObjectContext *))coreDataBlock
{
NSManagedObjectContext * privateContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
Expand Down
48 changes: 44 additions & 4 deletions APCAppCore/APCAppCore/DataSubstrate/APCDataSubstrate.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,56 @@

#pragma mark - Core Data Public Methods

- (void)loadStaticTasksAndSchedules:(NSDictionary *)jsonDictionary;

/** EXERCISE CAUTION IN CALLING THIS METHOD. */
- (void)resetCoreData;


#pragma mark - Core Data Helpers - ONLY RETURNS in NSManagedObjects in mainContext

- (NSUInteger)countOfAllScheduledTasksForToday;
- (NSUInteger)countOfCompletedScheduledTasksForToday;
/**
Tracks the total number of required tasks for "today," whenever
"today" is. This is updated by the Activities screen, or the
CoreData method called by that screen, whenever appropriate.
*/
@property (readonly) NSUInteger countOfTotalRequiredTasksForToday;

/**
Tracks the total number of completed tasks for "today," whenever
"today" is. This is updated by the Activities screen, or the
CoreData method called by that screen, whenever appropriate.
*/
@property (readonly) NSUInteger countOfTotalCompletedTasksForToday;

/**
Called by the Activities screen, or the CoreData method
called by that screen, whenever appropriate. Updates the
two -count properties on this object.
*/
- (void) updateCountOfTotalRequiredTasksForToday: (NSUInteger) countOfRequiredTasks
andTotalCompletedTasksToday: (NSUInteger) countOfCompletedTasks;

/**
Former name for -countOfTotalRequiredTasksForToday.
Please use that method instead.

This method used to run a CoreData query which counted
today's total (completed + uncompleted) tasks. The
replacement method, in contrast, simply tracks the most
recent stuff appearing on the Activities screen, which
was the point.
*/
- (NSUInteger)countOfAllScheduledTasksForToday __attribute__((deprecated("Please use -countOfTotalRequiredTasksForToday instead.")));

/**
Former name for -countOfTotalCompletedTasksForToday.
Please use that method instead.

This method used to run a CoreData query which counted
today's completed tasks. The replacement method, in
contrast, simply tracks the most recent stuff appearing
on the Activities screen, which was the point.
*/
- (NSUInteger) countOfCompletedScheduledTasksForToday __attribute__((deprecated("Please use -countOfTotalCompletedTasksForToday instead.")));


#pragma mark - HealthKit
Expand Down
Loading