Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiao committed Oct 11, 2018
1 parent 9657c75 commit de881b4
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface DNImageFetchOperation : NSOperation
NS_CLASS_AVAILABLE_IOS(8.0) @interface DNImageFetchOperation : NSOperation

@property (nonatomic, strong, nullable) PHAsset *asset;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ @interface DNImageFlowViewController () <UICollectionViewDataSource, UICollectio
@property (nonatomic, strong) NSMutableArray *assetsArray;
@property (nonatomic, strong) NSMutableArray *selectedAssetsArray;

@property (nonatomic, strong) UIActivityIndicatorView *indicatorView;

@property (nonatomic, assign) BOOL isFullImage;
@end

Expand Down Expand Up @@ -69,23 +71,31 @@ - (void)viewDidLoad {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.toolbarHidden = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadData) name:DNImagePickerPhotoLibraryChangedNotification object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
self.navigationController.toolbarHidden = YES;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)setupData {

if (!self.album && self.albumIdentifier.length > 0) {
self.album = [DNImagePickerHelper fetchCurrentAlbum];
__weak typeof(self) wSelf = self;
[DNImagePickerHelper requestCurrentAblumWithCompleteHandler:^(DNAlbum *album) {
__strong typeof(wSelf) sSelf = wSelf;
sSelf.album = album;
sSelf.title = sSelf.album.albumTitle;
[sSelf loadData];
}];
} else {
self.title = self.album.albumTitle;
[self loadData];
}
self.title = self.album.albumTitle;
[self loadData];
}


- (void)setupView
{
- (void)setupView {
self.view.backgroundColor = [UIColor whiteColor];
[self createBarButtonItemAtPosition:DNImagePickerNavigationBarPositionLeft
statusNormalImage:[UIImage imageNamed:@"back_normal"]
Expand Down Expand Up @@ -116,9 +126,13 @@ - (void)setupView
}

- (void)loadData {
if (!self.assetsArray.count) {
[self.indicatorView startAnimating];
}
__weak typeof(self) wSelf = self;
[DNImagePickerHelper fetchImageAssetsInAlbum:self.album completeHandler:^(NSArray<DNAsset *> * imageArray) {
__strong typeof(wSelf) sSelf = wSelf;
[sSelf.indicatorView stopAnimating];
[sSelf.assetsArray removeAllObjects];
[sSelf.assetsArray addObjectsFromArray:imageArray];
[self.imageFlowCollectionView reloadData];
Expand Down Expand Up @@ -156,8 +170,7 @@ - (void)addAssetsObject:(DNAsset *)asset {

#pragma mark - priviate methods
- (void)sendImages {
[[NSUserDefaults standardUserDefaults] setObject:self.album.identifier forKey:kDNImagePickerStoredGroupKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[DNImagePickerHelper saveAblumIdentifier:self.album.identifier];

DNImagePickerController *imagePicker = [self dnImagePickerController];
if (imagePicker && [imagePicker.imagePickerDelegate respondsToSelector:@selector(dnImagePickerController:sendImages:isFullImage:)]) {
Expand Down Expand Up @@ -217,7 +230,6 @@ - (UICollectionView *)imageFlowCollectionView {
_imageFlowCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) collectionViewLayout:layout];
_imageFlowCollectionView.backgroundColor = [UIColor clearColor];
[_imageFlowCollectionView registerClass:[DNAssetsViewCell class] forCellWithReuseIdentifier:dnAssetsViewCellReuseIdentifier];

_imageFlowCollectionView.alwaysBounceVertical = YES;
_imageFlowCollectionView.delegate = self;
_imageFlowCollectionView.dataSource = self;
Expand All @@ -236,6 +248,17 @@ - (DNSendButton *)sendButton {
return _sendButton;
}

- (UIActivityIndicatorView *)indicatorView {
if (!_indicatorView) {
_indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_indicatorView.hidesWhenStopped = YES;
_indicatorView.centerX = CGRectGetWidth(self.view.bounds)/2;
_indicatorView.centerY = CGRectGetHeight(self.view.bounds)/2;
[self.view addSubview:_indicatorView];
}
return _indicatorView;
}

#pragma mark - ui action
- (void)backButtonAction {
[self.navigationController popViewControllerAnimated:YES];
Expand Down Expand Up @@ -335,4 +358,5 @@ - (void)photoBrowser:(DNPhotoBrowser *)photoBrowser deseletedAsset:(DNAsset *)as
- (void)photoBrowser:(DNPhotoBrowser *)photoBrowser seleteFullImage:(BOOL)fullImage {
self.isFullImage = fullImage;
}

@end
5 changes: 4 additions & 1 deletion DNImagePicker/DNImagePicker/Classes/DNImagePickerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

@class DNAlbum;
@class DNAsset;

FOUNDATION_EXTERN NSString * const DNImagePickerPhotoLibraryChangedNotification;

NS_ASSUME_NONNULL_BEGIN

@interface DNImagePickerHelper : NSObject
Expand Down Expand Up @@ -38,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return the stored album
*/
+ (DNAlbum *)fetchCurrentAlbum;
+ (void)requestCurrentAblumWithCompleteHandler:(void(^)(DNAlbum * album))completeHandler;


/**
Expand Down
Loading

0 comments on commit de881b4

Please sign in to comment.