Skip to content

Commit

Permalink
Merge pull request wymsee#4 from yunhaia/master
Browse files Browse the repository at this point in the history
iOS image picker
  • Loading branch information
leonzhang1109 committed Apr 24, 2015
2 parents 7c7ee65 + 52b0b25 commit 4498c8a
Show file tree
Hide file tree
Showing 129 changed files with 3,798 additions and 2,167 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cordova-imagePicker
===================
hello,

Cordova Plugin For Multiple Image Selection - implemented for iOS and Android 4.0 and above.

Expand Down Expand Up @@ -109,4 +110,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
89 changes: 72 additions & 17 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,84 @@
<header-file src="src/ios/SOSPicker.h" />
<source-file src="src/ios/SOSPicker.m" />

<header-file src="src/ios/ELCImagePicker/ELCAlbumPickerController.h" />
<source-file src="src/ios/ELCImagePicker/ELCAlbumPickerController.m" />
<header-file src="src/ios/DNImagePicker/DNAlbumTableViewController.h" />
<source-file src="src/ios/DNImagePicker/DNAlbumTableViewController.m" />

<header-file src="src/ios/ELCImagePicker/ELCAsset.h" />
<source-file src="src/ios/ELCImagePicker/ELCAsset.m" />
<header-file src="src/ios/DNImagePicker/DNAsset.h" />
<source-file src="src/ios/DNImagePicker/DNAsset.m" />

<header-file src="src/ios/ELCImagePicker/ELCAssetCell.h" />
<source-file src="src/ios/ELCImagePicker/ELCAssetCell.m" />
<header-file src="src/ios/DNImagePicker/DNImageFlowViewController.h" />
<source-file src="src/ios/DNImagePicker/DNImageFlowViewController.m" />

<header-file src="src/ios/ELCImagePicker/ELCAssetPickerFilterDelegate.h" />
<header-file src="src/ios/ELCImagePicker/ELCAssetSelectionDelegate.h" />
<header-file src="src/ios/DNImagePicker/DNImagePickerController.h" />
<source-file src="src/ios/DNImagePicker/DNImagePickerController.m" />

<header-file src="src/ios/ELCImagePicker/ELCAssetTablePicker.h" />
<source-file src="src/ios/ELCImagePicker/ELCAssetTablePicker.m" />
<header-file src="src/ios/DNImagePicker/DNPhotoBrowser.h" />
<source-file src="src/ios/DNImagePicker/DNPhotoBrowser.m" />

<header-file src="src/ios/ELCImagePicker/ELCImagePickerController.h" />
<source-file src="src/ios/ELCImagePicker/ELCImagePickerController.m" />
<header-file src="src/ios/DNImagePicker/Extensions/NSURL+DNIMagePickerUrlEqual.h" />
<source-file src="src/ios/DNImagePicker/Extensions/NSURL+DNIMagePickerUrlEqual.m" />

<resource-file src="src/ios/ELCImagePicker/Resources/ELCAlbumPickerController.xib" />
<resource-file src="src/ios/ELCImagePicker/Resources/ELCAssetPicker.xib" />
<resource-file src="src/ios/ELCImagePicker/Resources/ELCAssetTablePicker.xib" />
<resource-file src="src/ios/ELCImagePicker/Resources/Overlay.png" />
<resource-file src="src/ios/ELCImagePicker/Resources/Overlay@2x.png" />
<header-file src="src/ios/DNImagePicker/Extensions/UIColor+Hex.h" />
<source-file src="src/ios/DNImagePicker/Extensions/UIColor+Hex.m" />

<header-file src="src/ios/DNImagePicker/Extensions/UIView+DNImagePicker.h" />
<source-file src="src/ios/DNImagePicker/Extensions/UIView+DNImagePicker.m" />

<header-file src="src/ios/DNImagePicker/Extensions/UIViewController+DNImagePicker.h" />
<source-file src="src/ios/DNImagePicker/Extensions/UIViewController+DNImagePicker.m" />

<header-file src="src/ios/DNImagePicker/Views/DNAssetsViewCell.h" />
<source-file src="src/ios/DNImagePicker/Views/DNAssetsViewCell.m" />

<header-file src="src/ios/DNImagePicker/Views/DNBadgeLabel.h" />
<source-file src="src/ios/DNImagePicker/Views/DNBadgeLabel.m" />

<header-file src="src/ios/DNImagePicker/Views/DNBrowserCell.h" />
<source-file src="src/ios/DNImagePicker/Views/DNBrowserCell.m" />

<header-file src="src/ios/DNImagePicker/Views/DNFullImageButton.h" />
<source-file src="src/ios/DNImagePicker/Views/DNFullImageButton.m" />

<header-file src="src/ios/DNImagePicker/Views/DNSendButton.h" />
<source-file src="src/ios/DNImagePicker/Views/DNSendButton.m" />

<header-file src="src/ios/DNImagePicker/Views/DNUnAuthorizedTipsView.h" />
<source-file src="src/ios/DNImagePicker/Views/DNUnAuthorizedTipsView.m" />

<header-file src="src/ios/DNImagePicker/Views/JKPromptView.h" />
<source-file src="src/ios/DNImagePicker/Views/JKPromptView.m" />

<header-file src="src/ios/DNImagePicker/Views/MWTapDetectingImageView.h" />
<source-file src="src/ios/DNImagePicker/Views/MWTapDetectingImageView.m" />

<resource-file src="src/ios/DNImagePicker/zh-Hans.lproj/DNImagePicker.strings" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/assets_placeholder_picture.imageset/assets_placeholder_picture@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/camera_edit_cut_cancel.imageset/camera_edit_cut_cancel@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/camera_edit_cut_cancel_highlighted.imageset/camera_edit_cut_cancel_highlighted@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photo_original.imageset/compose_photo_original@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photo_original.imageset/compose_photo_original@3x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photo_original_highlighted.imageset/compose_photo_original_highlighted@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photo_original_highlighted.imageset/compose_photo_original_highlighted@3x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photograph.imageset/compose_photograph@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photograph.imageset/compose_photograph@3x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photograph_background.imageset/compose_photograph_background@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photograph_highlighted.imageset/compose_photograph_highlighted@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/compose_photograph_highlighted.imageset/compose_photograph_highlighted@3x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/navigationbar_arrow_down.imageset/navigationbar_arrow_down@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/navigationbar_arrow_up.imageset/navigationbar_arrow_up@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/navigationbar_title_highlighted.imageset/navigationbar_title_highlighted@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/photo_check_default.imageset/photo_check_default@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/photo_check_default.imageset/photo_check_default@3x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/photo_check_selected.imageset/photo_check_selected@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/photo_check_selected.imageset/photo_check_selected@3x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/picker_alert_sigh.imageset/picker_alert_sigh@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/picker_button_orange.imageset/picker_button_orange@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/picker_button_orange_highlighted.imageset/picker_button_orange_highlighted@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/picker_image_placeholder.imageset/picker_image_placeholder@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/picker_photo_filter_checked.imageset/picker_photo_filter_checked@2x.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/back_normal.imageset/back_normal.png" />
<resource-file src="src/ios/DNImagePicker/ImagesPicker.xcassets/images/back_highlight.imageset/back_highlight.png" />
</platform>

<!-- android -->
Expand Down
13 changes: 13 additions & 0 deletions src/ios/DNImagePicker/DNAlbumTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DNAlbumTableViewController.h
// ImagePicker
//
// Created by DingXiao on 15/2/10.
// Copyright (c) 2015年 Dennis. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface DNAlbumTableViewController : UITableViewController

@end
226 changes: 226 additions & 0 deletions src/ios/DNImagePicker/DNAlbumTableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
//
// DNAlbumTableViewController.m
// ImagePicker
//
// Created by DingXiao on 15/2/10.
// Copyright (c) 2015年 Dennis. All rights reserved.
//
#import <AssetsLibrary/AssetsLibrary.h>

#import "DNAlbumTableViewController.h"
#import "DNImagePickerController.h"
#import "DNImageFlowViewController.h"
#import "UIViewController+DNImagePicker.h"
#import "DNUnAuthorizedTipsView.h"

static NSString* const dnalbumTableViewCellReuseIdentifier = @"dnalbumTableViewCellReuseIdentifier";

@interface DNAlbumTableViewController ()
@property (nonatomic, strong) ALAssetsLibrary *assetsLibrary;
@property (nonatomic, strong) NSArray *groupTypes;

#pragma mark - dataSources
@property (nonatomic, strong) NSArray *assetsGroups;
@end

@implementation DNAlbumTableViewController

#pragma mark - life cycle
- (void)viewDidLoad {
[super viewDidLoad];
[self setupView];
[self setupData];
[self loadData];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - mark setup Data and View
- (void)loadData
{
__typeof__(self) __weak weakSelf = self;
//__weak typeof(self) weakSelf = self;
[self loadAssetsGroupsWithTypes:self.groupTypes completion:^(NSArray *groupAssets)
{
weakSelf.assetsGroups = groupAssets;
[weakSelf.tableView reloadData];
}];
}

- (void)setupData
{
self.groupTypes = @[@(ALAssetsGroupAll)];
self.assetsGroups = [NSMutableArray new];
}

- (void)setupView
{
self.title = NSLocalizedStringFromTable(@"albumTitle", @"DNImagePicker", @"photos");
[self createBarButtonItemAtPosition:DNImagePickerNavigationBarPositionRight
text:NSLocalizedStringFromTable(@"cancel", @"DNImagePicker", @"取消")
action:@selector(cancelAction:)];

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:dnalbumTableViewCellReuseIdentifier];
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
self.tableView.tableFooterView = view;
}


#pragma mark - ui actions
- (void)cancelAction:(id)sender
{
DNImagePickerController *navController = [self dnImagePickerController];
if (navController && [navController.imagePickerDelegate respondsToSelector:@selector(dnImagePickerControllerDidCancel:)]) {
[navController.imagePickerDelegate dnImagePickerControllerDidCancel:navController];
}
}

#pragma mark - getter/setter
- (ALAssetsLibrary *)assetsLibrary
{
if (nil == _assetsLibrary) {
_assetsLibrary = [[ALAssetsLibrary alloc] init];
}
return _assetsLibrary;
}

- (DNImagePickerController *)dnImagePickerController
{

if (nil == self.navigationController
||
![self.navigationController isKindOfClass:[DNImagePickerController class]])
{
NSAssert(false, @"check the navigation controller");
}
return (DNImagePickerController *)self.navigationController;
}

- (NSAttributedString *)albumTitle:(ALAssetsGroup *)assetsGroup
{
NSString *albumTitle = [assetsGroup valueForProperty:ALAssetsGroupPropertyName];
NSString *numberString = [NSString stringWithFormat:@" (%@)",@(assetsGroup.numberOfAssets)];
NSString *cellTitleString = [NSString stringWithFormat:@"%@%@",albumTitle,numberString];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:cellTitleString];
[attributedString setAttributes: @{
NSFontAttributeName : [UIFont systemFontOfSize:16.0f],
NSForegroundColorAttributeName : [UIColor blackColor],
}
range:NSMakeRange(0, albumTitle.length)];
[attributedString setAttributes:@{
NSFontAttributeName : [UIFont systemFontOfSize:16.0f],
NSForegroundColorAttributeName : [UIColor grayColor],
} range:NSMakeRange(albumTitle.length, numberString.length)];
return attributedString;

}

- (void)showUnAuthorizedTipsView
{
DNUnAuthorizedTipsView *view = [[DNUnAuthorizedTipsView alloc] initWithFrame:self.tableView.frame];
self.tableView.backgroundView = view;
// [self.tableView addSubview:view];
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.assetsGroups.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dnalbumTableViewCellReuseIdentifier forIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
ALAssetsGroup *group = self.assetsGroups[indexPath.row];
cell.textLabel.attributedText = [self albumTitle:group];

//choose the latest pic as poster image
__weak UITableViewCell *blockCell = cell;
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:group.numberOfAssets-1] options:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
*stop = YES;
blockCell.imageView.image = [UIImage imageWithCGImage:result.thumbnail];
}
}];
return cell;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 64;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 64;
}

#pragma mark - tableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ALAssetsGroup *group = self.assetsGroups[indexPath.row];
NSURL *url = [group valueForProperty:ALAssetsGroupPropertyURL];
DNImageFlowViewController *imageFlowViewController = [[DNImageFlowViewController alloc] initWithGroupURL:url];
[self.navigationController pushViewController:imageFlowViewController animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}


#pragma mark - get assetGroups
- (void)loadAssetsGroupsWithTypes:(NSArray *)types completion:(void (^)(NSArray *assetsGroups))completion
{
__block NSMutableArray *assetsGroups = [NSMutableArray array];
__block NSUInteger numberOfFinishedTypes = 0;

for (NSNumber *type in types) {
__typeof__(self) __weak weakSelf = self;
//__weak typeof(self) weakSelf = self;
[self.assetsLibrary enumerateGroupsWithTypes:[type unsignedIntegerValue]
usingBlock:^(ALAssetsGroup *assetsGroup, BOOL *stop)
{
if (assetsGroup) {
// Filter the assets group
[assetsGroup setAssetsFilter:ALAssetsFilterFromDNImagePickerControllerFilterType([[weakSelf dnImagePickerController] filterType])];
// Add assets group
if (assetsGroup.numberOfAssets > 0) {
// Add assets group
[assetsGroups addObject:assetsGroup];
}
} else {
numberOfFinishedTypes++;
}

// Check if the loading finished
if (numberOfFinishedTypes == types.count) {
//sort
NSArray *sortedAssetsGroups = [assetsGroups sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {

ALAssetsGroup *a = obj1;
ALAssetsGroup *b = obj2;

NSNumber *apropertyType = [a valueForProperty:ALAssetsGroupPropertyType];
NSNumber *bpropertyType = [b valueForProperty:ALAssetsGroupPropertyType];
if ([apropertyType compare:bpropertyType] == NSOrderedAscending)
{
return NSOrderedDescending;
}
return NSOrderedSame;
}];

// Call completion block
if (completion) {
completion(sortedAssetsGroups);
}
}
} failureBlock:^(NSError *error) {
// NSLog(@"%@",error.description);
if ([ALAssetsLibrary authorizationStatus] != ALAuthorizationStatusAuthorized){
[self showUnAuthorizedTipsView];
}
}];
}
}
@end
20 changes: 20 additions & 0 deletions src/ios/DNImagePicker/DNAsset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// DNAsset.h
// ImagePicker
//
// Created by DingXiao on 15/3/6.
// Copyright (c) 2015年 Dennis. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <AssetsLibrary/AssetsLibrary.h>

@interface DNAsset : NSObject

@property (nonatomic, strong) ALAsset *ALAsset;
@property (nonatomic, strong) NSURL *url; //ALAsset url

- (BOOL)isEqualToAsset:(DNAsset *)asset;

@end
Loading

0 comments on commit 4498c8a

Please sign in to comment.