@@ -237,6 +237,9 @@ - (void)refreshData
237237 [self .collectionView setContentOffset: CGPointMake (0 , - [[self topLayoutGuide ] length ] - (self .refreshControl.frame.size.height)) animated: YES ];
238238 [self .refreshControl beginRefreshing ];
239239 }
240+ // NOTE: Sergio Estevao (2015-11-19)
241+ // Clean all assets and refresh collection view when the group was changed
242+ // This avoid to see data from previous group while the new one is loading.
240243 [self .collectionView reloadData ];
241244 }
242245 self.collectionView .allowsSelection = NO ;
@@ -657,13 +660,15 @@ - (void)showAlertAboutMediaCapturePermission
657660
658661- (void )processMediaCaptured : (NSDictionary *)info
659662{
663+ NSInteger mediaItemsBefore = [self .dataSource numberOfAssets ];
660664 self.ignoreMediaTimestamp = [NSDate timeIntervalSinceReferenceDate ];
661665 WPMediaAddedBlock completionBlock = ^(id <WPMediaAsset> media, NSError *error) {
662666 if (error || !media) {
663- NSLog (@" %@ " , error);
667+ NSLog (@" Adding media failed: %@ " , [ error localizedDescription ] );
664668 return ;
665669 }
666- [self addMedia: media];
670+ NSInteger mediaItemsAfter = [self .dataSource numberOfAssets ];
671+ [self addMedia: media animated: mediaItemsAfter != mediaItemsBefore];
667672 };
668673 if ([info[UIImagePickerControllerMediaType] isEqual: (NSString *)kUTTypeImage ]) {
669674 UIImage *image = (UIImage *)info[UIImagePickerControllerOriginalImage];
@@ -675,7 +680,7 @@ - (void)processMediaCaptured:(NSDictionary *)info
675680 }
676681}
677682
678- - (void )addMedia : (id <WPMediaAsset>)asset
683+ - (void )addMedia : (id <WPMediaAsset>)asset animated : ( BOOL ) animated
679684{
680685 BOOL willBeSelected = YES ;
681686 if ([self .picker.delegate respondsToSelector: @selector (mediaPickerController:shouldSelectAsset: )]) {
@@ -687,21 +692,21 @@ - (void)addMedia:(id<WPMediaAsset>)asset
687692 } else {
688693 [self .selectedAssets addObject: asset];
689694 }
690-
691695 NSUInteger insertPosition = [self showMostRecentFirst ] ? 1 : [self .dataSource numberOfAssets ]-1 ;
696+ if (animated){
697+ [self .collectionView insertItemsAtIndexPaths: @[[NSIndexPath indexPathForItem: insertPosition inSection: 0 ]]];
692698
693- [self .collectionView insertItemsAtIndexPaths: @[[NSIndexPath indexPathForItem: insertPosition inSection: 0 ]]];
694-
695- if ( ![self showMostRecentFirst ] ){
696- NSUInteger reloadPosition = [self .dataSource numberOfAssets ];
697- [self .collectionView reloadItemsAtIndexPaths: @[[NSIndexPath indexPathForItem: reloadPosition inSection: 0 ]]];
698- } else {
699- NSUInteger reloadPosition = MIN ([self .dataSource numberOfAssets ], 2 );
700- [self .collectionView reloadItemsAtIndexPaths: @[[NSIndexPath indexPathForItem: reloadPosition inSection: 0 ]]];
701- }
702- if (!self.showMostRecentFirst ) {
703- [self .collectionView scrollToItemAtIndexPath: [NSIndexPath indexPathForItem: [self .dataSource numberOfAssets ] inSection: 0 ]
704- atScrollPosition: UICollectionViewScrollPositionBottom animated: YES ];
699+ if ( ![self showMostRecentFirst ] ){
700+ NSUInteger reloadPosition = [self .dataSource numberOfAssets ];
701+ [self .collectionView reloadItemsAtIndexPaths: @[[NSIndexPath indexPathForItem: reloadPosition inSection: 0 ]]];
702+ } else {
703+ NSUInteger reloadPosition = MIN ([self .dataSource numberOfAssets ], 2 );
704+ [self .collectionView reloadItemsAtIndexPaths: @[[NSIndexPath indexPathForItem: reloadPosition inSection: 0 ]]];
705+ }
706+ if (!self.showMostRecentFirst ) {
707+ [self .collectionView scrollToItemAtIndexPath: [NSIndexPath indexPathForItem: [self .dataSource numberOfAssets ] inSection: 0 ]
708+ atScrollPosition: UICollectionViewScrollPositionBottom animated: YES ];
709+ }
705710 }
706711
707712 if (!willBeSelected) {
0 commit comments