Skip to content

Commit

Permalink
day planner view: dimming views are now cached for efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
jumartin committed Nov 8, 2016
1 parent 9c09574 commit abcaa52
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions CalendarLib/MGCDayPlannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#import "MGCInteractiveEventView.h"
#import "MGCTimeRowsView.h"
#import "MGCAlignedGeometry.h"
#import "OSCache.h"


// used to restrict scrolling to one direction / axis
Expand Down Expand Up @@ -150,6 +151,8 @@ @interface MGCDayPlannerView () <UICollectionViewDataSource, MGCTimedEventsViewL
@property (nonatomic) CGFloat hourSlotHeightForGesture;
@property (copy, nonatomic) dispatch_block_t scrollViewAnimationCompletionBlock;

@property (nonatomic) OSCache *dimmedTimeRangesCache; // cache for dimmed time ranges (indexed by date)

@end


Expand Down Expand Up @@ -192,6 +195,9 @@ - (void)setup
_reuseQueue = [[MGCReusableObjectQueue alloc] init];
_loadingDays = [NSMutableOrderedSet orderedSetWithCapacity:14];

_dimmedTimeRangesCache = [[OSCache alloc]init];
_dimmedTimeRangesCache.countLimit = 200;

self.backgroundColor = [UIColor whiteColor];
self.autoresizesSubviews = NO;

Expand Down Expand Up @@ -384,6 +390,8 @@ - (void)setHourRange:(NSRange)hourRange

_hourRange = hourRange;

[self.dimmedTimeRangesCache removeAllObjects];

self.timedEventsViewLayout.dayColumnSize = self.dayColumnSize;
[self.timedEventsViewLayout invalidateLayout];

Expand Down Expand Up @@ -1905,12 +1913,10 @@ - (CGRect)collectionView:(UICollectionView *)collectionView layout:(MGCTimedEven
return CGRectNull;
}

- (NSArray*)collectionView:(UICollectionView *)collectionView layout:(MGCTimedEventsViewLayout *)layout dimmingRectsForSection:(NSUInteger)section
- (NSArray*)dimmedTimeRangesAtDate:(NSDate*)date
{
NSMutableArray *ranges = [NSMutableArray array];

NSDate *date = [self dateFromDayOffset:section];


if ([self.delegate respondsToSelector:@selector(dayPlannerView:numberOfDimmedTimeRangesAtDate:)]) {
NSInteger count = [self.delegate dayPlannerView:self numberOfDimmedTimeRangesAtDate:date];

Expand All @@ -1928,8 +1934,21 @@ - (NSArray*)collectionView:(UICollectionView *)collectionView layout:(MGCTimedEv
}
}
}

return ranges;
}

- (NSArray*)collectionView:(UICollectionView *)collectionView layout:(MGCTimedEventsViewLayout *)layout dimmingRectsForSection:(NSUInteger)section
{
NSDate *date = [self dateFromDayOffset:section];

NSArray *ranges = [self.dimmedTimeRangesCache objectForKey:date];
if (!ranges) {
ranges = [self dimmedTimeRangesAtDate:date];
[self.dimmedTimeRangesCache setObject:ranges forKey:date];
}

NSMutableArray *rects = [NSMutableArray arrayWithCapacity:ranges.count];

for (MGCDateRange *range in ranges) {
if (!range.isEmpty) {
CGFloat y1 = [self offsetFromDate:range.start];
Expand All @@ -1941,6 +1960,7 @@ - (NSArray*)collectionView:(UICollectionView *)collectionView layout:(MGCTimedEv
return rects;
}


#pragma mark - MGCAllDayEventsViewLayoutDelegate

- (NSRange)collectionView:(UICollectionView*)view layout:(MGCAllDayEventsViewLayout*)layout dayRangeForEventAtIndexPath:(NSIndexPath*)indexPath
Expand Down

0 comments on commit abcaa52

Please sign in to comment.