Skip to content
Open
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
1 change: 1 addition & 0 deletions DayFlow/DFDatePickerDayCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

@property (nonatomic, readwrite, assign) DFDatePickerDate date;
@property (nonatomic, getter=isEnabled) BOOL enabled;
@property (nonatomic, assign) BOOL hasActivity;

@end
38 changes: 38 additions & 0 deletions DayFlow/DFDatePickerDayCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ + (id) cacheKeyForPickerDate:(DFDatePickerDate)date;
+ (id) fetchObjectForKey:(id)key withCreator:(id(^)(void))block;
@property (nonatomic, readonly, strong) UIImageView *imageView;
@property (nonatomic, readonly, strong) UIView *overlayView;
@property (nonatomic, strong) UIImageView *activityDot;
@end

@implementation DFDatePickerDayCell
Expand Down Expand Up @@ -39,6 +40,12 @@ - (void) setSelected:(BOOL)selected {
[self setNeedsLayout];
}

- (void) setHasActivity:(BOOL)hasActivity
{
_hasActivity = hasActivity;
[self setNeedsLayout];
}

- (void) layoutSubviews {

[super layoutSubviews];
Expand Down Expand Up @@ -95,6 +102,22 @@ - (void) layoutSubviews {

}];

self.activityDot.image = [[self class] fetchObjectForKey:[[self class] cacheKeyForActivity:self.hasActivity] withCreator:^id{
UIGraphicsBeginImageContextWithOptions(self.activityDot.bounds.size, NO, self.window.screen.scale);
CGContextRef context = UIGraphicsGetCurrentContext();

if (self.hasActivity){
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillEllipseInRect(context, self.activityDot.bounds);
}

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}];

self.activityDot.hidden = !self.hasActivity;

self.overlayView.hidden = !(self.selected || self.highlighted);

}
Expand All @@ -119,6 +142,17 @@ - (UIImageView *) imageView {
return _imageView;
}

- (UIImageView *) activityDot {
if (!_activityDot) {
CGFloat circleWidth = 5.0;
CGRect circleRect = (CGRectMake((self.bounds.size.width / 2) - (circleWidth / 2), self.bounds.size.height - (circleWidth * 2), circleWidth, circleWidth));

_activityDot = [[UIImageView alloc] initWithFrame:circleRect];
[self.contentView addSubview:_activityDot];
}
return _activityDot;
}

+ (NSCache *) imageCache {
static NSCache *cache;
static dispatch_once_t onceToken;
Expand All @@ -132,6 +166,10 @@ + (id) cacheKeyForPickerDate:(DFDatePickerDate)date {
return @(date.day);
}

+ (id) cacheKeyForActivity:(BOOL)hasActivity {
return [NSString stringWithFormat:@"HasActivity-%d", hasActivity];
}

+ (id) fetchObjectForKey:(id)key withCreator:(id(^)(void))block {
id answer = [[self imageCache] objectForKey:key];
if (!answer) {
Expand Down
10 changes: 10 additions & 0 deletions DayFlow/DFDatePickerView.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#import <UIKit/UIKit.h>

@class DFDatePickerView;

@protocol DFDatePickerViewDataSource <NSObject>

- (BOOL) datePickerView:(DFDatePickerView *)datePickerView shouldShowActivityOnDate:(NSDate *)date;

@end

@interface DFDatePickerView : UIView

- (instancetype) initWithCalendar:(NSCalendar *)calendar;

@property (nonatomic, readwrite, strong) NSDate *selectedDate;

@property (nonatomic, weak) id <DFDatePickerViewDataSource> dataSource;

@end
4 changes: 3 additions & 1 deletion DayFlow/DFDatePickerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ - (void) shiftDatesByComponents:(NSDateComponents *)components {
NSIndexPath *fromIndexPath = [cv indexPathForCell:((UICollectionViewCell *)visibleCells[0]) ];
NSInteger fromSection = fromIndexPath.section;
NSDate *fromSectionOfDate = [self dateForFirstDayInSection:fromSection];
CGPoint fromSectionOrigin = [self convertPoint:[cvLayout layoutAttributesForItemAtIndexPath:fromIndexPath].frame.origin fromView:cv];
UICollectionViewLayoutAttributes *fromAttrs = [cvLayout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:fromSection]];
CGPoint fromSectionOrigin = [self convertPoint:fromAttrs.frame.origin fromView:cv];

_fromDate = [self pickerDateFromDate:[self.calendar dateByAddingComponents:components toDate:[self dateFromPickerDate:self.fromDate] options:0]];
_toDate = [self pickerDateFromDate:[self.calendar dateByAddingComponents:components toDate:[self dateFromPickerDate:self.toDate] options:0]];
Expand Down Expand Up @@ -318,6 +319,7 @@ - (DFDatePickerDayCell *)collectionView:(UICollectionView *)collectionView cellF
cell.date = cellPickerDate;
cell.enabled = ((firstDayPickerDate.year == cellPickerDate.year) && (firstDayPickerDate.month == cellPickerDate.month));
cell.selected = [self.selectedDate isEqualToDate:cellDate];
cell.hasActivity = [self.dataSource datePickerView:self shouldShowActivityOnDate:cellDate];

return cell;

Expand Down
1 change: 1 addition & 0 deletions DayFlow/DFDatePickerViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@protocol DFDatePickerViewControllerDelegate

- (void) datePickerViewController:(DFDatePickerViewController *)controller didSelectDate:(NSDate *)date;
- (BOOL) datePickerViewController:(DFDatePickerViewController *)controller shouldShowActivityOnDate:(NSDate *)date;

@end

Expand Down
10 changes: 10 additions & 0 deletions DayFlow/DFDatePickerViewController.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#import "DFDatePickerViewController.h"

@interface DFDatePickerViewController () <DFDatePickerViewDataSource>

@end

@implementation DFDatePickerViewController
@synthesize datePickerView = _datePickerView;

Expand All @@ -13,6 +17,7 @@ - (DFDatePickerView *) datePickerView {
_datePickerView = [DFDatePickerView new];
_datePickerView.frame = self.view.bounds;
_datePickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
_datePickerView.dataSource = self;
}
return _datePickerView;
}
Expand All @@ -37,4 +42,9 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
}
}

- (BOOL) datePickerView:(DFDatePickerView *)datePickerView shouldShowActivityOnDate:(NSDate *)date
{
return [self.delegate datePickerViewController:self shouldShowActivityOnDate:date];
}

@end