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

iOS: Changed returning image order: images are now ordered in the sa… #91

Open
wants to merge 2 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
3 changes: 2 additions & 1 deletion src/ios/ELCImagePicker/ELCAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
@property (nonatomic, strong) ALAsset *asset;
@property (nonatomic, weak) id<ELCAssetDelegate> parent;
@property (nonatomic, assign) BOOL selected;
@property (nonatomic,assign) double index;

- (id)initWithAsset:(ALAsset *)asset;

- (NSComparisonResult)compareWithIndex:(ELCAsset *)_ass;
@end
12 changes: 12 additions & 0 deletions src/ios/ELCImagePicker/ELCAsset.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ - (void)setSelected:(BOOL)selected
}
}

- (NSComparisonResult)compareWithIndex:(ELCAsset *)_ass
{
if (self.index > _ass.index) {
return NSOrderedDescending;
}
else if (self.index < _ass.index)
{
return NSOrderedAscending;
}
return NSOrderedSame;
}


@end

1 change: 1 addition & 0 deletions src/ios/ELCImagePicker/ELCAssetCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ - (void)cellTapped:(UITapGestureRecognizer *)tapRecognizer
if (CGRectContainsPoint(frame, point)) {
ELCAsset *asset = [_rowAssets objectAtIndex:i];
asset.selected = !asset.selected;
asset.index = CACurrentMediaTime();
UIImageView *overlayView = [_overlayViewArray objectAtIndex:i];
overlayView.hidden = !asset.selected;
break;
Expand Down
59 changes: 37 additions & 22 deletions src/ios/ELCImagePicker/ELCAssetTablePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (id)init
if (self) {
//Sets a reasonable default bigger then 0 for columns
//So that we don't have a divide by 0 scenario
self.columns = 4;
self.columns = 10;
}
return self;
}
Expand All @@ -38,13 +38,13 @@ - (void)viewDidLoad

NSMutableArray *tempArray = [[NSMutableArray alloc] init];
self.elcAssets = tempArray;

if (self.immediateReturn) {

} else {
UIBarButtonItem *doneButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneAction:)];
[self.navigationItem setRightBarButtonItem:doneButtonItem];
[self.navigationItem setTitle:@"Loading..."];
[self.navigationItem setTitle:@"Lade..."];
}

[self performSelectorInBackground:@selector(preparePhotos) withObject:nil];
Expand All @@ -53,7 +53,8 @@ - (void)viewDidLoad
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.columns = self.view.bounds.size.width / 80;
//self.columns = self.view.bounds.size.width / 80;

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
Expand All @@ -64,7 +65,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfa
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
self.columns = self.view.bounds.size.width / 80;
//self.columns = self.view.bounds.size.width / 80;
[self.tableView reloadData];
}

Expand All @@ -73,14 +74,14 @@ - (void)preparePhotos
@autoreleasepool {

[self.assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {

if (result == nil) {
return;
}

ELCAsset *elcAsset = [[ELCAsset alloc] initWithAsset:result];
[elcAsset setParent:self];

BOOL isAssetFiltered = NO;
if (self.assetPickerFilterDelegate &&
[self.assetPickerFilterDelegate respondsToSelector:@selector(assetTablePicker:isAssetFilteredOut:)])
Expand All @@ -106,21 +107,35 @@ - (void)preparePhotos
atScrollPosition:UITableViewScrollPositionBottom
animated:NO];
}
[self.navigationItem setTitle:self.singleSelection ? @"Pick Photo" : @"Pick Photos"];

[self.navigationItem setTitle:self.singleSelection ? @"Selektiere ein Foto" : @"Selektiere Fotos"];
});
}
}


- (void)doneAction:(id)sender
{
{

NSMutableArray *temp = [[NSMutableArray alloc] init];
for (ELCAsset *elcAsset in self.elcAssets) {
if ([elcAsset selected]) {

[temp addObject:elcAsset];
}
}
[temp sortUsingSelector:@selector(compareWithIndex:)];

NSMutableArray *selectedAssetsImages = [[NSMutableArray alloc] init];
for (ELCAsset *elcAsset in self.elcAssets) {

for (ELCAsset *elcAsset in temp) {
if ([elcAsset selected]) {
[selectedAssetsImages addObject:[elcAsset asset]];
//[selectedAssetsImages addObject:elcAsset];
}
}


[self.parent selectedAssets:selectedAssetsImages];
}

Expand Down Expand Up @@ -166,7 +181,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.columns <= 0) { //Sometimes called before we know how many columns we have
self.columns = 4;
self.columns = 10;
}
NSInteger numRows = ceil([self.elcAssets count] / (float)self.columns);
return numRows;
Expand All @@ -181,17 +196,17 @@ - (NSArray *)assetsForIndexPath:(NSIndexPath *)path

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
{
static NSString *CellIdentifier = @"Cell";

ELCAssetCell *cell = (ELCAssetCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
if (cell == nil) {
cell = [[ELCAssetCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

[cell setAssets:[self assetsForIndexPath:indexPath]];

return cell;
}

Expand All @@ -203,13 +218,13 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
- (int)totalSelectedAssets
{
int count = 0;

for (ELCAsset *asset in self.elcAssets) {
if (asset.selected) {
count++;
count++;
}
}

return count;
}

Expand Down