Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a fix of assetIsSelect method #50

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Pod::Spec.new do |s|

s.name = "UzysAssetsPickerController"
s.version = "0.9.7"
s.name = "UzysAssetsPickerController+CacheSelect"
s.version = "1.0.0"
s.summary = "Alternative UIImagePickerController , You can take a picture with camera and pick multiple photos and videos."
s.author = { "UzysJung" => "[email protected]" }

s.homepage = "https://github.com/uzysjung/UzysAssetsPickerController"
s.homepage = "https://github.com/lexiaoyao20/UzysAssetsPickerController"
s.license = { :type => "MIT", :file => "LICENSE" }

s.platform = :ios , '7.0'
s.source = { :git => "https://github.com/uzysjung/UzysAssetsPickerController.git", :tag => "0.9.7" }
s.source = { :git => "https://github.com/lexiaoyao20/UzysAssetsPickerController.git", :tag => "1.0.0" }
s.requires_arc = true
s.source_files = "UzysAssetsPickerController/Library"
s.resources = ["UzysAssetsPickerController/Library/*.{xib}","UzysAssetsPickerController/Library/UzysAssetPickerController.bundle"]
s.public_header_files = "UzysAssetsPickerController/Library/*.{h}"
s.ios.frameworks = "QuartzCore" , "MobileCoreServices" , "AVFoundation" , "AssetsLibrary" , "CoreGraphics"

end
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@property (nonatomic, assign) NSInteger maximumNumberOfSelectionPhoto;
//--------------------------------------------------------------------
@property (nonatomic, assign) NSInteger maximumNumberOfSelectionMedia;
@property (nonatomic, strong) NSMutableArray *selectedAssetArray;

@property (nonatomic, weak) id <UzysAssetsPickerControllerDelegate> delegate;
+ (ALAssetsLibrary *)defaultAssetsLibrary;
Expand Down
64 changes: 51 additions & 13 deletions UzysAssetsPickerController/Library/UzysAssetsPickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ @interface UzysAssetsPickerController ()<UICollectionViewDataSource,UICollection
@property (nonatomic, assign) NSInteger maximumNumberOfSelection;
@property (nonatomic, assign) NSInteger curAssetFilterType;

@property (nonatomic, strong) NSMutableArray *orderedSelectedItem;

- (IBAction)btnAction:(id)sender;
- (IBAction)indexDidChangeForSegmentedControl:(id)sender;

Expand Down Expand Up @@ -96,12 +94,21 @@ - (void)viewDidLoad
__weak typeof(self) weakSelf = self;
[self setupGroup:^{
[weakSelf.groupPicker.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];

for (ALAsset *asset in self.assets) {
if ([self assetIsSelect:asset]) {
NSUInteger index = [self.assets indexOfObject:asset];
NSIndexPath *path = [NSIndexPath indexPathForItem:index inSection:0];
[self.collectionView selectItemAtIndexPath:path animated:NO scrollPosition:UICollectionViewScrollPositionNone];
}
}
[self setAssetsCountWithSelectedIndexPaths:self.collectionView.indexPathsForSelectedItems];

} withSetupAsset:YES];
[self setupLayout];
[self setupCollectionView];
[self setupGroupPickerview];
[self initNoAssetView];

}

- (void)initVariable
Expand All @@ -110,7 +117,7 @@ - (void)initVariable
[self setAssetsFilter:[ALAssetsFilter allPhotos] type:1];
self.maximumNumberOfSelection = self.maximumNumberOfSelectionPhoto;
self.view.clipsToBounds = YES;
self.orderedSelectedItem = [[NSMutableArray alloc] init];
// self.orderedSelectedItem = [[NSMutableArray alloc] init];
}
- (void)initImagePicker
{
Expand Down Expand Up @@ -574,6 +581,25 @@ - (void)showNoAssetsIfNeeded
}
}

- (BOOL)assetIsSelect:(ALAsset *)asset {
BOOL isEqualAsset = NO;
int index = 0;
for ( int i = 0; i < self.selectedAssetArray.count; i++)
{
ALAsset *selectedAsset = self.selectedAssetArray[i];
if ([asset.defaultRepresentation.url isEqual:selectedAsset.defaultRepresentation.url]) {
index = i;
isEqualAsset = YES;
break;
}
}
if(isEqualAsset)
{
self.selectedAssetArray[index] = asset;
}

return isEqualAsset;
}

#pragma mark - Collection View Data Source

Expand All @@ -592,8 +618,9 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
static NSString *CellIdentifier = kAssetsViewCellIdentifier;

UzysAssetsViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

[cell applyData:[self.assets objectAtIndex:indexPath.row]];
ALAsset *asset = [self.assets objectAtIndex:indexPath.row];
[cell applyData:asset];
// [cell setSelected:[self assetIsSelect:asset]];

return cell;
}
Expand All @@ -612,15 +639,15 @@ - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtInde
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
ALAsset *selectedAsset = [self.assets objectAtIndex:indexPath.item];
[self.orderedSelectedItem addObject:selectedAsset];
[self.selectedAssetArray addObject:selectedAsset];
[self setAssetsCountWithSelectedIndexPaths:collectionView.indexPathsForSelectedItems];
}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
ALAsset *deselectedAsset = [self.assets objectAtIndex:indexPath.item];

[self.orderedSelectedItem removeObject:deselectedAsset];
[self.selectedAssetArray removeObject:deselectedAsset];
[self setAssetsCountWithSelectedIndexPaths:collectionView.indexPathsForSelectedItems];
}

Expand All @@ -629,7 +656,7 @@ - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndex

- (void)finishPickingAssets
{
NSMutableArray *assets = [[NSMutableArray alloc] initWithArray:self.orderedSelectedItem];
NSMutableArray *assets = [[NSMutableArray alloc] initWithArray:self.selectedAssetArray];
//
// for (NSIndexPath *index in self.orderedSelectedItem)
// {
Expand Down Expand Up @@ -745,12 +772,12 @@ - (void)assetsLibraryUpdated:(NSNotification *)notification
dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(self) strongSelf = weakSelf;
NSDictionary* info = [notification userInfo];
NSSet *updatedAssets = [info objectForKey:ALAssetLibraryUpdatedAssetsKey];
// NSSet *updatedAssets = [info objectForKey:ALAssetLibraryUpdatedAssetsKey];
NSSet *updatedAssetGroup = [info objectForKey:ALAssetLibraryUpdatedAssetGroupsKey];
NSSet *deletedAssetGroup = [info objectForKey:ALAssetLibraryDeletedAssetGroupsKey];
NSSet *insertedAssetGroup = [info objectForKey:ALAssetLibraryInsertedAssetGroupsKey];
DLog(@"-------------+");
DLog(@"updated assets:%@", updatedAssets);
// DLog(@"updated assets:%@", updatedAssets);
DLog(@"updated asset group:%@", updatedAssetGroup);
DLog(@"deleted asset group:%@", deletedAssetGroup);
DLog(@"inserted asset group:%@", insertedAssetGroup);
Expand Down Expand Up @@ -830,7 +857,7 @@ - (void)assetsLibraryUpdated:(NSNotification *)notification
}
if(isExist ==false)
{
[strongSelf.orderedSelectedItem removeObject:item];
[strongSelf.selectedAssetArray removeObject:item];
}
}

Expand Down Expand Up @@ -995,7 +1022,7 @@ - (void)saveAssetsAction:(NSURL *)assetURL error:(NSError *)error isPhoto:(BOOL)
{
NSIndexPath *newPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.collectionView selectItemAtIndexPath:newPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
[self.orderedSelectedItem addObject:asset];
[self.selectedAssetArray addObject:asset];
}
[self setAssetsCountWithSelectedIndexPaths:self.collectionView.indexPathsForSelectedItems];
}
Expand Down Expand Up @@ -1128,4 +1155,15 @@ - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
return UIInterfaceOrientationPortrait;
}

#pragma mark -
#pragma mark .....:::::: Getter and Setter ::::::.....

- (NSMutableArray *)selectedAssetArray {
if (!_selectedAssetArray) {
_selectedAssetArray = [[NSMutableArray alloc] init];
}

return _selectedAssetArray;
}

@end
17 changes: 17 additions & 0 deletions UzysAssetsPickerController/uzysViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ @interface uzysViewController () <UzysAssetsPickerControllerDelegate>
@property (nonatomic,strong) UIButton *btnImageAndVideo;
@property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UILabel *labelDescription;

@property (nonatomic,strong) NSMutableArray *selectedAssets;

@end

@implementation uzysViewController
Expand Down Expand Up @@ -91,6 +94,7 @@ - (void)btnAction:(id)sender
#endif

UzysAssetsPickerController *picker = [[UzysAssetsPickerController alloc] init];
picker.selectedAssetArray = self.selectedAssets;
picker.delegate = self;
if([sender isEqual:self.btnImage])
{
Expand Down Expand Up @@ -118,8 +122,13 @@ - (void)btnAction:(id)sender
}

#pragma mark - UzysAssetsPickerControllerDelegate methods
- (void)uzysAssetsPickerControllerDidCancel:(UzysAssetsPickerController *)picker {
[self.selectedAssets removeAllObjects];
}

- (void)uzysAssetsPickerController:(UzysAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
self.selectedAssets = [assets mutableCopy];
self.imageView.backgroundColor = [UIColor clearColor];
DLog(@"assets %@",assets);
if(assets.count ==1)
Expand Down Expand Up @@ -188,4 +197,12 @@ - (void)uzysAssetsPickerControllerDidExceedMaximumNumberOfSelection:(UzysAssetsP
otherButtonTitles:nil];
[alert show];
}

- (NSMutableArray *)selectedAssets {
if (!_selectedAssets) {
_selectedAssets = [[NSMutableArray alloc] init];
}
return _selectedAssets;
}

@end