Skip to content

Commit

Permalink
Merge branch 'master' into custom-fetch
Browse files Browse the repository at this point in the history
Conflicts:
	CTAssetsPickerController/CTAssetsGridViewController.h
  • Loading branch information
felix-dumit committed Apr 8, 2016
2 parents 4654667 + e05c0b4 commit b6d7a25
Show file tree
Hide file tree
Showing 39 changed files with 267 additions and 131 deletions.
24 changes: 12 additions & 12 deletions CTAssetsPickerController/CTAssetCollectionViewCell.h
Expand Up @@ -32,23 +32,23 @@

@interface CTAssetCollectionViewCell : UITableViewCell

@property (nonatomic, strong, readonly) CTAssetThumbnailStacks *thumbnailStacks;
@property (nonatomic, strong, readonly, nonnull) CTAssetThumbnailStacks *thumbnailStacks;

@property (nonatomic, weak) UIFont *titleFont UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIColor *titleTextColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIColor *selectedTitleTextColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, weak, nullable) UIFont *titleFont UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong, nullable) UIColor *titleTextColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong, nullable) UIColor *selectedTitleTextColor UI_APPEARANCE_SELECTOR;

@property (nonatomic, weak) UIFont *countFont UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIColor *countTextColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIColor *selectedCountTextColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, weak, nullable) UIFont *countFont UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong, nullable) UIColor *countTextColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong, nullable) UIColor *selectedCountTextColor UI_APPEARANCE_SELECTOR;

@property (nonatomic, strong) UIColor *accessoryColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIColor *selectedAccessoryColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong, nullable) UIColor *accessoryColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong, nullable) UIColor *selectedAccessoryColor UI_APPEARANCE_SELECTOR;

@property (nonatomic, weak) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, weak, nullable) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR;


- (instancetype)initWithThumbnailSize:(CGSize)size reuseIdentifier:(NSString *)reuseIdentifier;
- (void)bind:(PHAssetCollection *)collection count:(NSUInteger)count;
- (instancetype)initWithThumbnailSize:(CGSize)size reuseIdentifier:(nullable NSString *)reuseIdentifier;
- (void)bind:(nonnull PHAssetCollection *)collection count:(NSUInteger)count;

@end
6 changes: 3 additions & 3 deletions CTAssetsPickerController/CTAssetCollectionViewCell.m
Expand Up @@ -123,7 +123,7 @@ - (void)setupPlaceholderImage
for (CTAssetThumbnailView *thumbnailView in self.thumbnailStacks.thumbnailViews)
{
[thumbnailView bind:nil assetCollection:nil];
[thumbnailView setBackgroundImage:image];
thumbnailView.backgroundImage = image;
}
}

Expand Down Expand Up @@ -292,12 +292,12 @@ - (void)bind:(PHAssetCollection *)collection count:(NSUInteger)count

[self setupPlaceholderImage];

[self.titleLabel setText:collection.localizedTitle];
self.titleLabel.text = collection.localizedTitle;

if (count != NSNotFound)
{
NSNumberFormatter *nf = [NSNumberFormatter new];
[self.countLabel setText:[nf ctassetsPickerStringFromAssetsCount:count]];
self.countLabel.text = [nf ctassetsPickerStringFromAssetsCount:count];
}

[self setNeedsUpdateConstraints];
Expand Down
6 changes: 3 additions & 3 deletions CTAssetsPickerController/CTAssetCollectionViewController.m
Expand Up @@ -32,6 +32,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTAssetsGridViewController.h"
#import "PHAssetCollection+CTAssetsPickerController.h"
#import "PHAsset+CTAssetsPickerController.h"
#import "PHImageManager+CTAssetsPickerController.h"
#import "NSBundle+CTAssetsPickerController.h"


Expand Down Expand Up @@ -308,8 +309,7 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance
if (!updatedFetchResults)
updatedFetchResults = [self.fetchResults mutableCopy];

[updatedFetchResults replaceObjectAtIndex:[self.fetchResults indexOfObject:fetchResult]
withObject:[changeDetails fetchResultAfterChanges]];
updatedFetchResults[[self.fetchResults indexOfObject:fetchResult]] = changeDetails.fetchResultAfterChanges;
}
}

Expand Down Expand Up @@ -440,7 +440,7 @@ - (void)requestThumbnailsForCell:(CTAssetCollectionViewCell *)cell assetCollecti
if (index < assets.count)
{
PHAsset *asset = assets[index];
[self.imageManager requestImageForAsset:asset
[self.imageManager ctassetsPickerRequestImageForAsset:asset
targetSize:targetSize
contentMode:PHImageContentModeAspectFill
options:self.picker.thumbnailRequestOptions
Expand Down
12 changes: 7 additions & 5 deletions CTAssetsPickerController/CTAssetItemViewController.h
Expand Up @@ -27,17 +27,19 @@
#import <UIKit/UIKit.h>
#import <Photos/Photos.h>


NS_ASSUME_NONNULL_BEGIN

@interface CTAssetItemViewController : UIViewController

@property (nonatomic, assign) BOOL allowsSelection;
@property (nonatomic, strong, readonly) PHAsset *asset;
@property (nonatomic, strong, readonly) UIImage *image;
@property (nonatomic, strong, readonly, nullable) UIImage *image;

+ (CTAssetItemViewController *)assetItemViewControllerForAsset:(PHAsset *)asset;

- (void)playAsset:(id)sender;
- (void)pauseAsset:(id)sender;
- (void)playAsset:(nullable id)sender;
- (void)pauseAsset:(nullable id)sender;

@end

@end
NS_ASSUME_NONNULL_END
7 changes: 4 additions & 3 deletions CTAssetsPickerController/CTAssetItemViewController.m
Expand Up @@ -31,6 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTAssetScrollView.h"
#import "NSBundle+CTAssetsPickerController.h"
#import "PHAsset+CTAssetsPickerController.h"
#import "PHImageManager+CTAssetsPickerController.h"



Expand Down Expand Up @@ -185,7 +186,7 @@ - (void)requestAssetImage
PHImageRequestOptions *options = [self imageRequestOptions];

self.imageRequestID =
[self.imageManager requestImageForAsset:self.asset
[self.imageManager ctassetsPickerRequestImageForAsset:self.asset
targetSize:targetSize
contentMode:PHImageContentModeAspectFit
options:options
Expand All @@ -196,7 +197,7 @@ - (void)requestAssetImage

dispatch_async(dispatch_get_main_queue(), ^{

NSError *error = [info objectForKey:PHImageErrorKey];
NSError *error = info[PHImageErrorKey];

if (error)
[self showRequestImageError:error title:nil];
Expand Down Expand Up @@ -241,7 +242,7 @@ - (void)requestAssetPlayerItem:(id)sender
resultHandler:^(AVPlayerItem *playerItem, NSDictionary *info) {
dispatch_async(dispatch_get_main_queue(), ^{

NSError *error = [info objectForKey:PHImageErrorKey];
NSError *error = info[PHImageErrorKey];
NSString * title = CTAssetsPickerLocalizedString(@"Cannot Play Stream Video", nil);

if (error)
Expand Down
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetPlayButton.m
Expand Up @@ -173,7 +173,7 @@ - (void)updateConstraints

- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
super.highlighted = highlighted;
self.highlightedView.hidden = !highlighted;
}

Expand Down
12 changes: 7 additions & 5 deletions CTAssetsPickerController/CTAssetScrollView.h
Expand Up @@ -30,7 +30,7 @@
#import "CTAssetSelectionButton.h"



NS_ASSUME_NONNULL_BEGIN

extern NSString * const CTAssetScrollViewDidTapNotification;
extern NSString * const CTAssetScrollViewPlayerWillPlayNotification;
Expand All @@ -41,8 +41,8 @@ extern NSString * const CTAssetScrollViewPlayerWillPauseNotification;

@property (nonatomic, assign) BOOL allowsSelection;

@property (nonatomic, strong, readonly) UIImage *image;
@property (nonatomic, strong, readonly) AVPlayer *player;
@property (nonatomic, strong, readonly, nullable) UIImage *image;
@property (nonatomic, strong, readonly, nullable) AVPlayer *player;

@property (nonatomic, strong, readonly) UIImageView *imageView;
@property (nonatomic, strong, readonly) CTAssetPlayButton *playButton;
Expand All @@ -54,12 +54,14 @@ extern NSString * const CTAssetScrollViewPlayerWillPauseNotification;

- (void)setProgress:(CGFloat)progress;

- (void)bind:(PHAsset *)asset image:(UIImage *)image requestInfo:(NSDictionary *)info;
- (void)bind:(AVPlayerItem *)playerItem requestInfo:(NSDictionary *)info;
- (void)bind:(PHAsset *)asset image:(nullable UIImage *)image requestInfo:(nullable NSDictionary<NSString*, id> *)info;
- (void)bind:(AVPlayerItem *)playerItem requestInfo:(nullable NSDictionary *)info;

- (void)updateZoomScalesAndZoom:(BOOL)zoom;

- (void)playVideo;
- (void)pauseVideo;

@end

NS_ASSUME_NONNULL_END
18 changes: 9 additions & 9 deletions CTAssetsPickerController/CTAssetScrollView.m
Expand Up @@ -235,10 +235,10 @@ - (void)stopActivityAnimating
- (void)setProgress:(CGFloat)progress
{
#if !defined(CT_APP_EXTENSIONS)
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:(progress < 1)];
[UIApplication sharedApplication].networkActivityIndicatorVisible = progress < 1;
#endif
[self.progressView setProgress:progress animated:(progress < 1)];
[self.progressView setHidden:(progress == 1)];
self.progressView.hidden = progress == 1;
}

// To mimic image downloading progress
Expand Down Expand Up @@ -311,7 +311,7 @@ - (void)bind:(AVPlayerItem *)playerItem requestInfo:(NSDictionary *)info

CALayer *layer = self.imageView.layer;
[layer addSublayer:playerLayer];
[playerLayer setFrame:layer.bounds];
playerLayer.frame = layer.bounds;

self.player = player;

Expand Down Expand Up @@ -487,11 +487,11 @@ - (void)addGestureRecognizers
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapping:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapping:)];

[doubleTap setNumberOfTapsRequired:2.0];
doubleTap.numberOfTapsRequired = 2.0;
[singleTap requireGestureRecognizerToFail:doubleTap];

[singleTap setDelegate:self];
[doubleTap setDelegate:self];
singleTap.delegate = self;
doubleTap.delegate = self;

[self addGestureRecognizer:singleTap];
[self addGestureRecognizer:doubleTap];
Expand Down Expand Up @@ -523,7 +523,7 @@ - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *

- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
[self setScrollEnabled:(self.zoomScale != self.perspectiveZoomScale)];
self.scrollEnabled = self.zoomScale != self.perspectiveZoomScale;

if (self.shouldUpdateConstraints)
{
Expand Down Expand Up @@ -607,9 +607,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
{
if (object == self.player && [keyPath isEqual:@"currentItem.loadedTimeRanges"])
{
NSArray *timeRanges = [change objectForKey:NSKeyValueChangeNewKey];
NSArray *timeRanges = change[NSKeyValueChangeNewKey];

if (timeRanges && [timeRanges count])
if (timeRanges && timeRanges.count)
{
CMTimeRange timeRange = [timeRanges.firstObject CMTimeRangeValue];

Expand Down
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetSelectionButton.m
Expand Up @@ -112,7 +112,7 @@ - (void)updateConstraints

- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
super.selected = selected;
self.checkmark.hidden = !selected;

self.accessibilityLabel = (selected) ? CTAssetsPickerLocalizedString(@"Deselect", nil) : CTAssetsPickerLocalizedString(@"Select", nil);
Expand Down
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetSelectionLabel.h
Expand Up @@ -94,6 +94,6 @@
*
* @param textAttributes The text attributes used to display the label.
*/
- (void)setTextAttributes:(NSDictionary *)textAttributes UI_APPEARANCE_SELECTOR;
- (void)setTextAttributes:(NSDictionary<NSString*, id> *)textAttributes UI_APPEARANCE_SELECTOR;

@end
6 changes: 3 additions & 3 deletions CTAssetsPickerController/CTAssetSelectionLabel.m
Expand Up @@ -188,9 +188,9 @@ - (void)setMargin:(CGFloat)margin forVerticalEdge:(NSLayoutAttribute)edgeX horiz
*/
- (void)setTextAttributes:(NSDictionary *)textAttributes
{
self.font = (textAttributes) ? [textAttributes objectForKey:NSFontAttributeName] : CTAssetLabelFont;
self.textColor = (textAttributes) ? [textAttributes objectForKey:NSForegroundColorAttributeName] : CTAssetLabelTextColor;
self.backgroundColor = (textAttributes) ? [textAttributes objectForKey:NSBackgroundColorAttributeName] : CTAssetLabelBackgroundColor;
self.font = (textAttributes) ? textAttributes[NSFontAttributeName] : CTAssetLabelFont;
self.textColor = (textAttributes) ? textAttributes[NSForegroundColorAttributeName] : CTAssetLabelTextColor;
self.backgroundColor = (textAttributes) ? textAttributes[NSBackgroundColorAttributeName] : CTAssetLabelBackgroundColor;
}


Expand Down
4 changes: 2 additions & 2 deletions CTAssetsPickerController/CTAssetThumbnailOverlay.h
Expand Up @@ -30,7 +30,7 @@

@interface CTAssetThumbnailOverlay : UIView

- (void)bind:(PHAsset *)asset duration:(NSString *)duration;
- (void)bind:(PHAssetCollection *)assetCollection;
- (void)bind:(nullable PHAsset *)asset duration:(nullable NSString *)duration;
- (void)bind:(nullable PHAssetCollection *)assetCollection;

@end
4 changes: 2 additions & 2 deletions CTAssetsPickerController/CTAssetThumbnailStacks.h
Expand Up @@ -30,10 +30,10 @@
@interface CTAssetThumbnailStacks : UIView

@property (nonatomic, assign) CGSize thumbnailSize;
@property (nonatomic, copy, readonly) NSArray *thumbnailViews;
@property (nonatomic, copy, readonly) NSArray<CTAssetThumbnailView*> *thumbnailViews;
@property (nonatomic, assign, readonly) UIEdgeInsets edgeInsets;

- (CTAssetThumbnailView *)thumbnailAtIndex:(NSUInteger)index;
- (nonnull CTAssetThumbnailView *)thumbnailAtIndex:(NSUInteger)index;
- (void)setHighlighted:(BOOL)highlighted;

@end
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetThumbnailStacks.m
Expand Up @@ -129,7 +129,7 @@ - (void)updateConstraints

- (CTAssetThumbnailView *)thumbnailAtIndex:(NSUInteger)index
{
return [self.thumbnailViews objectAtIndex:index];
return self.thumbnailViews[index];
}

- (void)setHighlighted:(BOOL)highlighted
Expand Down
7 changes: 3 additions & 4 deletions CTAssetsPickerController/CTAssetThumbnailView.h
Expand Up @@ -27,13 +27,12 @@
#import <UIKit/UIKit.h>
#import <Photos/Photos.h>


@interface CTAssetThumbnailView : UIView

@property (nonatomic, assign) BOOL showsDuration;
@property (nonatomic, strong) UIImage *backgroundImage;
@property (nonatomic, strong, nullable) UIImage *backgroundImage;

- (void)bind:(UIImage *)image asset:(PHAsset *)asset;
- (void)bind:(UIImage *)image assetCollection:(PHAssetCollection *)assetCollection;
- (void)bind:(nullable UIImage *)image asset:(nullable PHAsset *)asset;
- (void)bind:(nullable UIImage *)image assetCollection:(nullable PHAssetCollection *)assetCollection;

@end
4 changes: 2 additions & 2 deletions CTAssetsPickerController/CTAssetThumbnailView.m
Expand Up @@ -95,9 +95,9 @@ - (void)setBackgroundImage:(UIImage *)backgroundImage

-(void)setBounds:(CGRect)bounds
{
[super setBounds:bounds];
super.bounds = bounds;

[self.overlay setFrame:bounds];
self.overlay.frame = bounds;
[self.overlay setNeedsDisplay];
}

Expand Down
6 changes: 3 additions & 3 deletions CTAssetsPickerController/CTAssetsGridSelectedView.h
Expand Up @@ -31,11 +31,11 @@
@property (nonatomic, assign) BOOL showsSelectionIndex;
@property (nonatomic, assign) NSUInteger selectionIndex;

@property (nonatomic, weak) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, weak, nullable) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, assign) CGFloat borderWidth UI_APPEARANCE_SELECTOR;

@property (nonatomic, weak) UIFont *font UI_APPEARANCE_SELECTOR DEPRECATED_MSG_ATTRIBUTE("Use setTextAttributes: of CTAssetSelectionLabel instead.");
@property (nonatomic, weak) UIColor *textColor UI_APPEARANCE_SELECTOR DEPRECATED_MSG_ATTRIBUTE("Use setTextAttributes: of CTAssetSelectionLabel instead.");
@property (nonatomic, weak, nullable) UIFont *font UI_APPEARANCE_SELECTOR DEPRECATED_MSG_ATTRIBUTE("Use setTextAttributes: of CTAssetSelectionLabel instead.");
@property (nonatomic, weak, nullable) UIColor *textColor UI_APPEARANCE_SELECTOR DEPRECATED_MSG_ATTRIBUTE("Use setTextAttributes: of CTAssetSelectionLabel instead.");


@end
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetsGridView.h
Expand Up @@ -28,6 +28,6 @@

@interface CTAssetsGridView : UIView

@property (nonatomic, weak) UIColor *gridBackgroundColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, weak, nullable) UIColor *gridBackgroundColor UI_APPEARANCE_SELECTOR;

@end
6 changes: 3 additions & 3 deletions CTAssetsPickerController/CTAssetsGridViewCell.h
Expand Up @@ -36,9 +36,9 @@
@property (nonatomic, assign) BOOL showsSelectionIndex;
@property (nonatomic, assign) NSUInteger selectionIndex;

@property (nonatomic, weak) UIColor *disabledColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, weak) UIColor *highlightedColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, weak, nullable) UIColor *disabledColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, weak, nullable) UIColor *highlightedColor UI_APPEARANCE_SELECTOR;

- (void)bind:(PHAsset *)asset;
- (void)bind:(nonnull PHAsset *)asset;

@end
4 changes: 2 additions & 2 deletions CTAssetsPickerController/CTAssetsGridViewCell.m
Expand Up @@ -137,13 +137,13 @@ - (void)setEnabled:(BOOL)enabled

- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
super.highlighted = highlighted;
self.highlightedView.hidden = !highlighted;
}

- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
super.selected = selected;
self.selectedView.hidden = !selected;
}

Expand Down

0 comments on commit b6d7a25

Please sign in to comment.