Skip to content

Commit

Permalink
Add CustomSegmentedControl section + change logic inside the OCKCareC…
Browse files Browse the repository at this point in the history
…ontentsViewController to display newly added section only for the "non-prescribed trackables" table view section
  • Loading branch information
Damian Dara committed Jan 13, 2019
1 parent d290232 commit 20ea80b
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CareKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@
FC9047CE21E5626D0012C685 /* CustomActivityTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FC9047CC21E5626D0012C685 /* CustomActivityTableViewCell.m */; };
FC9047E721E5A1890012C685 /* CustomSectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = FC9047E521E5A1890012C685 /* CustomSectionView.h */; };
FC9047E821E5A1890012C685 /* CustomSectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = FC9047E621E5A1890012C685 /* CustomSectionView.m */; };
FCE629F121EBE40600D541A9 /* CustomSegmentedControlSection.h in Headers */ = {isa = PBXBuildFile; fileRef = FCE629EF21EBE40600D541A9 /* CustomSegmentedControlSection.h */; };
FCE629F221EBE40600D541A9 /* CustomSegmentedControlSection.m in Sources */ = {isa = PBXBuildFile; fileRef = FCE629F021EBE40600D541A9 /* CustomSegmentedControlSection.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -386,6 +388,8 @@
FC9047CC21E5626D0012C685 /* CustomActivityTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CustomActivityTableViewCell.m; sourceTree = "<group>"; };
FC9047E521E5A1890012C685 /* CustomSectionView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomSectionView.h; sourceTree = "<group>"; };
FC9047E621E5A1890012C685 /* CustomSectionView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CustomSectionView.m; sourceTree = "<group>"; };
FCE629EF21EBE40600D541A9 /* CustomSegmentedControlSection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomSegmentedControlSection.h; sourceTree = "<group>"; };
FCE629F021EBE40600D541A9 /* CustomSegmentedControlSection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CustomSegmentedControlSection.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -894,6 +898,8 @@
children = (
FC9047E521E5A1890012C685 /* CustomSectionView.h */,
FC9047E621E5A1890012C685 /* CustomSectionView.m */,
FCE629EF21EBE40600D541A9 /* CustomSegmentedControlSection.h */,
FCE629F021EBE40600D541A9 /* CustomSegmentedControlSection.m */,
);
name = "Section Views";
sourceTree = "<group>";
Expand Down Expand Up @@ -971,6 +977,7 @@
8677EE101C9775EB00588CD6 /* OCKCarePlanActivity_Internal.h in Headers */,
BA274F471EB703DC00DD17EF /* OCKTextView.h in Headers */,
8677EE141C9775EB00588CD6 /* OCKCarePlanEventResult.h in Headers */,
FCE629F121EBE40600D541A9 /* CustomSegmentedControlSection.h in Headers */,
2489297B1C90E70100EBBE1F /* OCKConnectTableViewHeader.h in Headers */,
BA3793D81EB66BC50004A540 /* OCKPatientWidget.h in Headers */,
BA3793E81EB66D7D0004A540 /* OCKDefaultPatientWidgetView.h in Headers */,
Expand Down Expand Up @@ -1158,6 +1165,7 @@
244A924A1CA210F7007B42D6 /* OCKWeekViewController.m in Sources */,
241707CA1C9A3AB7005D7123 /* OCKChart.m in Sources */,
BA38457F1D9CA698007990DA /* OCKGlyph.m in Sources */,
FCE629F221EBE40600D541A9 /* CustomSegmentedControlSection.m in Sources */,
24FD43741E56843E004439EA /* OCKConnectHeaderView.m in Sources */,
8677EE191C9775EB00588CD6 /* OCKCarePlanStore.xcdatamodeld in Sources */,
241707D01C9A3AB7005D7123 /* OCKGroupedBarChartView.m in Sources */,
Expand Down
29 changes: 19 additions & 10 deletions CareKit/CareContents/OCKCareContentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#import "OCKGlyph_Internal.h"
#import "CustomActivityTableViewCell.h"
#import "CustomSectionView.h"
#import "CustomSegmentedControlSection.h"


#define RedColor() OCKColorFromRGB(0xEF445B);
Expand Down Expand Up @@ -845,28 +846,36 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl
#pragma mark - UITableViewDelegate

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *HeaderIdentifier = @"DefaultSection";
CustomSectionView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HeaderIdentifier];
if (!sectionView) {
sectionView = [[CustomSectionView alloc] initWithReuseIdentifier:HeaderIdentifier];
}

NSString *sectionTitle = _sectionTitles[section];
sectionView.title = sectionTitle;

OCKCarePlanEvent *selectedEvent = _tableViewData[section].firstObject.firstObject;
OCKCarePlanActivityType type = selectedEvent.activity.type;
NSString *sectionTitle = _sectionTitles[section];

if (type == OCKCarePlanActivityTypeNonPrescribedTrackables) {
NSString *HeaderIdentifier = @"NonPrescribedTrackablesSection";
CustomSegmentedControlSection *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HeaderIdentifier];
if (!sectionView) {
sectionView = [[CustomSegmentedControlSection alloc] initWithReuseIdentifier:HeaderIdentifier];
}

sectionView.title = sectionTitle;
if (_tableViewData[section].count > 0) {
sectionView.subtitle = _nonPrescribedTrackablesSectionSubheaderString;
} else {
sectionView.subtitle = _nonPrescribedTrackablesEmptySectionSubheaderString;
}
return sectionView;
} else {
sectionView.subtitle = @"";
NSString *HeaderIdentifier = @"DefaultSection";
CustomSectionView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HeaderIdentifier];
if (!sectionView) {
sectionView = [[CustomSectionView alloc] initWithReuseIdentifier:HeaderIdentifier];
}
sectionView.title = sectionTitle;
return sectionView;
}

return sectionView;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Expand Down
20 changes: 20 additions & 0 deletions CareKit/Common/CustomSegmentedControlSection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// CustomSegmentedControlSection.h
// CareKit
//
// Created by Damian Dara on 14/1/19.
// Copyright © 2019 carekit.org. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface CustomSegmentedControlSection : UITableViewHeaderFooterView

@property (copy, nonatomic) NSString *title;
@property (copy, nonatomic) NSString *subtitle;

@end

NS_ASSUME_NONNULL_END
142 changes: 142 additions & 0 deletions CareKit/Common/CustomSegmentedControlSection.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//
// CustomSegmentedControlSection.m
// CareKit
//
// Created by Damian Dara on 14/1/19.
// Copyright © 2019 carekit.org. All rights reserved.
//

#import "OCKLabel.h"
#import "CustomSegmentedControlSection.h"

@implementation CustomSegmentedControlSection {
OCKLabel *_titleLabel;
OCKLabel *_subtitleLabel;
UISegmentedControl *_segmentedControl;
NSMutableArray<NSLayoutConstraint *> *_constraints;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithReuseIdentifier:reuseIdentifier];
if (self) {
[self initViews];
[self initConstraints];
}
return self;
}

- (void)initViews {
UIView *backgroundView = [UIView new];
backgroundView.backgroundColor = [UIColor whiteColor];
self.backgroundView = backgroundView;

_titleLabel = [OCKLabel new];
_titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
_titleLabel.numberOfLines = 0;
[self.contentView addSubview:_titleLabel];

_subtitleLabel = [OCKLabel new];
_subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_subtitleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
_subtitleLabel.numberOfLines = 0;
[self.contentView addSubview:_subtitleLabel];

_segmentedControl = [[UISegmentedControl alloc] initWithItems: @[ @"My Health", @"My Symptoms" ]];
_segmentedControl.translatesAutoresizingMaskIntoConstraints = NO;
_segmentedControl.selectedSegmentIndex = 0;
[self.contentView addSubview:_segmentedControl];
}

- (void)setTitle:(NSString *)title {
_title = title;
_titleLabel.text = _title;
}

- (void)setSubtitle:(NSString *)subtitle {
_subtitle = subtitle;
_subtitleLabel.text = _subtitle;
}

- (void)initConstraints {
_constraints = [NSMutableArray arrayWithArray: @[
// Title Label
[NSLayoutConstraint constraintWithItem:_titleLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.contentView
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:25.0],
[NSLayoutConstraint constraintWithItem:_titleLabel
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.contentView
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant:20.0],
[NSLayoutConstraint constraintWithItem:_titleLabel
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.contentView
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:-15.0],
// Subtitle Label
[NSLayoutConstraint constraintWithItem: _subtitleLabel
attribute: NSLayoutAttributeTop
relatedBy: NSLayoutRelationEqual
toItem: _titleLabel
attribute: NSLayoutAttributeBottom
multiplier: 1.0
constant: 5.0],
[NSLayoutConstraint constraintWithItem: _subtitleLabel
attribute: NSLayoutAttributeTrailing
relatedBy: NSLayoutRelationEqual
toItem: _titleLabel
attribute: NSLayoutAttributeTrailing
multiplier: 1.0
constant: 0.0],
[NSLayoutConstraint constraintWithItem: _subtitleLabel
attribute: NSLayoutAttributeLeading
relatedBy: NSLayoutRelationEqual
toItem: _titleLabel
attribute: NSLayoutAttributeLeading
multiplier: 1.0
constant: 0.0],
[NSLayoutConstraint constraintWithItem: _subtitleLabel
attribute: NSLayoutAttributeBottom
relatedBy: NSLayoutRelationEqual
toItem: _segmentedControl
attribute: NSLayoutAttributeTop
multiplier: 1.0
constant: -7.0],
// Segmented control
[NSLayoutConstraint constraintWithItem:_segmentedControl
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:_titleLabel
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant: 0.0],
[NSLayoutConstraint constraintWithItem:_segmentedControl
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:_titleLabel
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0.0],
[NSLayoutConstraint constraintWithItem: _segmentedControl
attribute: NSLayoutAttributeBottom
relatedBy: NSLayoutRelationEqual
toItem: self.contentView
attribute: NSLayoutAttributeBottom
multiplier: 1.0
constant: -7.0]
]
];
[NSLayoutConstraint activateConstraints:_constraints];
}

@end

0 comments on commit 20ea80b

Please sign in to comment.