Skip to content

Commit

Permalink
Follow WordPress coding standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioEstevao committed Apr 20, 2015
1 parent 4fe5d54 commit 3ed49f5
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 161 deletions.
20 changes: 10 additions & 10 deletions Pod/Classes/WPMediaCaptureCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ @interface WPMediaCaptureCollectionViewCell ()

@property (nonatomic, strong) AVCaptureSession *session;
@property (nonatomic, strong) dispatch_queue_t sessionQueue;
@property (nonatomic, strong) UIView * previewView;
@property (nonatomic, strong) UIView *previewView;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;

@end
Expand All @@ -16,7 +16,7 @@ @implementation WPMediaCaptureCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self){
if (self) {
[self commonInit];
}
return self;
Expand All @@ -25,16 +25,16 @@ - (instancetype)initWithFrame:(CGRect)frame
- (void)commonInit
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

self.backgroundColor = [UIColor blackColor];
_sessionQueue = dispatch_queue_create("org.wordpress.WPMediaCaptureCollectionViewCell", DISPATCH_QUEUE_SERIAL);
_previewView = [[UIView alloc] initWithFrame:self.bounds];
_previewView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.contentView addSubview:_previewView];
UIImage * cameraImage = [WPMediaPickerResources imageNamed:@"camera" withExtension:@"png"];
UIImageView * imageView = [[UIImageView alloc] initWithImage:cameraImage];

UIImage *cameraImage = [WPMediaPickerResources imageNamed:@"camera" withExtension:@"png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:cameraImage];
imageView.center = self.contentView.center;
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:imageView];
Expand All @@ -61,7 +61,7 @@ - (void)stopCaptureOnCompletion:(void (^)(void))block

- (void)startCapture
{
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]!=AVAuthorizationStatusAuthorized && [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]!=AVAuthorizationStatusNotDetermined){
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized && [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusNotDetermined) {
return;
}
dispatch_async(self.sessionQueue, ^{
Expand All @@ -87,12 +87,12 @@ - (void)startCapture
[viewLayer addSublayer:_captureVideoPreviewLayer];
});
}
});
});
}

- (void)deviceOrientationDidChange:(NSNotification *)notification
{
if(self.captureVideoPreviewLayer.connection.supportsVideoOrientation){
if (self.captureVideoPreviewLayer.connection.supportsVideoOrientation) {
self.captureVideoPreviewLayer.connection.videoOrientation = (AVCaptureVideoOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}
}
Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/WPMediaCollectionViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

@interface WPMediaCollectionViewCell : UICollectionViewCell

@property (nonatomic, strong) UIImage * image;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, assign) NSInteger position;

- (void)setCaption:(NSString *) caption;
- (void)setCaption:(NSString *)caption;

@end
42 changes: 19 additions & 23 deletions Pod/Classes/WPMediaCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

@interface WPMediaCollectionViewCell ()

@property (nonatomic, strong) UILabel * positionLabel;
@property (nonatomic, strong) UIView * selectionFrame;
@property (nonatomic, strong) UIImageView * imageView;
@property (nonatomic, strong) UILabel * captionLabel;
@property (nonatomic, strong) UILabel *positionLabel;
@property (nonatomic, strong) UIView *selectionFrame;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *captionLabel;

@end

@implementation WPMediaCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self){
if (self) {
[self commonInit];
}
return self;
Expand All @@ -24,7 +23,7 @@ - (instancetype)initWithFrame:(CGRect)frame
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self){
if (self) {
[self commonInit];
}
return self;
Expand All @@ -46,43 +45,41 @@ - (void)commonInit
_selectionFrame = [[UIView alloc] initWithFrame:self.backgroundView.frame];
_selectionFrame.layer.borderColor = [[self tintColor] CGColor];
_selectionFrame.layer.borderWidth = 3;

CGFloat counterTextSize = [UIFont smallSystemFontSize];
CGFloat labelSize = (counterTextSize*2)+2;
_positionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,labelSize,labelSize)];
CGFloat labelSize = (counterTextSize * 2) + 2;
_positionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, labelSize, labelSize)];
_positionLabel.backgroundColor = [self tintColor];
_positionLabel.textColor = [UIColor whiteColor];
_positionLabel.textAlignment = NSTextAlignmentCenter;
_positionLabel.font = [UIFont systemFontOfSize:counterTextSize];

[_selectionFrame addSubview:_positionLabel];

self.selectedBackgroundView = _selectionFrame;
_captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,self.contentView.frame.size.height-counterTextSize,self.contentView.frame.size.width,counterTextSize)];

_captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.contentView.frame.size.height - counterTextSize, self.contentView.frame.size.width, counterTextSize)];
_captionLabel.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.7];
_captionLabel.hidden = YES;
_captionLabel.textColor = [UIColor whiteColor];
_captionLabel.textAlignment = NSTextAlignmentRight;
_captionLabel.font = [UIFont systemFontOfSize:counterTextSize-2];
_captionLabel.font = [UIFont systemFontOfSize:counterTextSize - 2];
[self.contentView addSubview:_captionLabel];


}

- (void)setImage:(UIImage *) image
- (void)setImage:(UIImage *)image
{
self.imageView.image = image;
}

- (void)setPosition:(NSInteger) position
- (void)setPosition:(NSInteger)position
{
_position = position;
self.positionLabel.hidden = position == NSNotFound;
self.positionLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)(position)];
}

- (void)setCaption:(NSString *) caption
- (void)setCaption:(NSString *)caption
{
self.captionLabel.hidden = !(caption.length > 0);
self.captionLabel.text = caption;
Expand All @@ -91,21 +88,20 @@ - (void)setCaption:(NSString *) caption
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
if (self.isSelected){
if (self.isSelected) {
_captionLabel.backgroundColor = [self tintColor];
} else {
self.positionLabel.hidden = YES;
_captionLabel.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.7];
}

}

- (void)tintColorDidChange
{
[super tintColorDidChange];
_selectionFrame.layer.borderColor = [[self tintColor] CGColor];
_positionLabel.backgroundColor = [self tintColor];
if (self.isSelected){
if (self.isSelected) {
_captionLabel.backgroundColor = [self tintColor];
} else {
_captionLabel.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.7];
Expand Down
2 changes: 0 additions & 2 deletions Pod/Classes/WPMediaCollectionViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@
@property (nonatomic, assign) BOOL showMostRecentFirst;

@end


Loading

0 comments on commit 3ed49f5

Please sign in to comment.