Skip to content

Commit

Permalink
Remove distance sort
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Jun 19, 2015
1 parent 3d49e80 commit ef74690
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 393 deletions.
18 changes: 4 additions & 14 deletions iBurn/BRCDatabaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
#import "YapDatabaseFilteredView.h"
#import "YapDatabaseFullTextSearch.h"

typedef NS_ENUM(NSUInteger, BRCDatabaseViewExtensionType) {
BRCDatabaseViewExtensionTypeUnknown,
BRCDatabaseViewExtensionTypeDistance,
BRCDatabaseViewExtensionTypeTimeThenDistance,
};

typedef NS_ENUM(NSUInteger, BRCDatabaseFilteredViewType) {
BRCDatabaseFilteredViewTypeUnknown,
BRCDatabaseFilteredViewTypeEverything,
Expand Down Expand Up @@ -51,19 +45,15 @@ typedef NS_ENUM(NSUInteger, BRCDatabaseFilteredViewType) {

+ (YapDatabaseViewFiltering*) eventsSelectedDayOnlyFiltering;

+ (YapDatabaseViewSorting*)sortingForClass:(Class)viewClass extensionType:(BRCDatabaseViewExtensionType)extensionType fromLocation:(CLLocation*)fromLocation;

+ (YapDatabaseViewGrouping*)groupingForClass:(Class)viewClass extensionType:(BRCDatabaseViewExtensionType)extensionType;
+ (YapDatabaseViewSorting*)sortingForClass:(Class)viewClass;
+ (YapDatabaseViewGrouping*)groupingForClass:(Class)viewClass;

/**
* Creates a new databaseView extension that should be registered with the name
* extensionNameForClass:extensionType:
*/
+ (YapDatabaseView*) databaseViewForClass:(Class)viewClass
extensionType:(BRCDatabaseViewExtensionType)extensionType
fromLocation:(CLLocation*)fromLocation;
+ (NSString*) databaseViewNameForClass:(Class)viewClass
extensionType:(BRCDatabaseViewExtensionType)extensionType;
+ (YapDatabaseView*) databaseViewForClass:(Class)viewClass;
+ (NSString*) databaseViewNameForClass:(Class)viewClass;

/**
* Creates a new filteredView extension that should be registered with the name
Expand Down
66 changes: 11 additions & 55 deletions iBurn/BRCDatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,7 @@ + (instancetype)sharedInstance
return databaseManager;
}

+ (YapDatabaseViewBlockType)groupingBlockTypeForClass:(Class)viewClass extensionType:(BRCDatabaseViewExtensionType)extensionType {
YapDatabaseViewBlockType groupingBlockType;
if (viewClass == [BRCEventObject class]) {
groupingBlockType = YapDatabaseViewBlockTypeWithObject;
} else {
groupingBlockType = YapDatabaseViewBlockTypeWithKey;
}

return groupingBlockType;
}

+ (YapDatabaseViewGrouping*)groupingForClass:(Class)viewClass extensionType:(BRCDatabaseViewExtensionType)extensionType {
+ (YapDatabaseViewGrouping*)groupingForClass:(Class)viewClass {
YapDatabaseViewGrouping *grouping = nil;

if (viewClass == [BRCEventObject class]) {
Expand Down Expand Up @@ -173,9 +162,9 @@ + (NSComparisonResult) compareDistanceOfFirstObject:(BRCDataObject*)object1 seco
return [@(distance1) compare:@(distance2)];
}

+ (YapDatabaseViewSorting*)sortingForClass:(Class)viewClass extensionType:(BRCDatabaseViewExtensionType)extensionType fromLocation:(CLLocation*)fromLocation {
+ (YapDatabaseViewSorting*)sortingForClass:(Class)viewClass {
YapDatabaseViewSorting* sorting = nil;
if (extensionType == BRCDatabaseViewExtensionTypeTimeThenDistance) {
if (viewClass == [BRCEventObject class]) {
BOOL shouldSortEventsByStartTime = [[NSUserDefaults standardUserDefaults] shouldSortEventsByStartTime];
sorting = [YapDatabaseViewSorting withObjectBlock:^(NSString *group, NSString *collection1, NSString *key1, id obj1,
NSString *collection2, NSString *key2, id obj2){
Expand All @@ -196,25 +185,19 @@ + (YapDatabaseViewSorting*)sortingForClass:(Class)viewClass extensionType:(BRCDa
dateComparison = [event1.endDate compare:event2.endDate];
}
if (dateComparison == NSOrderedSame) {
NSComparisonResult distanceComparison = [self compareDistanceOfFirstObject:event1 secondObject:event2 fromLocation:fromLocation];
return distanceComparison;
} else {
return dateComparison;
return [event1.title compare:event2.title];
}
return dateComparison;
}
return NSOrderedSame;
}];
} else if (extensionType == BRCDatabaseViewExtensionTypeDistance) {
} else {
sorting = [YapDatabaseViewSorting withObjectBlock:^(NSString *group, NSString *collection1, NSString *key1, id obj1,
NSString *collection2, NSString *key2, id obj2){
if ([obj1 isKindOfClass:viewClass] && [obj2 isKindOfClass:viewClass]) {
BRCDataObject *data1 = (BRCDataObject *)obj1;
BRCDataObject *data2 = (BRCDataObject *)obj2;
NSComparisonResult result = [self compareDistanceOfFirstObject:data1 secondObject:data2 fromLocation:fromLocation];
if (result == NSOrderedSame) {
result = [data1.title compare:data2.title];
}
return result;
return [data1.title compare:data2.title];
}
return NSOrderedSame;
}];
Expand All @@ -227,11 +210,9 @@ + (YapDatabaseViewSorting*)sortingForClass:(Class)viewClass extensionType:(BRCDa
* the registered view if it exists. (Caller should register the view)
*/
+ (YapDatabaseView*) databaseViewForClass:(Class)viewClass
extensionType:(BRCDatabaseViewExtensionType)extensionType
fromLocation:(CLLocation*)fromLocation
{
YapDatabaseViewGrouping *grouping = [[self class] groupingForClass:viewClass extensionType:extensionType];
YapDatabaseViewSorting *sorting = [[self class] sortingForClass:viewClass extensionType:extensionType fromLocation:fromLocation];
YapDatabaseViewGrouping *grouping = [[self class] groupingForClass:viewClass];
YapDatabaseViewSorting *sorting = [[self class] sortingForClass:viewClass];
YapDatabaseViewOptions *options = [[YapDatabaseViewOptions alloc] init];
NSString *versionTag = versionTag = [[NSUUID UUID] UUIDString];
options.allowedCollections = [[YapWhitelistBlacklist alloc] initWithWhitelist:[NSSet setWithObject:[viewClass collection]]];
Expand Down Expand Up @@ -324,20 +305,6 @@ + (YapDatabaseFilteredView*) filteredViewForType:(BRCDatabaseFilteredViewType)fi
return filteredView;
}

+ (NSString*) stringForExtensionType:(BRCDatabaseViewExtensionType)extensionType {
switch (extensionType) {
case BRCDatabaseViewExtensionTypeDistance:
return @"Distance";
break;
case BRCDatabaseViewExtensionTypeTimeThenDistance:
return @"TimeThenDistance";
break;
default:
return nil;
break;
}
}

+ (NSString*) stringForFilteredExtensionType:(BRCDatabaseFilteredViewType)extensionType {
switch (extensionType) {
case BRCDatabaseFilteredViewTypeEventSelectedDayOnly:
Expand All @@ -363,26 +330,15 @@ + (NSString*) stringForFilteredExtensionType:(BRCDatabaseFilteredViewType)extens

+ (NSString*) filteredViewNameForType:(BRCDatabaseFilteredViewType)filterType
parentViewName:(NSString*)parentViewName {
NSParameterAssert(filterType != BRCDatabaseViewExtensionTypeUnknown);
if (filterType == BRCDatabaseViewExtensionTypeUnknown) {
return nil;
}
NSString *extensionString = [self stringForFilteredExtensionType:filterType];
NSParameterAssert(parentViewName != nil);
NSParameterAssert(extensionString != nil);
return [NSString stringWithFormat:@"%@-%@Filter", parentViewName, extensionString];
}

+ (NSString*) databaseViewNameForClass:(Class)viewClass
extensionType:(BRCDatabaseViewExtensionType)extensionType {
NSParameterAssert(extensionType != BRCDatabaseViewExtensionTypeUnknown);
if (extensionType == BRCDatabaseViewExtensionTypeUnknown) {
return nil;
}
+ (NSString*) databaseViewNameForClass:(Class)viewClass {
NSString *classString = NSStringFromClass(viewClass);
NSString *extensionString = [self stringForExtensionType:extensionType];
NSParameterAssert(extensionString != nil);
return [NSString stringWithFormat:@"%@%@View", classString, extensionString];
return [NSString stringWithFormat:@"%@View", classString];
}

+ (YapDatabaseViewFiltering*) allItemsFiltering {
Expand Down
2 changes: 1 addition & 1 deletion iBurn/BRCEmbargoPasscodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ - (void) refreshCountdownLabel:(id)sender {
[self.countdownTimer invalidate];
} else {
// Get conversion to months, days, hours, minutes
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSSecondCalendarUnit;
unsigned int unitFlags = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitDay | NSCalendarUnitSecond;

NSDateComponents *breakdownInfo = [[NSCalendar currentCalendar] components:unitFlags fromDate:now toDate:festivalStartDate options:0];

Expand Down
2 changes: 1 addition & 1 deletion iBurn/BRCEventObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ + (NSArray*) majorEvents {
}

+ (NSArray*) datesOfFestival {
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDate *festivalStartDate = [self festivalStartDate];
NSUInteger numberOfDays = [self majorEvents].count;

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

@interface BRCEventsTableViewController : BRCFilteredTableViewController

@property (nonatomic, strong, readonly) NSString *favoritesFilterForTimeAndDistanceViewName;

@property (atomic, strong, readonly) NSDate *selectedDay;

@end
Loading

0 comments on commit ef74690

Please sign in to comment.