Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Burning-Man-Earth/iBurn-iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchiles committed Aug 5, 2014
2 parents b889787 + 1034f29 commit 5ba151d
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 250 deletions.
12 changes: 6 additions & 6 deletions iBurn.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
D92562C319886EBF00ED6B50 /* BRCDataObjectTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D92562C119886EBF00ED6B50 /* BRCDataObjectTableViewCell.xib */; };
D92562C6198876C400ED6B50 /* BRCEventObjectTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D92562C5198876C400ED6B50 /* BRCEventObjectTableViewCell.m */; };
D92562C81988771400ED6B50 /* BRCEventObjectTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D92562C71988771400ED6B50 /* BRCEventObjectTableViewCell.xib */; };
D92562CC1988929A00ED6B50 /* BRCLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D92562CB1988929A00ED6B50 /* BRCLocationManager.m */; };
D92562CF198A20D600ED6B50 /* RMMapView+iBurn.m in Sources */ = {isa = PBXBuildFile; fileRef = D92562CE198A20D600ED6B50 /* RMMapView+iBurn.m */; };
D94EFA51199158D2009F12F4 /* CLLocationManager+iBurn.m in Sources */ = {isa = PBXBuildFile; fileRef = D94EFA50199158D2009F12F4 /* CLLocationManager+iBurn.m */; };
D975CAF2198DAB5A00CC8226 /* BRCSecrets.m in Sources */ = {isa = PBXBuildFile; fileRef = D975CAF1198DAB5A00CC8226 /* BRCSecrets.m */; };
D9794B74198BBFB400D7FDA7 /* UIColor+iBurn.m in Sources */ = {isa = PBXBuildFile; fileRef = D9794B73198BBFB400D7FDA7 /* UIColor+iBurn.m */; };
D97D7A31198ADBE400CA7828 /* NSDateFormatter+iBurn.m in Sources */ = {isa = PBXBuildFile; fileRef = D97D7A30198ADBE400CA7828 /* NSDateFormatter+iBurn.m */; };
Expand Down Expand Up @@ -109,10 +109,10 @@
D92562C4198876C400ED6B50 /* BRCEventObjectTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BRCEventObjectTableViewCell.h; sourceTree = "<group>"; };
D92562C5198876C400ED6B50 /* BRCEventObjectTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BRCEventObjectTableViewCell.m; sourceTree = "<group>"; };
D92562C71988771400ED6B50 /* BRCEventObjectTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BRCEventObjectTableViewCell.xib; sourceTree = "<group>"; };
D92562CA1988929A00ED6B50 /* BRCLocationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BRCLocationManager.h; sourceTree = "<group>"; };
D92562CB1988929A00ED6B50 /* BRCLocationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BRCLocationManager.m; sourceTree = "<group>"; };
D92562CD198A20D600ED6B50 /* RMMapView+iBurn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RMMapView+iBurn.h"; sourceTree = "<group>"; };
D92562CE198A20D600ED6B50 /* RMMapView+iBurn.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RMMapView+iBurn.m"; sourceTree = "<group>"; };
D94EFA4F199158D2009F12F4 /* CLLocationManager+iBurn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CLLocationManager+iBurn.h"; sourceTree = "<group>"; };
D94EFA50199158D2009F12F4 /* CLLocationManager+iBurn.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CLLocationManager+iBurn.m"; sourceTree = "<group>"; };
D975CAF0198DAB5A00CC8226 /* BRCSecrets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BRCSecrets.h; sourceTree = "<group>"; };
D975CAF1198DAB5A00CC8226 /* BRCSecrets.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BRCSecrets.m; sourceTree = "<group>"; };
D9794B72198BBFB400D7FDA7 /* UIColor+iBurn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+iBurn.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -377,8 +377,8 @@
D994157B1987278400D245C7 /* Data */ = {
isa = PBXGroup;
children = (
D92562CA1988929A00ED6B50 /* BRCLocationManager.h */,
D92562CB1988929A00ED6B50 /* BRCLocationManager.m */,
D94EFA4F199158D2009F12F4 /* CLLocationManager+iBurn.h */,
D94EFA50199158D2009F12F4 /* CLLocationManager+iBurn.m */,
D99415781987277500D245C7 /* BRCDatabaseManager.h */,
D99415791987277500D245C7 /* BRCDatabaseManager.m */,
D994156F198726F400D245C7 /* BRCDataImporter.h */,
Expand Down Expand Up @@ -501,6 +501,7 @@
6322830B19882153009E472B /* BRCRelationshipDetailInfoCell.m in Sources */,
D99395A8198B897B00E9ADD2 /* BRCDetailInfoTableViewCell.m in Sources */,
6322830119881DDE009E472B /* BRCDetailViewController.m in Sources */,
D94EFA51199158D2009F12F4 /* CLLocationManager+iBurn.m in Sources */,
D9941568198726A700D245C7 /* BRCArtObject.m in Sources */,
6322830519881F41009E472B /* BRCDetailCellInfo.m in Sources */,
D99395AE198B991900E9ADD2 /* TTTLocationFormatter+iBurn.m in Sources */,
Expand All @@ -513,7 +514,6 @@
63CE2A681987140F00F65B01 /* BRCAppDelegate.m in Sources */,
D975CAF2198DAB5A00CC8226 /* BRCSecrets.m in Sources */,
D92562C219886EBF00ED6B50 /* BRCDataObjectTableViewCell.m in Sources */,
D92562CC1988929A00ED6B50 /* BRCLocationManager.m in Sources */,
D92562CF198A20D600ED6B50 /* RMMapView+iBurn.m in Sources */,
63D270F91987159A00204954 /* BRCMapViewController.m in Sources */,
D97D7A34198AF7BD00CA7828 /* NSDate+iBurn.m in Sources */,
Expand Down
3 changes: 0 additions & 3 deletions iBurn/BRCAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#import "BRCArtObject.h"
#import "BRCCampObject.h"
#import "BRCRecurringEventObject.h"
#import "BRCLocationManager.h"
#import "BRCEventObject_Private.h"
#import "NSDateFormatter+iBurn.h"
#import "BRCSecrets.h"
Expand Down Expand Up @@ -62,8 +61,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = @[mapNavController, artNavController, campNavController, eventsNavController];

[[BRCLocationManager sharedInstance] updateRecentLocation];

self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = tabBarController;

Expand Down
2 changes: 2 additions & 0 deletions iBurn/BRCDataObjectTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <UIKit/UIKit.h>
#import "MCSwipeTableViewCell.h"
#import <CoreLocation/CoreLocation.h>

@class BRCDataObject;

Expand All @@ -21,5 +22,6 @@
+ (CGFloat) cellHeight;

- (void) setTitleLabelBold:(BOOL)isBold;
- (void) updateDistanceLabelFromLocation:(CLLocation*)fromLocation toLocation:(CLLocation*)toLocation;

@end
17 changes: 10 additions & 7 deletions iBurn/BRCDataObjectTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
#import "BRCDataObjectTableViewCell.h"
#import "BRCDataObject.h"
#import "TTTLocationFormatter+iBurn.h"
#import "BRCLocationManager.h"

@implementation BRCDataObjectTableViewCell

- (void) setDataObject:(BRCDataObject*)dataObject {
_dataObject = dataObject;
CLLocation *recentLocation = [BRCLocationManager sharedInstance].recentLocation;
CLLocation *objectLocation = dataObject.location;

self.titleLabel.text = dataObject.title;

[self setTitleLabelBold:dataObject.isFavorite];
}

- (void) updateDistanceLabelFromLocation:(CLLocation*)fromLocation toLocation:(CLLocation*)toLocation {
CLLocation *recentLocation = fromLocation;
CLLocation *objectLocation = toLocation;
CLLocationDistance distance = CLLocationDistanceMax;
if (recentLocation && objectLocation) {
distance = [objectLocation distanceFromLocation:recentLocation];
Expand All @@ -26,12 +32,9 @@ - (void) setDataObject:(BRCDataObject*)dataObject {
} else {
self.subtitleLabel.attributedText = [TTTLocationFormatter brc_humanizedStringForDistance:distance];
}

self.titleLabel.text = dataObject.title;

[self setTitleLabelBold:dataObject.isFavorite];
}


+ (NSString*) cellIdentifier {
return NSStringFromClass([self class]);
}
Expand Down
7 changes: 2 additions & 5 deletions iBurn/BRCDatabaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import "YapDatabase.h"
#import "YapDatabaseFilteredViewTypes.h"
#import "YapDatabaseFilteredView.h"
Expand All @@ -30,23 +31,20 @@ typedef NS_ENUM(NSUInteger, BRCDatabaseFilteredViewType) {
@property (nonatomic, strong, readonly) YapDatabase *database;
@property (nonatomic, strong, readonly) YapDatabaseConnection *readWriteDatabaseConnection;

@property (nonatomic, strong) YapDatabaseFilteredView *eventDistanceView;
@property (nonatomic, strong) YapDatabaseFilteredView *eventTimeView;

- (BOOL)setupDatabaseWithName:(NSString*)databaseName;

+ (instancetype) sharedInstance;

+ (YapDatabaseViewFilteringBlock)everythingFilteringBlock;


/**
* Does not register the view, but checks if it is registered and returns
* the registered view if it exists. (Caller should register the view if needed)
* @see extensionNameForClass:extensionType:
*/
- (YapDatabaseView*) databaseViewForClass:(Class)viewClass
extensionType:(BRCDatabaseViewExtensionType)extensionType
fromLocation:(CLLocation*)fromLocation
extensionName:(NSString**)extensionName
previouslyRegistered:(BOOL*)previouslyRegistered;

Expand All @@ -67,5 +65,4 @@ typedef NS_ENUM(NSUInteger, BRCDatabaseFilteredViewType) {
withIndexedProperties:(NSArray *)properties
extensionName:(NSString**)extensionName
previouslyRegistered:(BOOL*)previouslyRegistered;

@end
64 changes: 11 additions & 53 deletions iBurn/BRCDatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#import "YapDatabaseFilteredView.h"
#import "NSDateFormatter+iBurn.h"
#import "NSUserDefaults+iBurn.h"
#import "BRCLocationManager.h"

@interface BRCDatabaseManager()
@property (nonatomic, strong) YapDatabase *database;
Expand Down Expand Up @@ -69,56 +68,19 @@ - (BOOL)setupDatabaseWithName:(NSString *)name
self.readWriteDatabaseConnection.objectCacheLimit = 200;
self.readWriteDatabaseConnection.metadataCacheLimit = 200;
self.readWriteDatabaseConnection.name = @"readOnlyDatabaseConnection";

NSArray *viewsToRegister = @[[BRCArtObject class],
[BRCCampObject class],
[BRCEventObject class]];

[viewsToRegister enumerateObjectsUsingBlock:^(Class viewClass, NSUInteger idx, BOOL *stop) {
// Registering Distance View and Filtered Subviews
NSString *distanceViewName = nil;
YapDatabaseView *distanceView = [self databaseViewForClass:viewClass extensionType:BRCDatabaseViewExtensionTypeDistance extensionName:&distanceViewName previouslyRegistered:NULL];
[self.database asyncRegisterExtension:distanceView withName:distanceViewName completionBlock:^(BOOL ready) {
NSLog(@"%@ ready %d", distanceViewName, ready);
if (ready && viewClass == [BRCEventObject class]) {
NSString *filteredDistanceViewName = nil;
YapDatabaseFilteredView *filteredDistanceView = [self filteredDatabaseViewForType:BRCDatabaseFilteredViewTypeEventExpirationAndType parentViewName:distanceViewName extensionName:&filteredDistanceViewName previouslyRegistered:NULL];
[self.database asyncRegisterExtension:filteredDistanceView withName:filteredDistanceViewName completionBlock:^(BOOL ready) {
NSLog(@"%@ ready %d", filteredDistanceViewName, ready);
self.eventDistanceView = filteredDistanceView;
}];
}
}];

// full text search
NSString *ftsName = nil;
YapDatabaseFullTextSearch *fullTextSearch = [self fullTextSearchForClass:viewClass withIndexedProperties:@[@"title"] extensionName:&ftsName previouslyRegistered:NULL];
[self.database asyncRegisterExtension:fullTextSearch withName:ftsName completionBlock:^(BOOL ready) {
NSLog(@"%@ ready %d", ftsName, ready);
}];

//events
if (viewClass == [BRCEventObject class]) {
NSString *timeViewName = nil;
YapDatabaseView *timeView = [self databaseViewForClass:viewClass extensionType:BRCDatabaseViewExtensionTypeTime extensionName:&timeViewName previouslyRegistered:NULL];
[self.database asyncRegisterExtension:timeView withName:timeViewName completionBlock:^(BOOL ready) {
NSLog(@"%@ ready %d", timeViewName, ready);
NSString *favoriteTimeViewName = nil;
YapDatabaseFilteredView *favoriteTimeView = [self filteredDatabaseViewForType:BRCDatabaseFilteredViewTypeFavorites parentViewName:timeViewName extensionName:&favoriteTimeViewName previouslyRegistered:NULL];
[self.database asyncRegisterExtension:favoriteTimeView withName:favoriteTimeViewName completionBlock:^(BOOL ready) {
NSLog(@"%@ ready %d", favoriteTimeViewName, ready);
}];
NSString *filteredTimeViewName = nil;
YapDatabaseFilteredView *filteredTimeView = [self filteredDatabaseViewForType:BRCDatabaseFilteredViewTypeEventExpirationAndType parentViewName:timeViewName extensionName:&filteredTimeViewName previouslyRegistered:NULL];
[self.database asyncRegisterExtension:filteredTimeView withName:filteredTimeViewName completionBlock:^(BOOL ready) {
NSLog(@"%@ ready %d", filteredTimeViewName, ready);
self.eventTimeView = filteredTimeView;
}];
}];
}
}];



if (self.database) {
return YES;
Expand Down Expand Up @@ -181,8 +143,8 @@ - (YapDatabaseViewBlockType)sortingBlockTypeForClass:(Class)viewClass extensionT
return sortingBlockType;
}

- (NSComparisonResult) compareDistanceOfFirstObject:(BRCDataObject*)object1 secondObject:(BRCDataObject*)object2 {
CLLocation *currentLocation = [BRCLocationManager sharedInstance].recentLocation;
+ (NSComparisonResult) compareDistanceOfFirstObject:(BRCDataObject*)object1 secondObject:(BRCDataObject*)object2 fromLocation:(CLLocation*)fromLocation {
CLLocation *currentLocation = fromLocation;
if (!currentLocation) {
return NSOrderedSame;
}
Expand All @@ -200,7 +162,7 @@ - (NSComparisonResult) compareDistanceOfFirstObject:(BRCDataObject*)object1 seco
return [@(distance1) compare:@(distance2)];
}

- (YapDatabaseViewSortingBlock)sortingBlockForClass:(Class)viewClass extensionType:(BRCDatabaseViewExtensionType)extensionType {
+ (YapDatabaseViewSortingBlock)sortingBlockForClass:(Class)viewClass extensionType:(BRCDatabaseViewExtensionType)extensionType fromLocation:(CLLocation*)fromLocation {
YapDatabaseViewSortingBlock sortingBlock;
if (extensionType == BRCDatabaseViewExtensionTypeTime) {
sortingBlock = ^(NSString *group, NSString *collection1, NSString *key1, id obj1,
Expand All @@ -218,7 +180,7 @@ - (YapDatabaseViewSortingBlock)sortingBlockForClass:(Class)viewClass extensionTy

NSComparisonResult dateComparison = [event1.startDate compare:event2.startDate];
if (dateComparison == NSOrderedSame) {
NSComparisonResult distanceComparison = [self compareDistanceOfFirstObject:event1 secondObject:event2];
NSComparisonResult distanceComparison = [self compareDistanceOfFirstObject:event1 secondObject:event2 fromLocation:fromLocation];
return distanceComparison;
} else {
return dateComparison;
Expand All @@ -232,7 +194,8 @@ - (YapDatabaseViewSortingBlock)sortingBlockForClass:(Class)viewClass extensionTy
if ([obj1 isKindOfClass:viewClass] && [obj2 isKindOfClass:viewClass]) {
BRCDataObject *data1 = (BRCDataObject *)obj1;
BRCDataObject *data2 = (BRCDataObject *)obj2;
return [self compareDistanceOfFirstObject:data1 secondObject:data2];
return [self compareDistanceOfFirstObject:data1 secondObject:data2 fromLocation:fromLocation
];
}
return NSOrderedSame;
};
Expand All @@ -247,6 +210,7 @@ - (YapDatabaseViewSortingBlock)sortingBlockForClass:(Class)viewClass extensionTy
*/
- (YapDatabaseView*) databaseViewForClass:(Class)viewClass
extensionType:(BRCDatabaseViewExtensionType)extensionType
fromLocation:(CLLocation*)fromLocation
extensionName:(NSString**)extensionName
previouslyRegistered:(BOOL*)previouslyRegistered
{
Expand All @@ -268,24 +232,18 @@ - (YapDatabaseView*) databaseViewForClass:(Class)viewClass

YapDatabaseViewBlockType groupingBlockType = [self groupingBlockTypeForClass:viewClass extensionType:extensionType];
YapDatabaseViewGroupingBlock groupingBlock = [self groupingBlockForClass:viewClass extensionType:extensionType];

YapDatabaseViewBlockType sortingBlockType = [self sortingBlockTypeForClass:viewClass extensionType:extensionType];
YapDatabaseViewSortingBlock sortingBlock = [self sortingBlockForClass:viewClass extensionType:extensionType];

YapDatabaseViewSortingBlock sortingBlock = [[self class] sortingBlockForClass:viewClass extensionType:extensionType fromLocation:fromLocation];
YapDatabaseViewOptions *options = [[YapDatabaseViewOptions alloc] init];
if (extensionType == BRCDatabaseViewExtensionTypeDistance) {
options.isPersistent = NO;
} else {
options.isPersistent = YES;
}
NSString *versionTag = versionTag = [[NSUUID UUID] UUIDString];
options.allowedCollections = [NSSet setWithObject:[viewClass collection]];

YapDatabaseView *databaseView =
[[YapDatabaseView alloc] initWithGroupingBlock:groupingBlock
groupingBlockType:groupingBlockType
sortingBlock:sortingBlock
sortingBlockType:sortingBlockType
versionTag:@"1"
versionTag:versionTag
options:options];
return databaseView;
}
Expand Down
1 change: 0 additions & 1 deletion iBurn/BRCDetailInfoTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#import "BRCDetailCellInfo.h"
#import "BRCRelationshipDetailInfoCell.h"
#import "BRCDataObject.h"
#import "BRCLocationManager.h"
#import "TTTLocationFormatter.h"
#import "TTTTimeIntervalFormatter+iBurn.h"
#import "TTTLocationFormatter+iBurn.h"
Expand Down
Loading

0 comments on commit 5ba151d

Please sign in to comment.