Переглянути джерело

Photos opened from the home screen.

Iñigo Valentin 9 роки тому
батько
коміт
c640d388df
2 змінених файлів з 94 додано та 0 видалено
  1. 20 0
      app/HomeView.swift
  2. 74 0
      app/RowHomeGallery.swift

+ 20 - 0
app/HomeView.swift

@@ -469,11 +469,31 @@ class HomeView: UIView {
 	
 			var id: Int
 			var image: String
+			var albumId: Int
 			var i = 0
 			for r in searchResults as [NSManagedObject] {
 				
 				image = r.value(forKey: "file")! as! String
+				id = r.value(forKey: "id")! as! Int
+				
+				// TODO Get album id
+				// Get album title
+				let albumFetchRequest: NSFetchRequest<Photo_album> = Photo_album.fetchRequest()
+				albumFetchRequest.predicate = NSPredicate(format: "photo = %i", id)
+				do {
+					let results = try context.fetch(albumFetchRequest)
+					let r = results[0]
+					albumId = r.value(forKey: "album")! as! Int
+					row.albumIds[i] = albumId
+				}
+				catch {
+					NSLog(":GALLERYCONTROLLER:ERROR: Error getting album info: \(error)")
+				}
+				
+				
+				
 				row.setImage(idx: i, filename: image)
+				row.photoIds[i] = id
 				NSLog(":HOME:DEBUG: Photo \(i)")
 				
 				//TODO Set click listener

+ 74 - 0
app/RowHomeGallery.swift

@@ -34,6 +34,9 @@ Extension of UIView to be formatted as sections.
 	
 	var photos: [UIImageView] = []
 	
+	var photoIds: [Int] = [-1, -1, -1, -1]
+	var albumIds: [Int] = [-1, -1, -1, -1]
+	
 	
 	/**
 	Default constructor
@@ -77,6 +80,46 @@ Extension of UIView to be formatted as sections.
 	}
 	
 	
+	/**
+	Open the first photo in the photo viewer.
+	*/
+	func openFirstPhoto(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ROWHOMEGALLERY:DEBUG: Getting delegate and showing first photo.")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPhoto(album: self.albumIds[0], photo: self.photoIds[0])
+	}
+	
+	
+	/**
+	Open the second photo in the photo viewer.
+	*/
+	func openSecondPhoto(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ROWHOMEGALLERY:DEBUG: Getting delegate and showing second photo.")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPhoto(album: self.albumIds[1], photo: self.photoIds[1])
+	}
+	
+	
+	/**
+	Open the third photo in the photo viewer.
+	*/
+	func openThirdPhoto(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ROWHOMEGALLERY:DEBUG: Getting delegate and showing third photo.")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPhoto(album: self.albumIds[2], photo: self.photoIds[2])
+	}
+	
+	
+	/**
+	Open the fourth photo in the photo viewer.
+	*/
+	func openFourthPhoto(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ROWHOMEGALLERY:DEBUG: Getting delegate and showing fourth photo.")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPhoto(album: self.albumIds[3], photo: self.photoIds[3])
+	}
+	
+	
 	/**
 	Default constructor for the interface builder
 	*/
@@ -98,6 +141,37 @@ Extension of UIView to be formatted as sections.
 		else{
 			let path = "img/galeria/thumb/\(filename)"
 			photos[idx].setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
+			
+			// Set tap recognizer
+			NSLog(":ROWHOMEGALLERY:DEBUG: Setting tap recognizer for index \(idx)")
+			switch idx{
+				case 0:
+					let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowHomeGallery.openFirstPhoto(_:)))
+					tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
+					self.photos[idx].isUserInteractionEnabled = true
+					self.photos[idx].addGestureRecognizer(tapRecognizer)
+					break;
+				case 1:
+					let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowHomeGallery.openSecondPhoto(_:)))
+					tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
+					self.photos[idx].isUserInteractionEnabled = true
+					self.photos[idx].addGestureRecognizer(tapRecognizer)
+					break;
+				case 2:
+					let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowHomeGallery.openThirdPhoto(_:)))
+					tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
+					self.photos[idx].isUserInteractionEnabled = true
+					self.photos[idx].addGestureRecognizer(tapRecognizer)
+					break;
+				case 3:
+					let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowHomeGallery.openFourthPhoto(_:)))
+					tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
+					self.photos[idx].isUserInteractionEnabled = true
+					self.photos[idx].addGestureRecognizer(tapRecognizer)
+					break;
+				default:
+					NSLog(":ROWHOMEGALLERY:ERROR: Trying to set tap recognizer for invalid photo index \(idx).")
+			}
 		}
 	}