Skip to content

Commit

Permalink
Merge pull request ResearchKit#67 from dephillipsmichael/feature/FPHS…
Browse files Browse the repository at this point in the history
…-118

Changes in AppCore to support weekday frequency reminders
  • Loading branch information
syoung-smallwisdom committed Jan 27, 2016
2 parents 3cc29e6 + 11004a3 commit b50ec92
Show file tree
Hide file tree
Showing 8 changed files with 780 additions and 108 deletions.
24 changes: 22 additions & 2 deletions APCAppCore/APCAppCore.xcodeproj/project.pbxproj
Expand Up @@ -308,6 +308,10 @@
A7CFE4B61A8B05F4009A171C /* APCStudyOverviewCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A7CFE4B21A8B05F4009A171C /* APCStudyOverviewCollectionViewCell.m */; };
A7CFE4B71A8B05F4009A171C /* APCStudyOverviewCollectionViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CFE4B31A8B05F4009A171C /* APCStudyOverviewCollectionViewController.h */; };
A7CFE4B81A8B05F4009A171C /* APCStudyOverviewCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A7CFE4B41A8B05F4009A171C /* APCStudyOverviewCollectionViewController.m */; };
CBC2593A1C58077A0091308E /* MockAPCTasksReminderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = CBC259391C58077A0091308E /* MockAPCTasksReminderManager.h */; };
CBC2593B1C5838940091308E /* APCScheduleExpressionEnumeratorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5F129DF1A2F78490015982C /* APCScheduleExpressionEnumeratorTests.m */; };
CBD5DBF21C57FFB400AD654E /* MockAPCTasksReminderManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CBD5DBF11C57FFB400AD654E /* MockAPCTasksReminderManager.m */; };
CBD5DBF61C5806AD00AD654E /* APCTasksReminderManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CBD5DBF51C5806AD00AD654E /* APCTasksReminderManagerTests.m */; };
CF03CD021AA23DA2000437FF /* APCMedicationDetailsTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = CF03CCFF1AA23DA2000437FF /* APCMedicationDetailsTableViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
CF03CD031AA23DA2000437FF /* APCMedicationDetailsTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = CF03CD001AA23DA2000437FF /* APCMedicationDetailsTableViewCell.m */; };
CF03CD041AA23DA2000437FF /* APCMedicationDetailsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = CF03CD011AA23DA2000437FF /* APCMedicationDetailsTableViewCell.xib */; };
Expand Down Expand Up @@ -719,7 +723,6 @@
FF44E51B1C1B94A700F07DA9 /* APCTaskResultArchiverTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FF44E51A1C1B94A700F07DA9 /* APCTaskResultArchiverTests.m */; };
FF9469871C1A2D4000CF7075 /* APCAppCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5179B2919D09128001DCCB7 /* APCAppCore.framework */; };
FF9469881C1A2F0400CF7075 /* ORKOrderedTask+APCHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FF9469831C1A294E00CF7075 /* ORKOrderedTask+APCHelperTests.m */; };
FF9469891C1A2F0900CF7075 /* APCScheduleExpressionEnumeratorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5F129DF1A2F78490015982C /* APCScheduleExpressionEnumeratorTests.m */; };
FF94698A1C1A2F0900CF7075 /* APCScheduleExpressionListSelectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5F129DA1A2F78490015982C /* APCScheduleExpressionListSelectorTests.m */; };
FF94698B1C1A2F0900CF7075 /* APCScheduleExpressionParserTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5F129DD1A2F78490015982C /* APCScheduleExpressionParserTests.m */; };
FF94698C1C1A2F0900CF7075 /* APCScheduleExpressionPointSelectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5F129DC1A2F78490015982C /* APCScheduleExpressionPointSelectorTests.m */; };
Expand Down Expand Up @@ -1053,6 +1056,9 @@
A7CFE4B21A8B05F4009A171C /* APCStudyOverviewCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCStudyOverviewCollectionViewCell.m; sourceTree = "<group>"; };
A7CFE4B31A8B05F4009A171C /* APCStudyOverviewCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APCStudyOverviewCollectionViewController.h; sourceTree = "<group>"; };
A7CFE4B41A8B05F4009A171C /* APCStudyOverviewCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = APCStudyOverviewCollectionViewController.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
CBC259391C58077A0091308E /* MockAPCTasksReminderManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MockAPCTasksReminderManager.h; path = "Reminder Tests/MockAPCTasksReminderManager.h"; sourceTree = "<group>"; };
CBD5DBF11C57FFB400AD654E /* MockAPCTasksReminderManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MockAPCTasksReminderManager.m; path = "Reminder Tests/MockAPCTasksReminderManager.m"; sourceTree = "<group>"; };
CBD5DBF51C5806AD00AD654E /* APCTasksReminderManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = APCTasksReminderManagerTests.m; path = "Reminder Tests/APCTasksReminderManagerTests.m"; sourceTree = "<group>"; };
CF03CCFF1AA23DA2000437FF /* APCMedicationDetailsTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = APCMedicationDetailsTableViewCell.h; path = MedicationTrackingAppComponent/APCMedicationDetailsTableViewCell.h; sourceTree = "<group>"; };
CF03CD001AA23DA2000437FF /* APCMedicationDetailsTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = APCMedicationDetailsTableViewCell.m; path = MedicationTrackingAppComponent/APCMedicationDetailsTableViewCell.m; sourceTree = "<group>"; };
CF03CD011AA23DA2000437FF /* APCMedicationDetailsTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = APCMedicationDetailsTableViewCell.xib; path = MedicationTrackingAppComponent/APCMedicationDetailsTableViewCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1990,6 +1996,16 @@
name = Localization;
sourceTree = "<group>";
};
CB1B241F1C57FE5A009DD367 /* Reminder Tests */ = {
isa = PBXGroup;
children = (
CBD5DBF11C57FFB400AD654E /* MockAPCTasksReminderManager.m */,
CBC259391C58077A0091308E /* MockAPCTasksReminderManager.h */,
CBD5DBF51C5806AD00AD654E /* APCTasksReminderManagerTests.m */,
);
name = "Reminder Tests";
sourceTree = "<group>";
};
CF03CCFB1AA23CE7000437FF /* Main Calendar View */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3037,6 +3053,7 @@
F5F129D91A2F78490015982C /* APCAppCoreTests */ = {
isa = PBXGroup;
children = (
CB1B241F1C57FE5A009DD367 /* Reminder Tests */,
FFFA23A71C20A49700727DA8 /* test files */,
F5F129E01A2F78490015982C /* Info.plist */,
FFB892241C46194E00CD0081 /* APCDataGroupsManagerTests.m */,
Expand Down Expand Up @@ -3301,6 +3318,7 @@
F5B9480A1A73272C0034C522 /* APCScheduleExpressionToken.h in Headers */,
F5F12AD01A2F78490015982C /* APCWithdrawSurveyViewController.h in Headers */,
368BAFE91A9AD91A00F04ABB /* APCMedTrackerDailyDosageRecord.h in Headers */,
CBC2593A1C58077A0091308E /* MockAPCTasksReminderManager.h in Headers */,
F5B947F61A73272C0034C522 /* APCParametersDashboardTableViewController.h in Headers */,
F5F12AF21A2F78490015982C /* APCBaseTaskViewController.h in Headers */,
F5F12AF41A2F78490015982C /* APCBaseWithProgressTaskViewController.h in Headers */,
Expand Down Expand Up @@ -3898,12 +3916,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CBD5DBF21C57FFB400AD654E /* MockAPCTasksReminderManager.m in Sources */,
FF94698E1C1A2F0D00CF7075 /* NSDateComponentsHelperTests.m in Sources */,
FF44E51B1C1B94A700F07DA9 /* APCTaskResultArchiverTests.m in Sources */,
FF94698A1C1A2F0900CF7075 /* APCScheduleExpressionListSelectorTests.m in Sources */,
CBC2593B1C5838940091308E /* APCScheduleExpressionEnumeratorTests.m in Sources */,
FF9469881C1A2F0400CF7075 /* ORKOrderedTask+APCHelperTests.m in Sources */,
FF9469891C1A2F0900CF7075 /* APCScheduleExpressionEnumeratorTests.m in Sources */,
0833AE1E1A76C016001D8AA0 /* (null) in Sources */,
CBD5DBF61C5806AD00AD654E /* APCTasksReminderManagerTests.m in Sources */,
FF94698B1C1A2F0900CF7075 /* APCScheduleExpressionParserTests.m in Sources */,
FF94698D1C1A2F0900CF7075 /* APCScheduleExpressionRealLifeTests.m in Sources */,
FFB892251C46194E00CD0081 /* APCDataGroupsManagerTests.m in Sources */,
Expand Down
11 changes: 11 additions & 0 deletions APCAppCore/APCAppCore/Library/Categories/NSDate+Helper.h
Expand Up @@ -36,6 +36,11 @@
extern NSString * const NSDateDefaultDateFormat;
extern NSString * const DateFormatISO8601DateOnly;

/*
* Seems self-explanitory, but adding as a constant anyways
*/
static NSUInteger const kDateHelperDaysInAWeek = 7;

@interface NSDate (Helper)

/**
Expand All @@ -54,6 +59,7 @@ extern NSString * const DateFormatISO8601DateOnly;
*/
- (NSString *) toStringInISO8601Format;


/**
Tries to interpret the specified string with any of
several legal ISO 8601 formats.
Expand Down Expand Up @@ -86,9 +92,14 @@ extern NSString * const DateFormatISO8601DateOnly;

+(instancetype) todayAtMidnight;
+(instancetype) tomorrowAtMidnight;
+(instancetype)todayAtMidnightFromDate:(NSDate*)date;
+(instancetype)tomorrowAtMidnightFromDate:(NSDate*)date;
+(instancetype) yesterdayAtMidnight;
+(instancetype) weekAgoAtMidnight;

+(instancetype) priorSundayAtMidnightFromDate:(NSDate *)date;
+(instancetype) nextSundayAtMidnightFromDate:(NSDate *)date;

+ (instancetype) dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;

- (BOOL) isEarlierThanDate: (NSDate*) otherDate;
Expand Down
36 changes: 21 additions & 15 deletions APCAppCore/APCAppCore/Library/Categories/NSDate+Helper.m
Expand Up @@ -68,8 +68,6 @@
APCDateDirectionBackwards,
} APCDateDirection;



@implementation NSDate (Helper)

/**
Expand Down Expand Up @@ -121,13 +119,7 @@ - (NSString *) toStringWithFormat:(NSString *)format {

- (NSDate *)dateByAddingDays:(NSInteger)inDays
{
static NSCalendar *cal;
static dispatch_once_t once;
dispatch_once(&once, ^
{
cal = [NSCalendar currentCalendar];
});

NSCalendar* cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:(NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear) fromDate:self];
[components setDay:[components day] + inDays];
return [cal dateFromComponents:components];
Expand Down Expand Up @@ -304,21 +296,29 @@ + (instancetype) startOfTomorrow: (NSDate*) date
return [cal dateFromComponents:components];
}

+(instancetype)todayAtMidnight
+(instancetype)todayAtMidnightFromDate:(NSDate*)date
{
NSDate *today = [NSDate date];
return [self startOfDay:today];
return [self startOfDay:date];
}

+(instancetype)tomorrowAtMidnight
+(instancetype)tomorrowAtMidnightFromDate:(NSDate*)date
{
NSDate *today = [NSDate date];
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:(NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear) fromDate:today];
NSDateComponents *components = [cal components:(NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear) fromDate:date];
[components setDay:[components day] + 1];
return [cal dateFromComponents:components];
}

+(instancetype)todayAtMidnight
{
return [self todayAtMidnightFromDate:[NSDate date]];
}

+(instancetype)tomorrowAtMidnight
{
return [self tomorrowAtMidnightFromDate:[NSDate date]];
}

+(instancetype)yesterdayAtMidnight
{
NSDate *today = [NSDate date];
Expand All @@ -345,6 +345,12 @@ +(instancetype)priorSundayAtMidnightFromDate:(NSDate *)date
return [cal dateFromComponents:components];
}

+(instancetype)nextSundayAtMidnightFromDate:(NSDate *)date
{
NSDate* priorSunday = [self priorSundayAtMidnightFromDate:date];
return [priorSunday dateByAddingDays:kDateHelperDaysInAWeek];
}

- (BOOL) isEarlierThanDate: (NSDate*) otherDate
{
BOOL result = [self compare: otherDate] == NSOrderedAscending;
Expand Down
37 changes: 37 additions & 0 deletions APCAppCore/APCAppCore/Library/Objects/APCTasksReminderManager.h
Expand Up @@ -33,15 +33,52 @@

#import <Foundation/Foundation.h>
#import "APCTaskReminder.h"

// These must be reflected by NSCalendar NSCalendarUnitWeekday, except for the EveryDay value
static NSUInteger const kAPCTaskReminderDayOfWeekEveryDay = 0;
static NSUInteger const kAPCTaskReminderDayOfWeekSunday = 1;
static NSUInteger const kAPCTaskReminderDayOfWeekMonday = 2;
static NSUInteger const kAPCTaskReminderDayOfWeekTuesday = 3;
static NSUInteger const kAPCTaskReminderDayOfWeekWednesday = 4;
static NSUInteger const kAPCTaskReminderDayOfWeekThursday = 5;
static NSUInteger const kAPCTaskReminderDayOfWeekFriday = 6;
static NSUInteger const kAPCTaskReminderDayOfWeekSaturday = 7;

@interface APCTasksReminderManager : NSObject
@property (nonatomic) BOOL reminderOn;
@property (nonatomic, strong) NSString * reminderTime; //Should be an element of reminderTimesArray
@property (strong, nonatomic, getter=reminders) NSMutableArray *reminders;

/**
* The days of the week to repeat the reminder, defaults to include every day
* Object in the array must be of type APCTaskReminderDayOfWeek
*/
@property (nonatomic, strong) NSArray* daysOfTheWeekToRepeat;

/*
* If true, all local notifications in this app (even ones that are not reminders) will be removed
* If false, the app will try and find only reminder notifications to delete; however this has inconsistant behavior
*/
@property (nonatomic) BOOL updatingRemindersRemovesAllLocalNotifications;

/*
* Update reminder messaging
* This defualts to...
* "Please complete your StudyName activities today. Thank you for participating in the StudyName study!"
*/
- (void) setReminderMessage:(NSString*)reminderMessage
andDelayMessage:(NSString*)delayMessage;

- (void) updateTasksReminder;
- (void)manageTaskReminder:(APCTaskReminder *)reminder;
+ (NSArray*) reminderTimesArray;
+ (NSSet *) taskReminderCategories;

- (void)handleActivitiesUpdateWithTodaysTaskGroups:(NSArray *) todaysTaskGroups;

/*
* Get the name of the study
*/
+ (NSString *)studyName;

@end

0 comments on commit b50ec92

Please sign in to comment.