Iñigo Valentin vor 9 Jahren
Ursprung
Commit
a45804d6aa
3 geänderte Dateien mit 37 neuen und 71 gelöschten Zeilen
  1. 17 52
      app/GalleryView.swift
  2. 12 15
      app/RowGallery.swift
  3. 8 4
      app/ViewController.swift

+ 17 - 52
app/GalleryView.swift

@@ -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)

+ 12 - 15
app/RowGallery.swift

@@ -26,9 +26,10 @@ Extension of UIView to be formatted as sections.
 */
 @IBDesignable class RowGallery: UIView {
 	
-	//This view
+	// This view
 	var v: UIView!
 	
+	// Outlets
 	@IBOutlet weak var container: UIView!
 	@IBOutlet weak var title: UILabel!
 	@IBOutlet weak var photo0: UIImageView!
@@ -36,9 +37,10 @@ Extension of UIView to be formatted as sections.
 	@IBOutlet weak var photo2: UIImageView!
 	@IBOutlet weak var photo3: UIImageView!
 	
-	//Array with the imageviews
+	// Array with the imageviews
 	var preview: [UIImageView] = []
 	
+	// Album ID
 	var id = -1
 	
 	
@@ -49,6 +51,9 @@ Extension of UIView to be formatted as sections.
 		super.init(coder: aDecoder)
 	}
 	
+	/**
+	Loads the view from the xib with the same name as the class.
+	*/
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
@@ -61,7 +66,7 @@ Extension of UIView to be formatted as sections.
 	:param: i Custom identifier
 	*/
 	init(s: String, i: Int) {
-		print("ROWGALLERY:DEBUG: Init \(s), \(i)")
+		NSLog(":ROWGALLERY:DEBUG: Init \(s), \(i)")
 		
 		super.init(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))
 		loadViewFromNib()
@@ -77,21 +82,14 @@ Extension of UIView to be formatted as sections.
 		v.addSubview(container)
 		
 		//Populate review array
-		//print("ROWGALLERY:DEBUG: Populating preview array")
 		preview = [photo0, photo1, photo2, photo3]
 		
 		// Set tap recognizer
-		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
 		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
 	*/
@@ -100,11 +98,9 @@ Extension of UIView to be formatted as sections.
 	}
 	
 	func openAlbum(_ sender:UITapGestureRecognizer? = nil){
-		print("ROW_GALLERY:DEBUG: getting delegate and showing album.")
+		NSLog(":ROW_GALLERY:DEBUG: Getting delegate and showing album \(self.id).")
 		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.")
 	}
 	
 	/**
@@ -122,11 +118,12 @@ Extension of UIView to be formatted as sections.
 	*/
 	func setImage(idx: Int, filename: String){
 		if (filename == ""){
-			print("ROWGALLERY:LOG: No image.")
+			NSLog(":ROWGALLERY:DEBUG: No image for album \(self.id) at index \(idx).")
+			preview[idx].isHidden = true
 			//TODO hide the imageview
 		}
 		else{
-			print("Set image \(filename)")
+			NSLog(":ROWGALLERY:DEBUG: Set image \(filename) for album \(self.id) at index \(idx).")
 			let path = "img/galeria/thumb/\(filename)"
 			preview[idx].setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 		}

+ 8 - 4
app/ViewController.swift

@@ -48,22 +48,26 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	}
 	
 	func showPost(id: Int){
-		print("CONTROLLER:DEBUG: showPost \(id)")
+		print("CONTROLLER:DEBUG: Showing Post \(id)")
 		self.passId = id
 		performSegue(withIdentifier: "SeguePost", sender: nil)
 	}
 	
 	func showAlbum(id: Int){
-		print("CONTROLLER:DEBUG: showAlbum \(id)")
+		NSLog(":CONTROLLER:DEBUG: Showing album \(id)")
 		self.passId = id
-		performSegue(withIdentifier: "SegueAlbum", sender: nil)
+		// TODO: Uncomment when ready
+		//performSegue(withIdentifier: "SegueAlbum", sender: nil)
 	}
 	
 	override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-		print("CONTROLLER:DEBUG: preparing for segue \(segue.identifier) with id \(self.passId)")
+		NSLog(":CONTROLLER:DEBUG: preparing for segue '\(segue.identifier)' with id \(self.passId)")
 		if segue.identifier == "SeguePost"{
 			(segue.destination as! PostViewController).id = passId
 		}
+		if segue.identifier == "SegueAlbum"{
+			(segue.destination as! PostViewController).id = passId
+		}
 	}
 	
 	/**