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

Add support for an additional cells within the OCKCareContentsViewCon… #3

Merged
merged 1 commit into from
Jan 9, 2019
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
86 changes: 77 additions & 9 deletions CareKit/CareContents/OCKCareContentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#import "OCKHelpers.h"
#import "OCKDefines_Private.h"
#import "OCKGlyph_Internal.h"
#import "CustomActivityTableViewCell.h"


#define RedColor() OCKColorFromRGB(0xEF445B);
Expand Down Expand Up @@ -79,6 +80,9 @@ @implementation OCKCareContentsViewController {
NSString *_otherString;
NSString *_optionalString;
NSString *_readOnlyString;
NSString *_healthDataSectionString;
NSString *_buttonSectionString;
NSString *_nonPrescribedTrackablesSectionString;
BOOL _isGrouped;
BOOL _isSorted;
}
Expand All @@ -105,6 +109,9 @@ - (void)viewDidLoad {
_otherString = OCKLocalizedString(@"ACTIVITY_TYPE_OTHER_SECTION_HEADER", nil);
_optionalString = OCKLocalizedString(@"ACTIVITY_TYPE_OPTIONAL_SECTION_HEADER", nil);
_readOnlyString = OCKLocalizedString(@"ACTIVITY_TYPE_READ_ONLY_SECTION_HEADER", nil);
_healthDataSectionString = OCKLocalizedString(@"ACTIVITY_TYPE_HEALTH_DATA_SECTION_HEADER", nil);
_buttonSectionString = OCKLocalizedString(@"ACTIVITY_TYPE_BUTTON_SECTION_HEADER", nil);
_nonPrescribedTrackablesSectionString = OCKLocalizedString(@"ACTIVITY_TYPE_NON_PRESCRIBED_TRACKABLE_SECTION_HEADER", nil);
if (self.optionalSectionHeader && ![self.optionalSectionHeader isEqual: @""]) {
_optionalString = _optionalSectionHeader;
}
Expand All @@ -117,7 +124,11 @@ - (void)viewDidLoad {
[self setGlyphTintColor: _glyphTintColor];
NSDictionary *_initialDictionary = @{ @(OCKCarePlanActivityTypeAssessment): [NSMutableArray new],
@(OCKCarePlanActivityTypeIntervention): [NSMutableArray new],
@(OCKCarePlanActivityTypeReadOnly): [NSMutableArray new] };
@(OCKCarePlanActivityTypeReadOnly): [NSMutableArray new],
@(OCKCarePlanActivityTypeHealthEntry): [NSMutableArray new],
@(OCKCarePlanActivityTypeNonPrescribedTrackables): [NSMutableArray new],
@(OCKCarePlanActivityTypeButton): [NSMutableArray new]
};
_allEvents = [_initialDictionary mutableCopy];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:OCKLocalizedString(@"TODAY_BUTTON_TITLE", nil)
Expand All @@ -126,7 +137,8 @@ - (void)viewDidLoad {
action:@selector(showToday:)];
self.navigationItem.rightBarButtonItem.tintColor = self.glyphTintColor;

_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.separatorStyle = UITableViewCellAccessoryNone;
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];
Expand Down Expand Up @@ -379,6 +391,9 @@ - (void)fetchEvents {
[self fetchEventsOfType:OCKCarePlanActivityTypeIntervention];
[self fetchEventsOfType:OCKCarePlanActivityTypeAssessment];
[self fetchEventsOfType:OCKCarePlanActivityTypeReadOnly];
[self fetchEventsOfType:OCKCarePlanActivityTypeHealthEntry];
[self fetchEventsOfType:OCKCarePlanActivityTypeNonPrescribedTrackables];
[self fetchEventsOfType:OCKCarePlanActivityTypeButton];
});
}

Expand Down Expand Up @@ -571,11 +586,14 @@ - (void)createGroupedEventDictionaryForEvents {
NSArray<OCKCarePlanEvent *> *interventions = _allEvents[@(OCKCarePlanActivityTypeIntervention)];
NSArray<OCKCarePlanEvent *> *assessments = _allEvents[@(OCKCarePlanActivityTypeAssessment)];
NSArray<OCKCarePlanEvent *> *readOnly = _allEvents[@(OCKCarePlanActivityTypeReadOnly)];
NSArray<OCKCarePlanEvent *> *healthEntries = _allEvents[@(OCKCarePlanActivityTypeHealthEntry)];
NSArray<OCKCarePlanEvent *> *nonPrescribedTrackables = _allEvents[@(OCKCarePlanActivityTypeNonPrescribedTrackables)];
NSArray<OCKCarePlanEvent *> *buttons = _allEvents[@(OCKCarePlanActivityTypeButton)];

NSMutableArray *interventionGroupIdentifiers = [[NSMutableArray alloc] init];
NSMutableArray *assessmentGroupIdentifiers = [[NSMutableArray alloc] init];

NSArray<NSArray<OCKCarePlanEvent *> *> *events = [NSArray arrayWithArray:[interventions arrayByAddingObjectsFromArray:[assessments arrayByAddingObjectsFromArray:readOnly]]];
NSArray<NSArray<OCKCarePlanEvent *> *> *events = [NSArray arrayWithArray:[interventions arrayByAddingObjectsFromArray:[assessments arrayByAddingObjectsFromArray:[readOnly arrayByAddingObjectsFromArray:[healthEntries arrayByAddingObjectsFromArray:[nonPrescribedTrackables arrayByAddingObjectsFromArray:buttons]]]]]];
NSMutableDictionary *groupedEvents = [NSMutableDictionary new];
NSMutableArray *groupArray = [NSMutableArray new];

Expand Down Expand Up @@ -648,6 +666,21 @@ - (void)createGroupedEventDictionaryForEvents {
[sortedKeys removeObject:_readOnlyString];
[sortedKeys addObject:_readOnlyString];
}

if ([sortedKeys containsObject:_healthDataSectionString]) {
[sortedKeys removeObject:_healthDataSectionString];
[sortedKeys addObject:_healthDataSectionString];
}

if ([sortedKeys containsObject:_nonPrescribedTrackablesSectionString]) {
[sortedKeys removeObject:_nonPrescribedTrackablesSectionString];
[sortedKeys addObject:_nonPrescribedTrackablesSectionString];
}

if ([sortedKeys containsObject:_buttonSectionString]) {
[sortedKeys removeObject:_buttonSectionString];
[sortedKeys addObject:_buttonSectionString];
}

_sectionTitles = [sortedKeys copy];

Expand Down Expand Up @@ -839,18 +872,54 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
OCKCarePlanActivityType type = activity.type;

if (type == OCKCarePlanActivityTypeAssessment) {

static NSString *CellIdentifier = @"SymptomTrackerCell";
OCKSymptomTrackerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
CustomActivityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[OCKSymptomTrackerTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
cell = [[CustomActivityTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}

cell.assessmentEvent = event;
cell.event = event;
cell.cellBackgroundColor = [UIColor purpleColor];

return cell;
}
else if (type == OCKCarePlanActivityTypeHealthEntry) {

static NSString *CellIdentifier = @"HealthEntryCell";
CustomActivityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[CustomActivityTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.event = event;
cell.cellBackgroundColor = [UIColor purpleColor];

return cell;
}
else if (type == OCKCarePlanActivityTypeNonPrescribedTrackables) {

static NSString *CellIdentifier = @"NonPrescribedTrackablesCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = event.activity.title;
cell.detailTextLabel.text = event.activity.text;

return cell
}
else if (type == OCKCarePlanActivityTypeButton) {

static NSString *CellIdentifier = @"ButtonCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = event.activity.text;

return cell;
}
else if (type == OCKCarePlanActivityTypeReadOnly) {

static NSString *CellIdentifier = @"ReadOnlyCell";
Expand All @@ -859,7 +928,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[OCKReadOnlyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}

cell.readOnlyEvent = event;

return cell;
Expand Down
3 changes: 3 additions & 0 deletions CareKit/Localization/en.lproj/CareKit.strings
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"ACTIVITY_TYPE_OTHER_SECTION_HEADER" = "Other";
"ACTIVITY_TYPE_OPTIONAL_SECTION_HEADER" = "Optional";
"ACTIVITY_TYPE_READ_ONLY_SECTION_HEADER" = "Read Only";
"ACTIVITY_TYPE_HEALTH_DATA_SECTION_HEADER" = "Device Health Data";
"ACTIVITY_TYPE_BUTTON_SECTION_HEADER" = "";
"ACTIVITY_TYPE_NON_PRESCRIBED_TRACKABLE_SECTION_HEADER" = "Non-prescribed Trackables";
"HEADER_TITLE_CARE_OVERVIEW" = "Your care overview is %@ complete";
"HEADER_TITLE_ACTIVITY_STATUS" = "Your activity status is %@ complete";

Expand Down