Skip to content

Commit

Permalink
More code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
klazuka committed Jan 3, 2010
1 parent 26d83dc commit caf6724
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 41 deletions.
16 changes: 7 additions & 9 deletions Kal/KalGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ - (id)initWithFrame:(CGRect)frame logic:(KalLogic *)theLogic delegate:(id<KalVie
CGRect monthRect = CGRectMake(0.f, 0.f, frame.size.width, frame.size.height);
frontMonthView = [[KalMonthView alloc] initWithFrame:monthRect];
backMonthView = [[KalMonthView alloc] initWithFrame:monthRect];
// frontMonthView.backgroundColor = [UIColor colorWithRed:1.f green:0.0f blue:0.0f alpha:0.3f];
// backMonthView.backgroundColor = [UIColor colorWithRed:0.f green:0.0f blue:1.f alpha:0.3f];
backMonthView.hidden = YES;
[self addSubview:backMonthView];
[self addSubview:frontMonthView];
Expand Down Expand Up @@ -152,13 +150,6 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
self.highlightedTile = nil;
}

- (void)selectTodayIfVisible
{
KalTileView *todayTile = [frontMonthView todaysTileIfVisible];
if (todayTile)
self.selectedTile = todayTile;
}

#pragma mark -
#pragma mark Slide Animation

Expand Down Expand Up @@ -227,6 +218,13 @@ - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished c

#pragma mark -

- (void)selectTodayIfVisible
{
KalTileView *todayTile = [frontMonthView todaysTileIfVisible];
if (todayTile)
self.selectedTile = todayTile;
}

- (void)swapMonthViews
{
KalMonthView *tmp = backMonthView;
Expand Down
40 changes: 13 additions & 27 deletions Kal/KalMonthView.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,22 @@ - (id)initWithFrame:(CGRect)frame

- (void)showDates:(NSArray *)mainDates leadingAdjacentDates:(NSArray *)leadingAdjacentDates trailingAdjacentDates:(NSArray *)trailingAdjacentDates
{
int i = 0;
int tileNum = 0;
NSArray *dates[] = { leadingAdjacentDates, mainDates, trailingAdjacentDates };

for (KalDate *d in leadingAdjacentDates) {
KalTileView *tile = [self.subviews objectAtIndex:i];
[tile resetState];
tile.type = KalTileTypeAdjacent;
tile.date = d;
[tile setNeedsDisplay];
i++;
}

for (KalDate *d in mainDates) {
KalTileView *tile = [self.subviews objectAtIndex:i];
[tile resetState];
tile.type = [d isToday] ? KalTileTypeToday : KalTileTypeRegular;
tile.date = d;
[tile setNeedsDisplay];
i++;
}

for (KalDate *d in trailingAdjacentDates) {
KalTileView *tile = [self.subviews objectAtIndex:i];
[tile resetState];
tile.type = KalTileTypeAdjacent;
tile.date = d;
[tile setNeedsDisplay];
i++;
for (int i=0; i<3; i++) {
for (KalDate *d in dates[i]) {
KalTileView *tile = [self.subviews objectAtIndex:tileNum];
[tile resetState];
tile.date = d;
tile.type = dates[i] != mainDates
? KalTileTypeAdjacent
: [d isToday] ? KalTileTypeToday : KalTileTypeRegular;
tileNum++;
}
}

numWeeks = ceilf(i / 7.f);
numWeeks = ceilf(tileNum / 7.f);
[self sizeToFit];
[self setNeedsDisplay];
}
Expand Down
5 changes: 0 additions & 5 deletions Kal/KalView.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,17 @@ @implementation KalView
- (id)initWithFrame:(CGRect)frame delegate:(id<KalViewDelegate>)theDelegate logic:(KalLogic *)theLogic
{
if ((self = [super initWithFrame:frame])) {

delegate = theDelegate;

logic = [theLogic retain];
[logic addObserver:self forKeyPath:@"selectedMonthNameAndYear" options:NSKeyValueObservingOptionNew context:NULL];

self.autoresizesSubviews = YES;
self.autoresizingMask = UIViewAutoresizingFlexibleHeight;

// Header
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, frame.size.width, kHeaderHeight)] autorelease];
headerView.backgroundColor = [UIColor grayColor];
[self addSubviewsToHeaderView:headerView];
[self addSubview:headerView];

// Content
UIView *contentView = [[[UIView alloc] initWithFrame:CGRectMake(0.f, kHeaderHeight, frame.size.width, frame.size.height - kHeaderHeight)] autorelease];
contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[self addSubviewsToContentView:contentView];
Expand Down

0 comments on commit caf6724

Please sign in to comment.