-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurantDataViewController.swift
More file actions
317 lines (232 loc) · 11.7 KB
/
RestaurantDataViewController.swift
File metadata and controls
317 lines (232 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
//
// RestaurantDataViewController.swift
// Dindr
//
// Created by lsecrease on 8/15/15.
// Copyright (c) 2015 ImagineME. All rights reserved.
//
import Foundation
import UIKit
import Photos
import Parse
class RestaurantDataViewController: UIViewController, UIAlertViewDelegate,
UINavigationControllerDelegate,
UIImagePickerControllerDelegate {
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var restImage1: UIImageView!
@IBOutlet weak var restImage2: UIImageView!
@IBOutlet weak var restImage3: UIImageView!
@IBOutlet weak var restImage4: UIImageView!
private var postImage: UIImage! //Used to Store restImage image
@IBOutlet weak var numberOfDishesSwiped: UILabel!
@IBOutlet weak var checkInTotal: UILabel!
@IBOutlet weak var usersInRadius: UILabel!
var swipeObj = PFObject(className: "")
var baseArray:[DishModel] = []
override func viewDidLoad() {
super.viewDidLoad()
print("\(PFUser.currentUser())")
// Do any additional setup after loading the view.
//numberOfDishesSwiped.text = "\(swipeObj[])"
let dish1 = DishModel(image: UIImage(named: "f1.jpg"))
let dish2 = DishModel(image: UIImage(named: "f2.jpg"))
let dish3 = DishModel(image: UIImage(named: "f4.jpg"))
baseArray = [dish1, dish2, dish3, DishModel(image: UIImage(named: "f1")), DishModel(image: UIImage(named: "f1")), DishModel(image: UIImage(named: "f1"))]
print("\(baseArray)")
}
//Check to see if User is logged in; If not, head over to login
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if (PFUser.currentUser() == nil) {
self.performSegueWithIdentifier("login", sender: self)
} else if (PFUser.currentUser() != nil) {
self.storyboard?.instantiateViewControllerWithIdentifier("RestaurantData")
}
}
//Using ImagePickerSheet Controller
@IBAction func pickFeaturedImageClicked(sender: UITapGestureRecognizer) {
let authorization = PHPhotoLibrary.authorizationStatus()
if authorization == .NotDetermined {
PHPhotoLibrary.requestAuthorization({ (status) -> Void in
//self.pickFeaturedImageClicked(sender)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.pickFeaturedImageClicked(sender)
})
})
return
}
//Do you want to Take a Photo or Video with the Camera
if authorization == .Authorized {
let controller = ImagePickerSheetController()
controller.addAction(ImageAction(title: NSLocalizedString("Take Photo or Video", comment: "ActionTitle"), secondaryTitle: NSLocalizedString("Use This One", comment: "ActionTitle"), handler: { (_) -> () in
self.presentCamera()
}, secondaryHandler: { (action, numberOfPhotos) -> () in
controller.getSelectedImagesWithCompletion({ (images) -> Void in
self.postImage = images[0]
self.restImage1.image = self.postImage
})
}))
controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .Cancel))
presentViewController(controller, animated: true, completion: nil)
}
}
func presentCamera() {
}
//Using ImagePickerSheet Controller for 2nd Image
@IBAction func pick2ndFeaturedImageClicked(sender: UITapGestureRecognizer) {
let authorization = PHPhotoLibrary.authorizationStatus()
if authorization == .NotDetermined {
PHPhotoLibrary.requestAuthorization({ (status) -> Void in
//self.pickFeaturedImageClicked(sender)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.pickFeaturedImageClicked(sender)
})
})
return
}
//Do you want to Take a Photo or Video with the Camera
if authorization == .Authorized {
let controller = ImagePickerSheetController()
controller.addAction(ImageAction(title: NSLocalizedString("Take Photo or Video", comment: "ActionTitle"), secondaryTitle: NSLocalizedString("Use This One", comment: "ActionTitle"), handler: { (_) -> () in
self.presentCamera()
}, secondaryHandler: { (action, numberOfPhotos) -> () in
controller.getSelectedImagesWithCompletion({ (images) -> Void in
self.postImage = images[0]
self.restImage2.image = self.postImage
})
}))
controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .Cancel))
presentViewController(controller, animated: true, completion: nil)
}
}
//Using ImagePickerSheet Controller
@IBAction func pick3rdFeaturedImageClicked(sender: UITapGestureRecognizer) {
let authorization = PHPhotoLibrary.authorizationStatus()
if authorization == .NotDetermined {
PHPhotoLibrary.requestAuthorization({ (status) -> Void in
//self.pickFeaturedImageClicked(sender)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.pickFeaturedImageClicked(sender)
})
})
return
}
//Do you want to Take a Photo or Video with the Camera
if authorization == .Authorized {
let controller = ImagePickerSheetController()
controller.addAction(ImageAction(title: NSLocalizedString("Take Photo or Video", comment: "ActionTitle"), secondaryTitle: NSLocalizedString("Use This One", comment: "ActionTitle"), handler: { (_) -> () in
self.presentCamera()
}, secondaryHandler: { (action, numberOfPhotos) -> () in
controller.getSelectedImagesWithCompletion({ (images) -> Void in
self.postImage = images[0]
self.restImage3.image = self.postImage
})
}))
controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .Cancel))
presentViewController(controller, animated: true, completion: nil)
}
}
//Using ImagePickerSheet Controller
@IBAction func pick4thFeaturedImageClicked(sender: UITapGestureRecognizer) {
let authorization = PHPhotoLibrary.authorizationStatus()
if authorization == .NotDetermined {
PHPhotoLibrary.requestAuthorization({ (status) -> Void in
//self.pickFeaturedImageClicked(sender)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.pickFeaturedImageClicked(sender)
})
})
return
}
//Do you want to Take a Photo or Video with the Camera
if authorization == .Authorized {
let controller = ImagePickerSheetController()
controller.addAction(ImageAction(title: NSLocalizedString("Take Photo or Video", comment: "ActionTitle"), secondaryTitle: NSLocalizedString("Use This One", comment: "ActionTitle"), handler: { (_) -> () in
self.presentCamera()
}, secondaryHandler: { (action, numberOfPhotos) -> () in
controller.getSelectedImagesWithCompletion({ (images) -> Void in
self.postImage = images[0]
self.restImage4.image = self.postImage
})
}))
controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .Cancel))
presentViewController(controller, animated: true, completion: nil)
}
}
// // BUTTON FOR IMAGES
// func buttImageTapped(sender: UIButton) {
// var button = sender as UIButton
// buttTAG = button.tag
// println("\(buttTAG)")
// println("\(button.tag)")
//
// var alert = UIAlertView(title: "Dindr",
// message: "Add a Photo",
// delegate: self,
// cancelButtonTitle: "Cancel",
// otherButtonTitles:
// "Take a picture",
// "Choose from Library"
// )
// alert.show()
//
// }
// // AlertView delegate
// func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
//
// // OPEN DEVICE'S CAMERA
// if alertView.buttonTitleAtIndex(buttonIndex) == "Take a picture" {
// if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
// var imagePicker = UIImagePickerController()
// imagePicker.delegate = self
// imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
// imagePicker.allowsEditing = false
// self.presentViewController(imagePicker, animated: true, completion: nil)
// }
//
//
// // PICK A PHOTO FROM LIBRARY
// } else if alertView.buttonTitleAtIndex(buttonIndex) == "Choose from Library" {
// if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) {
// var imagePicker = UIImagePickerController()
// imagePicker.delegate = self
// imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary;
// imagePicker.allowsEditing = false
// self.presentViewController(imagePicker, animated: true, completion: nil)
// }
// }
// }
// // ImagePicker Delegate
// func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
//
// // Assign Images
// switch buttTAG {
// case 0: restImage1.image = image; break
// case 1: restImage2.image = image; break
// case 2: restImage3.image = image; break
// case 3: restImage4.image = image; break
// default: break
// }
// dismissViewControllerAnimated(true, completion: nil)
// }
@IBAction func editSpecialButtonTapped(sender: AnyObject) {
print("Edit Specials Button Tapped!")
self.performSegueWithIdentifier("showPerks", sender: self)
}
}
extension RestaurantDataViewController : UICollectionViewDataSource
{
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return baseArray.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let thisDish = baseArray[indexPath.item]
let cellIdentifier = "Dish"
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! RestCollectionViewCell
cell.dishImage = thisDish.image
return cell
}
}