Procházet zdrojové kódy

Past activities properly dispayed.

Iñigo Valentin před 9 roky
rodič
revize
69cab81165

+ 0 - 86
app/ActivitiesView.swift

@@ -38,9 +38,6 @@ class ActivitiesView: UIView {
 	var pastList: UIStackView? = nil
 	var pastList: UIStackView? = nil
 	var context: NSManagedObjectContext? = nil
 	var context: NSManagedObjectContext? = nil
 	
 	
-	// Section row list
-	var pastRows: Array<RowPastActivity> = []
-	var futureRows: Array<RowFutureActivity> = []
 	
 	
 	override init(frame: CGRect){
 	override init(frame: CGRect){
 		super.init(frame: frame)
 		super.init(frame: frame)
@@ -144,13 +141,6 @@ class ActivitiesView: UIView {
 					}
 					}
 				
 				
 					self.futureList?.addArrangedSubview(row)
 					self.futureList?.addArrangedSubview(row)
-					self.futureRows.append(row)
-					
-					// TODO: Do this on the row didLoad method
-					// Set tap recognizer
-					//let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openActivity(_:)))
-					//row.isUserInteractionEnabled = true
-					//row.addGestureRecognizer(tapRecognizer)
 				}
 				}
 				self.futureList?.setNeedsLayout()
 				self.futureList?.setNeedsLayout()
 				self.futureList?.layoutIfNeeded()
 				self.futureList?.layoutIfNeeded()
@@ -160,8 +150,6 @@ class ActivitiesView: UIView {
 		catch {
 		catch {
 			NSLog(":ACTIVITIES:ERROR: Error with request: \(error)")
 			NSLog(":ACTIVITIES:ERROR: Error with request: \(error)")
 		}
 		}
-		setUpFutureRowsTapRecognizers()
-		
 		
 		
 		
 		
 		// Show past activities
 		// Show past activities
@@ -214,13 +202,6 @@ class ActivitiesView: UIView {
 				
 				
 				
 				
 				self.pastList?.addArrangedSubview(row)
 				self.pastList?.addArrangedSubview(row)
-				self.pastRows.append(row)
-				
-				// TODO: Do this on the row didLoad method
-				// Set tap recognizer
-				//let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openActivity(_:)))
-				//row.isUserInteractionEnabled = true
-				//row.addGestureRecognizer(tapRecognizer)
 			}
 			}
 			self.pastList?.setNeedsLayout()
 			self.pastList?.setNeedsLayout()
 			self.pastList?.layoutIfNeeded()
 			self.pastList?.layoutIfNeeded()
@@ -229,76 +210,9 @@ class ActivitiesView: UIView {
 			NSLog(":ACTIVITIES:ERROR: Error with request: \(error)")
 			NSLog(":ACTIVITIES:ERROR: Error with request: \(error)")
 		}
 		}
 		
 		
-		//setUpPastRowsTapRecognizers()
 		NSLog(":ACTIVITIES:DEBUG: Finished loading ActivitiesView")
 		NSLog(":ACTIVITIES:DEBUG: Finished loading ActivitiesView")
 	}
 	}
 	
 	
-	
-	/*func openActivity(){//(_ sender:UITapGestureRecognizer? = nil){
-		NSLog(":ACTIVITIES:DEBUG: getting delegate and showing activity.")
-		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
-		delegate.controller?.showActivity(id: 4)
-		NSLog(":ACTIVITIES:DEBUG: Activity should be shown.")
-	}
-	
-	
-	func openActivity(_ sender:UITapGestureRecognizer? = nil){
-		NSLog(":ACTIVITIES:DEBUG: getting delegate and showing activity.")
-		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
-		delegate.controller?.showActivity(id: 4)
-		NSLog(":ACTIVITIES:DEBUG: Activity should be shown.")
-	}*/
-	
-	
-	/**
-	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.
 	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.
 	If the device has another language, Spanish will be selected by default.

+ 5 - 5
app/Base.lproj/Main.storyboard

@@ -1113,18 +1113,18 @@
                                                                     </label>
                                                                     </label>
                                                                     <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="LmH-0o-Hku" userLabel="Separator">
                                                                     <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="LmH-0o-Hku" userLabel="Separator">
                                                                         <rect key="frame" x="17" y="917" width="305.5" height="2"/>
                                                                         <rect key="frame" x="17" y="917" width="305.5" height="2"/>
-                                                                        <color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
+                                                                        <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                                                         <constraints>
                                                                         <constraints>
                                                                             <constraint firstAttribute="height" constant="2" id="X7n-cL-6Hk"/>
                                                                             <constraint firstAttribute="height" constant="2" id="X7n-cL-6Hk"/>
                                                                         </constraints>
                                                                         </constraints>
                                                                     </view>
                                                                     </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">
+                                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="254" text="Date" textAlignment="center" 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"/>
                                                                         <rect key="frame" x="17" y="929" width="305.5" height="20"/>
                                                                         <constraints>
                                                                         <constraints>
                                                                             <constraint firstAttribute="height" constant="20" id="8LF-YM-5Cn"/>
                                                                             <constraint firstAttribute="height" constant="20" id="8LF-YM-5Cn"/>
                                                                         </constraints>
                                                                         </constraints>
-                                                                        <fontDescription key="fontDescription" type="system" pointSize="17"/>
-                                                                        <nil key="textColor"/>
+                                                                        <fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
+                                                                        <color key="textColor" red="0.1529411765" green="0.33333333329999998" blue="0.45098039220000002" alpha="1" colorSpace="calibratedRGB"/>
                                                                         <nil key="highlightedColor"/>
                                                                         <nil key="highlightedColor"/>
                                                                     </label>
                                                                     </label>
                                                                 </subviews>
                                                                 </subviews>
@@ -1216,7 +1216,7 @@
                                 </userDefinedRuntimeAttributes>
                                 </userDefinedRuntimeAttributes>
                             </view>
                             </view>
                         </subviews>
                         </subviews>
-                        <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                        <color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <constraints>
                         <constraints>
                             <constraint firstItem="BxO-VS-eP5" firstAttribute="centerX" secondItem="SdM-pu-zm3" secondAttribute="centerX" id="0eo-Jq-yKG"/>
                             <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="JgN-DW-xUZ" firstAttribute="centerX" secondItem="SdM-pu-zm3" secondAttribute="centerX" id="XMm-11-4Bs"/>

+ 61 - 7
app/PastActivityViewController.swift

@@ -84,7 +84,7 @@ class PastActivityViewController: UIViewController, UIGestureRecognizerDelegate
 	*/
 	*/
 	public func loadActivity(id: Int){
 	public func loadActivity(id: Int){
 		
 		
-		NSLog(":POSTCONTROLLER:DEBUG: Loading post \(id)")
+		NSLog(":PASTACTIVITYCONTROLLER:DEBUG: Loading past activity \(id)")
 		
 		
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
@@ -99,18 +99,21 @@ class PastActivityViewController: UIViewController, UIGestureRecognizerDelegate
 			var sTitle: String
 			var sTitle: String
 			var sText: String
 			var sText: String
 			var image: String
 			var image: String
+			var date: NSDate
 			
 			
 			for r in searchResults as [NSManagedObject] {
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
 				count = count + 1
 				sTitle = r.value(forKey: "title_\(lang)")! as! String
 				sTitle = r.value(forKey: "title_\(lang)")! as! String
-				if (r.value(forKey: "after_\(lang)")! as! String).length == 0{
+				if (r.value(forKey: "after_\(lang)")! as! String).length != 0{
 					sText = r.value(forKey: "after_\(lang)")! as! String
 					sText = r.value(forKey: "after_\(lang)")! as! String
 				}
 				}
 				else{
 				else{
-					sText = r.value(forKey: "description_\(lang)")! as! String
+					sText = r.value(forKey: "text_\(lang)")! as! String
 				}
 				}
-				activityTitle.text = "  \(sTitle)"
-				activityText.text = sText.stripHtml()
+				date = r.value(forKey: "date")! as! NSDate
+				activityTitle.text = "  \(sTitle.decode().stripHtml())"
+				activityText.text = sText.decode().stripHtml()
+				activityDate.text = formatDate(date: date, lang: lang)
 				
 				
 				// Get main image
 				// Get main image
 				image = ""
 				image = ""
@@ -128,15 +131,66 @@ class PastActivityViewController: UIViewController, UIGestureRecognizerDelegate
 						self.activityImage.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 						self.activityImage.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 					}
 					}
 				} catch {
 				} catch {
-					NSLog(":POSTCONTROLLER:DEBUG: Error getting image for post \(id): \(error)")
+					NSLog(":PASTACTIVITYCONTROLLER:DEBUG: Error getting image for post \(id): \(error)")
 				}
 				}
 				
 				
 			}
 			}
 		} catch {
 		} catch {
-			NSLog(":POSTCONTROLLER:DEBUG: Error with request: \(error)")
+			NSLog(":PASTACTIVITYCONTROLLER:DEBUG: Error with request: \(error)")
 		}
 		}
 	}
 	}
 	
 	
+	
+	/**
+	Formats a date to the desired language.
+	:param: text The date.
+	:param: lang Device language (only 'es', 'en', or 'eu').
+	*/
+	func formatDate(date: NSDate, lang: String) -> String{
+		
+		let months_es = ["0index", "enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"]
+		let months_en = ["0index", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
+		let months_eu = ["0index", "urtarrilaren", "otsailaren", "martxoaren", "abrilaren", "maiatzaren", "ekainaren", "ustailaren", "abustuaren", "irailaren", "urriaren", "azaroaren", "abenduaren"]
+		let days_es = ["0index", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sábado", "Domingo"]
+		let days_en = ["0index", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
+		let days_eu = ["0index", "Astelehena", "Asteartea", "Asteazkena", "Osteguna", "Ostirala", "Larumbata", "Igandea"]
+		
+		let calendar = Calendar.current
+		let day = calendar.component(.day, from: date as Date)
+		let month = calendar.component(.month, from: date as Date)
+		let weekday = calendar.component(.weekday, from: date as Date)
+		var strDate = ""
+		
+		switch lang{
+		case "en":
+			
+			var dayNum = ""
+			switch day{
+			case 1:
+				dayNum = "1th"
+				break
+			case 2:
+				dayNum = "2nd"
+				break;
+			case 3:
+				dayNum = "3rd"
+				break;
+			default:
+				dayNum = "\(weekday)th"
+			}
+			
+			strDate = "\(days_en[weekday]), \(months_en[month]) \(dayNum)"
+			break
+		case "eu":
+			strDate = "\(days_eu[weekday]) \(months_eu[month]) \(day)an"
+			break
+		default:
+			strDate = "\(days_es[weekday]) \(day) de \(months_es[month])"
+		}
+		
+		return strDate
+	}
+	
 	/**
 	/**
 	Gets the device language. The only recognized languages are Spanish, English and Basque.
 	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.
 	If the device has another language, Spanish will be selected by default.