Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

Reverse Grid View #44

Open
wants to merge 5 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
11 changes: 6 additions & 5 deletions GMImagePicker/GMAlbumsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ -(void)updateFetchResults
{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType in %@", self.picker.mediaTypes];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsWithOptions:options];
[allFetchResultArray addObject:assetsFetchResult];
[allFetchResultLabel addObject:NSLocalizedStringFromTableInBundle(@"picker.table.all-photos-label", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"All photos")];
Expand All @@ -159,6 +159,7 @@ -(void)updateFetchResults
{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType in %@", self.picker.mediaTypes];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHAssetCollection *assetCollection = (PHAssetCollection *)collection;

//Albums collections are allways PHAssetCollectionType=1 & PHAssetCollectionSubtype=2
Expand All @@ -184,7 +185,7 @@ -(void)updateFetchResults
{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType in %@", self.picker.mediaTypes];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];

PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];
if(assetsFetchResult.count>0)
Expand Down Expand Up @@ -270,7 +271,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

//Compute the thumbnail pixel size:
CGSize tableCellThumbnailSize1 = CGSizeMake(kAlbumThumbnailSize1.width*scale, kAlbumThumbnailSize1.height*scale);
PHAsset *asset = assetsFetchResult[0];
PHAsset *asset = assetsFetchResult[[assetsFetchResult count] - 1];
[cell setVideoLayout:(asset.mediaType==PHAssetMediaTypeVideo)];
[self.imageManager requestImageForAsset:asset
targetSize:tableCellThumbnailSize1
Expand All @@ -287,7 +288,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
if ([assetsFetchResult count] > 1) {
//Compute the thumbnail pixel size:
CGSize tableCellThumbnailSize2 = CGSizeMake(kAlbumThumbnailSize2.width*scale, kAlbumThumbnailSize2.height*scale);
PHAsset *asset = assetsFetchResult[1];
PHAsset *asset = assetsFetchResult[[assetsFetchResult count] - 2];
[self.imageManager requestImageForAsset:asset
targetSize:tableCellThumbnailSize2
contentMode:PHImageContentModeAspectFill
Expand All @@ -303,7 +304,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

if ([assetsFetchResult count] > 2) {
CGSize tableCellThumbnailSize3 = CGSizeMake(kAlbumThumbnailSize3.width*scale, kAlbumThumbnailSize3.height*scale);
PHAsset *asset = assetsFetchResult[2];
PHAsset *asset = assetsFetchResult[[assetsFetchResult count] - 3];
[self.imageManager requestImageForAsset:asset
targetSize:tableCellThumbnailSize3
contentMode:PHImageContentModeAspectFill
Expand Down
11 changes: 10 additions & 1 deletion GMImagePicker/GMGridViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ - (void)viewWillAppear:(BOOL)animated

[self setupButtons];
[self setupToolbar];

[self.collectionView setNeedsLayout];
[self.collectionView layoutIfNeeded];

[self.collectionView setContentOffset:CGPointMake(0, [[self.collectionView collectionViewLayout] collectionViewContentSize].height)];
}

- (void)viewDidAppear:(BOOL)animated
Expand Down Expand Up @@ -495,7 +500,11 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance
if ([changedIndexes count]) {
[collectionView reloadItemsAtIndexPaths:[changedIndexes aapl_indexPathsFromIndexesWithSection:0]];
}
} completion:NULL];
} completion:^(BOOL finished) {
NSIndexSet *insertedIndexes = [collectionChanges insertedIndexes];
NSIndexPath *lastPath = [insertedIndexes aapl_indexPathsFromIndexesWithSection:0].lastObject;
[self.collectionView scrollToItemAtIndexPath:lastPath atScrollPosition:UICollectionViewScrollPositionBottom animated:true];
}];
}

[self resetCachedAssets];
Expand Down