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 f008dce + 5a5b080 commit 46af243
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pod 'FormatterKit/LocationFormatter', '~> 1.6'
pod 'FormatterKit/TimeIntervalFormatter', '~> 1.6'
pod 'HockeySDK', '~> 3.5'
pod 'PureLayout', '~> 1.0'
pod 'SWTableViewCell', '~> 0.3'
pod 'MCSwipeTableViewCell', '~> 2.1'
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ PODS:
- FMDB (= 2.3)
- GRMustache (= 6.8.3)
- SMCalloutView (= 2.0)
- MCSwipeTableViewCell (2.1.0)
- PureLayout (1.0.1)
- SMCalloutView (2.0)
- SWTableViewCell (0.3.0)
- YapDatabase (2.4.3):
- YapDatabase/standard
- YapDatabase/common (2.4.3):
Expand All @@ -41,8 +41,8 @@ DEPENDENCIES:
- HockeySDK (~> 3.5)
- Mantle (~> 1.5)
- Mapbox-iOS-SDK (~> 1.2)
- MCSwipeTableViewCell (~> 2.1)
- PureLayout (~> 1.0)
- SWTableViewCell (~> 0.3)
- YapDatabase (~> 2.4)

SPEC CHECKSUMS:
Expand All @@ -55,9 +55,9 @@ SPEC CHECKSUMS:
JRSwizzle: 30da7a2c539a4ebf954b16d15f6dd8221c9f6fa5
Mantle: c67a7e45e14196ed42b2a7cbb98ff6a9920e6b92
Mapbox-iOS-SDK: 961de5e8caba54a093d69b89696816b55f4c0254
MCSwipeTableViewCell: 713086e29ce3c2171a0102fc594bf583fa7dd323
PureLayout: 972964b21dbcbc5cc36785aed16aba03176f057d
SMCalloutView: c1906604d47c058400ade5c9d52ab98aa77b7e76
SWTableViewCell: 1725f7607ce4c154264c18aeb78e4636b11b0b29
YapDatabase: 2ec54726596299c88e09e899e8f17c15d7f6b18a

COCOAPODS: 0.33.1
11 changes: 3 additions & 8 deletions iBurn/BRCDataObjectTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@
//

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

@class BRCDataObject;

@interface SWTableViewCell()
@property (nonatomic, assign) SWCellState cellState; // The state of the cell within the scroll view, can be left, right or middle
@end

@interface BRCDataObjectTableViewCell : SWTableViewCell
@interface BRCDataObjectTableViewCell : MCSwipeTableViewCell

@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UILabel *subtitleLabel;

- (void) setDataObject:(BRCDataObject*)dataObject;
@property (nonatomic, strong) BRCDataObject *dataObject;

+ (NSString*) cellIdentifier;
+ (CGFloat) cellHeight;
Expand Down
1 change: 1 addition & 0 deletions iBurn/BRCDataObjectTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@implementation BRCDataObjectTableViewCell

- (void) setDataObject:(BRCDataObject*)dataObject {
_dataObject = dataObject;
CLLocationDistance distance = dataObject.distanceFromUser;
if (distance == CLLocationDistanceMax || distance == 0) {
self.subtitleLabel.text = @"";
Expand Down
105 changes: 44 additions & 61 deletions iBurn/BRCFilteredTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,9 @@
#import "BRCFilteredTableViewController_Private.h"
#import "UIColor+iBurn.h"
#import "PureLayout.h"
#import "MCSwipeTableViewCell.h"

@interface UIImage(Overlay)
- (UIImage *)imageWithColor:(UIColor *)color1;
@end

@implementation UIImage(Overlay)

// http://stackoverflow.com/a/19275079/805882
- (UIImage *)imageWithColor:(UIColor *)color1
{
UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, self.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextClipToMask(context, rect, self.CGImage);
[color1 setFill];
CGContextFillRect(context, rect);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end

@interface BRCFilteredTableViewController () <UIToolbarDelegate, SWTableViewCellDelegate>
@interface BRCFilteredTableViewController () <UIToolbarDelegate, MCSwipeTableViewCellDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UISegmentedControl *segmentedControl;
@property (nonatomic, strong) NSArray *searchResults;
Expand All @@ -56,7 +33,8 @@ @interface BRCFilteredTableViewController () <UIToolbarDelegate, SWTableViewCell
@property (nonatomic) BOOL updatingDistanceInformation;
@property (nonatomic) UIToolbar *sortControlToolbar;
@property (nonatomic, strong) UIImageView *navBarHairlineImageView;
@property (nonatomic, strong) UIButton *favoriteButton;
@property (nonatomic, strong) UIImageView *favoriteImageView;
@property (nonatomic, strong) UIImageView *notYetFavoriteImageView;
@end

@implementation BRCFilteredTableViewController
Expand Down Expand Up @@ -91,6 +69,9 @@ - (void)viewDidLoad
[self updateAllMappings];

self.navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

self.favoriteImageView = [self imageViewForFavoriteWithImageName:@"BRCDarkStar"];
self.notYetFavoriteImageView = [self imageViewForFavoriteWithImageName:@"BRCLightStar"];

NSArray *segmentedControlInfo = [self segmentedControlInfo];
[segmentedControlInfo enumerateObjectsUsingBlock:^(NSArray *infoArray, NSUInteger idx, BOOL *stop) {
Expand Down Expand Up @@ -361,51 +342,53 @@ - (BOOL)isSearchResultsControllerTableView:(UITableView *)tableView
return NO;
}

#pragma - mark UITableViewDataSource Methods

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BRCDataObjectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[[self cellClass] cellIdentifier] forIndexPath:indexPath];
BRCDataObject *dataObject = [self dataObjectForIndexPath:indexPath tableView:tableView];
[cell setDataObject:dataObject];

cell.leftUtilityButtons = [self leftButtonsForObject:dataObject];
cell.delegate = self;
return cell;
- (UIImageView *)imageViewForFavoriteWithImageName:(NSString *)imageName {
UIImage *image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeCenter;
UIColor *tintColor = [[[UIApplication sharedApplication] keyWindow] tintColor];
imageView.tintColor = tintColor;
return imageView;
}

- (NSArray *)leftButtonsForObject:(BRCDataObject*)object
{
UIColor *tintColor = [[[UIApplication sharedApplication] keyWindow] tintColor];
UIButton *favoriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
favoriteButton.backgroundColor = [UIColor whiteColor];
UIImage *lightStar = [[UIImage imageNamed:@"BRCLightStar"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImage *darkStar = [[UIImage imageNamed:@"BRCDarkStar"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[favoriteButton setImage:lightStar forState:UIControlStateNormal];
[favoriteButton setImage:darkStar forState:UIControlStateHighlighted];
[favoriteButton setImage:darkStar forState:UIControlStateSelected];

favoriteButton.tintColor = tintColor;
if (object.isFavorite) {
favoriteButton.selected = YES;
- (UIImageView *) imageViewForFavoriteStatus:(BOOL)isFavorite {
UIImageView *viewState = nil;
if (isFavorite) {
viewState = self.favoriteImageView;
} else {
favoriteButton.selected = NO;
viewState = self.notYetFavoriteImageView;
}
return @[favoriteButton];
return viewState;
}

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index {
if (index == 0) {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
__block BRCDataObject *dataObject = [self dataObjectForIndexPath:indexPath tableView:self.tableView];
#pragma - mark UITableViewDataSource Methods

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BRCDataObjectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[[self cellClass] cellIdentifier] forIndexPath:indexPath];
__block BRCDataObject *dataObject = [self dataObjectForIndexPath:indexPath tableView:tableView];
cell.dataObject = dataObject;
// Adding gestures per state basis.
UIImageView *viewState = [self imageViewForFavoriteStatus:dataObject.isFavorite];
UIColor *color = [UIColor brc_navBarColor];
[cell setSwipeGestureWithView:viewState color:color mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState1 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
[[BRCDatabaseManager sharedInstance].readWriteDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
dataObject = [[transaction objectForKey:dataObject.uniqueID inCollection:[[dataObject class] collection]] copy];
dataObject.isFavorite = !dataObject.isFavorite;
[transaction setObject:dataObject forKey:dataObject.uniqueID inCollection:[[dataObject class] collection]];
} completionBlock:^{
UIButton *favoriteButton = [cell.leftUtilityButtons objectAtIndex:index];
[favoriteButton setHighlighted:dataObject.isFavorite];
}];
} completionBlock:nil];
}];
cell.delegate = self;
return cell;
}

- (void)swipeTableViewCell:(BRCDataObjectTableViewCell *)cell didSwipeWithPercentage:(CGFloat)percentage {
// We want to switch states to give a hint of the future value
// is there a way to optimize this further?
if (percentage >= cell.firstTrigger) {
cell.view1 = [self imageViewForFavoriteStatus:!cell.dataObject.isFavorite];
} else if (percentage < cell.firstTrigger) {
cell.view1 = [self imageViewForFavoriteStatus:cell.dataObject.isFavorite];
}
}

Expand Down

0 comments on commit 46af243

Please sign in to comment.