Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Kugler committed Aug 8, 2013
0 parents commit 21b5b35
Show file tree
Hide file tree
Showing 27 changed files with 1,523 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.DS_Store
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
Pods/
358 changes: 358 additions & 0 deletions Calendar.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions Calendar/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
18 changes: 18 additions & 0 deletions Calendar/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// AppDelegate.m
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}

@end
41 changes: 41 additions & 0 deletions Calendar/Calendar-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.olebegemann.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>MainStoryboard</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
14 changes: 14 additions & 0 deletions Calendar/Calendar-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Prefix header for all source files of the 'Calendar' target in the 'Calendar' project
//

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
25 changes: 25 additions & 0 deletions Calendar/CalendarDataSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// CalendarDataSource.h
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CalendarEvent.h"
#import "CalendarEventCell.h"
#import "HeaderView.h"

typedef void (^ConfigureCellBlock)(CalendarEventCell *cell, NSIndexPath *indexPath, id<CalendarEvent> event);
typedef void (^ConfigureHeaderViewBlock)(HeaderView *headerView, NSString *kind, NSIndexPath *indexPath);

@interface CalendarDataSource : NSObject <UICollectionViewDataSource>

@property (copy, nonatomic) ConfigureCellBlock configureCellBlock;
@property (copy, nonatomic) ConfigureHeaderViewBlock configureHeaderViewBlock;

- (id<CalendarEvent>)eventAtIndexPath:(NSIndexPath *)indexPath;
- (NSArray *)indexPathsOfEventsBetweenMinDayIndex:(NSInteger)minDayIndex maxDayIndex:(NSInteger)maxDayIndex minStartHour:(NSInteger)minStartHour maxStartHour:(NSInteger)maxStartHour;

@end
89 changes: 89 additions & 0 deletions Calendar/CalendarDataSource.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// CalendarDataSource.m
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import "CalendarDataSource.h"
#import "SampleCalendarEvent.h"

@interface CalendarDataSource ()

@property (strong, nonatomic) NSMutableArray *events;

@end

@implementation CalendarDataSource

- (void)awakeFromNib
{
_events = [[NSMutableArray alloc] init];

// Prepare some example events
// In a real app, these should be retrieved from the calendar data store (EventKit.framework)
// We use a very simple data format for our events. In a real calendar app, event times should be
// represented with NSDate objects and correct calendrical date calculcations should be used.
[self generateSampleData];
}

- (void)generateSampleData
{
for (NSUInteger idx = 0; idx < 20; idx++) {
SampleCalendarEvent *event = [SampleCalendarEvent randomEvent];
[self.events addObject:event];
}
}

#pragma mark - CalendarDataSource

// The layout object calls these methods to identify the events that correspond to
// a given index path or that are visible in a certain rectangle

- (id<CalendarEvent>)eventAtIndexPath:(NSIndexPath *)indexPath
{
return self.events[indexPath.item];
}

- (NSArray *)indexPathsOfEventsBetweenMinDayIndex:(NSInteger)minDayIndex maxDayIndex:(NSInteger)maxDayIndex minStartHour:(NSInteger)minStartHour maxStartHour:(NSInteger)maxStartHour
{
NSMutableArray *indexPaths = [NSMutableArray array];
[self.events enumerateObjectsUsingBlock:^(id event, NSUInteger idx, BOOL *stop) {
if ([event day] >= minDayIndex && [event day] <= maxDayIndex && [event startHour] >= minStartHour && [event startHour] <= maxStartHour)
{
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:idx inSection:0];
[indexPaths addObject:indexPath];
}
}];
return indexPaths;
}

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.events count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
id<CalendarEvent> event = self.events[indexPath.item];
CalendarEventCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CalendarEventCell" forIndexPath:indexPath];

if (self.configureCellBlock) {
self.configureCellBlock(cell, indexPath, event);
}
return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
HeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
if (self.configureHeaderViewBlock) {
self.configureHeaderViewBlock(headerView, kind, indexPath);
}
return headerView;
}

@end
18 changes: 18 additions & 0 deletions Calendar/CalendarEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CalendarEvent.h
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol CalendarEvent <NSObject>

@property (copy, nonatomic) NSString *title;
@property (assign, nonatomic) NSInteger day;
@property (assign, nonatomic) NSInteger startHour;
@property (assign, nonatomic) NSInteger durationInHours;

@end
15 changes: 15 additions & 0 deletions Calendar/CalendarEventCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// CalendarEventCell.h
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CalendarEventCell : UICollectionViewCell

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@end
39 changes: 39 additions & 0 deletions Calendar/CalendarEventCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// CalendarEventCell.m
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>
#import "CalendarEventCell.h"

@implementation CalendarEventCell

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}

- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if (self) {
[self setup];
}
return self;
}

- (void)setup
{
self.layer.cornerRadius = 10;
self.layer.borderWidth = 1.0;
self.layer.borderColor = [[UIColor colorWithRed:0 green:0 blue:0.7 alpha:1] CGColor];
}

@end
13 changes: 13 additions & 0 deletions Calendar/CalendarViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CalendarViewController.h
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CalendarViewController : UICollectionViewController

@end
44 changes: 44 additions & 0 deletions Calendar/CalendarViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// CalendarViewController.m
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import "CalendarViewController.h"
#import "CalendarDataSource.h"
#import "HeaderView.h"

@interface CalendarViewController ()

@property (strong, nonatomic) IBOutlet CalendarDataSource *calendarDataSource;

@end

@implementation CalendarViewController

- (void)viewDidLoad
{
[super viewDidLoad];

// Register NIB for supplementary views
UINib *headerViewNib = [UINib nibWithNibName:@"HeaderView" bundle:nil];
[self.collectionView registerNib:headerViewNib forSupplementaryViewOfKind:@"DayHeaderView" withReuseIdentifier:@"HeaderView"];
[self.collectionView registerNib:headerViewNib forSupplementaryViewOfKind:@"HourHeaderView" withReuseIdentifier:@"HeaderView"];

// Define cell and header view configuration
CalendarDataSource *dataSource = (CalendarDataSource *)self.collectionView.dataSource;
dataSource.configureCellBlock = ^(CalendarEventCell *cell, NSIndexPath *indexPath, id<CalendarEvent> event) {
cell.titleLabel.text = event.title;
};
dataSource.configureHeaderViewBlock = ^(HeaderView *headerView, NSString *kind, NSIndexPath *indexPath) {
if ([kind isEqualToString:@"DayHeaderView"]) {
headerView.titleLabel.text = [NSString stringWithFormat:@"Day %d", indexPath.item + 1];
} else if ([kind isEqualToString:@"HourHeaderView"]) {
headerView.titleLabel.text = [NSString stringWithFormat:@"%2d:00", indexPath.item + 1];
}
};
}

@end
Binary file added Calendar/Default-568h@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Calendar/Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Calendar/Default@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Calendar/HeaderView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// HeaderView.h
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface HeaderView : UICollectionReusableView

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@end
13 changes: 13 additions & 0 deletions Calendar/HeaderView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// HeaderView.m
// Calendar
//
// Created by Ole Begemann on 29.07.13.
// Copyright (c) 2013 Ole Begemann. All rights reserved.
//

#import "HeaderView.h"

@implementation HeaderView

@end
Loading

0 comments on commit 21b5b35

Please sign in to comment.