Przeglądaj źródła

Albums opened from the gallery view.

Iñigo Valentin 9 lat temu
rodzic
commit
db4b573a6e

+ 1 - 1
app/Base.lproj/Main.storyboard

@@ -64,7 +64,7 @@
                                 </collectionViewFlowLayout>
                                 </collectionViewFlowLayout>
                                 <cells>
                                 <cells>
                                     <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell" id="a4j-DF-epb" customClass="MenuCollectionViewCell" customModule="app" customModuleProvider="target">
                                     <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell" id="a4j-DF-epb" customClass="MenuCollectionViewCell" customModule="app" customModuleProvider="target">
-                                        <rect key="frame" x="0.0" y="-3" width="100" height="50"/>
+                                        <rect key="frame" x="0.0" y="-2.5" width="100" height="50"/>
                                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                         <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                         <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                             <rect key="frame" x="0.0" y="0.0" width="100" height="50"/>
                                             <rect key="frame" x="0.0" y="0.0" width="100" height="50"/>

+ 46 - 5
app/GalleryView.swift

@@ -31,10 +31,19 @@ class GalleryView: UIView {
 	@IBOutlet weak var section: Section!
 	@IBOutlet weak var section: Section!
 	var delegate: AppDelegate? = nil
 	var delegate: AppDelegate? = nil
 	
 	
+	var idToOpen = -1
+	
+	// Row list
+	var rows: Array<RowGallery> = []
+	
 	override init(frame: CGRect){
 	override init(frame: CGRect){
 		super.init(frame: frame)
 		super.init(frame: frame)
 	}
 	}
 	
 	
+	func getRows() -> Array<RowGallery>{
+		return rows
+	}
+	
 	/**
 	/**
 	Run when the view is started.
 	Run when the view is started.
 	*/
 	*/
@@ -82,8 +91,15 @@ class GalleryView: UIView {
 				id = r.value(forKey: "id")! as! Int
 				id = r.value(forKey: "id")! as! Int
 				
 				
 				title = r.value(forKey: "title_\(lang)")! as! String
 				title = r.value(forKey: "title_\(lang)")! as! String
+				row.id = id
 				row.setTitle(text: title)
 				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
 				// Get 4 random images from the album
 				let imgFetchRequest: NSFetchRequest<Photo_album> = Photo_album.fetchRequest()
 				let imgFetchRequest: NSFetchRequest<Photo_album> = Photo_album.fetchRequest()
 				// TODO Order random
 				// TODO Order random
@@ -124,15 +140,19 @@ class GalleryView: UIView {
 					print("GALLERY:ERROR: Error getting image for post \(id): \(error)")
 					print("GALLERY:ERROR: Error getting image for post \(id): \(error)")
 				}
 				}
 				
 				
+				row.backgroundColor = UIColor.red
 				parent.addArrangedSubview(row)
 				parent.addArrangedSubview(row)
-				row.setNeedsLayout()
-				row.layoutIfNeeded()
+				//row.setNeedsLayout()
+				//row.layoutIfNeeded()
+				
+				// Add to the rows array
+				rows.append(row)
 				
 				
 				// TODO: Do this on the row didLoad method
 				// TODO: Do this on the row didLoad method
 				// Set tap recognizer
 				// Set tap recognizer
-				//let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openPost(_:)))
-				//row.isUserInteractionEnabled = true
-				//row.addGestureRecognizer(tapRecognizer)
+				let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openAlbum(_:)))
+				row.isUserInteractionEnabled = true
+				row.addGestureRecognizer(tapRecognizer)
 				
 				
 				
 				
 				
 				
@@ -167,6 +187,18 @@ class GalleryView: UIView {
 		
 		
 		
 		
 		print("GALLERY:DEBUG: Finished loading GalleryView")
 		print("GALLERY:DEBUG: Finished loading GalleryView")
+		//let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openAlbum(_:)))
+		//row.isUserInteractionEnabled = true
+		//container.addGestureRecognizer(tapRecognizer)
+		self.setUpRowsTapRecognizers()
+	}
+	
+	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
+		delegate.controller?.showAlbum(id: id)
+		print("GALLERY:DEBUG: Album should be shown.")
 	}
 	}
 	
 	
 	func getLanguage() -> String{
 	func getLanguage() -> String{
@@ -178,4 +210,13 @@ class GalleryView: UIView {
 			return "es"
 			return "es"
 		}
 		}
 	}
 	}
+	
+	func setUpRowsTapRecognizers(){
+		print("GALLERY:DEBUG: Setting up tap recognizers")
+		for row in rows{
+			let tapRecognizer = UITapGestureRecognizer(target: row, action: #selector(openAlbum(_:)))
+			row.isUserInteractionEnabled = true
+			container.addGestureRecognizer(tapRecognizer)
+		}
+	}
 }
 }

+ 19 - 5
app/RowGallery.swift

@@ -39,6 +39,8 @@ Extension of UIView to be formatted as sections.
 	//Array with the imageviews
 	//Array with the imageviews
 	var preview: [UIImageView] = []
 	var preview: [UIImageView] = []
 	
 	
+	var id = -1
+	
 	
 	
 	/**
 	/**
 	Default constructor
 	Default constructor
@@ -60,7 +62,8 @@ Extension of UIView to be formatted as sections.
 	*/
 	*/
 	init(s: String, i: Int) {
 	init(s: String, i: Int) {
 		print("ROWGALLERY:DEBUG: Init \(s), \(i)")
 		print("ROWGALLERY:DEBUG: Init \(s), \(i)")
-		super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
+		
+		super.init(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))
 		loadViewFromNib()
 		loadViewFromNib()
 		v = self
 		v = self
 		v.frame = bounds
 		v.frame = bounds
@@ -78,12 +81,17 @@ Extension of UIView to be formatted as sections.
 		preview = [photo0, photo1, photo2, photo3]
 		preview = [photo0, photo1, photo2, photo3]
 		
 		
 		// Set tap recognizer
 		// Set tap recognizer
-		/*print("ROW_BLOG:DEBUG: set tap recognizer")
-		let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (self.openPost (_:)))
+		print("ROW_GALLERY:DEBUG: Row \(id) frame h \(self.frame.height) w \(self.frame.width)")
+		print("ROW_GALLERY:DEBUG: set tap recognizer")
+		let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowGallery.openAlbum (_:)))
 		tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
 		tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
-		addGestureRecognizer(tapRecognizer)*/
+		self.addGestureRecognizer(tapRecognizer)
 	}
 	}
 	
 	
+	//override func viewDidLoad() {
+	//	print("ROW_GALLERY:DEBUG: LAYOUT Row \(id) frame h \(self.frame.height) w \(self.frame.width)")
+	//}
+	
 	/**
 	/**
 	Default constructor for the interface builder
 	Default constructor for the interface builder
 	*/
 	*/
@@ -91,7 +99,13 @@ Extension of UIView to be formatted as sections.
 		super.init(frame: frame)
 		super.init(frame: frame)
 	}
 	}
 	
 	
-	
+	func openAlbum(_ sender:UITapGestureRecognizer? = nil){
+		print("ROW_GALLERY:DEBUG: getting delegate and showing album.")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		//id = (sender?.view as! RowGallery).id
+		delegate.controller?.showAlbum(id: self.id)
+		print("ROW_GALLERY:DEBUG: Album should be shown.")
+	}
 	
 	
 	/**
 	/**
 	Changes the title of the album. Decodes HTML.
 	Changes the title of the album. Decodes HTML.

+ 7 - 6
app/RowHomeGallery.swift

@@ -59,13 +59,14 @@ Extension of UIView to be formatted as sections.
 		super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
 		super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
 		loadViewFromNib()
 		loadViewFromNib()
 		v = self
 		v = self
-		v.frame = bounds
-		v.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-		v.translatesAutoresizingMaskIntoConstraints = true
-		container.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-		container.translatesAutoresizingMaskIntoConstraints = true
+		//v.frame = bounds
+		//v.bounds = v.frame
+		//v.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+		//v.translatesAutoresizingMaskIntoConstraints = true
+		//container.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+		//container.translatesAutoresizingMaskIntoConstraints = true
 		
 		
-		container.frame = v.bounds
+		//container.frame = v.bounds
 		v.addSubview(container)
 		v.addSubview(container)
 		
 		
 		photos = [photo0, photo1, photo2, photo3]
 		photos = [photo0, photo1, photo2, photo3]

+ 13 - 7
app/ViewController.swift

@@ -32,12 +32,12 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	var sectionCollection: UICollectionView!
 	var sectionCollection: UICollectionView!
 
 
 	//Each of the sections of the app.
 	//Each of the sections of the app.
-	@IBOutlet weak var containerViewGallery: UIView!
-	@IBOutlet weak var containerViewBlog: BlogView!
-	@IBOutlet weak var containerViewActivities: UIView!
-	@IBOutlet weak var containerViewLablanca: UIView!
-	@IBOutlet weak var containerViewLocation: UIView!
-	@IBOutlet weak var containerViewHome: HomeView!
+	@IBOutlet var containerViewGallery: GalleryView!
+	@IBOutlet var containerViewBlog: BlogView!
+	@IBOutlet var containerViewActivities: UIView!
+	@IBOutlet var containerViewLablanca: UIView!
+	@IBOutlet var containerViewLocation: UIView!
+	@IBOutlet var containerViewHome: HomeView!
 	
 	
 	var passId: Int = -1
 	var passId: Int = -1
 	
 	
@@ -53,6 +53,12 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		performSegue(withIdentifier: "SeguePost", sender: nil)
 		performSegue(withIdentifier: "SeguePost", sender: nil)
 	}
 	}
 	
 	
+	func showAlbum(id: Int){
+		print("CONTROLLER:DEBUG: showAlbum \(id)")
+		self.passId = id
+		performSegue(withIdentifier: "SegueAlbum", sender: nil)
+	}
+	
 	override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
 	override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
 		print("CONTROLLER:DEBUG: preparing for segue \(segue.identifier) with id \(self.passId)")
 		print("CONTROLLER:DEBUG: preparing for segue \(segue.identifier) with id \(self.passId)")
 		if segue.identifier == "SeguePost"{
 		if segue.identifier == "SeguePost"{
@@ -73,7 +79,6 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		self.containerViewGallery.alpha = 0
 		self.containerViewGallery.alpha = 0
 		
 		
 		
 		
-		
 		//self.containerViewBlog.isHidden = true
 		//self.containerViewBlog.isHidden = true
 				
 				
 		print("CONTROLLER:LOG: viewDidLoad()")
 		print("CONTROLLER:LOG: viewDidLoad()")
@@ -82,6 +87,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		
 		
 		super.viewDidLoad()
 		super.viewDidLoad()
 		// Do any additional setup after loading the view, typically from a nib.
 		// Do any additional setup after loading the view, typically from a nib.
+
 		
 		
 		//self.containerViewBlog.setController(controller: self as ViewController)
 		//self.containerViewBlog.setController(controller: self as ViewController)