Explorar el Código

Merge branch 'BaseProject'

Iñigo Valentin hace 9 años
padre
commit
3190674f8d
Se han modificado 6 ficheros con 364 adiciones y 39 borrados
  1. 38 0
      MenuCollectionViewCell.swift
  2. 2 2
      app/Base.lproj/Main.storyboard
  3. 95 4
      app/HomeView.swift
  4. 195 10
      app/HomeView.xib
  5. 20 14
      app/Sync.swift
  6. 14 9
      app/ViewController.swift

+ 38 - 0
MenuCollectionViewCell.swift

@@ -20,6 +20,8 @@
 
 import UIKit
 
+private let highlightedColor = UIColor(rgb: 0xD8D8D8)
+
 /**
  Extension of UICollectionViewCell for the main menu.
  */
@@ -28,4 +30,40 @@ class MenuCollectionViewCell: UICollectionViewCell {
 	@IBOutlet weak var label: UILabel!
  
 	@IBOutlet weak var bar: UIView!
+	
+	var shouldTintBackgroundWhenSelected = true // You can change default value
+	var specialHighlightedArea: UIView?
+	
+	override var isHighlighted: Bool { // make lightgray background show immediately
+		willSet {
+			onSelected(newValue)
+		}
+	}
+	override var isSelected: Bool { // keep lightGray background until unselected
+		willSet {
+			onSelected(newValue)
+		}
+	}
+	func onSelected(_ newValue: Bool) {
+		//self.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
+		//self.label.font = UIFont.boldSystemFont(ofSize: self.label.font.pointSize)
+		guard selectedBackgroundView == nil else { return }
+		if newValue == true {
+			//contentView.backgroundColor = newValue ? highlightedColor : UIColor.clear
+			self.bar.backgroundColor = UIColor(red: 148/255, green: 209/255, blue: 255/255, alpha: 1)
+			self.label.font = UIFont.boldSystemFont(ofSize: self.label.font.pointSize)
+			self.label.textColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)
+		}
+		else{
+			self.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
+			self.label.font = UIFont.systemFont(ofSize: self.label.font.pointSize)
+			self.label.textColor = UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 1)
+		}
+	}
+}
+
+extension UIColor {
+	convenience init(rgb: Int, alpha: CGFloat = 1.0) {
+		self.init(red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0, green: CGFloat((rgb & 0xFF00) >> 8) / 255.0, blue: CGFloat(rgb & 0xFF) / 255.0, alpha: alpha)
+	}
 }

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

@@ -85,12 +85,12 @@
                                                         <constraint firstAttribute="width" constant="100" id="eKL-ga-53F"/>
                                                     </constraints>
                                                     <fontDescription key="fontDescription" type="system" pointSize="17"/>
-                                                    <color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+                                                    <color key="textColor" red="0.78431372549019607" green="0.78431372549019607" blue="0.78431372549019607" alpha="1" colorSpace="calibratedRGB"/>
                                                     <nil key="highlightedColor"/>
                                                 </label>
                                                 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ZNu-9N-o6K">
                                                     <rect key="frame" x="4" y="38" width="92" height="4"/>
-                                                    <color key="backgroundColor" red="0.80000000000000004" green="0.80000000000000004" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+                                                    <color key="backgroundColor" red="0.3529411764705882" green="0.70588235294117641" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                                                     <constraints>
                                                         <constraint firstAttribute="height" constant="4" id="Si5-HX-bjR"/>
                                                     </constraints>

+ 95 - 4
app/HomeView.swift

@@ -29,9 +29,12 @@ class HomeView: UIView {
 	// Outlets
 	@IBOutlet weak var scrollView: UIScrollView!
 	@IBOutlet weak var container: UIView!
+	@IBOutlet weak var locationMessage: UILabel!
+	@IBOutlet weak var lablancaImage: UIImageView!
+	@IBOutlet weak var lablancaText: UILabel!
 	
 	//Each of the sections of the view.
-	@IBOutlet weak var locationSection: Section!
+	@IBOutlet weak var locationSection: UIView!
 	@IBOutlet weak var lablancaSection: Section!
 	@IBOutlet weak var futureActivitiesSection: Section!
 	@IBOutlet weak var blogSection: Section!
@@ -43,6 +46,8 @@ class HomeView: UIView {
 	var delegate: AppDelegate? = nil
 	var lang: String? = nil
 	var locationTimer: Timer? = nil
+	var controller: ViewController
+	var storyboard: UIStoryboard
 	
 	
 	/**
@@ -50,6 +55,8 @@ class HomeView: UIView {
 	:param: frame View frame.
 	*/
 	override init(frame: CGRect){
+		self.storyboard = UIStoryboard(name: "Main", bundle: nil)
+		self.controller = storyboard.instantiateViewController(withIdentifier: "GMViewController") as! ViewController
 		super.init(frame: frame)
 		
 	}
@@ -60,6 +67,8 @@ class HomeView: UIView {
 	*/
 	required init?(coder aDecoder: NSCoder) {
 		
+		self.storyboard = UIStoryboard(name: "Main", bundle: nil)
+		self.controller = storyboard.instantiateViewController(withIdentifier: "GMViewController") as! ViewController
 		super.init(coder: aDecoder)
 		
 		//Load the contents of the HomeView.xib file.
@@ -68,8 +77,6 @@ class HomeView: UIView {
 		container.frame = self.bounds
 		
 		//Set titles for each section
-		locationSection.setTitle(text: "Encuéntranos")
-		lablancaSection.setTitle(text: "La Blanca")
 		futureActivitiesSection.setTitle(text: "Próximas actividades")
 		blogSection.setTitle(text: "Últimos posts")
 		gallerySection.setTitle(text: "Últimas fotos")
@@ -131,13 +138,30 @@ class HomeView: UIView {
 	If no location is reported, it hiddes the section.
 	*/
 	func setUpLocation(){
+		// TODO: Also set up tap recognizer.
 		let defaults = UserDefaults.standard
 		if (defaults.value(forKey: "GMLocLat") != nil && defaults.value(forKey: "GMLocLon") != nil){
+			let lat = defaults.value(forKey: "GMLocLat") as! Double
+			let lon = defaults.value(forKey: "GMLocLon") as! Double
 			let time = defaults.value(forKey: "GMLocTime") as! Date
 			let cTime = Date()
 			let minutes = Calendar.current.dateComponents([.minute], from: time, to: cTime).minute
 			if (minutes! < 30){
 				self.locationSection.isHidden = false
+				let location = self.controller.getLocation()
+				if location != nil {
+					let d: Int = calculateDistance(lat1: location.latitude, lon1: location.longitude, lat2: lat, lon2: lon)
+					
+					if d <= 1000 {
+						self.locationMessage.text = "¡Gasteizko Margolariak está por ahí! A \(d) metros de ti."
+					}
+					else{
+						self.locationMessage.text = "¡Gasteizko Margolariak está por ahí! A \(Int(d/1000)) kilómetros de ti."
+					}
+				}
+				else{
+					self.locationMessage.text = "¡Gasteizko Margolariak está por ahí!"
+				}
 			}
 			else{
 				self.locationSection.isHidden = true
@@ -157,11 +181,44 @@ class HomeView: UIView {
 	:param: lang Language code (two letter code, lowercase. Only 'es', 'en' and 'eu' supported).
 	*/
 	func setUpLablanca(context : NSManagedObjectContext, delegate: AppDelegate, lang: String){
+		
+		// TODO set listener.
 		let defaults = UserDefaults.standard
 		if (defaults.value(forKey: "festivals") != nil){
 			let festivals = defaults.value(forKey: "festivals") as! Int
 			if festivals == 1{
-				// TODO Actualy show something
+				// TODO: Get current year
+				let year = 2017
+				
+				// Get info about festivals
+				let fetchRequest: NSFetchRequest<Festival> = Festival.fetchRequest()
+				fetchRequest.predicate = NSPredicate(format: "year = %i", year)
+				
+				do {
+					
+					// Get info from festivals
+					let searchResults = try context.fetch(fetchRequest)
+					
+					if searchResults.count > 0 {
+						let r = searchResults[0]
+						
+						// Set image and text
+						self.lablancaText.text = (r.value(forKey: "text_\(lang)") as! String?)?.decode().stripHtml()
+						let filename: String = r.value(forKey: "img") as! String
+						if (filename == ""){
+							// Hide the imageview
+							self.lablancaImage.isHidden = true;
+						}
+						else{
+							let path = "img/blog/thumb/\(filename)"
+							self.lablancaImage.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
+						}
+					}
+					
+				}
+				catch {
+					NSLog(":LABLANCA:ERROR: Error getting festivals info: \(error)")
+				}
 			}
 			else{
 				self.lablancaSection.isHidden = true
@@ -430,6 +487,40 @@ class HomeView: UIView {
 	}
 	
 	
+	/**
+	Converts degrees to radians.
+	:params: degrees Angle in degrees.
+	:return: Angle in radians.
+	*/
+	func degreesToRadians(degrees: Double) -> Double {
+		return degrees * Double.pi / 180;
+	}
+	
+	
+	/**
+	Calculates the distance between two coordinates.
+	:param: lat1 Latitude of the first coordinate.
+	:param: lon1 Longitude of the first coordinate.
+	:param: lat2 Latitude of the second coordinate.
+	:param: lon2 Longitude of the second coordinate.
+	:return: Distance between the points, in meters.
+	*/
+	func calculateDistance(lat1: Double, lon1: Double, lat2: Double, lon2: Double) -> Int {
+		let eRadius: Double = 6371
+		
+		let dLat: Double = degreesToRadians(degrees: lat2-lat1)
+		let dLon: Double = degreesToRadians(degrees: lon2-lon1)
+		
+		let l1: Double = degreesToRadians(degrees: lat1)
+		let l2: Double = degreesToRadians(degrees: lat2)
+		
+		let a: Double = sin(dLat/2) * sin(dLat/2) + sin(dLon/2) * sin(dLon/2) * cos(l1) * cos(l2)
+		let c: Double = 2 * atan2(sqrt(a), sqrt(1-a))
+		let m: Double = eRadius * c * 1000
+		return Int(m)
+	}
+	
+	
 	/**
 	Opens a post.
 	*/

+ 195 - 10
app/HomeView.xib

@@ -15,7 +15,10 @@
                 <outlet property="container" destination="iN0-l3-epB" id="cfT-rm-jA0"/>
                 <outlet property="futureActivitiesSection" destination="FQo-nm-4Mo" id="TAU-5k-Sc5"/>
                 <outlet property="gallerySection" destination="v6A-Ya-esA" id="TPS-Ut-DK1"/>
+                <outlet property="lablancaImage" destination="gkF-He-baV" id="pCZ-g7-TMf"/>
                 <outlet property="lablancaSection" destination="9nu-j1-wGI" id="3eu-wW-jM4"/>
+                <outlet property="lablancaText" destination="YsW-Bq-7gd" id="Oce-9m-0Io"/>
+                <outlet property="locationMessage" destination="JXP-eW-H8r" id="fic-KB-N90"/>
                 <outlet property="locationSection" destination="Ljm-NP-c4e" id="bCD-0M-vqb"/>
                 <outlet property="pastActivitiesSection" destination="fZk-r1-Tca" id="U8D-Sh-TpR"/>
                 <outlet property="scrollView" destination="Poy-ba-9jX" id="PyU-Nb-kOS"/>
@@ -31,25 +34,203 @@
                     <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
                     <subviews>
                         <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" axis="vertical" alignment="center" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="gOz-rr-CeQ">
-                            <rect key="frame" x="0.0" y="0.0" width="320" height="930"/>
+                            <rect key="frame" x="0.0" y="0.0" width="320" height="1144"/>
                             <subviews>
-                                <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ljm-NP-c4e" customClass="Section" customModule="app">
-                                    <rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
+                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ljm-NP-c4e">
+                                    <rect key="frame" x="0.0" y="0.0" width="320" height="157"/>
+                                    <subviews>
+                                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ZvF-yV-TQm" userLabel="LocationContainer">
+                                            <rect key="frame" x="10" y="9.5" width="300" height="137"/>
+                                            <subviews>
+                                                <textView clipsSubviews="YES" multipleTouchEnabled="YES" userInteractionEnabled="NO" contentMode="scaleToFill" bounces="NO" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" editable="NO" text="Encuéntranos" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="xcx-xq-doc">
+                                                    <rect key="frame" x="0.0" y="0.0" width="300" height="27"/>
+                                                    <color key="backgroundColor" red="0.0" green="0.47058823529999999" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="27" id="GLS-4B-sku"/>
+                                                    </constraints>
+                                                    <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                                    <fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
+                                                    <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
+                                                </textView>
+                                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qqh-sw-MbH" userLabel="Entry">
+                                                    <rect key="frame" x="10" y="37" width="280" height="90"/>
+                                                    <subviews>
+                                                        <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PinpointGM" translatesAutoresizingMaskIntoConstraints="NO" id="HgA-hw-nFb">
+                                                            <rect key="frame" x="10" y="19.5" width="40" height="50"/>
+                                                            <constraints>
+                                                                <constraint firstAttribute="width" constant="40" id="LL7-qW-58P"/>
+                                                                <constraint firstAttribute="height" constant="50" id="Ye3-b8-p9O"/>
+                                                            </constraints>
+                                                        </imageView>
+                                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="¡Gasteizko Margolariak está por ahí!" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JXP-eW-H8r" userLabel="Text">
+                                                            <rect key="frame" x="65" y="10" width="205" height="70"/>
+                                                            <constraints>
+                                                                <constraint firstAttribute="height" constant="70" id="EF3-nL-xJE"/>
+                                                            </constraints>
+                                                            <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                                            <nil key="textColor"/>
+                                                            <nil key="highlightedColor"/>
+                                                        </label>
+                                                    </subviews>
+                                                    <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+                                                    <constraints>
+                                                        <constraint firstItem="HgA-hw-nFb" firstAttribute="leading" secondItem="qqh-sw-MbH" secondAttribute="leading" constant="10" id="K2O-i3-xXX"/>
+                                                        <constraint firstItem="HgA-hw-nFb" firstAttribute="centerY" secondItem="qqh-sw-MbH" secondAttribute="centerY" id="KM1-Yd-1CZ"/>
+                                                        <constraint firstItem="JXP-eW-H8r" firstAttribute="height" secondItem="qqh-sw-MbH" secondAttribute="height" constant="-20" id="KPu-k0-bCe"/>
+                                                        <constraint firstItem="JXP-eW-H8r" firstAttribute="leading" secondItem="HgA-hw-nFb" secondAttribute="trailing" constant="15" id="aTU-Xn-urr"/>
+                                                        <constraint firstAttribute="trailing" secondItem="JXP-eW-H8r" secondAttribute="trailing" constant="10" id="gOz-7L-IQ6"/>
+                                                        <constraint firstItem="JXP-eW-H8r" firstAttribute="centerY" secondItem="qqh-sw-MbH" secondAttribute="centerY" id="yEV-Vl-cMY"/>
+                                                    </constraints>
+                                                    <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"/>
+                                            <constraints>
+                                                <constraint firstItem="xcx-xq-doc" firstAttribute="top" secondItem="ZvF-yV-TQm" secondAttribute="top" id="1Hp-p6-gXS"/>
+                                                <constraint firstItem="qqh-sw-MbH" firstAttribute="width" secondItem="ZvF-yV-TQm" secondAttribute="width" constant="-20" id="FS5-DP-F6y"/>
+                                                <constraint firstItem="xcx-xq-doc" firstAttribute="centerX" secondItem="ZvF-yV-TQm" secondAttribute="centerX" id="Xq6-tK-aZf"/>
+                                                <constraint firstAttribute="bottom" secondItem="qqh-sw-MbH" secondAttribute="bottom" constant="10" id="gAr-Ar-e57"/>
+                                                <constraint firstItem="qqh-sw-MbH" firstAttribute="top" secondItem="xcx-xq-doc" secondAttribute="bottom" constant="10" id="kOJ-wR-oGj"/>
+                                                <constraint firstItem="xcx-xq-doc" firstAttribute="width" secondItem="ZvF-yV-TQm" secondAttribute="width" id="ldg-HY-G9g"/>
+                                                <constraint firstItem="qqh-sw-MbH" firstAttribute="centerX" secondItem="ZvF-yV-TQm" secondAttribute="centerX" id="llP-Al-gqL"/>
+                                            </constraints>
+                                            <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>
+                                    <constraints>
+                                        <constraint firstItem="ZvF-yV-TQm" firstAttribute="width" secondItem="Ljm-NP-c4e" secondAttribute="width" constant="-20" id="A3M-1s-2gK"/>
+                                        <constraint firstItem="ZvF-yV-TQm" firstAttribute="centerY" secondItem="Ljm-NP-c4e" secondAttribute="centerY" id="ZQZ-8v-OrW"/>
+                                        <constraint firstItem="ZvF-yV-TQm" firstAttribute="centerX" secondItem="Ljm-NP-c4e" secondAttribute="centerX" id="jhS-6W-MWI"/>
+                                        <constraint firstItem="ZvF-yV-TQm" firstAttribute="height" secondItem="Ljm-NP-c4e" secondAttribute="height" constant="-20" id="nie-wn-NTt"/>
+                                    </constraints>
+                                    <userDefinedRuntimeAttributes>
+                                        <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                            <real key="value" value="0.0"/>
+                                        </userDefinedRuntimeAttribute>
+                                        <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                            <real key="value" value="0.0"/>
+                                        </userDefinedRuntimeAttribute>
+                                    </userDefinedRuntimeAttributes>
                                 </view>
-                                <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9nu-j1-wGI" customClass="Section" customModule="app">
-                                    <rect key="frame" x="0.0" y="60" width="320" height="50"/>
+                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9nu-j1-wGI">
+                                    <rect key="frame" x="0.0" y="167" width="320" height="157"/>
+                                    <subviews>
+                                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="RyS-ln-grn" userLabel="LablancaContainer">
+                                            <rect key="frame" x="9.5" y="10" width="300" height="137"/>
+                                            <subviews>
+                                                <textView clipsSubviews="YES" multipleTouchEnabled="YES" userInteractionEnabled="NO" contentMode="scaleToFill" bounces="NO" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" editable="NO" text="La Blanca" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="ftX-qb-57S">
+                                                    <rect key="frame" x="0.0" y="0.0" width="300" height="27"/>
+                                                    <color key="backgroundColor" red="0.0" green="0.47058823529999999" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="27" id="oV8-jh-6e5"/>
+                                                    </constraints>
+                                                    <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                                    <fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
+                                                    <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
+                                                </textView>
+                                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fBq-qg-fz9" userLabel="Entry">
+                                                    <rect key="frame" x="10" y="37" width="280" height="90"/>
+                                                    <subviews>
+                                                        <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="gkF-He-baV">
+                                                            <rect key="frame" x="10" y="9.5" width="70" height="70"/>
+                                                            <constraints>
+                                                                <constraint firstAttribute="width" constant="70" id="ChM-hX-OnO"/>
+                                                                <constraint firstAttribute="height" constant="70" id="hNg-Je-ufU"/>
+                                                            </constraints>
+                                                        </imageView>
+                                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="¡Gasteizko Margolariak está por ahí!" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YsW-Bq-7gd" userLabel="Text">
+                                                            <rect key="frame" x="95" y="10" width="175" height="70"/>
+                                                            <constraints>
+                                                                <constraint firstAttribute="height" constant="70" id="Txi-or-Pra"/>
+                                                            </constraints>
+                                                            <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                                            <nil key="textColor"/>
+                                                            <nil key="highlightedColor"/>
+                                                        </label>
+                                                    </subviews>
+                                                    <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+                                                    <constraints>
+                                                        <constraint firstItem="gkF-He-baV" firstAttribute="centerY" secondItem="fBq-qg-fz9" secondAttribute="centerY" id="Pi9-t0-oOa"/>
+                                                        <constraint firstAttribute="trailing" secondItem="YsW-Bq-7gd" secondAttribute="trailing" constant="10" id="VAj-dj-MLd"/>
+                                                        <constraint firstItem="YsW-Bq-7gd" firstAttribute="centerY" secondItem="fBq-qg-fz9" secondAttribute="centerY" id="jjq-4v-b9d"/>
+                                                        <constraint firstItem="gkF-He-baV" firstAttribute="leading" secondItem="fBq-qg-fz9" secondAttribute="leading" constant="10" id="jtF-UZ-btH"/>
+                                                        <constraint firstItem="YsW-Bq-7gd" firstAttribute="height" secondItem="fBq-qg-fz9" secondAttribute="height" constant="-20" id="uVT-PP-R5k"/>
+                                                        <constraint firstItem="YsW-Bq-7gd" firstAttribute="leading" secondItem="gkF-He-baV" secondAttribute="trailing" constant="15" id="zdn-rO-ngp"/>
+                                                    </constraints>
+                                                    <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"/>
+                                            <constraints>
+                                                <constraint firstItem="fBq-qg-fz9" firstAttribute="centerX" secondItem="RyS-ln-grn" secondAttribute="centerX" id="AqL-EH-Tjq"/>
+                                                <constraint firstItem="ftX-qb-57S" firstAttribute="centerX" secondItem="RyS-ln-grn" secondAttribute="centerX" id="FJ5-wt-uIa"/>
+                                                <constraint firstItem="fBq-qg-fz9" firstAttribute="top" secondItem="ftX-qb-57S" secondAttribute="bottom" constant="10" id="G4N-Ok-LJL"/>
+                                                <constraint firstItem="ftX-qb-57S" firstAttribute="top" secondItem="RyS-ln-grn" secondAttribute="top" id="SEd-7H-WX5"/>
+                                                <constraint firstItem="fBq-qg-fz9" firstAttribute="width" secondItem="RyS-ln-grn" secondAttribute="width" constant="-20" id="ay3-po-Etb"/>
+                                                <constraint firstItem="ftX-qb-57S" firstAttribute="width" secondItem="RyS-ln-grn" secondAttribute="width" id="kFI-rY-JTv"/>
+                                                <constraint firstAttribute="bottom" secondItem="fBq-qg-fz9" secondAttribute="bottom" constant="10" id="vka-uG-rAI"/>
+                                            </constraints>
+                                            <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>
+                                    <constraints>
+                                        <constraint firstItem="RyS-ln-grn" firstAttribute="height" secondItem="9nu-j1-wGI" secondAttribute="height" constant="-20" id="IVY-CC-5KF"/>
+                                        <constraint firstItem="RyS-ln-grn" firstAttribute="width" secondItem="9nu-j1-wGI" secondAttribute="width" constant="-20" id="Qen-Pe-Hql"/>
+                                        <constraint firstItem="RyS-ln-grn" firstAttribute="centerY" secondItem="9nu-j1-wGI" secondAttribute="centerY" id="TnC-Qy-tMy"/>
+                                        <constraint firstItem="RyS-ln-grn" firstAttribute="centerX" secondItem="9nu-j1-wGI" secondAttribute="centerX" id="wGj-v9-Ljw"/>
+                                    </constraints>
                                 </view>
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FQo-nm-4Mo" customClass="Section" customModule="app">
-                                    <rect key="frame" x="0.0" y="120" width="320" height="50"/>
+                                    <rect key="frame" x="0.0" y="334" width="320" height="50"/>
                                 </view>
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uHa-Mu-U68" customClass="Section" customModule="app">
-                                    <rect key="frame" x="0.0" y="180" width="320" height="50"/>
+                                    <rect key="frame" x="0.0" y="394" width="320" height="50"/>
                                 </view>
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="v6A-Ya-esA" customClass="Section" customModule="app" customModuleProvider="target">
-                                    <rect key="frame" x="0.0" y="240" width="320" height="200"/>
+                                    <rect key="frame" x="0.0" y="454" width="320" height="200"/>
                                 </view>
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fZk-r1-Tca" customClass="Section" customModule="app">
-                                    <rect key="frame" x="0.0" y="450" width="320" height="350"/>
+                                    <rect key="frame" x="0.0" y="664" width="320" height="350"/>
                                     <userDefinedRuntimeAttributes>
                                         <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
                                             <real key="value" value="0.0"/>
@@ -57,7 +238,7 @@
                                     </userDefinedRuntimeAttributes>
                                 </view>
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dgk-s8-xje" customClass="Section" customModule="app">
-                                    <rect key="frame" x="0.0" y="810" width="320" height="120"/>
+                                    <rect key="frame" x="0.0" y="1024" width="320" height="120"/>
                                 </view>
                             </subviews>
                             <color key="backgroundColor" red="1" green="1" blue="0.42787000868055558" alpha="1" colorSpace="calibratedRGB"/>
@@ -100,4 +281,8 @@
             <point key="canvasLocation" x="26" y="52"/>
         </view>
     </objects>
+    <resources>
+        <image name="PhotoPlaceholder" width="170" height="108"/>
+        <image name="PinpointGM" width="15" height="20"/>
+    </resources>
 </document>

+ 20 - 14
app/Sync.swift

@@ -121,14 +121,14 @@ class Sync{
 			var vrGallery: Int = 0
 			var vrBlanca: Int = 0
 			vrAll = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"all\":")! + 7, end : strVersions.indexOf(target : "}")!-2))!
-			strVersions = strVersions.subStr(start : strVersions.indexOf(target : ",\"")! + 1, end : strVersions.length - 1)
-			vrBlog = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"blog\":")! + 7, end : strVersions.indexOf(target : "}")!-2))!
-			strVersions = strVersions.subStr(start : strVersions.indexOf(target : ",\"")! + 1, end : strVersions.length - 1)
-			vrActivities = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"activities\":")! + 13, end : strVersions.indexOf(target : "}")!-2))!
-			strVersions = strVersions.subStr(start : strVersions.indexOf(target : ",\"")! + 1, end : strVersions.length - 1)
-			vrGallery = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"gallery\":")! + 10, end : strVersions.indexOf(target : "}")!-2))!
-			strVersions = strVersions.subStr(start : strVersions.indexOf(target : ",\"")! + 1, end : strVersions.length - 1)
-			vrBlanca = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"lablanca\":")! + 11, end : strVersions.indexOf(target : "}")!-2))!
+			strVersions = strVersions.subStr(start : strVersions.indexOf(target : ",")! + 1, end : strVersions.length - 1)
+			vrBlog = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"blog\":")! + 8, end : strVersions.indexOf(target : "}")!-2))!
+			strVersions = strVersions.subStr(start : strVersions.indexOf(target : ",")! + 1, end : strVersions.length - 1)
+			vrActivities = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"activities\":")! + 14, end : strVersions.indexOf(target : "}")!-2))!
+			strVersions = strVersions.subStr(start : strVersions.indexOf(target : ",")! + 1, end : strVersions.length - 1)
+			vrGallery = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"gallery\":")! + 11, end : strVersions.indexOf(target : "}")!-2))!
+			strVersions = strVersions.subStr(start : strVersions.indexOf(target : ",")! + 1, end : strVersions.length - 1)
+			vrBlanca = Int(strVersions.subStr(start : strVersions.indexOf(target : "\"lablanca\":")! + 12, end : strVersions.indexOf(target : "}")!-2))!
 			
 			let dataIdx = strData?.indexOf(target: "{\"data\"")
 			strData = strData!.subStr(start: dataIdx!, end: strData!.length - 1)
@@ -546,9 +546,9 @@ class Sync{
 			var str = entry
 			let id : Int = Int(str.subStr(start : str.indexOf(target : "\"id\":")! + 6, end : str.indexOf(target : ",\"")! - 2))!
 			
-			//Get activity
+			//Get post
 			str = str.subStr(start : str.indexOf(target : ",\"")! + 1, end : str.length - 1)
-			let post : String = str.subStr(start : str.indexOf(target : "\"post\":")! + 8, end : str.indexOf(target : ",\"")! - 2)
+			let post : Int = Int(str.subStr(start : str.indexOf(target : "\"post\":")! + 8, end : str.indexOf(target : ",\"")! - 2))!
 			
 			//Get text
 			str = str.subStr(start : str.indexOf(target : ",\"")! + 1, end : str.length - 1)
@@ -556,7 +556,7 @@ class Sync{
 			
 			//Get dtime
 			str = str.subStr(start : str.indexOf(target : ",\"")! + 1, end : str.length - 1)
-			dateFormatter.dateFormat = "yyyy-MM-dd"
+			dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
 			let dtime = dateFormatter.date(from : str.subStr(start : str.indexOf(target : "\"dtime\":")! + 9, end : str.indexOf(target : ",\"")! - 2))!
 			
 			//Get username
@@ -1811,11 +1811,17 @@ class Sync{
 
 			// Get day
 			// Special item, not in the sync content
-			dateFormatter.dateFormat = "yyyy-MM-dd"
-			var day = dateFormatter.date(from: str.subStr(start : str.indexOf(target : "\"start\":")! + 9, end : str.indexOf(target : ",\"")! - 11))!
+			dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
+			dateFormatter.calendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.ISO8601)! as Calendar
+			dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") as Locale!
+			//dateFormatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) as TimeZone!
+			dateFormatter.timeZone = NSTimeZone.local
+			var dayString = "\(str.subStr(start : str.indexOf(target : "\"start\":")! + 9, end : str.indexOf(target : ",\"")! - 11)) 00:00:00"
+			var day = dateFormatter.date(from: dayString)!
 			// If on the first hours of the next day...
 			let calendar = Calendar.current
-			let hours = calendar.component(.hour, from: day )
+			let hours = calendar.component(.hour, from: start )
+			
 			// ... the event belongs to the previous day.
 			if hours < 6{
 				day = Calendar.current.date(byAdding: .day, value: -1, to: day)!	

+ 14 - 9
app/ViewController.swift

@@ -239,9 +239,9 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		fetchLocation()
 		self.locationTimer = Timer.scheduledTimer(timeInterval: 90, target: self, selector: #selector(fetchLocation), userInfo: nil, repeats: true)
 				
-		//NSLog(":CONTROLLER:DEBUG: Don't skyp sync")
-		NSLog(":CONTROLLER:DEBUG: Skyp sync")
-		//Sync()
+		NSLog(":CONTROLLER:DEBUG: Don't skyp sync")
+		//NSLog(":CONTROLLER:DEBUG: Skyp sync")
+		Sync()
 
 		
 		self.delegate = UIApplication.shared.delegate as? AppDelegate
@@ -347,16 +347,18 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		cell.label.text = self.items[indexPath.item]
 		
 		//Mark the first cell as selected...
-		if indexPath.item == selected{
-			cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
+		/*if indexPath.item == selected{
+			cell.bar.backgroundColor = UIColor(red: 148/255, green: 209/255, blue: 255/255, alpha: 1)
 			cell.label.font = UIFont.boldSystemFont(ofSize: cell.label.font.pointSize)
+			cell.label.textColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)
 		}
 			
 		//... and the others as unselected
 		else{
-			cell.bar.backgroundColor = UIColor(red: 148/255, green: 209/255, blue: 255/255, alpha: 1)
+			cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
 			cell.label.font = UIFont.systemFont(ofSize: cell.label.font.pointSize)
-		}
+			cell.label.textColor = UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 1)
+		}*/
 		
 		return cell
 	}
@@ -373,9 +375,12 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	:param: selected Index of the selected item.
 	*/
 	@IBAction func showComponent(selected: Int) {
+		NSLog(":CONTROLLER:DEBUG: Selected: \(selected)")
 		//Activate label
 		var i = 0
-		for cell in sectionCollection.visibleCells as! [MenuCollectionViewCell]{ //TODO: Not only visibles!
+
+		
+		/*for cell in sectionCollection.visibleCells as! [MenuCollectionViewCell]{ //TODO: Not only visibles!
 			if i == selected + 1{
 				cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
 				cell.label.font = UIFont.boldSystemFont(ofSize: cell.label.font.pointSize)
@@ -386,7 +391,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 				
 			}
 			i = i + 1
-		}
+		}*/
 		
 		//Show the view
 		if selected == 0 {