|
|
@@ -26,24 +26,24 @@ Class to handle the home view.
|
|
|
*/
|
|
|
class GalleryView: UIView {
|
|
|
|
|
|
+ // Outlets
|
|
|
@IBOutlet var container: UIView!
|
|
|
@IBOutlet weak var scrollView: UIScrollView!
|
|
|
@IBOutlet weak var section: Section!
|
|
|
- var delegate: AppDelegate? = nil
|
|
|
|
|
|
- var idToOpen = -1
|
|
|
+ // App delegate
|
|
|
+ var delegate: AppDelegate? = nil
|
|
|
|
|
|
- // Row list
|
|
|
+ // Section row list
|
|
|
var rows: Array<RowGallery> = []
|
|
|
|
|
|
+ /**
|
|
|
+ Run when the view is started.
|
|
|
+ */
|
|
|
override init(frame: CGRect){
|
|
|
super.init(frame: frame)
|
|
|
}
|
|
|
|
|
|
- func getRows() -> Array<RowGallery>{
|
|
|
- return rows
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
Run when the view is started.
|
|
|
*/
|
|
|
@@ -51,7 +51,7 @@ class GalleryView: UIView {
|
|
|
|
|
|
super.init(coder: aDecoder)
|
|
|
|
|
|
- print("GALLERY:DEBUG: init.")
|
|
|
+ NSLog(":GALLERY:LOG: Init gallery section.")
|
|
|
|
|
|
//Load the contents of the HomeView.xib file.
|
|
|
Bundle.main.loadNibNamed("GalleryView", owner: self, options: nil)
|
|
|
@@ -94,12 +94,6 @@ class GalleryView: UIView {
|
|
|
row.id = id
|
|
|
row.setTitle(text: title)
|
|
|
|
|
|
- // Set tap recognizer
|
|
|
- //let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openAlbum(_:)))
|
|
|
- //tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
|
|
|
- //row.isUserInteractionEnabled = true
|
|
|
- //row.addGestureRecognizer(tapRecognizer)
|
|
|
-
|
|
|
// Get 4 random images from the album
|
|
|
let imgFetchRequest: NSFetchRequest<Photo_album> = Photo_album.fetchRequest()
|
|
|
// TODO Order random
|
|
|
@@ -133,32 +127,23 @@ class GalleryView: UIView {
|
|
|
imageIdx = imageIdx + 1
|
|
|
}
|
|
|
catch {
|
|
|
- print("GALLERY:ERROR: Error getting image from photo entity: \(error)")
|
|
|
+ NSLog(":GALLERY:ERROR: Error getting image from photo entity: \(error)")
|
|
|
}
|
|
|
}
|
|
|
} catch {
|
|
|
- print("GALLERY:ERROR: Error getting image for post \(id): \(error)")
|
|
|
+ NSLog(":GALLERY:ERROR: Error getting image for album \(id): \(error)")
|
|
|
}
|
|
|
|
|
|
- row.backgroundColor = UIColor.red
|
|
|
parent.addArrangedSubview(row)
|
|
|
- //row.setNeedsLayout()
|
|
|
- //row.layoutIfNeeded()
|
|
|
|
|
|
// Add to the rows array
|
|
|
- rows.append(row)
|
|
|
-
|
|
|
- // TODO: Do this on the row didLoad method
|
|
|
- // Set tap recognizer
|
|
|
- let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openAlbum(_:)))
|
|
|
- row.isUserInteractionEnabled = true
|
|
|
- row.addGestureRecognizer(tapRecognizer)
|
|
|
+ self.rows.append(row)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
} catch {
|
|
|
- print("GALLERY:ERROR: Error with request: \(error)")
|
|
|
+ NSLog(":GALLERY:ERROR: Error with request: \(error)")
|
|
|
}
|
|
|
|
|
|
//Always at the end: update scrollview
|
|
|
@@ -170,35 +155,15 @@ class GalleryView: UIView {
|
|
|
// TODO: Calculate at the end
|
|
|
self.scrollView.contentSize.height = 2500//CGFloat(h);
|
|
|
|
|
|
- // The view controller
|
|
|
- //var viewController: ViewController = self.window?.rootViewController as! ViewController
|
|
|
-
|
|
|
-
|
|
|
- //let viewController = UIApplication.topViewController() as! ViewController
|
|
|
-
|
|
|
- //viewController.showPost(id: 4)
|
|
|
-
|
|
|
- //print("BLOG:DEBUG: Show post on load.")
|
|
|
- //self.delegate?.controller?.showPost(id: 4)
|
|
|
-
|
|
|
- //controller.showPost(id: 4)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- print("GALLERY:DEBUG: Finished loading GalleryView")
|
|
|
- //let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openAlbum(_:)))
|
|
|
- //row.isUserInteractionEnabled = true
|
|
|
- //container.addGestureRecognizer(tapRecognizer)
|
|
|
self.setUpRowsTapRecognizers()
|
|
|
+ NSLog(":GALLERY:LOG: Finished loading gallery section.")
|
|
|
}
|
|
|
|
|
|
func openAlbum(_ sender:UITapGestureRecognizer? = nil){
|
|
|
- print("GALLERY:DEBUG: getting delegate and showing album.")
|
|
|
- let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
let id = (sender?.view as! RowGallery).id
|
|
|
+ NSLog(":GALLERY:DEBUG: getting delegate and showing album \(id).")
|
|
|
+ let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
delegate.controller?.showAlbum(id: id)
|
|
|
- print("GALLERY:DEBUG: Album should be shown.")
|
|
|
}
|
|
|
|
|
|
func getLanguage() -> String{
|
|
|
@@ -212,8 +177,8 @@ class GalleryView: UIView {
|
|
|
}
|
|
|
|
|
|
func setUpRowsTapRecognizers(){
|
|
|
- print("GALLERY:DEBUG: Setting up tap recognizers")
|
|
|
- for row in rows{
|
|
|
+ NSLog(":GALLERY:DEBUG: Setting up tap recognizers")
|
|
|
+ for row in self.rows{
|
|
|
let tapRecognizer = UITapGestureRecognizer(target: row, action: #selector(openAlbum(_:)))
|
|
|
row.isUserInteractionEnabled = true
|
|
|
container.addGestureRecognizer(tapRecognizer)
|