Преглед изворни кода

Photo segue implemented on the main controller.

Iñigo Valentin пре 9 година
родитељ
комит
f16b48e4ff
5 измењених фајлова са 65 додато и 11 уклоњено
  1. 3 3
      app/ActivitiesView.xib
  2. 7 1
      app/AlbumViewController.swift
  3. 1 0
      app/PhotoViewController.swift
  4. 34 6
      app/RowAlbum.swift
  5. 20 1
      app/ViewController.swift

+ 3 - 3
app/ActivitiesView.xib

@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
     <device id="retina4_7" orientation="portrait">
     <device id="retina4_7" orientation="portrait">
         <adaptation id="fullscreen"/>
         <adaptation id="fullscreen"/>
     </device>
     </device>
     <dependencies>
     <dependencies>
         <deployment identifier="iOS"/>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     </dependencies>
     <objects>
     <objects>
@@ -24,7 +24,7 @@
                 <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xyM-cc-W1r">
                 <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xyM-cc-W1r">
                     <rect key="frame" x="0.0" y="0.0" width="375" height="666"/>
                     <rect key="frame" x="0.0" y="0.0" width="375" height="666"/>
                     <subviews>
                     <subviews>
-                        <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="gvi-ij-s5Q">
+                        <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="gvi-ij-s5Q">
                             <rect key="frame" x="0.0" y="0.0" width="375" height="306"/>
                             <rect key="frame" x="0.0" y="0.0" width="375" height="306"/>
                             <subviews>
                             <subviews>
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jdf-74-tJS" customClass="Section" customModule="app">
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jdf-74-tJS" customClass="Section" customModule="app">

+ 7 - 1
app/AlbumViewController.swift

@@ -108,8 +108,11 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 				
 				
 				var r = searchResults[i]
 				var r = searchResults[i]
 				var photoId = r.value(forKey: "photo")! as! Int
 				var photoId = r.value(forKey: "photo")! as! Int
+				var leftId: Int = -1
+				var rightId: Int = -1
 				
 				
 				row = RowAlbum.init(s: "rowAlbum\(i)", i: i)
 				row = RowAlbum.init(s: "rowAlbum\(i)", i: i)
+				row.id = id
 				
 				
 				// Get photo info from Photo entity
 				// Get photo info from Photo entity
 				let imgFetchRequest: NSFetchRequest<Photo> = Photo.fetchRequest()
 				let imgFetchRequest: NSFetchRequest<Photo> = Photo.fetchRequest()
@@ -122,17 +125,20 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 					var imgSearchResults = try context.fetch(imgFetchRequest)
 					var imgSearchResults = try context.fetch(imgFetchRequest)
 					var imgR = imgSearchResults[0]
 					var imgR = imgSearchResults[0]
 					image = imgR.value(forKey: "file")! as! String
 					image = imgR.value(forKey: "file")! as! String
+					leftId = imgR.value(forKey: "id")! as! Int
 					NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) left: \(image)")
 					NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) left: \(image)")
 					row.setImage(idx: 0, filename: image)
 					row.setImage(idx: 0, filename: image)
 					if i + 1 < searchResults.count {
 					if i + 1 < searchResults.count {
 						r = searchResults[i + 1]
 						r = searchResults[i + 1]
 						photoId = r.value(forKey: "photo")! as! Int
 						photoId = r.value(forKey: "photo")! as! Int
+						
 						imgFetchRequest.predicate = NSPredicate(format: "id == %i", photoId)
 						imgFetchRequest.predicate = NSPredicate(format: "id == %i", photoId)
 						imgSearchResults = try context.fetch(imgFetchRequest)
 						imgSearchResults = try context.fetch(imgFetchRequest)
 						
 						
 						
 						
 						imgR = imgSearchResults[0]
 						imgR = imgSearchResults[0]
 						image = imgR.value(forKey: "file")! as! String
 						image = imgR.value(forKey: "file")! as! String
+						rightId = imgR.value(forKey: "id")! as! Int
 						NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) right: \(image)")
 						NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) right: \(image)")
 						row.setImage(idx: 1, filename: image)
 						row.setImage(idx: 1, filename: image)
 					}
 					}
@@ -145,7 +151,7 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 					NSLog(":GALLERYCONTROLLER:ERROR: Error getting image for post \(id): \(error)")
 					NSLog(":GALLERYCONTROLLER:ERROR: Error getting image for post \(id): \(error)")
 				}
 				}
 				
 				
-				NSLog(":GALLERYCONTROLLER:DEBUG: Adding row: height: \(row.frame.height)")
+				row.setIds(left: leftId, right: rightId)
 				albumContainer.addArrangedSubview(row)
 				albumContainer.addArrangedSubview(row)
 				
 				
 				rowcount = rowcount + 1
 				rowcount = rowcount + 1

+ 1 - 0
app/PhotoViewController.swift

@@ -61,6 +61,7 @@ class PhotoViewController: UIViewController, UIGestureRecognizerDelegate {
 	Run when the app loads.
 	Run when the app loads.
 	*/
 	*/
 	override func viewDidLoad() {
 	override func viewDidLoad() {
+		NSLog(":PHOTOCONTROLLER:DEBUG: viewDidLoad")
 		
 		
 		super.viewDidLoad()
 		super.viewDidLoad()
 		self.loadPhoto(id: photoId)
 		self.loadPhoto(id: photoId)

+ 34 - 6
app/RowAlbum.swift

@@ -34,6 +34,9 @@ Extension of UIView to be formatted as sections.
 	// Album ID
 	// Album ID
 	var id = -1
 	var id = -1
 	
 	
+	// Photo ids
+	var photoIds: [Int] = [-1, -1]
+	
 	// Array with the imageviews
 	// Array with the imageviews
 	var preview: [UIImageView] = []
 	var preview: [UIImageView] = []
 
 
@@ -95,29 +98,54 @@ Extension of UIView to be formatted as sections.
 		super.init(frame: frame)
 		super.init(frame: frame)
 	}
 	}
 	
 	
-	func openPhoto(_ sender:UITapGestureRecognizer? = nil){
-		NSLog(":ROWALBUM:DEBUG: Getting delegate and showing photo.")
-		// TODO
-		//let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
-		//delegate.controller?.showAlbum(id: self.id)
+	func openLeftPhoto(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ROWALBUM:DEBUG: Getting delegate and showing left photo.")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPhoto(album: self.id, photo: self.photoIds[0])
+	}
+	
+	func openRightPhoto(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ROWALBUM:DEBUG: Getting delegate and showing right photo.")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPhoto(album: self.id, photo: self.photoIds[1])
 	}
 	}
 	
 	
 	
 	
 	/**
 	/**
 	Changes the preview image of the photos.
 	Changes the preview image of the photos.
 	If null or empty, the igage is hidden.
 	If null or empty, the igage is hidden.
+	It also sets the tap listener to show the photo.
 	:param: idx Id of the image in the row. 0 for left, 1 for right.
 	:param: idx Id of the image in the row. 0 for left, 1 for right.
 	:param: filename Filename of the image.
 	:param: filename Filename of the image.
 	*/
 	*/
 	func setImage(idx: Int, filename: String){
 	func setImage(idx: Int, filename: String){
 		if (filename == ""){
 		if (filename == ""){
 			self.preview[idx].isHidden = true
 			self.preview[idx].isHidden = true
-			//TODO hide the imageview
 		}
 		}
 		else{
 		else{
 			let path = "img/galeria/thumb/\(filename)"
 			let path = "img/galeria/thumb/\(filename)"
 			self.preview[idx].setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 			self.preview[idx].setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
+			// Set tap listener
+			if idx == 0 {
+				let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowAlbum.openLeftPhoto(_:)))
+				tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
+				self.preview[idx].isUserInteractionEnabled = true
+				NSLog(":ROWALBUM:DEBUG: Setting tap recognizer for left photo.")
+				self.preview[idx].addGestureRecognizer(tapRecognizer)
+			}
+			else{
+				let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowAlbum.openRightPhoto(_:)))
+				tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
+				self.preview[idx].isUserInteractionEnabled = true
+				NSLog(":ROWALBUM:DEBUG: Setting tap recognizer for right photo.")
+				self.preview[idx].addGestureRecognizer(tapRecognizer)
+			}
 		}
 		}
 	}
 	}
 	
 	
+	func setIds(left: Int, right: Int){
+		self.photoIds[0] = left
+		self.photoIds[1] = right
+	}
+	
 }
 }

+ 20 - 1
app/ViewController.swift

@@ -45,6 +45,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	
 	
 	// Passed id to perform segues.
 	// Passed id to perform segues.
 	var passId: Int = -1
 	var passId: Int = -1
+	var passAlbum: Int = -1
 	
 	
 	// Location-related variables.
 	// Location-related variables.
 	var locationManager = CLLocationManager()
 	var locationManager = CLLocationManager()
@@ -125,6 +126,20 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	}
 	}
 	
 	
 	
 	
+	// TODO: This must go in it AlbumViewController
+	/**
+	Shows a photo.
+	:param: id The album id.
+	*/
+	func showPhoto(album: Int, photo: Int){
+		NSLog(":CONTROLLER:DEBUG: Showing photo \(photo) of album \(album)")
+		self.passAlbum = album
+		self.passId = photo
+		performSegue(withIdentifier: "SeguePhoto", sender: nil)
+		NSLog(":CONTROLLER:DEBUG: PHOTO should be shown")
+	}
+	
+	
 	/**
 	/**
 	Shows a schedule.
 	Shows a schedule.
 	:param: margolari True for the margolari schedule, false for the city one.
 	:param: margolari True for the margolari schedule, false for the city one.
@@ -141,7 +156,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	}
 	}
 	
 	
 	
 	
-	/**
+	/** m
 	Handles the initial sync process.
 	Handles the initial sync process.
 	It can start it, showing the sync screen, or finish it, hidding the screen.
 	It can start it, showing the sync screen, or finish it, hidding the screen.
 	:param: showScreen True to start the sync, false to end it.
 	:param: showScreen True to start the sync, false to end it.
@@ -174,6 +189,10 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		if segue.identifier == "SegueAlbum"{
 		if segue.identifier == "SegueAlbum"{
 			(segue.destination as! AlbumViewController).id = passId
 			(segue.destination as! AlbumViewController).id = passId
 		}
 		}
+		if segue.identifier == "SeguePhoto"{
+			(segue.destination as! PhotoViewController).photoId = passId
+			(segue.destination as! PhotoViewController).albumId = passAlbum
+		}
 		if segue.identifier == "SegueSchedule"{
 		if segue.identifier == "SegueSchedule"{
 			if passId == 1{
 			if passId == 1{
 				(segue.destination as! ScheduleViewController).margolari = true
 				(segue.destination as! ScheduleViewController).margolari = true