|
12 | 12 | @implementation AttachmentCollectionDataStore |
13 | 13 |
|
14 | 14 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { |
15 | | - NSMutableArray *allAttachments = [NSMutableArray arrayWithArray:[_observation.attachments allObjects]]; |
16 | | - [allAttachments addObjectsFromArray:_observation.transientAttachments]; |
| 15 | + NSMutableArray *allAttachments = [NSMutableArray arrayWithArray:[self.observation.attachments allObjects]]; |
| 16 | + [allAttachments addObjectsFromArray:self.observation.transientAttachments]; |
17 | 17 |
|
18 | | - AttachmentCell *cell = [_attachmentCollection dequeueReusableCellWithReuseIdentifier:@"AttachmentCell" forIndexPath:indexPath]; |
19 | | - Attachment *attachment = [allAttachments objectAtIndex:[indexPath indexAtPosition:[indexPath length]-1]]; |
20 | | - |
21 | | - FICImageCacheCompletionBlock completionBlock = ^(id <FICEntity> entity, NSString *formatName, UIImage *image) { |
22 | | - if (!image) return; |
23 | | - |
24 | | - cell.imageView.image = image; |
25 | | - [cell.imageView.layer addAnimation:[CATransition animation] forKey:kCATransition]; |
26 | | - cell.imageView.layer.cornerRadius = 5; |
27 | | - cell.imageView.clipsToBounds = YES; |
28 | | - }; |
29 | | - AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; |
30 | | - |
31 | | - BOOL imageExists = [delegate.imageCache retrieveImageForEntity:attachment withFormatName:AttachmentMediumSquare completionBlock:completionBlock]; |
32 | | - |
33 | | - if (imageExists == NO) { |
34 | | - cell.imageView.image = [UIImage imageNamed:@"download"]; |
35 | | - } |
| 18 | + AttachmentCell *cell = [self.attachmentCollection dequeueReusableCellWithReuseIdentifier:@"AttachmentCell" forIndexPath:indexPath]; |
| 19 | + Attachment *attachment = [allAttachments objectAtIndex:[indexPath row]]; |
| 20 | + [cell setImageForAttachament:attachment]; |
| 21 | + |
36 | 22 | return cell; |
37 | 23 | } |
38 | 24 |
|
39 | 25 | - (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { |
40 | | - return _observation.attachments.count + _observation.transientAttachments.count; |
| 26 | + return self.observation.attachments.count + self.observation.transientAttachments.count; |
41 | 27 | } |
42 | 28 |
|
43 | 29 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { |
44 | | - NSMutableArray *allAttachments = [NSMutableArray arrayWithArray:[_observation.attachments allObjects]]; |
45 | | - [allAttachments addObjectsFromArray:_observation.transientAttachments]; |
46 | | - |
47 | | - Attachment *attachment = [allAttachments objectAtIndex:[indexPath indexAtPosition:[indexPath length]-1]]; |
48 | | - NSLog(@"clicked attachment %@", attachment.url); |
| 30 | + NSMutableArray *allAttachments = [NSMutableArray arrayWithArray:[self.observation.attachments allObjects]]; |
| 31 | + [allAttachments addObjectsFromArray:self.observation.transientAttachments]; |
49 | 32 |
|
50 | 33 | if (self.attachmentSelectionDelegate) { |
| 34 | + Attachment *attachment = [allAttachments objectAtIndex:[indexPath row]]; |
51 | 35 | [self.attachmentSelectionDelegate selectedAttachment:attachment]; |
52 | 36 | } |
53 | 37 | } |
|
0 commit comments