Explorar el Código

Listeners implemented to the past activities in the home screen.

Iñigo Valentin hace 9 años
padre
commit
655ffa66fa

+ 2 - 2
app/ActivitiesView.swift

@@ -21,11 +21,13 @@
 import Foundation
 import CoreData
 import UIKit
+
 /**
 Class to handle the home view.
 */
 class ActivitiesView: UIView {
 	
+	// Outlets.
 	@IBOutlet var container: ActivitiesView!
 	@IBOutlet weak var futureSection: Section!
 	@IBOutlet weak var pastSection: Section!
@@ -209,8 +211,6 @@ class ActivitiesView: UIView {
 		} catch {
 			NSLog(":ACTIVITIES:ERROR: Error with request: \(error)")
 		}
-		
-		NSLog(":ACTIVITIES:DEBUG: Finished loading ActivitiesView")
 	}
 	
 	/**

+ 4 - 4
app/HomeView.swift

@@ -26,10 +26,8 @@ import UIKit
  */
 class HomeView: UIView {
 	
-	//The main scroll view.
+	// Outlets
 	@IBOutlet weak var scrollView: UIScrollView!
-	
-	//The container of the view.
 	@IBOutlet weak var container: UIView!
 	
 	//Each of the sections of the view.
@@ -157,7 +155,8 @@ class HomeView: UIView {
 				title = r.value(forKey: "title_\(lang)")! as! String
 				text = r.value(forKey: "text_\(lang)")! as! String
 				row.setTitle(text: title)
-				row.setText(text: text.decode())
+				row.setText(text: text)
+				row.id = id
 				
 				// Get main image
 				image = ""
@@ -291,6 +290,7 @@ class HomeView: UIView {
 				
 				row.setTitle(text: title)
 				row.setText(text: text)
+				row.id = id
 				
 				// Get main image
 				image = ""

+ 28 - 15
app/RowFutureActivity.swift

@@ -22,11 +22,11 @@ import Foundation
 import UIKit
 
 /**
-Extension of UIView to be formatted as sections.
+Extension of UIView to be formatted as future activity rows.
 */
 @IBDesignable class RowFutureActivity: UIView {
 
-	// Outlets
+	// Outlets.
 	@IBOutlet weak var container: UIView!
 	@IBOutlet weak var title: UILabel!
 	@IBOutlet weak var image: UIImageView!
@@ -35,9 +35,10 @@ Extension of UIView to be formatted as sections.
 	@IBOutlet weak var city: UILabel!
 	@IBOutlet weak var price: UILabel!
 	
-	// Activity ID
+	// Activity ID.
 	var id = -1
 	
+	
 	/**
 	Default constructor
 	:param: coder Coder.
@@ -47,13 +48,16 @@ Extension of UIView to be formatted as sections.
 	}
 	
 	
-	
+	/**
+	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)
 		nib.instantiate(withOwner: self, options: nil).first
 	}
 	
+	
 	/**
 	Default constructor.
 	:param: s Custom identifier
@@ -68,16 +72,16 @@ Extension of UIView to be formatted as sections.
 		container.autoresizingMask = [.flexibleWidth, .flexibleHeight]
 		container.translatesAutoresizingMaskIntoConstraints = true
 		
-		container.frame = self.bounds
-		self.addSubview(container)
+		self.container.frame = self.bounds
+		self.addSubview(self.container)
 		
 		// Set tap recognizer
-		/*print("ROW_FUTURE_ACTIVITY:DEBUG: set tap recognizer")
-		let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (self.openActivity (_:)))
+		let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowPastActivity.openActivity (_:)))
 		tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
-		addGestureRecognizer(tapRecognizer)*/
+		self.addGestureRecognizer(tapRecognizer)
 	}
 	
+	
 	/**
 	Default constructor for the interface builder
 	*/
@@ -86,7 +90,6 @@ Extension of UIView to be formatted as sections.
 	}
 	
 	
-	
 	/**
 	Changes the title of the activity. Decodes HTML.
 	:param: text The new title.
@@ -95,6 +98,7 @@ Extension of UIView to be formatted as sections.
 		self.title.text = text.decode().stripHtml()
 	}
 	
+	
 	/**
 	Sets the city of the activity.
 	:param: text The city.
@@ -103,6 +107,7 @@ Extension of UIView to be formatted as sections.
 		self.city.text = text.decode().stripHtml()
 	}
 	
+	
 	/**
 	Sets the price of the activity.
 	:param: price The price, in Euros. If 0, nothing is shown.
@@ -116,6 +121,7 @@ Extension of UIView to be formatted as sections.
 		}
 	}
 	
+	
 	/**
 	Changes the description of the activity. Decodes HTML.
 	:param: text The new text.
@@ -124,6 +130,7 @@ Extension of UIView to be formatted as sections.
 		self.descript.text = text.decode().stripHtml()
 	}
 	
+	
 	/**
 	Sets the date of the activity in a human readable format.
 	:param: text The date.
@@ -174,6 +181,7 @@ Extension of UIView to be formatted as sections.
 		self.date.text = strDate
 	}
 	
+	
 	/**
 	Changes the image of the activity.
 	If null or empty, the igage is hidden.
@@ -181,17 +189,22 @@ Extension of UIView to be formatted as sections.
 	*/
 	func setImage(filename: String){
 		if (filename == ""){
-			NSLog("ROW_FUTURE_ACTIVITY:DEBUG: No image")
-			//TODO hide the imageview
+			// Hide the imageview
+			self.image.isHidden = true
 		}
 		else{
-			NSLog(":ROW_FUTURE_ACTIVITY:DEBUG: Set image \(filename)")
 			let path = "img/actividades/thumb/\(filename)"
-			image.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
+			self.image.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 		}
 	}
 	
+	
+	/**
+	Opens an activity.
+	*/
 	func openActivity(_ sender:UITapGestureRecognizer? = nil){
-		NSLog(":ROW_FUTURE_ACTIVITY:DEBUG: open activity")
+		NSLog(":ROWFUTUREACTIVITY:DEBUG: Getting delegate and showing past activity \(self.id).")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPastActivity(id: self.id)
 	}
 }

+ 19 - 9
app/RowHomeFutureActivities.swift

@@ -26,21 +26,16 @@ Extension of UIView to be formatted as sections.
 */
 @IBDesignable class RowHomeFutureActivities: UIView {
 	
-	//The container.
+	// Outlets.
 	@IBOutlet weak var container: UIView!
-	
-	//The entry
 	@IBOutlet weak var entry: UIView!
-	
-	//The activity title.
 	@IBOutlet weak var title: UILabel!
-	
-	//The activity description.
 	@IBOutlet weak var descrip: UILabel!
-	
-	//The activity image.
 	@IBOutlet weak var image: UIImageView!
 	
+	// Activity ID.
+	var id: Int = -1;
+	
 	
 	/**
 	Default constructor
@@ -76,6 +71,11 @@ Extension of UIView to be formatted as sections.
 		
 		self.container.frame = self.bounds
 		self.addSubview(container)
+		
+		// Set tap recognizer
+		let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowHomeFutureActivities.openActivity (_:)))
+		tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
+		self.addGestureRecognizer(tapRecognizer)
 	}
 	
 	
@@ -120,4 +120,14 @@ Extension of UIView to be formatted as sections.
 			self.image.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 		}
 	}
+	
+	
+	/**
+	Opens an activity.
+	*/
+	func openActivity(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ROWFUTUREACTIVITY:DEBUG: Getting delegate and showing past activity \(self.id).")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showFutureActivity(id: self.id)
+	}
 }

+ 20 - 10
app/RowHomePastActivities.swift

@@ -22,25 +22,20 @@ import Foundation
 import UIKit
 
 /**
-Extension of UIView to be formatted as sections.
+Extension of UIView to be formatted as past activity rows.
 */
 @IBDesignable class RowHomePastActivities: UIView {
 	
-	//The container.
+	// Outlets.
 	@IBOutlet weak var container: UIView!
-	
-	//The entry
 	@IBOutlet weak var entry: UIView!
-	
-	//The activity title.
 	@IBOutlet weak var title: UILabel!
-	
-	//The activity description.
 	@IBOutlet weak var descrip: UILabel!
-	
-	//The activity image.
 	@IBOutlet weak var image: UIImageView!
 	
+	// Activity ID.
+	var id: Int = -1;
+	
 	
 	/**
 	Default constructor
@@ -76,6 +71,11 @@ Extension of UIView to be formatted as sections.
 
 		self.container.frame = self.bounds
 		self.addSubview(container)
+		
+		// Set tap recognizer
+		let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowHomePastActivities.openActivity (_:)))
+		tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
+		self.addGestureRecognizer(tapRecognizer)
 	}
 	
 	
@@ -120,4 +120,14 @@ Extension of UIView to be formatted as sections.
 			self.image.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 		}
 	}
+	
+	
+	/**
+	Opens an activity.
+	*/
+	func openActivity(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ROWPASTACTIVITY:DEBUG: Getting delegate and showing past activity \(self.id).")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPastActivity(id: self.id)
+	}
 }

+ 4 - 18
app/RowPastActivity.swift

@@ -32,7 +32,7 @@ Extension of UIView to be formatted as sections.
 	@IBOutlet weak var image: UIImageView!
 	@IBOutlet weak var descript: UILabel!
 	
-	// Activity ID
+	// Activity ID.
 	var id = -1
 	
 	/**
@@ -74,12 +74,6 @@ Extension of UIView to be formatted as sections.
 		let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (RowPastActivity.openActivity (_:)))
 		tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
 		self.addGestureRecognizer(tapRecognizer)
-		
-		// Set tap recognizer
-		/*print("ROW_PAST_ACTIVITY:DEBUG: set tap recognizer")
-		let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (self.openActivity (_:)))
-		tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
-		addGestureRecognizer(tapRecognizer)*/
 	}
 	
 	
@@ -124,22 +118,14 @@ Extension of UIView to be formatted as sections.
 			image.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 		}
 	}
-	
+
+
 	/**
-	Opens an album.
+	Opens an activity.
 	*/
 	func openActivity(_ sender:UITapGestureRecognizer? = nil){
 		NSLog(":ROWPASTACTIVITY:DEBUG: Getting delegate and showing past activity \(self.id).")
 		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
 		delegate.controller?.showPastActivity(id: self.id)
 	}
-	
-	
-	/**
-	Opens an activity.
-	*/
-	/*func openActivity(_ sender:UITapGestureRecognizer? = nil){
-		// TODO: Implement openActivity.
-		NSLog(":ROW_PAST_ACTIVITY:DEBUG: open activity")
-	}*/
 }