Explorar el Código

Merge branch 'BaseProject'

Iñigo Valentin hace 9 años
padre
commit
126783e6ab

+ 16 - 22
app/AlbumViewController.swift

@@ -146,7 +146,6 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 					var imgR = imgSearchResults[0]
 					image = imgR.value(forKey: "file")! as! String
 					leftId = imgR.value(forKey: "id")! as! Int
-					NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) left: \(image)")
 					row.setImage(idx: 0, filename: image)
 					if i + 1 < searchResults.count {
 						r = searchResults[i + 1]
@@ -159,15 +158,10 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 						imgR = imgSearchResults[0]
 						image = imgR.value(forKey: "file")! as! String
 						rightId = imgR.value(forKey: "id")! as! Int
-						NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) right: \(image)")
 						row.setImage(idx: 1, filename: image)
 					}
-					else{
-						NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) right: none")
-					}
-					//TODO create row, add images (L+R), add row to container.
-					//row.setImage(filename: image)
-				} catch {
+				}
+				catch {
 					NSLog(":GALLERYCONTROLLER:ERROR: Error getting image for post \(id): \(error)")
 				}
 				
@@ -183,6 +177,20 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 	}
 	
 	
+	/**
+	Run before performing a segue.
+	Assigns id if neccessary.
+	:param: segue The segue to perform.
+	:sender: The calling view.
+	*/
+	override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
+		if segue.identifier == "SeguePhotoAlbum"{
+			(segue.destination as! PhotoViewController).albumId = passAlbum
+			(segue.destination as! PhotoViewController).photoId = passId
+		}
+	}
+	
+	
 	/**
 	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.
@@ -199,20 +207,6 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 	}
 	
 	
-	/**
-	Run before performing a segue.
-	Assigns id if neccessary.
-	:param: segue The segue to perform.
-	:sender: The calling view.
-	*/
-	override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-		if segue.identifier == "SeguePhotoAlbum"{
-			(segue.destination as! PhotoViewController).albumId = passAlbum
-			(segue.destination as! PhotoViewController).photoId = passId
-		}
-	}
-	
-	
 	/**
 	Shows a photo.
 	:param: id The album id.

+ 1 - 12
app/AppDelegate.swift

@@ -29,6 +29,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 	var window: UIWindow?
 	var controller: ViewController?
 	var albumController: AlbumViewController?
+	var syncController: SyncController?
 
 	
 	func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
@@ -61,20 +62,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 		
 		let when = DispatchTime.now() + 120 // 2 minutes to perform the sync.
 		DispatchQueue.main.asyncAfter(deadline: when) {
-			NSLog(":BACKGROUND:LOG: Calling completion handler.")
 			completionHandler(UIBackgroundFetchResult.newData)
 		}
-		
-		/*if let tabBarController = window?.rootViewController as? UITabBarController, let viewControllers = tabBarController.viewControllers {
-			for viewController in viewControllers {
-				if let fetchViewController = viewController as? FetchViewController {
-					fetchViewController.fetch {
-						fetchViewController.updateUI()
-						completionHandler(.newData)
-					}
-				}
-			}
-		}*/
 	}
 
 

+ 12 - 8
app/Base.lproj/Main.storyboard

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="3o1-ab-AT4">
     <device id="retina4_7" orientation="portrait">
         <adaptation id="fullscreen"/>
     </device>
@@ -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>
@@ -198,7 +198,6 @@
                         <segue destination="UkS-wI-Yhx" kind="show" identifier="SeguePost" id="gs2-jd-cPW"/>
                         <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"/>
                         <segue destination="DDO-dI-c0J" kind="show" identifier="SegueFutureActivity" id="ec7-aO-4Ac"/>
                     </connections>
@@ -989,7 +988,7 @@
                                     <constraint firstAttribute="width" secondItem="dxh-Z0-luU" secondAttribute="height" multiplier="1:1" id="Bdr-NA-IH6"/>
                                 </constraints>
                             </imageView>
-                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sincronizando..." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="up0-1V-tTd">
+                            <label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sincronizando..." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="up0-1V-tTd">
                                 <rect key="frame" x="0.0" y="475" width="375" height="30"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="30" id="mIj-oN-tq7"/>
@@ -998,13 +997,16 @@
                                 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <nil key="highlightedColor"/>
                             </label>
-                            <progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="VkR-DT-y3S">
+                            <progressView hidden="YES" opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="VkR-DT-y3S">
                                 <rect key="frame" x="56.5" y="515" width="262.5" height="2"/>
                                 <color key="progressTintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <color key="trackTintColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
                             </progressView>
-                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Message" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pgU-dx-MvQ">
-                                <rect key="frame" x="56.5" y="525" width="262.5" height="18"/>
+                            <label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Message" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pgU-dx-MvQ">
+                                <rect key="frame" x="56.5" y="525" width="262.5" height="60"/>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="60" id="QWb-tU-jUd"/>
+                                </constraints>
                                 <fontDescription key="fontDescription" type="italicSystem" pointSize="15"/>
                                 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <nil key="highlightedColor"/>
@@ -1028,7 +1030,9 @@
                     </view>
                     <connections>
                         <outlet property="lb" destination="pgU-dx-MvQ" id="ATL-SS-rxd"/>
+                        <outlet property="lbTitle" destination="up0-1V-tTd" id="l37-DZ-jpR"/>
                         <outlet property="pb" destination="VkR-DT-y3S" id="NMd-7R-Rlc"/>
+                        <segue destination="BYZ-38-t0r" kind="showDetail" identifier="SegueInit" action="showViewController:sender:" id="kSh-cP-och"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="fRm-1Y-Xmm" userLabel="First Responder" sceneMemberID="firstResponder"/>

+ 3 - 3
app/BlogView.swift

@@ -62,7 +62,7 @@ class BlogView: UIView {
 		self.storyboard = UIStoryboard(name: "Main", bundle: nil)
 		self.controller = storyboard?.instantiateViewController(withIdentifier: "GMViewController") as! ViewController
 		self.context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
-		self.delegate = UIApplication.shared.delegate as! AppDelegate
+		self.delegate = UIApplication.shared.delegate as? AppDelegate
 		self.lang = getLanguage()
 		self.context?.persistentStoreCoordinator = delegate?.persistentStoreCoordinator
 		
@@ -95,7 +95,7 @@ class BlogView: UIView {
 			var text: String
 			var image: String
 			
-			for r in searchResults as! [NSManagedObject] {
+			for r in searchResults! {
 								
 				//Create a new row
 				row = RowBlog.init(s: "rowBlog\(count)", i: count)
@@ -116,7 +116,7 @@ class BlogView: UIView {
 				imgFetchRequest.fetchLimit = 1
 				do{
 					let imgSearchResults = try context?.fetch(imgFetchRequest)
-					for imgR in imgSearchResults as! [NSManagedObject]{
+					for imgR in imgSearchResults!{
 						image = imgR.value(forKey: "image")! as! String
 						row.setImage(filename: image)
 					}

+ 0 - 1
app/FetchLocation.swift

@@ -46,7 +46,6 @@ class FetchLocation{
 			}
 			let status = (response as! HTTPURLResponse).statusCode
 			
-			NSLog(":LOCATION:LOG: Response code \(status)")
 			if status == 200{
 			
 				guard let data = data else {

+ 0 - 1
app/FutureActivityViewController.swift

@@ -142,7 +142,6 @@ class FutureActivityViewController: UIViewController, UIGestureRecognizerDelegat
 				do {
 					let itiSearchResults = try context.fetch(itiFetchRequest)
 					if itiSearchResults.count == 0{
-						NSLog(":FUTUREACTIVITY:DEBUG: No itinerary for activity \(id)")
 						self.itineraryContainer.isHidden = true
 					}
 					else{

+ 0 - 3
app/GalleryView.swift

@@ -53,8 +53,6 @@ class GalleryView: UIView {
 		
 		super.init(coder: aDecoder)
 		
-		NSLog(":GALLERY:LOG: Init gallery section.")
-		
 		//Load the contents of the HomeView.xib file.
 		Bundle.main.loadNibNamed("GalleryView", owner: self, options: nil)
 		self.addSubview(container)
@@ -155,7 +153,6 @@ class GalleryView: UIView {
 		self.scrollView.contentSize.height = 2500 //CGFloat(h);
 		
 		self.setUpRowsTapRecognizers()
-		NSLog(":GALLERY:LOG: Finished loading gallery section.")
 	}
 	
 	

+ 1 - 1
app/HomeView.swift

@@ -221,7 +221,7 @@ class HomeView: UIView {
 							self.lablancaImage.isHidden = true;
 						}
 						else{
-							let path = "img/blog/thumb/\(filename)"
+							let path = "img/fiestas/thumb/\(filename)"
 							self.lablancaImage.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
 						}
 					}

+ 11 - 2
app/LablancaView.swift

@@ -57,8 +57,6 @@ class LablancaView: UIView {
 		
 		super.init(coder: aDecoder)
 		
-		NSLog(":LABLANCA:LOG: Init lablanca section.")
-
 		Bundle.main.loadNibNamed("LablancaView", owner: self, options: nil)
 		self.addSubview(container)
 		self.container.frame = self.bounds
@@ -108,6 +106,17 @@ class LablancaView: UIView {
 			
 				// Set description
 				self.fText.text = (r.value(forKey: "text_\(lang)") as! String?)?.decode().stripHtml()
+				
+				// Set image
+				let filename: String = r.value(forKey: "img") as! String
+				if (filename == ""){
+					// Hide the imageview
+					self.fImage.isHidden = true;
+				}
+				else{
+					let path = "img/fiestas/thumb/\(filename)"
+					self.fImage.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
+				}
 			}
 
 		}

+ 0 - 1
app/LocationView.swift

@@ -92,7 +92,6 @@ class LocationView: UIView {
 	Get new location
 	*/
 	func getNewLocation(){
-		NSLog(":LOCATION:LOG: Recalculating location.")
 		let defaults = UserDefaults.standard
 		if (defaults.value(forKey: "GMLocLat") != nil && defaults.value(forKey: "GMLocLon") != nil){
 			let lat = defaults.value(forKey: "GMLocLat") as! Double

+ 3 - 3
app/LocationView.xib

@@ -36,7 +36,7 @@
                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3aZ-8G-e8X" userLabel="Entry">
                             <rect key="frame" x="10" y="43" width="335" height="594"/>
                             <subviews>
-                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="La cuadrilla está por ahí!" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jwp-Sd-GF5" userLabel="Title">
+                                <label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="La cuadrilla está por ahí!" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jwp-Sd-GF5" userLabel="Title">
                                     <rect key="frame" x="10" y="10" width="315" height="22"/>
                                     <constraints>
                                         <constraint firstAttribute="height" constant="22" id="JQk-vd-DLN"/>
@@ -45,7 +45,7 @@
                                     <color key="textColor" red="0.1529411765" green="0.33333333329999998" blue="0.45098039220000002" alpha="1" colorSpace="calibratedRGB"/>
                                     <nil key="highlightedColor"/>
                                 </label>
-                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lB5-i1-GOe" userLabel="Message">
+                                <label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lB5-i1-GOe" userLabel="Message">
                                     <rect key="frame" x="11.5" y="42" width="311" height="21"/>
                                     <constraints>
                                         <constraint firstAttribute="height" constant="21" id="ann-h3-NzS"/>
@@ -60,7 +60,7 @@
                                     <nil key="textColor"/>
                                     <nil key="highlightedColor"/>
                                 </label>
-                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="guk-vu-ykd" customClass="GMSMapView">
+                                <view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="guk-vu-ykd" customClass="GMSMapView">
                                     <rect key="frame" x="10" y="73" width="315" height="492"/>
                                     <color key="backgroundColor" red="1" green="0.20334201390000001" blue="0.32001410590000001" alpha="1" colorSpace="calibratedRGB"/>
                                     <userDefinedRuntimeAttributes>

+ 1 - 1
app/Notifications.swift

@@ -71,8 +71,8 @@ class Notifications{
 			}
 			
 			let strData: String = String(data:data, encoding: String.Encoding.utf8)!
-			NSLog(":NOTIFICATION:LOG: Data received: \(strData)")
 			if strData.length > 0{
+				NSLog(":NOTIFICATION:LOG: Notifications received.")
 				let dataNotification: [String] = self.getData(data: strData)
 				self.saveNotifications(entries: dataNotification)
 			}

+ 0 - 1
app/PhotoViewController.swift

@@ -164,7 +164,6 @@ class PhotoViewController: UIViewController, UIGestureRecognizerDelegate {
 			let searchResults = try context.fetch(fetchRequest)
 			
 			var sTitle: String
-			var sText: String
 			var image: String
 			var date: NSDate
 			

+ 1 - 1
app/RowAlbum.swift

@@ -53,7 +53,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 		
 		self.frame = self.bounds
 		self.autoresizingMask = [.flexibleWidth, .flexibleHeight]

+ 1 - 1
app/RowBlog.swift

@@ -51,7 +51,7 @@ Extension of UIView to be formatted as post rows.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first as! UIView
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowFutureActivity.swift

@@ -54,7 +54,7 @@ Extension of UIView to be formatted as future activity rows.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowGallery.swift

@@ -55,7 +55,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowHomeGallery.swift

@@ -52,7 +52,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first as! UIView
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowHomePastActivities.swift

@@ -51,7 +51,7 @@ Extension of UIView to be formatted as past activity rows.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowHomeSocial.swift

@@ -56,7 +56,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	/**

+ 1 - 1
app/RowItinerary.swift

@@ -50,7 +50,7 @@ Extension of UIView to be formatted an activity itinerary.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowLabel.swift

@@ -46,7 +46,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowLablancaDay.swift

@@ -49,7 +49,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 		
 		self.frame = self.bounds
 		self.autoresizingMask = [.flexibleWidth, .flexibleHeight]

+ 1 - 1
app/RowLablancaOffer.swift

@@ -48,7 +48,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 		
 		self.frame = self.bounds
 		self.autoresizingMask = [.flexibleWidth, .flexibleHeight]

+ 1 - 1
app/RowSchedule.swift

@@ -49,7 +49,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 2 - 2
app/ScheduleViewController.swift

@@ -259,7 +259,7 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 			for r in searchResults! {
 				
 				title = r.value(forKey: "title_\(lang!)") as! String
-				if let tx = r.value(forKey: "description_\(lang!)"){
+				if r.value(forKey: "description_\(lang!)") != nil{
 					text = r.value(forKey: "description_\(lang!)") as! String
 				}
 				else{
@@ -279,7 +279,7 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 				locationFetchRequest.fetchLimit = 1
 				do{
 					var locationSearchResults = try self.context?.fetch(locationFetchRequest)
-					var locationR = locationSearchResults?[0]
+					let locationR = locationSearchResults?[0]
 					location = locationR?.value(forKey: "name_\(lang!)")! as! String
 					
 					row.setLocation(text: location)

+ 8 - 46
app/Sync.swift

@@ -33,7 +33,7 @@ class Sync{
 	var vGallery: Int = 0
 	var vBlanca: Int = 0
 	var vAll: Int = 0
-	
+		
 	/**
 	Starts the sync process.
 	Always asynchronously.
@@ -51,6 +51,7 @@ class Sync{
 		if synchronous == true{
 			NSLog(":SYNC:LOG: Synchronous sync started.")
 			self.initial = true
+			
 		}
 		let url = buildUrl();
 		sync(url: url)
@@ -94,6 +95,8 @@ class Sync{
 	func sync(url: URL){
 		
 		NSLog(":SYNC:LOG: Sync started.")
+		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+		delegate.syncController?.nowSyncing = true
 		
 		//Synchronously get data
 		let task = URLSession.shared.dataTask(with: url) { data, response, error in
@@ -198,8 +201,10 @@ class Sync{
 			// If it's the initial sync, hide the segue
 			if self.initial == true{
 				NSLog(":SYNC:LOG: Finishing synchronous sync.")
+				//let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
+				//delegate.syncController?.startApp()
 				let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
-				delegate.controller?.initialSync(showScreen: false)
+				delegate.syncController?.nowSyncing = false
 			}
 		}
 		
@@ -216,7 +221,6 @@ class Sync{
 	func getTable(data: String, table: String) -> [String]{
 		//Does the table exists?
 		if data.indexOf(target: "\"\(table)\":[") == nil{
-			NSLog(":SYNC:LOG: Empty table: \(table).")
 			return [String]()
 		}
 		let iS : Int? = data.indexOf(target: "\"\(table)\":[")
@@ -232,8 +236,6 @@ class Sync{
 		entries[0] = entries[0].subStr(start: 1, end: entries[0].length - 1)
 		entries[entries.count - 1] = entries[entries.count - 1].subStr(start: 0, end: entries[entries.count - 1].length - 2)
 		
-		NSLog(":SYNC:LOG: Table \(table) has \(entries.count) rows.")
-		
 		//Return the array
 		return entries
 	}
@@ -245,8 +247,6 @@ class Sync{
 	*/
 	func saveTablePlace(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Place.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -339,8 +339,6 @@ class Sync{
 	*/
 	func saveTablePeople(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table People.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -409,8 +407,6 @@ class Sync{
 	*/
 	func saveTablePost(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Post.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -514,8 +510,6 @@ class Sync{
 	*/
 	func saveTablePostComment(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Post_comment.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -593,8 +587,6 @@ class Sync{
 	*/
 	func saveTablePostImage(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Post_image.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -657,8 +649,6 @@ class Sync{
 	*/
 	func saveTablePostTag(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Post_tag.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -711,8 +701,6 @@ class Sync{
 	*/
 	func saveTableActivity(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Activity.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -869,8 +857,6 @@ class Sync{
 	*/
 	func saveTableActivityComment(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Activity_comment.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -948,8 +934,6 @@ class Sync{
 	*/
 	func saveTableActivityImage(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Activity_image.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -1012,8 +996,6 @@ class Sync{
 	*/
 	func saveTableActivityTag(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Activity_tag.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -1067,8 +1049,6 @@ class Sync{
 	//CHECK: New (and probably better format than the others.)
 	func saveTableActivityItinerary(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Activity_itinerary.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -1179,8 +1159,6 @@ class Sync{
 	*/
 	func saveTableAlbum(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Album.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -1275,8 +1253,6 @@ class Sync{
 	*/
 	func saveTablePhoto(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Photo.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -1392,8 +1368,6 @@ class Sync{
 	*/
 	func saveTablePhotoAlbum(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Photo_album.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -1450,8 +1424,6 @@ class Sync{
 	*/
 	func saveTableFestival(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Festival.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -1540,8 +1512,6 @@ class Sync{
 	*/
 	func saveTableFestivalDay(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table FestivalDay.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -1619,8 +1589,6 @@ class Sync{
 	*/
 	func saveTableFestivalOffer(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table FestivalOffer.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -1720,8 +1688,6 @@ class Sync{
 	*/
 	func saveTableFestivalEvent(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table FestivalEvent.")
-		
 		let dateFormatter = DateFormatter()
 		dateFormatter.timeZone = TimeZone.ReferenceType.local
 		
@@ -1820,9 +1786,8 @@ class Sync{
 			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"
+			let 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
@@ -1862,8 +1827,6 @@ class Sync{
 	*/
 	func saveTableSponsor(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving table Sponsor.")
-		
 		//Set up context
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@@ -1993,7 +1956,6 @@ class Sync{
 	*/
 	func saveSettings(entries : [String]){
 		
-		NSLog(":SYNC:LOG: Saving settings.")
 		let defaults = UserDefaults.standard
 		
 		// Loop new entries

+ 77 - 6
app/SyncController.swift

@@ -26,12 +26,18 @@ The view controller of the app.
 */
 class SyncController: UIViewController{
 	
+	var delegate: AppDelegate?
+	
+	var nowSyncing: Bool = false
+	var syncTimer: Timer? = nil
+	
 	@IBOutlet weak var pb: UIProgressView!
 	@IBOutlet weak var lb: UILabel!
+	@IBOutlet weak var lbTitle: UILabel!
 	
 	var completion: Float = 0.0
 	let messages: [String] = ["Contactando con Don Margolo...", "Arrancando la furgo...", "Preparando kalimotxos...",
-	"Tú eres el piloto", "Afinando la tuba...", "Margolari camina pa'lante, margolari camina pa'trás.", "Ari ari ari!", "Llegando tarde", "¿Cabe más gente en el Foro Margolari?"]
+	"Tú eres el piloto", "Afinando la tuba...", "Margolari camina pa'lante, margolari camina pa'trás.", "Ari ari ari!", "Llegando tarde...", "¿Cabe más gente en el Foro Margolari?", "Arreglando el tirador de cerveza...", "Descorchando botellas...", "Repartiendo pulseras...", "Pintando las fiestas...", "Desplegando pancarta..."]
 	
 	
 	/**
@@ -39,18 +45,83 @@ class SyncController: UIViewController{
 	*/
 	override func viewDidLoad() {
 		
-		NSLog(":SYNC:LOG: SyncController shown.")
+		NSLog(":SYNCCONTROLLER:LOG: SyncController shown.")
+		self.delegate = UIApplication.shared.delegate as? AppDelegate
+		self.delegate?.syncController = self
 		
 		super.viewDidLoad()
 		
-		// Initial setup
-		pb.progress = 0
 		
-		// Start the timer
-		Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(progress), userInfo: nil, repeats: true)
 		
 	}
 	
+	override func viewDidAppear(_ animated: Bool) {
+		if UserDefaults.standard.object(forKey: "userId") == nil{
+			NSLog(":SYNCCONTROLLER:LOG: First run. Generating user ID and syncing...")
+			let newUid = randomString(length: 16)
+			let defaults = UserDefaults.standard
+			defaults.set(newUid, forKey: "userId")
+			// Initial setup
+			pb.isHidden = false
+			lbTitle.isHidden = false
+			lb.isHidden = false
+			pb.progress = 0
+			
+			// Start the timer
+			Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(progress), userInfo: nil, repeats: true)
+			
+			syncTimer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(endSync), userInfo: nil, repeats: true)
+			
+			initialSync()
+		}
+		else{
+			startApp()
+		}
+	}
+	
+	func endSync(){
+		if self.nowSyncing == false{
+			syncTimer?.invalidate()
+			startApp()
+		}
+	}
+	
+	func startApp(){
+		performSegue(withIdentifier: "SegueInit", sender: nil)
+	}
+	
+	/**
+	Handles the initial sync process.
+	It can start it, showing the sync screen, or finish it, hidding the screen.
+	:param: showScreen True to start the sync, false to end it.
+	*/
+	func initialSync(){
+		//performSegue(withIdentifier: "SegueSync", sender: nil)
+		Sync(synchronous: true)
+	}
+	
+	
+	/**
+	Generates a random string to be used as a user identifier.
+	:param: length The length of the generated string.
+	:return: A random alphanumeric string with the indicated length.
+	*/
+	func randomString(length: Int) -> String {
+		
+		let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+		let len = UInt32(letters.length)
+		
+		var randomString = ""
+		
+		for _ in 0 ..< length {
+			let rand = arc4random_uniform(len)
+			var nextChar = letters.character(at: Int(rand))
+			randomString += NSString(characters: &nextChar, length: 1) as String
+		}
+		
+		return randomString
+	}
+	
 	
 	/**
 	Signal to update the progressbar and, maybe, the tag.

+ 2 - 6
app/UIImageView.swift

@@ -79,14 +79,10 @@ extension UIImageView {
 			let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
 				if let tempLocalUrl = tempLocalUrl, error == nil {
 					
-					// Success
-					if let statusCode = (response as? HTTPURLResponse)?.statusCode {
-						// TODO something.
-					}
-					
 					do {
 						try FileManager.default.copyItem(at: tempLocalUrl, to: destinationFileUrl)
-					} catch (let writeError) {
+					}
+					catch (let writeError) {
 						NSLog(":IMAGE:ERROR: Error creating a file \(destinationFileUrl) : \(writeError)")
 					}
 					

+ 0 - 1
app/UIView.swift

@@ -63,7 +63,6 @@ import UIKit
 	
 	var parentViewController: ViewController? {
 		var parentResponder: UIResponder? = self
-		var i = 0
 		while parentResponder != nil {
 			parentResponder = parentResponder!.next
 			if let viewController = parentResponder as? ViewController {

+ 8 - 36
app/ViewController.swift

@@ -60,6 +60,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	:param: coder Coder.
 	*/
 	required init?(coder aDecoder: NSCoder) {
+		NSLog(":CONTROLLER:DEBUG: Init.")
 		super.init(coder: aDecoder)
 		
 	}
@@ -146,19 +147,16 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	}
 	
 	
-	/** m
+	/** 
 	Handles the initial sync process.
 	It can start it, showing the sync screen, or finish it, hidding the screen.
 	:param: showScreen True to start the sync, false to end it.
 	*/
 	func initialSync(showScreen: Bool){
 		if showScreen == true{
-			performSegue(withIdentifier: "SegueSync", sender: nil)
 			Sync(synchronous: true)
 		}
 		else{
-			NSLog(":CONTROLLER:DEBUG: Re-populating disabled: Throws error.")
-			//self.populate()
 			syncSegue?.destination.dismiss(animated: true, completion: nil)
 		}
 	}
@@ -200,7 +198,6 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	}
 	
 	override func viewWillAppear(_ animated: Bool) {
-		self.populate()
 		super.viewWillAppear(animated)
 	}
 	
@@ -226,8 +223,8 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 				
 		NSLog(":CONTROLLER:DEBUG: Don't skyp sync")
 		//NSLog(":CONTROLLER:DEBUG: Skyp sync")
-		Notifications()
-		Sync()
+		//Notifications()
+		//Sync()
 
 		
 		self.delegate = UIApplication.shared.delegate as? AppDelegate
@@ -242,27 +239,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	func fetchLocation(){
 		FetchLocation()
 	}
-
-	/**
-	Actually populates all sections.
-	As of now, not working.
-	*/
-	func populate(){
-		// TODO Set this up.
-		if (self.containerViewHome != nil){
-			//(self.containerViewHome as HomeView).populate()
-			//let ng = self.containerViewHome.dbgTxt
-			//NSLog("AAAAA \(ng)")
-		}
-		else{
-			NSLog("CONTROLLER:ERROR: containerViewHome couldn't be populated: It is nil.")
-		}
-		//self.containerLocation.populate()
-		//self.containerLablanca.populate()
-		//self.containerViewActivities.populate()
-		//self.containerViewBlog.populate()
-		//self.containerGallery.populate()
-	}
+	
 	
 	/**
 	Executed when the view is actually shown.
@@ -272,12 +249,12 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	*/
 	override func viewDidAppear(_ animated: Bool) {
 		super.viewDidAppear(animated)
-		if UserDefaults.standard.object(forKey: "userId") == nil{
+		/*if UserDefaults.standard.object(forKey: "userId") == nil{
 			let newUid = randomString(length: 16)
 			let defaults = UserDefaults.standard
 			defaults.set(newUid, forKey: "userId")
 			initialSync(showScreen: true)
-		}
+		}*/
 		
 	}
 	
@@ -329,8 +306,6 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	//Make a cell for each section
 	func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
 		
-		var first = true
-		
 		//Get a reference to our storyboard cell
 		let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
 		
@@ -340,7 +315,6 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		// Mark the first one as selected.
 		if indexPath.item == 0{
 			cell.isSelected = true
-			first = false
 		}
 		
 		return cell
@@ -358,9 +332,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	:param: selected Index of the selected item.
 	*/
 	@IBAction func showComponent(selected: Int) {
-		//Activate label
-		var i = 0
-		
+				
 		//Show the view
 		if selected == 0 {
 			UIView.animate(withDuration: 0.5, animations: {