Ver Fonte

Segue to past activities working.

Iñigo Valentin há 9 anos atrás
pai
commit
252c634c99

+ 5 - 1
app.xcodeproj/project.pbxproj

@@ -86,6 +86,7 @@
 		93E0C5F41EBE306900905811 /* ScheduleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93E0C5F31EBE306900905811 /* ScheduleViewController.swift */; };
 		93EB2F0C1EBF5AEB00F64186 /* RowSchedule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93EB2F0B1EBF5AEB00F64186 /* RowSchedule.swift */; };
 		93EB2F0E1EBF5BF500F64186 /* RowSchedule.xib in Resources */ = {isa = PBXBuildFile; fileRef = 93EB2F0D1EBF5BF500F64186 /* RowSchedule.xib */; };
+		93EE9ECB1EE9B87100288F6E /* PastActivityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93EE9ECA1EE9B87100288F6E /* PastActivityViewController.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -171,6 +172,7 @@
 		93E0C5F31EBE306900905811 /* ScheduleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduleViewController.swift; sourceTree = "<group>"; };
 		93EB2F0B1EBF5AEB00F64186 /* RowSchedule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowSchedule.swift; sourceTree = "<group>"; };
 		93EB2F0D1EBF5BF500F64186 /* RowSchedule.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RowSchedule.xib; sourceTree = "<group>"; };
+		93EE9ECA1EE9B87100288F6E /* PastActivityViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PastActivityViewController.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -228,8 +230,8 @@
 				93B84B991D9C31AB006C0F67 /* AppDelegate.swift */,
 				93B84B9D1D9C31AB006C0F67 /* Main.storyboard */,
 				93B84B9B1D9C31AB006C0F67 /* ViewController.swift */,
-				93B408021D9ED44C000FBC99 /* MenuCollectionViewCell.swift */,
 				93BEB6D11E7E878300C68DE5 /* PostViewController.swift */,
+				93B408021D9ED44C000FBC99 /* MenuCollectionViewCell.swift */,
 				93D9EA5F1DE271E700089002 /* Section.xib */,
 				93D9EA631DE273FD00089002 /* Section.swift */,
 				931AA5AD1E218D0D003A2290 /* Entry.xib */,
@@ -284,6 +286,7 @@
 				93B9113C1ED7567B0061BA71 /* LocationView.xib */,
 				93B9113E1ED7582B0061BA71 /* LocationView.swift */,
 				93B9115E1ED765510061BA71 /* app-Bridging-Header.h */,
+				93EE9ECA1EE9B87100288F6E /* PastActivityViewController.swift */,
 			);
 			path = app;
 			sourceTree = "<group>";
@@ -440,6 +443,7 @@
 				93B84BA21D9C31AB006C0F67 /* app.xcdatamodeld in Sources */,
 				935D6E331E867C7E00CED3A1 /* RowGallery.swift in Sources */,
 				93EB2F0C1EBF5AEB00F64186 /* RowSchedule.swift in Sources */,
+				93EE9ECB1EE9B87100288F6E /* PastActivityViewController.swift in Sources */,
 				936966ED1E98445200A11055 /* AlbumViewController.swift in Sources */,
 				93D9EA681DE342AC00089002 /* UIView.swift in Sources */,
 				938D211F1EA2306300C47EC3 /* LablancaView.swift in Sources */,

+ 62 - 0
app/ActivitiesView.swift

@@ -38,6 +38,10 @@ class ActivitiesView: UIView {
 	var pastList: UIStackView? = nil
 	var context: NSManagedObjectContext? = nil
 	
+	// Section row list
+	var pastRows: Array<RowPastActivity> = []
+	var futureRows: Array<RowFutureActivity> = []
+	
 	override init(frame: CGRect){
 		super.init(frame: frame)
 	}
@@ -119,6 +123,7 @@ class ActivitiesView: UIView {
 					row.setPrice(price: price)
 					row.setCity(text: city)
 					row.setDate(date: date, lang: lang!)
+					row.id = id
 				
 					// Get main image
 					image = ""
@@ -139,6 +144,7 @@ class ActivitiesView: UIView {
 					}
 				
 					self.futureList?.addArrangedSubview(row)
+					self.futureRows.append(row)
 					
 					// TODO: Do this on the row didLoad method
 					// Set tap recognizer
@@ -148,11 +154,13 @@ class ActivitiesView: UIView {
 				}
 				self.futureList?.setNeedsLayout()
 				self.futureList?.layoutIfNeeded()
+				
 			}
 		}
 		catch {
 			NSLog(":ACTIVITIES:ERROR: Error with request: \(error)")
 		}
+		setUpFutureRowsTapRecognizers()
 		
 		
 		
@@ -183,6 +191,7 @@ class ActivitiesView: UIView {
 				text = r.value(forKey: "text_\(lang!)")! as! String
 				row.setTitle(text: title)
 				row.setText(text: text)
+				row.id = id
 				
 				// Get main image
 				image = ""
@@ -205,6 +214,7 @@ class ActivitiesView: UIView {
 				
 				
 				self.pastList?.addArrangedSubview(row)
+				self.pastRows.append(row)
 				
 				// TODO: Do this on the row didLoad method
 				// Set tap recognizer
@@ -214,9 +224,12 @@ class ActivitiesView: UIView {
 			}
 			self.pastList?.setNeedsLayout()
 			self.pastList?.layoutIfNeeded()
+			
 		} catch {
 			NSLog(":ACTIVITIES:ERROR: Error with request: \(error)")
 		}
+		
+		//setUpPastRowsTapRecognizers()
 		NSLog(":ACTIVITIES:DEBUG: Finished loading ActivitiesView")
 	}
 	
@@ -237,6 +250,55 @@ class ActivitiesView: UIView {
 	}*/
 	
 	
+	/**
+	Handles the click events to open past activities.
+	*/
+	func setUpPastRowsTapRecognizers(){
+		NSLog(":ACTIVITIES:DEBUG: Setting up past activitiesr tap recognizers")
+		for row in self.pastRows{
+			let tapRecognizer = UITapGestureRecognizer(target: row, action: #selector(openPastActivity(_:)))
+			row.isUserInteractionEnabled = true
+			row.addGestureRecognizer(tapRecognizer)
+		}
+	}
+	
+	
+	/**
+	Opens a past activity.
+	*/
+	func openPastActivity(_ sender:UITapGestureRecognizer? = nil){
+		NSLog(":ACTIVITIES:DEBUG: opening pastActivity.")
+		let id = (sender?.view as! RowPastActivity).id
+		NSLog(":ACTIVITIES:DEBUG: getting delegate and showing pastActivity \(id).")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showPastActivity(id: id)
+	}
+	
+	
+	/**
+	Handles the click events to open past activities.
+	*/
+	func setUpFutureRowsTapRecognizers(){
+		NSLog(":ACTIVITIES:DEBUG: Setting up future activities tap recognizers")
+		for row in self.futureRows{
+			let tapRecognizer = UITapGestureRecognizer(target: row, action: #selector(openFutureActivity(_:)))
+			row.isUserInteractionEnabled = true
+			//container.addGestureRecognizer(tapRecognizer)
+		}
+	}
+	
+	
+	/**
+	Opens a past activity.
+	*/
+	func openFutureActivity(_ sender:UITapGestureRecognizer? = nil){
+		let id = (sender?.view as! RowFutureActivity).id
+		NSLog(":ACTIVITIES:DEBUG: getting delegate and showing pastActivity \(id).")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.controller?.showFutureActivity(id: id)
+	}
+	
+	
 	/**
 	Gets the device language. The only recognized languages are Spanish, English and Basque.
 	If the device has another language, Spanish will be selected by default.

+ 207 - 0
app/Base.lproj/Main.storyboard

@@ -199,6 +199,7 @@
                         <segue destination="k0M-Sk-DZM" kind="show" identifier="SegueAlbum" id="Puc-tv-vaD"/>
                         <segue destination="zJF-Mh-CNb" kind="show" identifier="SegueSchedule" id="A70-jo-yAP"/>
                         <segue destination="3o1-ab-AT4" kind="show" identifier="SegueSync" id="E96-mK-gE9"/>
+                        <segue destination="jfx-Q2-RtY" kind="show" identifier="SeguePastActivity" id="MmG-k2-wHn"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
@@ -1032,6 +1033,212 @@
                 <placeholder placeholderIdentifier="IBFirstResponder" id="fRm-1Y-Xmm" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>
         </scene>
+        <!--Past Activity View Controller-->
+        <scene sceneID="0of-i7-sd6">
+            <objects>
+                <viewController id="jfx-Q2-RtY" customClass="PastActivityViewController" customModule="app" customModuleProvider="target" sceneMemberID="viewController">
+                    <layoutGuides>
+                        <viewControllerLayoutGuide type="top" id="u2P-so-lU7"/>
+                        <viewControllerLayoutGuide type="bottom" id="Lav-1c-S51"/>
+                    </layoutGuides>
+                    <view key="view" contentMode="scaleToFill" id="SdM-pu-zm3">
+                        <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <subviews>
+                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BxO-VS-eP5" userLabel="Toolbar">
+                                <rect key="frame" x="0.0" y="20" width="375" height="30"/>
+                                <subviews>
+                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Loj-Ff-gNj">
+                                        <rect key="frame" x="0.0" y="0.0" width="56.5" height="30"/>
+                                        <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
+                                        <state key="normal" title="&lt;">
+                                            <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                        </state>
+                                    </button>
+                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Gasteizko Margolariak" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xf1-tl-98b">
+                                        <rect key="frame" x="56.5" y="0.0" width="262.5" height="30"/>
+                                        <fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
+                                        <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                        <nil key="highlightedColor"/>
+                                    </label>
+                                </subviews>
+                                <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                <constraints>
+                                    <constraint firstItem="xf1-tl-98b" firstAttribute="height" secondItem="BxO-VS-eP5" secondAttribute="height" id="A9Y-Fw-3wT"/>
+                                    <constraint firstItem="Loj-Ff-gNj" firstAttribute="width" secondItem="BxO-VS-eP5" secondAttribute="width" multiplier="0.15" id="JAK-Wn-RB0"/>
+                                    <constraint firstItem="Loj-Ff-gNj" firstAttribute="leading" secondItem="BxO-VS-eP5" secondAttribute="leading" id="KWZ-5M-JBT"/>
+                                    <constraint firstItem="Loj-Ff-gNj" firstAttribute="height" secondItem="BxO-VS-eP5" secondAttribute="height" id="PRz-QI-LGC"/>
+                                    <constraint firstItem="xf1-tl-98b" firstAttribute="width" secondItem="BxO-VS-eP5" secondAttribute="width" multiplier="0.7" id="cAg-nR-WRl"/>
+                                    <constraint firstItem="xf1-tl-98b" firstAttribute="centerY" secondItem="BxO-VS-eP5" secondAttribute="centerY" id="cCD-R8-57d"/>
+                                    <constraint firstItem="xf1-tl-98b" firstAttribute="centerX" secondItem="BxO-VS-eP5" secondAttribute="centerX" id="ltM-gK-avh"/>
+                                    <constraint firstItem="Loj-Ff-gNj" firstAttribute="centerY" secondItem="BxO-VS-eP5" secondAttribute="centerY" id="rUy-8N-1cq"/>
+                                </constraints>
+                            </view>
+                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="JgN-DW-xUZ">
+                                <rect key="frame" x="0.0" y="50" width="375" height="617"/>
+                                <subviews>
+                                    <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" bounces="NO" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3SZ-u2-ZIb">
+                                        <rect key="frame" x="0.0" y="0.0" width="375" height="617"/>
+                                        <subviews>
+                                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xi6-iq-IpA" userLabel="Section">
+                                                <rect key="frame" x="10" y="10" width="355" height="995"/>
+                                                <subviews>
+                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" restorationIdentifier="Title" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cWR-TU-0Za" userLabel="Title">
+                                                        <rect key="frame" x="0.0" y="0.0" width="355" height="30"/>
+                                                        <color key="backgroundColor" red="0.0" green="0.47058823529999999" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                                        <constraints>
+                                                            <constraint firstAttribute="height" constant="30" id="s4L-e0-U96"/>
+                                                        </constraints>
+                                                        <fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
+                                                        <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                                        <nil key="highlightedColor"/>
+                                                    </label>
+                                                    <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="riK-xb-Vls" userLabel="Content">
+                                                        <rect key="frame" x="0.0" y="30" width="355" height="965"/>
+                                                        <subviews>
+                                                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Omg-cP-uvF" userLabel="Activity">
+                                                                <rect key="frame" x="8" y="8" width="339" height="949"/>
+                                                                <subviews>
+                                                                    <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="8Jn-h7-TSJ" userLabel="Image">
+                                                                        <rect key="frame" x="0.0" y="10" width="339" height="71"/>
+                                                                        <constraints>
+                                                                            <constraint firstAttribute="height" constant="71" id="lZg-2O-4LP"/>
+                                                                        </constraints>
+                                                                    </imageView>
+                                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Text" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Usd-Rm-Tq2" userLabel="Text">
+                                                                        <rect key="frame" x="17" y="91" width="305.5" height="826"/>
+                                                                        <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                                                        <nil key="textColor"/>
+                                                                        <nil key="highlightedColor"/>
+                                                                    </label>
+                                                                    <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="LmH-0o-Hku" userLabel="Separator">
+                                                                        <rect key="frame" x="17" y="917" width="305.5" height="2"/>
+                                                                        <color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
+                                                                        <constraints>
+                                                                            <constraint firstAttribute="height" constant="2" id="X7n-cL-6Hk"/>
+                                                                        </constraints>
+                                                                    </view>
+                                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="254" text="Date" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dvg-B2-xmI" userLabel="Date">
+                                                                        <rect key="frame" x="17" y="929" width="305.5" height="20"/>
+                                                                        <constraints>
+                                                                            <constraint firstAttribute="height" constant="20" id="8LF-YM-5Cn"/>
+                                                                        </constraints>
+                                                                        <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                                                        <nil key="textColor"/>
+                                                                        <nil key="highlightedColor"/>
+                                                                    </label>
+                                                                </subviews>
+                                                                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                                                <constraints>
+                                                                    <constraint firstItem="Usd-Rm-Tq2" firstAttribute="top" secondItem="8Jn-h7-TSJ" secondAttribute="bottom" constant="10" id="1oO-Iq-tff"/>
+                                                                    <constraint firstItem="LmH-0o-Hku" firstAttribute="top" secondItem="Usd-Rm-Tq2" secondAttribute="bottom" id="7Du-au-fft"/>
+                                                                    <constraint firstItem="8Jn-h7-TSJ" firstAttribute="centerX" secondItem="Omg-cP-uvF" secondAttribute="centerX" id="H9k-8U-X4o"/>
+                                                                    <constraint firstItem="dvg-B2-xmI" firstAttribute="width" secondItem="Omg-cP-uvF" secondAttribute="width" multiplier="0.9" id="LcU-3f-pz6"/>
+                                                                    <constraint firstItem="Usd-Rm-Tq2" firstAttribute="width" secondItem="Omg-cP-uvF" secondAttribute="width" multiplier="0.9" id="MQd-UV-3Ee"/>
+                                                                    <constraint firstItem="dvg-B2-xmI" firstAttribute="top" secondItem="LmH-0o-Hku" secondAttribute="bottom" constant="10" id="QrH-eq-mXV"/>
+                                                                    <constraint firstItem="Usd-Rm-Tq2" firstAttribute="centerX" secondItem="Omg-cP-uvF" secondAttribute="centerX" id="SHM-nk-s9u"/>
+                                                                    <constraint firstItem="dvg-B2-xmI" firstAttribute="centerX" secondItem="Omg-cP-uvF" secondAttribute="centerX" id="XBR-sR-Yqg"/>
+                                                                    <constraint firstItem="LmH-0o-Hku" firstAttribute="centerX" secondItem="Omg-cP-uvF" secondAttribute="centerX" id="a8v-br-EaA"/>
+                                                                    <constraint firstItem="8Jn-h7-TSJ" firstAttribute="width" secondItem="Omg-cP-uvF" secondAttribute="width" id="gm5-CU-FKw"/>
+                                                                    <constraint firstItem="8Jn-h7-TSJ" firstAttribute="top" secondItem="Omg-cP-uvF" secondAttribute="top" constant="10" id="js6-Fg-pg1"/>
+                                                                    <constraint firstAttribute="bottom" secondItem="dvg-B2-xmI" secondAttribute="bottom" id="lta-H9-CYI"/>
+                                                                    <constraint firstItem="LmH-0o-Hku" firstAttribute="width" secondItem="Omg-cP-uvF" secondAttribute="width" multiplier="0.9" id="xmH-tU-ZFp"/>
+                                                                </constraints>
+                                                                <edgeInsets key="layoutMargins" top="8" left="8" bottom="8" right="8"/>
+                                                                <userDefinedRuntimeAttributes>
+                                                                    <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                                                        <color key="value" red="0.42745098040000001" green="0.41176470590000003" blue="0.56470588239999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                                                    </userDefinedRuntimeAttribute>
+                                                                    <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                                                        <real key="value" value="1"/>
+                                                                    </userDefinedRuntimeAttribute>
+                                                                    <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                                                        <real key="value" value="3"/>
+                                                                    </userDefinedRuntimeAttribute>
+                                                                </userDefinedRuntimeAttributes>
+                                                            </view>
+                                                        </subviews>
+                                                        <color key="backgroundColor" red="0.59607843140000005" green="0.7843137255" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+                                                        <edgeInsets key="layoutMargins" top="8" left="8" bottom="8" right="8"/>
+                                                    </stackView>
+                                                </subviews>
+                                                <color key="backgroundColor" red="0.59607843140000005" green="0.7843137255" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+                                                <constraints>
+                                                    <constraint firstAttribute="bottom" secondItem="riK-xb-Vls" secondAttribute="bottom" id="Cx5-Kf-8OE"/>
+                                                    <constraint firstItem="cWR-TU-0Za" firstAttribute="width" secondItem="xi6-iq-IpA" secondAttribute="width" id="FVH-in-wHT"/>
+                                                    <constraint firstItem="riK-xb-Vls" firstAttribute="top" secondItem="cWR-TU-0Za" secondAttribute="bottom" id="Hn5-9l-iCk"/>
+                                                    <constraint firstItem="riK-xb-Vls" firstAttribute="centerX" secondItem="xi6-iq-IpA" secondAttribute="centerX" id="KR9-e1-CPc"/>
+                                                    <constraint firstItem="cWR-TU-0Za" firstAttribute="centerX" secondItem="xi6-iq-IpA" secondAttribute="centerX" id="eMS-XG-Mee"/>
+                                                    <constraint firstItem="riK-xb-Vls" firstAttribute="width" secondItem="xi6-iq-IpA" secondAttribute="width" id="g6A-Nh-o8X"/>
+                                                    <constraint firstItem="cWR-TU-0Za" firstAttribute="top" secondItem="xi6-iq-IpA" secondAttribute="top" id="yuP-2e-AdF"/>
+                                                </constraints>
+                                                <edgeInsets key="layoutMargins" top="10" left="10" bottom="10" right="10"/>
+                                                <userDefinedRuntimeAttributes>
+                                                    <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                                        <color key="value" red="0.0" green="0.0" blue="0.066666666669999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                                    </userDefinedRuntimeAttribute>
+                                                    <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                                        <real key="value" value="1"/>
+                                                    </userDefinedRuntimeAttribute>
+                                                    <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                                        <real key="value" value="8"/>
+                                                    </userDefinedRuntimeAttribute>
+                                                </userDefinedRuntimeAttributes>
+                                            </view>
+                                        </subviews>
+                                        <color key="backgroundColor" red="0.70980392160000005" green="0.82745098039999998" blue="0.8980392157" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                        <constraints>
+                                            <constraint firstItem="xi6-iq-IpA" firstAttribute="top" secondItem="3SZ-u2-ZIb" secondAttribute="top" constant="10" id="DOt-pc-3eb"/>
+                                            <constraint firstItem="xi6-iq-IpA" firstAttribute="centerX" secondItem="3SZ-u2-ZIb" secondAttribute="centerX" id="IFM-jn-576"/>
+                                            <constraint firstItem="xi6-iq-IpA" firstAttribute="trailing" secondItem="3SZ-u2-ZIb" secondAttribute="trailing" constant="10" id="SAk-SF-xVS"/>
+                                            <constraint firstAttribute="bottom" secondItem="xi6-iq-IpA" secondAttribute="bottom" constant="10" id="Xdk-K7-KDJ"/>
+                                            <constraint firstItem="xi6-iq-IpA" firstAttribute="leading" secondItem="3SZ-u2-ZIb" secondAttribute="leading" constant="10" id="wud-Ff-5hQ"/>
+                                        </constraints>
+                                        <edgeInsets key="layoutMargins" top="10" left="10" bottom="10" right="10"/>
+                                        <userDefinedRuntimeAttributes>
+                                            <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                                <real key="value" value="0.0"/>
+                                            </userDefinedRuntimeAttribute>
+                                        </userDefinedRuntimeAttributes>
+                                    </scrollView>
+                                </subviews>
+                                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                <constraints>
+                                    <constraint firstItem="3SZ-u2-ZIb" firstAttribute="width" secondItem="JgN-DW-xUZ" secondAttribute="width" id="31P-4U-Pt1"/>
+                                    <constraint firstAttribute="bottom" secondItem="3SZ-u2-ZIb" secondAttribute="bottom" id="Eou-gG-0WN"/>
+                                    <constraint firstItem="3SZ-u2-ZIb" firstAttribute="centerX" secondItem="JgN-DW-xUZ" secondAttribute="centerX" id="JzA-TZ-T6w"/>
+                                    <constraint firstItem="3SZ-u2-ZIb" firstAttribute="top" secondItem="JgN-DW-xUZ" secondAttribute="top" id="T5M-NN-rUZ"/>
+                                </constraints>
+                                <userDefinedRuntimeAttributes>
+                                    <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                        <color key="value" red="0.70980392160000005" green="0.82745098039999998" blue="0.8980392157" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                    </userDefinedRuntimeAttribute>
+                                </userDefinedRuntimeAttributes>
+                            </view>
+                        </subviews>
+                        <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                        <constraints>
+                            <constraint firstItem="BxO-VS-eP5" firstAttribute="centerX" secondItem="SdM-pu-zm3" secondAttribute="centerX" id="0eo-Jq-yKG"/>
+                            <constraint firstItem="JgN-DW-xUZ" firstAttribute="centerX" secondItem="SdM-pu-zm3" secondAttribute="centerX" id="XMm-11-4Bs"/>
+                            <constraint firstItem="Lav-1c-S51" firstAttribute="top" secondItem="JgN-DW-xUZ" secondAttribute="bottom" id="ai7-fu-CPH"/>
+                            <constraint firstItem="BxO-VS-eP5" firstAttribute="width" secondItem="SdM-pu-zm3" secondAttribute="width" id="d1M-W0-fTO"/>
+                            <constraint firstItem="JgN-DW-xUZ" firstAttribute="width" secondItem="SdM-pu-zm3" secondAttribute="width" id="jJF-ok-Gxw"/>
+                            <constraint firstItem="JgN-DW-xUZ" firstAttribute="top" secondItem="BxO-VS-eP5" secondAttribute="bottom" id="pqm-X9-1Pa"/>
+                            <constraint firstItem="BxO-VS-eP5" firstAttribute="top" secondItem="u2P-so-lU7" secondAttribute="bottom" id="qdC-D0-ERu"/>
+                        </constraints>
+                    </view>
+                    <connections>
+                        <outlet property="activityDate" destination="dvg-B2-xmI" id="hyQ-Wm-9J7"/>
+                        <outlet property="activityImage" destination="8Jn-h7-TSJ" id="OtM-Zu-0Qf"/>
+                        <outlet property="activityText" destination="Usd-Rm-Tq2" id="ySl-QS-kOh"/>
+                        <outlet property="activityTitle" destination="cWR-TU-0Za" id="oRe-G1-MMU"/>
+                        <outlet property="barButton" destination="Loj-Ff-gNj" id="0tW-a0-rNG"/>
+                        <outlet property="barTitle" destination="xf1-tl-98b" id="dO8-P5-V8C"/>
+                    </connections>
+                </viewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="YKC-ZH-aSz" userLabel="First Responder" sceneMemberID="firstResponder"/>
+            </objects>
+        </scene>
     </scenes>
     <resources>
         <image name="GM" width="120" height="120"/>

+ 156 - 0
app/PastActivityViewController.swift

@@ -0,0 +1,156 @@
+// Copyright (C) 2016 Inigo Valentin
+//
+// This file is part of the Gasteizko Margolariak IOS app.
+//
+// The Gasteizko Margolariak IOS app is free software: you can
+// redistribute it and/or modify it under the terms of the
+// GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your
+// option) any later version.
+//
+// The Gasteizko Margolariak IOS app is distributed in the
+// hope that it will be useful, but WITHOUT ANY WARRANTY;
+// without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+// Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with the Gasteizko Margolariak IOS app.
+// If not, see <http://www.gnu.org/licenses/>.
+
+import UIKit
+import CoreData
+
+/**
+Controller to show a past activity.
+*/
+class PastActivityViewController: UIViewController, UIGestureRecognizerDelegate {
+	
+	@IBOutlet weak var barButton: UIButton!
+	@IBOutlet weak var barTitle: UILabel!
+	@IBOutlet weak var activityTitle: UILabel!
+	@IBOutlet weak var activityImage: UIImageView!
+	@IBOutlet weak var activityText: UILabel!
+	@IBOutlet weak var activityDate: UILabel!
+
+	
+	// Activity id
+	var id: Int = -1
+	
+	var delegate: AppDelegate?
+	
+	var passId: Int = -1
+	
+	/**
+	Get the app context.
+	:return: The app context.
+	*/
+	func getContext () -> NSManagedObjectContext {
+		return NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
+	}
+	
+	
+	/**
+	Run when the app loads.
+	*/
+	override func viewDidLoad() {
+		super.viewDidLoad()
+		self.loadActivity(id: id)
+		// Set button action
+		barButton.addTarget(self, action: #selector(self.back), for: .touchUpInside)
+	}
+	
+	
+	/**
+	Dismisses the controller.
+	*/
+	func back() {
+		NSLog(":FUTUREACTIVITYCONTROLLER:CONTROLLER:DEBUG: Back")
+		self.dismiss(animated: true, completion: nil)
+	}
+	
+	
+	/**
+	Dispose of any resources that can be recreated.
+	*/
+	override func didReceiveMemoryWarning() {
+		super.didReceiveMemoryWarning()
+	}
+	
+	
+	/**
+	Loads the selected post.
+	:param: id Post id.
+	*/
+	public func loadActivity(id: Int){
+		
+		NSLog(":POSTCONTROLLER:DEBUG: Loading post \(id)")
+		
+		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
+		let appDelegate = UIApplication.shared.delegate as! AppDelegate
+		let lang : String = getLanguage()
+		context.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator
+		let fetchRequest: NSFetchRequest<Activity> = Activity.fetchRequest()
+		fetchRequest.predicate = NSPredicate(format: "id = %i", id)
+		
+		do {
+			let searchResults = try context.fetch(fetchRequest)
+			var count = 0
+			var sTitle: String
+			var sText: String
+			var image: String
+			
+			for r in searchResults as [NSManagedObject] {
+				count = count + 1
+				sTitle = r.value(forKey: "title_\(lang)")! as! String
+				if (r.value(forKey: "after_\(lang)")! as! String).length == 0{
+					sText = r.value(forKey: "after_\(lang)")! as! String
+				}
+				else{
+					sText = r.value(forKey: "description_\(lang)")! as! String
+				}
+				activityTitle.text = "  \(sTitle)"
+				activityText.text = sText.stripHtml()
+				
+				// Get main image
+				image = ""
+				let imgFetchRequest: NSFetchRequest<Activity_image> = Activity_image.fetchRequest()
+				let imgSortDescriptor = NSSortDescriptor(key: "idx", ascending: true)
+				let imgSortDescriptors = [imgSortDescriptor]
+				imgFetchRequest.sortDescriptors = imgSortDescriptors
+				imgFetchRequest.predicate = NSPredicate(format: "activity == %i", id)
+				imgFetchRequest.fetchLimit = 1
+				do{
+					let imgSearchResults = try context.fetch(imgFetchRequest)
+					for imgR in imgSearchResults as [NSManagedObject]{
+						image = imgR.value(forKey: "image")! as! String
+						let path = "img/actividades/preview/\(image)"
+						self.activityImage.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
+					}
+				} catch {
+					NSLog(":POSTCONTROLLER:DEBUG: Error getting image for post \(id): \(error)")
+				}
+				
+			}
+		} catch {
+			NSLog(":POSTCONTROLLER:DEBUG: Error with request: \(error)")
+		}
+	}
+	
+	/**
+	Gets the device language. The only recognized languages are Spanish, English and Basque.
+	If the device has another language, Spanish will be selected by default.
+	:return: Two-letter language code.
+	*/
+	func getLanguage() -> String{
+		let pre = NSLocale.preferredLanguages[0].subStr(start: 0, end: 1)
+		if(pre == "es" || pre == "en" || pre == "eu"){
+			return pre
+		}
+		else{
+			return "es"
+		}
+	}
+	
+}
+

+ 2 - 0
app/RowFutureActivity.swift

@@ -35,6 +35,8 @@ Extension of UIView to be formatted as sections.
 	@IBOutlet weak var city: UILabel!
 	@IBOutlet weak var price: UILabel!
 	
+	// Activity ID
+	var id = -1
 	
 	/**
 	Default constructor

+ 2 - 2
app/RowGallery.xib

@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" 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">
         <adaptation id="fullscreen"/>
     </device>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
         <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>

+ 19 - 5
app/RowPastActivity.swift

@@ -26,15 +26,15 @@ Extension of UIView to be formatted as sections.
 */
 @IBDesignable class RowPastActivity: UIView {
 	
-	//This view
-	var v: UIView!
-	
 	// Outlets
 	@IBOutlet weak var container: UIView!
 	@IBOutlet weak var title: UILabel!
 	@IBOutlet weak var image: UIImageView!
 	@IBOutlet weak var descript: UILabel!
 	
+	// Activity ID
+	var id = -1
+	
 	/**
 	Default constructor
 	*/
@@ -70,6 +70,11 @@ Extension of UIView to be formatted as sections.
 		self.container.frame = self.bounds
 		self.addSubview(self.container)
 		
+		// Set tap recognizer
+		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 (_:)))
@@ -120,12 +125,21 @@ Extension of UIView to be formatted as sections.
 		}
 	}
 	
+	/**
+	Opens an album.
+	*/
+	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){
+	/*func openActivity(_ sender:UITapGestureRecognizer? = nil){
 		// TODO: Implement openActivity.
 		NSLog(":ROW_PAST_ACTIVITY:DEBUG: open activity")
-	}
+	}*/
 }

+ 30 - 0
app/ViewController.swift

@@ -91,6 +91,29 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	}
 	
 	
+	/**
+	Shows a past activity.
+	:param: id The activity id.
+	*/
+	func showPastActivity(id: Int){
+		NSLog(":CONTROLLER:DEBUG: Showing past activity \(id)")
+		self.passId = id
+		performSegue(withIdentifier: "SeguePastActivity", sender: nil)
+	}
+	
+	
+	/**
+	Shows a future activity.
+	:param: id The activity id.
+	*/
+	func showFutureActivity(id: Int){
+		NSLog(":CONTROLLER:DEBUG: Showing future activity \(id)")
+		self.passId = id
+		// TODO
+		//performSegue(withIdentifier: "SegueFutureActivity", sender: nil)
+	}
+	
+	
 	/**
 	Shows an album.
 	:param: id The album id.
@@ -162,6 +185,13 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		if segue.identifier == "SegueSync"{
 			self.syncSegue = segue
 		}
+		if segue.identifier == "SeguePastActivity"{
+			(segue.destination as! PastActivityViewController).id = passId
+		}
+		if segue.identifier == "SegueFutureActivity"{
+			// TODO
+			//(segue.destination as! FutureActivityViewController).id = passId
+		}
 	}
 	
 	override func viewWillAppear(_ animated: Bool) {