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

Display photos of a place on details page filtered by followed users #92

Merged
merged 1 commit into from Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 32 additions & 16 deletions Storyboards/DetailsView.storyboard
Expand Up @@ -19,7 +19,7 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uHd-rJ-al7">
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uHd-rJ-al7">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Yrq-zh-yGL">
Expand Down Expand Up @@ -177,16 +177,16 @@
</connections>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FFx-Wc-XL8">
<rect key="frame" x="0.0" y="483.5" width="375" height="136"/>
<rect key="frame" x="0.0" y="483.5" width="375" height="144"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PHOTOS" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="scf-dM-qfD">
<rect key="frame" x="24" y="10" width="58" height="19.5"/>
<rect key="frame" x="24" y="16" width="58" height="19.5"/>
<fontDescription key="fontDescription" name="AvenirNext-DemiBold" family="Avenir Next" pointSize="14"/>
<color key="textColor" name="VTR_BlackLabel"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qFs-2t-aki">
<rect key="frame" x="236" y="4" width="115" height="32"/>
<rect key="frame" x="236" y="10" width="115" height="32"/>
<fontDescription key="fontDescription" name="AvenirNext-DemiBold" family="Avenir Next" pointSize="14"/>
<state key="normal" title="+ Upload a photo">
<color key="titleColor" name="VTR_Main"/>
Expand All @@ -195,34 +195,48 @@
<action selector="didTapUploadPhoto:" destination="eMh-9V-03L" eventType="touchUpInside" id="iAT-iV-AXj"/>
</connections>
</button>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="gh3-Rp-eXx">
<rect key="frame" x="0.0" y="40" width="375" height="72"/>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceHorizontal="YES" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="gh3-Rp-eXx">
<rect key="frame" x="0.0" y="48" width="375" height="72"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="72" id="pVk-6e-zA7"/>
</constraints>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="lxl-tu-BSv">
<size key="itemSize" width="50" height="50"/>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="10" minimumInteritemSpacing="10" id="lxl-tu-BSv">
<size key="itemSize" width="76" height="72"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="92X-y3-Kfk">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="PhotoCell" id="92X-y3-Kfk" customClass="PhotoCell">
<rect key="frame" x="0.0" y="0.0" width="76" height="72"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<rect key="frame" x="0.0" y="0.0" width="76" height="72"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="sE7-1s-oW6">
<rect key="frame" x="0.0" y="0.0" width="76" height="72"/>
</imageView>
</subviews>
</view>
<constraints>
<constraint firstItem="sE7-1s-oW6" firstAttribute="top" secondItem="92X-y3-Kfk" secondAttribute="top" id="Jby-ze-BVo"/>
<constraint firstAttribute="bottom" secondItem="sE7-1s-oW6" secondAttribute="bottom" id="dYj-tN-TK1"/>
<constraint firstAttribute="trailing" secondItem="sE7-1s-oW6" secondAttribute="trailing" id="fFP-yR-ybF"/>
<constraint firstItem="sE7-1s-oW6" firstAttribute="leading" secondItem="92X-y3-Kfk" secondAttribute="leading" id="nY9-95-eWk"/>
</constraints>
<connections>
<outlet property="photoView" destination="sE7-1s-oW6" id="1g2-s5-y6t"/>
</connections>
</collectionViewCell>
</cells>
</collectionView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="136" id="E81-8C-rZX"/>
<constraint firstItem="scf-dM-qfD" firstAttribute="top" secondItem="FFx-Wc-XL8" secondAttribute="top" constant="10" id="F64-PW-9aU"/>
<constraint firstAttribute="height" constant="144" id="E81-8C-rZX"/>
<constraint firstItem="scf-dM-qfD" firstAttribute="top" secondItem="FFx-Wc-XL8" secondAttribute="top" constant="16" id="F64-PW-9aU"/>
<constraint firstItem="qFs-2t-aki" firstAttribute="centerY" secondItem="scf-dM-qfD" secondAttribute="centerY" id="MvP-Jb-jTe"/>
<constraint firstAttribute="trailing" secondItem="gh3-Rp-eXx" secondAttribute="trailing" id="Rr3-XT-Jla"/>
<constraint firstAttribute="trailing" secondItem="qFs-2t-aki" secondAttribute="trailing" constant="24" id="fdV-t9-VPF"/>
Expand All @@ -232,7 +246,7 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2GV-3P-HEH">
<rect key="frame" x="0.0" y="619.5" width="375" height="1"/>
<rect key="frame" x="0.0" y="627.5" width="375" height="1"/>
<color key="backgroundColor" name="VTR_Borders"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="NkX-pv-aw4"/>
Expand Down Expand Up @@ -270,10 +284,10 @@
</subviews>
<color key="backgroundColor" name="VTR_Background"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="Yrq-zh-yGL" secondAttribute="bottom" id="0ku-GA-8v3"/>
<constraint firstItem="Yrq-zh-yGL" firstAttribute="leading" secondItem="uHd-rJ-al7" secondAttribute="leading" id="8vC-zm-CJE"/>
<constraint firstItem="Yrq-zh-yGL" firstAttribute="top" secondItem="uHd-rJ-al7" secondAttribute="top" id="XJC-nu-7zd"/>
<constraint firstItem="Yrq-zh-yGL" firstAttribute="centerY" secondItem="uHd-rJ-al7" secondAttribute="centerY" id="pK1-Uc-wAI"/>
<constraint firstItem="Yrq-zh-yGL" firstAttribute="centerY" secondItem="uHd-rJ-al7" secondAttribute="centerY" id="g0L-3c-t7A"/>
<constraint firstAttribute="bottom" secondItem="Yrq-zh-yGL" secondAttribute="bottom" id="osF-Ke-SE0"/>
<constraint firstAttribute="trailing" secondItem="Yrq-zh-yGL" secondAttribute="trailing" id="wvE-Rh-dyx"/>
</constraints>
</scrollView>
Expand All @@ -293,6 +307,8 @@
<connections>
<outlet property="addressLabel" destination="s4F-9e-J1e" id="zMU-nM-ram"/>
<outlet property="checkInLabel" destination="qIj-d5-76r" id="GlL-9E-yFM"/>
<outlet property="collectionView" destination="gh3-Rp-eXx" id="TPL-VO-ajP"/>
<outlet property="contentView" destination="uHd-rJ-al7" id="DSd-Jf-QQb"/>
<outlet property="favoriteButton" destination="2sB-TQ-YH0" id="3bC-CG-fB8"/>
<outlet property="placeNameLabel" destination="z5R-BN-ECD" id="jwA-9x-1UX"/>
<outlet property="placeView" destination="EV2-CO-0DA" id="uhh-Uu-mGf"/>
Expand Down
48 changes: 43 additions & 5 deletions View Controllers/DetailsViewController.m
Expand Up @@ -15,8 +15,9 @@
#import "Relationships.h"
#import "AlertHelper.h"
#import "ImageHelper.h"
#import "PhotoCell.h"

@interface DetailsViewController () <GMSMapViewDelegate>
@interface DetailsViewController () <GMSMapViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
// Outlet Definitions //
@property (weak, nonatomic) IBOutlet UILabel *placeNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
Expand All @@ -26,21 +27,27 @@ @interface DetailsViewController () <GMSMapViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *wishlistButton;
@property (weak, nonatomic) IBOutlet UILabel *usersLabel;
@property (weak, nonatomic) IBOutlet UIView *userPicsView;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIScrollView *contentView;

// Instance Properties //
@property (strong, nonatomic) GMSPlace *place;
@property (strong, nonatomic) Place *parsePlace;
@property (strong, nonatomic) GMSMapView *mapView;
@property (strong, nonatomic) NSArray<PFUser *> *usersCheckedIn;
@property (strong, nonatomic) NSDictionary<PFFile *, NSString *> *photos;
@property (strong, nonatomic) NSArray <Photo *> *photos;

@end

@implementation DetailsViewController

- (void)viewDidLoad {
[super viewDidLoad];


//adjust height for tab bar
UIEdgeInsets adjustForTabbarInsets = UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.tabBarController.tabBar.frame), 0 );
self.contentView.contentInset = adjustForTabbarInsets;

// create Parse Place from GMSPlace
[Place checkGMSPlaceExists:self.place result:^(Place * _Nonnull newPlace) {
self.parsePlace = newPlace;
Expand Down Expand Up @@ -69,6 +76,21 @@ - (void)updateContent {
[self updateCheckInLabel];
[self initUsersCheckedIn];

//configure photos collection view layout
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.minimumInteritemSpacing = 0;
layout.itemSize = CGSizeMake(72,72);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.contentInset = UIEdgeInsetsMake(0, 20, 0, 20);
self.collectionView.collectionViewLayout = layout;

//configure photos view
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.photos = [NSArray new];
[self fetchPlacePhotos];

// update the map
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:self.place.coordinate.latitude longitude:self.place.coordinate.longitude zoom:15];
self.mapView = [GMSMapView mapWithFrame:self.placeView.bounds camera:camera];
Expand Down Expand Up @@ -236,8 +258,24 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void) displayPlacePhotos {

- (void) fetchPlacePhotos {
[Relationships retrieveFollowingWithId:[PFUser currentUser].relationships.objectId WithCompletion:^(NSArray * _Nullable following) {
[self.parsePlace retrievePhotosFromFollowing:following withCompletion:^(NSArray<Photo *> *photos) {
self.photos = photos;
[self.collectionView reloadData];
}];
}];
}

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
PhotoCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCell" forIndexPath:indexPath];
cell.photo = self.photos[indexPath.item];
[cell configureCell];
return cell;
}

- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.photos.count;
}

@end
5 changes: 5 additions & 0 deletions Views/PhotoCell.h
Expand Up @@ -7,7 +7,12 @@
//

#import <UIKit/UIKit.h>
#import "Photo.h"

@interface PhotoCell : UICollectionViewCell

@property (weak, nonatomic) IBOutlet UIImageView *photoView;
@property (strong, nonatomic) Photo *photo;
- (void) configureCell;

@end
7 changes: 7 additions & 0 deletions Views/PhotoCell.m
Expand Up @@ -7,7 +7,14 @@
//

#import "PhotoCell.h"
#import "ParseImageHelper.h"

@implementation PhotoCell

- (void) configureCell {
if (self.photo) {
[ParseImageHelper setImageFromPFFile:self.photo.file forImageView:self.photoView];
}
}

@end