Parcourir la source

Merge branch 'Sync' into BaseProject

Iñigo Valentin il y a 9 ans
Parent
commit
ccc4e3df6b

+ 4 - 0
app.xcodeproj/project.pbxproj

@@ -20,6 +20,7 @@
 		93294FF81E336FA000FDAF50 /* Entry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93294FF71E336FA000FDAF50 /* Entry.swift */; };
 		93294FF81E336FA000FDAF50 /* Entry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93294FF71E336FA000FDAF50 /* Entry.swift */; };
 		93294FFA1E337D0D00FDAF50 /* RowHomePastActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93294FF91E337D0D00FDAF50 /* RowHomePastActivities.swift */; };
 		93294FFA1E337D0D00FDAF50 /* RowHomePastActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93294FF91E337D0D00FDAF50 /* RowHomePastActivities.swift */; };
 		935892D01E493C2300E1CD5F /* UIImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935892CF1E493C2300E1CD5F /* UIImageView.swift */; };
 		935892D01E493C2300E1CD5F /* UIImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935892CF1E493C2300E1CD5F /* UIImageView.swift */; };
+		935AE18A1EC6138D0055E71F /* SyncController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935AE1891EC6138D0055E71F /* SyncController.swift */; };
 		935D6E2D1E8678B700CED3A1 /* GalleryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 935D6E2C1E8678B700CED3A1 /* GalleryView.xib */; };
 		935D6E2D1E8678B700CED3A1 /* GalleryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 935D6E2C1E8678B700CED3A1 /* GalleryView.xib */; };
 		935D6E2F1E86792000CED3A1 /* GalleryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935D6E2E1E86792000CED3A1 /* GalleryView.swift */; };
 		935D6E2F1E86792000CED3A1 /* GalleryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935D6E2E1E86792000CED3A1 /* GalleryView.swift */; };
 		935D6E311E867C5E00CED3A1 /* RowGallery.xib in Resources */ = {isa = PBXBuildFile; fileRef = 935D6E301E867C5E00CED3A1 /* RowGallery.xib */; };
 		935D6E311E867C5E00CED3A1 /* RowGallery.xib in Resources */ = {isa = PBXBuildFile; fileRef = 935D6E301E867C5E00CED3A1 /* RowGallery.xib */; };
@@ -80,6 +81,7 @@
 		93294FF71E336FA000FDAF50 /* Entry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Entry.swift; sourceTree = "<group>"; };
 		93294FF71E336FA000FDAF50 /* Entry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Entry.swift; sourceTree = "<group>"; };
 		93294FF91E337D0D00FDAF50 /* RowHomePastActivities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowHomePastActivities.swift; sourceTree = "<group>"; };
 		93294FF91E337D0D00FDAF50 /* RowHomePastActivities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowHomePastActivities.swift; sourceTree = "<group>"; };
 		935892CF1E493C2300E1CD5F /* UIImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageView.swift; sourceTree = "<group>"; };
 		935892CF1E493C2300E1CD5F /* UIImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageView.swift; sourceTree = "<group>"; };
+		935AE1891EC6138D0055E71F /* SyncController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncController.swift; sourceTree = "<group>"; };
 		935D6E2C1E8678B700CED3A1 /* GalleryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GalleryView.xib; sourceTree = "<group>"; };
 		935D6E2C1E8678B700CED3A1 /* GalleryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GalleryView.xib; sourceTree = "<group>"; };
 		935D6E2E1E86792000CED3A1 /* GalleryView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GalleryView.swift; sourceTree = "<group>"; };
 		935D6E2E1E86792000CED3A1 /* GalleryView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GalleryView.swift; sourceTree = "<group>"; };
 		935D6E301E867C5E00CED3A1 /* RowGallery.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RowGallery.xib; sourceTree = "<group>"; };
 		935D6E301E867C5E00CED3A1 /* RowGallery.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RowGallery.xib; sourceTree = "<group>"; };
@@ -217,6 +219,7 @@
 				93E0C5F31EBE306900905811 /* ScheduleViewController.swift */,
 				93E0C5F31EBE306900905811 /* ScheduleViewController.swift */,
 				93EB2F0B1EBF5AEB00F64186 /* RowSchedule.swift */,
 				93EB2F0B1EBF5AEB00F64186 /* RowSchedule.swift */,
 				93EB2F0D1EBF5BF500F64186 /* RowSchedule.xib */,
 				93EB2F0D1EBF5BF500F64186 /* RowSchedule.xib */,
+				935AE1891EC6138D0055E71F /* SyncController.swift */,
 			);
 			);
 			path = app;
 			path = app;
 			sourceTree = "<group>";
 			sourceTree = "<group>";
@@ -341,6 +344,7 @@
 				93E0C5EA1EBDFFB400905811 /* RowPastActivity.swift in Sources */,
 				93E0C5EA1EBDFFB400905811 /* RowPastActivity.swift in Sources */,
 				93BAD2F41E585EE6009DF853 /* RowHomeFutureActivities.swift in Sources */,
 				93BAD2F41E585EE6009DF853 /* RowHomeFutureActivities.swift in Sources */,
 				931AA5891E1AFF8C003A2290 /* String.swift in Sources */,
 				931AA5891E1AFF8C003A2290 /* String.swift in Sources */,
+				935AE18A1EC6138D0055E71F /* SyncController.swift in Sources */,
 				93B84B9C1D9C31AB006C0F67 /* ViewController.swift in Sources */,
 				93B84B9C1D9C31AB006C0F67 /* ViewController.swift in Sources */,
 				93075C6C1E59CB6B00396389 /* BlogView.swift in Sources */,
 				93075C6C1E59CB6B00396389 /* BlogView.swift in Sources */,
 				93B84B9A1D9C31AB006C0F67 /* AppDelegate.swift in Sources */,
 				93B84B9A1D9C31AB006C0F67 /* AppDelegate.swift in Sources */,

+ 10 - 0
app.xcodeproj/xcuserdata/seavenois.xcuserdatad/xcschemes/app.xcscheme

@@ -39,6 +39,11 @@
          </BuildableReference>
          </BuildableReference>
       </MacroExpansion>
       </MacroExpansion>
       <AdditionalOptions>
       <AdditionalOptions>
+         <AdditionalOption
+            key = "NSZombieEnabled"
+            value = "YES"
+            isEnabled = "YES">
+         </AdditionalOption>
       </AdditionalOptions>
       </AdditionalOptions>
    </TestAction>
    </TestAction>
    <LaunchAction
    <LaunchAction
@@ -62,6 +67,11 @@
          </BuildableReference>
          </BuildableReference>
       </BuildableProductRunnable>
       </BuildableProductRunnable>
       <AdditionalOptions>
       <AdditionalOptions>
+         <AdditionalOption
+            key = "NSZombieEnabled"
+            value = "YES"
+            isEnabled = "YES">
+         </AdditionalOption>
       </AdditionalOptions>
       </AdditionalOptions>
    </LaunchAction>
    </LaunchAction>
    <ProfileAction
    <ProfileAction

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

@@ -64,7 +64,7 @@
                                 </collectionViewFlowLayout>
                                 </collectionViewFlowLayout>
                                 <cells>
                                 <cells>
                                     <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell" id="a4j-DF-epb" customClass="MenuCollectionViewCell" customModule="app" customModuleProvider="target">
                                     <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell" id="a4j-DF-epb" customClass="MenuCollectionViewCell" customModule="app" customModuleProvider="target">
-                                        <rect key="frame" x="0.0" y="-3" width="100" height="50"/>
+                                        <rect key="frame" x="0.0" y="-2.5" width="100" height="50"/>
                                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                         <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                         <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                             <rect key="frame" x="0.0" y="0.0" width="100" height="50"/>
                                             <rect key="frame" x="0.0" y="0.0" width="100" height="50"/>
@@ -959,7 +959,7 @@
         <!--Sync-->
         <!--Sync-->
         <scene sceneID="cqg-BI-2xm">
         <scene sceneID="cqg-BI-2xm">
             <objects>
             <objects>
-                <viewController title="Sync" id="3o1-ab-AT4" sceneMemberID="viewController">
+                <viewController title="Sync" id="3o1-ab-AT4" customClass="SyncController" customModule="app" customModuleProvider="target" sceneMemberID="viewController">
                     <layoutGuides>
                     <layoutGuides>
                         <viewControllerLayoutGuide type="top" id="RYy-ax-Nya"/>
                         <viewControllerLayoutGuide type="top" id="RYy-ax-Nya"/>
                         <viewControllerLayoutGuide type="bottom" id="rXD-89-8EQ"/>
                         <viewControllerLayoutGuide type="bottom" id="rXD-89-8EQ"/>
@@ -1006,6 +1006,10 @@
                             <constraint firstItem="pgU-dx-MvQ" firstAttribute="top" secondItem="VkR-DT-y3S" secondAttribute="bottom" constant="8" id="wts-Yk-LsB"/>
                             <constraint firstItem="pgU-dx-MvQ" firstAttribute="top" secondItem="VkR-DT-y3S" secondAttribute="bottom" constant="8" id="wts-Yk-LsB"/>
                         </constraints>
                         </constraints>
                     </view>
                     </view>
+                    <connections>
+                        <outlet property="lb" destination="pgU-dx-MvQ" id="ATL-SS-rxd"/>
+                        <outlet property="pb" destination="VkR-DT-y3S" id="NMd-7R-Rlc"/>
+                    </connections>
                 </viewController>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="fRm-1Y-Xmm" userLabel="First Responder" sceneMemberID="firstResponder"/>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="fRm-1Y-Xmm" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>
             </objects>

+ 99 - 78
app/HomeView.swift

@@ -21,48 +21,55 @@
 import Foundation
 import Foundation
 import CoreData
 import CoreData
 import UIKit
 import UIKit
+
+
 /**
 /**
- Class to handle the home view.
- */
+Class to handle the home view.
+*/
 class HomeView: UIView {
 class HomeView: UIView {
 	
 	
-	//The main scroll view.
-	@IBOutlet weak var scrollView: UIScrollView!
-	
-	//The container of the view.
-	@IBOutlet weak var container: UIView!
-	
-	//Each of the sections of the view.
-	@IBOutlet weak var locationSection: Section!
-	@IBOutlet weak var lablancaSection: Section!
-	@IBOutlet weak var futureActivitiesSection: Section!
-	@IBOutlet weak var blogSection: Section!
-	@IBOutlet weak var gallerySection: Section!
-	@IBOutlet weak var pastActivitiesSection: Section!
-	@IBOutlet weak var socialSection: Section!
+	// Outlets
+	@IBOutlet var scrollView: UIScrollView!
+	@IBOutlet var container: UIView!
+	@IBOutlet var locationSection: Section!
+	@IBOutlet var lablancaSection: Section!
+	@IBOutlet var futureActivitiesSection: Section!
+	@IBOutlet var blogSection: Section!
+	@IBOutlet var gallerySection: Section!
+	@IBOutlet var pastActivitiesSection: Section!
+	@IBOutlet var socialSection: Section!
 
 
 	var lang: String? = nil
 	var lang: String? = nil
 	var moc: NSManagedObjectContext? = nil
 	var moc: NSManagedObjectContext? = nil
 	var appDelegate: AppDelegate? = nil
 	var appDelegate: AppDelegate? = nil
 	
 	
+	let dbgTxt = "IVV"
+	
+	
+	/**
+	Run when the view is started.
+	:param: frame Frame for the view.
+	*/
 	override init(frame: CGRect){
 	override init(frame: CGRect){
 		super.init(frame: frame)
 		super.init(frame: frame)
 	}
 	}
 	
 	
+	
 	/**
 	/**
-	 Run when the view is started.
+	Run when the view is started.
+	:param: coder Application decoder.
 	*/
 	*/
 	required init?(coder aDecoder: NSCoder) {
 	required init?(coder aDecoder: NSCoder) {
 		
 		
 		super.init(coder: aDecoder)
 		super.init(coder: aDecoder)
 		
 		
-		//Load the contents of the HomeView.xib file.
+		// Load the contents of the HomeView.xib file.
 		Bundle.main.loadNibNamed("HomeView", owner: self, options: nil)
 		Bundle.main.loadNibNamed("HomeView", owner: self, options: nil)
 		self.addSubview(container)
 		self.addSubview(container)
-		container.frame = self.bounds
+		self.container.frame = self.bounds
 		
 		
 
 
-		//Set titles for each section
+		// Set titles for each section
 		locationSection.setTitle(text: "Encuentranos")
 		locationSection.setTitle(text: "Encuentranos")
 		lablancaSection.setTitle(text: "La Blanca")
 		lablancaSection.setTitle(text: "La Blanca")
 		futureActivitiesSection.setTitle(text: "Proximas actividades")
 		futureActivitiesSection.setTitle(text: "Proximas actividades")
@@ -71,13 +78,13 @@ class HomeView: UIView {
 		pastActivitiesSection.setTitle(text: "Ultimas actividades")
 		pastActivitiesSection.setTitle(text: "Ultimas actividades")
 		socialSection.setTitle(text: "Siguenos")
 		socialSection.setTitle(text: "Siguenos")
 		
 		
-		//Get info to populate sections
+		// Get info to populate sections
 		self.moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		self.moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		self.appDelegate = UIApplication.shared.delegate as! AppDelegate
 		self.appDelegate = UIApplication.shared.delegate as! AppDelegate
 		self.moc?.persistentStoreCoordinator = appDelegate?.persistentStoreCoordinator
 		self.moc?.persistentStoreCoordinator = appDelegate?.persistentStoreCoordinator
 		self.lang = getLanguage()
 		self.lang = getLanguage()
 		
 		
-		//Populate sections
+		// Populate sections
 		self.populate()
 		self.populate()
 		
 		
 		
 		
@@ -92,10 +99,17 @@ class HomeView: UIView {
 		//self.scrollView.contentSize.height = 1300// CGFloat(h);
 		//self.scrollView.contentSize.height = 1300// CGFloat(h);
 	}
 	}
 
 
+	
+	func populate2(){
+		NSLog(":HOME:DEBUG: Dummy Populating home view.")
+	}
+	
 	/**
 	/**
-	 Triggers a reloading (or initial loading) of all sections.
+	Triggers a reloading (or initial loading) of all sections.
 	*/
 	*/
-	func populate(){
+	open func populate(){
+		
+		NSLog(":HOME:DEBUG: Populating home view.")
 		
 		
 		//Populate sections
 		//Populate sections
 		self.setUpPastActivities(context: self.moc!, delegate: appDelegate!, lang: self.lang!, parent: self.pastActivitiesSection.getContentStack())
 		self.setUpPastActivities(context: self.moc!, delegate: appDelegate!, lang: self.lang!, parent: self.pastActivitiesSection.getContentStack())
@@ -106,6 +120,11 @@ class HomeView: UIView {
 		self.pastActivitiesSection.expandSection()
 		self.pastActivitiesSection.expandSection()
 	}
 	}
 	
 	
+	
+	/**
+	Retrieves the device language. The only available ones are Spanish, English and Basque.
+	:return: Two letter language code (en, eu, es). If other, spanish will be selected.
+	*/
 	func getLanguage() -> String{
 	func getLanguage() -> String{
 		let pre = NSLocale.preferredLanguages[0].subStr(start: 0, end: 1)
 		let pre = NSLocale.preferredLanguages[0].subStr(start: 0, end: 1)
 		if(pre == "es" || pre == "en" || pre == "eu"){
 		if(pre == "es" || pre == "en" || pre == "eu"){
@@ -116,9 +135,17 @@ class HomeView: UIView {
 		}
 		}
 	}
 	}
 	
 	
+	
+	/**
+	Sets the future activities section.
+	Loads up to two future activities.
+	:param: context Aplication context.
+	:param: delegate Application delegate.
+	:param: lang Device language. Two letter code. Accepts 'es', 'en' and 'eu'.
+	:param: parent View where the rows will be loaded.
+	*/
 	func setUpFutureActivities(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 	func setUpFutureActivities(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 		
 		
-		//context.persistentStoreCoordinator = delegate.persistentStoreCoordinator
 		let fetchRequest: NSFetchRequest<Activity> = Activity.fetchRequest()
 		let fetchRequest: NSFetchRequest<Activity> = Activity.fetchRequest()
 		let sortDescriptor = NSSortDescriptor(key: "date", ascending: true)
 		let sortDescriptor = NSSortDescriptor(key: "date", ascending: true)
 		let sortDescriptors = [sortDescriptor]
 		let sortDescriptors = [sortDescriptor]
@@ -127,11 +154,8 @@ class HomeView: UIView {
 		fetchRequest.fetchLimit = 2
 		fetchRequest.fetchLimit = 2
 		
 		
 		do {
 		do {
-			//go get the results
 			let searchResults = try context.fetch(fetchRequest)
 			let searchResults = try context.fetch(fetchRequest)
-			
-			//I like to check the size of the returned results!
-			print ("Activities: \(searchResults.count)")
+			NSLog(":HOME:DEBUG: Future activity count: \(searchResults.count)")
 			
 			
 			var row : RowHomePastActivities
 			var row : RowHomePastActivities
 			var count = 0
 			var count = 0
@@ -140,19 +164,14 @@ class HomeView: UIView {
 			var text: String
 			var text: String
 			var image: String
 			var image: String
 			
 			
-			//You need to convert to NSManagedObject to use 'for' loops
 			for r in searchResults as [NSManagedObject] {
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
 				count = count + 1
-				//get the Key Value pairs (although there may be a better way to do that...
-				print("Perm: \(r.value(forKey: "permalink"))")
-				
 				
 				
 				//Create a new row
 				//Create a new row
 				row = RowHomePastActivities.init(s: "rowHomeFutureActivities\(count)", i: count)
 				row = RowHomePastActivities.init(s: "rowHomeFutureActivities\(count)", i: count)
 				id = r.value(forKey: "id")! as! Int
 				id = r.value(forKey: "id")! as! Int
 				title = r.value(forKey: "title_\(lang)")! as! String
 				title = r.value(forKey: "title_\(lang)")! as! String
 				text = r.value(forKey: "text_\(lang)")! as! String
 				text = r.value(forKey: "text_\(lang)")! as! String
-				print(title)
 				row.setTitle(text: title)
 				row.setTitle(text: title)
 				row.setText(text: text)
 				row.setText(text: text)
 				
 				
@@ -168,26 +187,30 @@ class HomeView: UIView {
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					for imgR in imgSearchResults as [NSManagedObject]{
 					for imgR in imgSearchResults as [NSManagedObject]{
 						image = imgR.value(forKey: "image")! as! String
 						image = imgR.value(forKey: "image")! as! String
-						print ("IMAGE: \(image)")
 						row.setImage(filename: image)
 						row.setImage(filename: image)
 					}
 					}
 				} catch {
 				} catch {
-					print("Error getting image for activity \(id): \(error)")
+					NSLog(":HOME:ERROR: Error getting image for futureactivity \(id): \(error)")
 				}
 				}
-				
-				print("Row height: \(row.frame.height)")
-				
 				parent.addArrangedSubview(row)
 				parent.addArrangedSubview(row)
 				
 				
 			}
 			}
 		} catch {
 		} catch {
-			print("Error with request: \(error)")
+			NSLog(":HOME:ERROR: Error setting the future activities section up: \(error)")
 		}
 		}
 	}
 	}
 	
 	
+	
+	/**
+	Sets the blog section.
+	Loads up to two posts.
+	:param: context Aplication context.
+	:param: delegate Application delegate.
+	:param: lang Device language. Two letter code. Accepts 'es', 'en' and 'eu'.
+	:param: parent View where the rows will be loaded.
+	*/
 	func setUpBlog(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 	func setUpBlog(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 		
 		
-		//context.persistentStoreCoordinator = delegate.persistentStoreCoordinator
 		let fetchRequest: NSFetchRequest<Post> = Post.fetchRequest()
 		let fetchRequest: NSFetchRequest<Post> = Post.fetchRequest()
 		let sortDescriptor = NSSortDescriptor(key: "dtime", ascending: false)
 		let sortDescriptor = NSSortDescriptor(key: "dtime", ascending: false)
 		let sortDescriptors = [sortDescriptor]
 		let sortDescriptors = [sortDescriptor]
@@ -195,11 +218,8 @@ class HomeView: UIView {
 		fetchRequest.fetchLimit = 2
 		fetchRequest.fetchLimit = 2
 		
 		
 		do {
 		do {
-			//go get the results
 			let searchResults = try context.fetch(fetchRequest)
 			let searchResults = try context.fetch(fetchRequest)
-			
-			//I like to check the size of the returned results!
-			print ("Post: \(searchResults.count)")
+			NSLog(":HOME:DEBUG: Post count: \(searchResults.count)")
 			
 			
 			var row : RowHomeBlog
 			var row : RowHomeBlog
 			var count = 0
 			var count = 0
@@ -208,12 +228,8 @@ class HomeView: UIView {
 			var text: String
 			var text: String
 			var image: String
 			var image: String
 			
 			
-			//You need to convert to NSManagedObject to use 'for' loops
 			for r in searchResults as [NSManagedObject] {
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
 				count = count + 1
-				//get the Key Value pairs (although there may be a better way to do that...
-				print("Perm: \(r.value(forKey: "permalink"))")
-				
 				
 				
 				//Create a new row
 				//Create a new row
 				row = RowHomeBlog.init(s: "rowHomeBlog\(count)", i: count)
 				row = RowHomeBlog.init(s: "rowHomeBlog\(count)", i: count)
@@ -237,15 +253,12 @@ class HomeView: UIView {
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					for imgR in imgSearchResults as [NSManagedObject]{
 					for imgR in imgSearchResults as [NSManagedObject]{
 						image = imgR.value(forKey: "image")! as! String
 						image = imgR.value(forKey: "image")! as! String
-						print ("IMAGE: \(image)")
 						row.setImage(filename: image)
 						row.setImage(filename: image)
 					}
 					}
 				} catch {
 				} catch {
-					print("Error getting image for post \(id): \(error)")
+					NSLog(":HOME:ERROR: Error getting image for post \(id): \(error)")
 				}
 				}
 				
 				
-				print("Row height: \(row.frame.height)")
-				
 				parent.addArrangedSubview(row)
 				parent.addArrangedSubview(row)
 				
 				
 				let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openPost(_:)))
 				let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openPost(_:)))
@@ -254,13 +267,21 @@ class HomeView: UIView {
 				
 				
 			}
 			}
 		} catch {
 		} catch {
-			print("Error with request: \(error)")
+			NSLog(":HOME:ERROR: Error setting the blog section up: \(error)")
 		}
 		}
 	}
 	}
 	
 	
+	
+	/**
+	Sets the past activities section.
+	Loads up to two past activities.
+	:param: context Aplication context.
+	:param: delegate Application delegate.
+	:param: lang Device language. Two letter code. Accepts 'es', 'en' and 'eu'.
+	:param: parent View where the rows will be loaded.
+	*/
 	func setUpPastActivities(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 	func setUpPastActivities(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 		
 		
-		//context.persistentStoreCoordinator = delegate.persistentStoreCoordinator
 		let fetchRequest: NSFetchRequest<Activity> = Activity.fetchRequest()
 		let fetchRequest: NSFetchRequest<Activity> = Activity.fetchRequest()
 		let sortDescriptor = NSSortDescriptor(key: "date", ascending: false)
 		let sortDescriptor = NSSortDescriptor(key: "date", ascending: false)
 		let sortDescriptors = [sortDescriptor]
 		let sortDescriptors = [sortDescriptor]
@@ -269,11 +290,8 @@ class HomeView: UIView {
 		fetchRequest.fetchLimit = 2
 		fetchRequest.fetchLimit = 2
 		
 		
 		do {
 		do {
-			//go get the results
 			let searchResults = try context.fetch(fetchRequest)
 			let searchResults = try context.fetch(fetchRequest)
-			
-			//I like to check the size of the returned results!
-			print ("Activities: \(searchResults.count)")
+			NSLog(":HOME:LOG: Setting past activities up. Count: \(searchResults.count)")
 			
 			
 			var row : RowHomePastActivities
 			var row : RowHomePastActivities
 			var count = 0
 			var count = 0
@@ -282,12 +300,8 @@ class HomeView: UIView {
 			var text: String
 			var text: String
 			var image: String
 			var image: String
 			
 			
-			//You need to convert to NSManagedObject to use 'for' loops
 			for r in searchResults as [NSManagedObject] {
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
 				count = count + 1
-				//get the Key Value pairs (although there may be a better way to do that...
-				print("Perm: \(r.value(forKey: "permalink"))")
-				
 				
 				
 				//Create a new row
 				//Create a new row
 				row = RowHomePastActivities.init(s: "rowHomePastActivities\(count)", i: count)
 				row = RowHomePastActivities.init(s: "rowHomePastActivities\(count)", i: count)
@@ -311,32 +325,35 @@ class HomeView: UIView {
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					for imgR in imgSearchResults as [NSManagedObject]{
 					for imgR in imgSearchResults as [NSManagedObject]{
 						image = imgR.value(forKey: "image")! as! String
 						image = imgR.value(forKey: "image")! as! String
-						print ("IMAGE: \(image)")
 						row.setImage(filename: image)
 						row.setImage(filename: image)
 					}
 					}
 				} catch {
 				} catch {
-					print("Error getting image for activity \(id): \(error)")
+					NSLog(":HOME:ERROR: Error getting image for past activity \(id): \(error)")
 				}
 				}
 				
 				
-				print("Row height: \(row.frame.height)")
-				
 				parent.addArrangedSubview(row)
 				parent.addArrangedSubview(row)
 				
 				
 			}
 			}
 		} catch {
 		} catch {
-			print("Error with request: \(error)")
+			NSLog(":HOME:ERROR: Error setting the past activities section up: \(error)")
 		}
 		}
 	}
 	}
 	
 	
+	/**
+	Sets the fgallery section.
+	Loads up to four photos.
+	:param: context Aplication context.
+	:param: delegate Application delegate.
+	:param: parent View where the rows will be loaded.
+	*/
 	func setUpGallery(context : NSManagedObjectContext, delegate: AppDelegate,parent: UIStackView){
 	func setUpGallery(context : NSManagedObjectContext, delegate: AppDelegate,parent: UIStackView){
-		print("HOME:LOG: Setting up gallery.")
+		NSLog(":HOME:LOG: Setting gallery section up.")
 		
 		
 		// Create the row
 		// Create the row
 		var row: RowHomeGallery
 		var row: RowHomeGallery
 		row = RowHomeGallery.init(s: "rowHomeGallery", i: 0)
 		row = RowHomeGallery.init(s: "rowHomeGallery", i: 0)
 		parent.addArrangedSubview(row)
 		parent.addArrangedSubview(row)
 		
 		
-		
 		// Set images
 		// Set images
 		let fetchRequest: NSFetchRequest<Photo> = Photo.fetchRequest()
 		let fetchRequest: NSFetchRequest<Photo> = Photo.fetchRequest()
 		let sortDescriptor = NSSortDescriptor(key: "uploaded", ascending: false)
 		let sortDescriptor = NSSortDescriptor(key: "uploaded", ascending: false)
@@ -345,10 +362,7 @@ class HomeView: UIView {
 		fetchRequest.fetchLimit = 4
 		fetchRequest.fetchLimit = 4
 		
 		
 		do {
 		do {
-			//go get the results
 			let searchResults = try context.fetch(fetchRequest)
 			let searchResults = try context.fetch(fetchRequest)
-	
-			var id: Int
 			var image: String
 			var image: String
 			
 			
 			// Loop images
 			// Loop images
@@ -365,24 +379,31 @@ class HomeView: UIView {
 			
 			
 		}
 		}
 		catch{
 		catch{
-			print("HOME:ERROR: Error setting gallery up: \(error)")
+			NSLog(":HOME:ERROR: Error setting gallery up: \(error)")
 		}
 		}
 		
 		
 	}
 	}
 	
 	
+	/**
+	Sets the social section.
+	:param: parent View where the rows will be loaded.
+	*/
 	func setUpSocial(parent : UIStackView){
 	func setUpSocial(parent : UIStackView){
-		print("SETING UP SOCIAL")
+		NSLog(":HOME:LOG: Setting soceial section up.")
 		//Create a new row
 		//Create a new row
 		var row : RowHomeSocial
 		var row : RowHomeSocial
 		row = RowHomeSocial.init(s: "rowHomeSocial", i: 0)
 		row = RowHomeSocial.init(s: "rowHomeSocial", i: 0)
-		print("ROW CREATED")
 		parent.addArrangedSubview(row)
 		parent.addArrangedSubview(row)
 	}
 	}
 	
 	
+	/**
+	opens the blog section, showing a post.
+	:param: sender: View calling the function.
+	*/
 	func openPost(_ sender:UITapGestureRecognizer? = nil){
 	func openPost(_ sender:UITapGestureRecognizer? = nil){
-		print("HOME:DEBUG: getting delegate and showing post.")
+		NSLog(":HOME:DEBUG: Getting delegate and showing post.")
 		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
 		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
 		delegate.controller?.showPost(id: (sender?.view as! RowHomeBlog).id)
 		delegate.controller?.showPost(id: (sender?.view as! RowHomeBlog).id)
-		print("HOME:DEBUG: Post should be shown.")
+		NSLog(":HOME:DEBUG: Post should be shown.")
 	}
 	}
 }
 }

+ 5 - 5
app/HomeView.xib

@@ -1,15 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
     <device id="retina3_5" orientation="portrait">
     <device id="retina3_5" orientation="portrait">
         <adaptation id="fullscreen"/>
         <adaptation id="fullscreen"/>
     </device>
     </device>
     <dependencies>
     <dependencies>
         <deployment identifier="iOS"/>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     </dependencies>
     <objects>
     <objects>
-        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HomeView" customModule="app" customModuleProvider="target">
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner">
             <connections>
             <connections>
                 <outlet property="blogSection" destination="uHa-Mu-U68" id="RUp-Jg-AxI"/>
                 <outlet property="blogSection" destination="uHa-Mu-U68" id="RUp-Jg-AxI"/>
                 <outlet property="container" destination="iN0-l3-epB" id="cfT-rm-jA0"/>
                 <outlet property="container" destination="iN0-l3-epB" id="cfT-rm-jA0"/>
@@ -23,14 +23,14 @@
             </connections>
             </connections>
         </placeholder>
         </placeholder>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
-        <view contentMode="scaleToFill" id="iN0-l3-epB">
+        <view contentMode="scaleToFill" id="iN0-l3-epB" customClass="HomeView" customModule="app">
             <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
             <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
             <subviews>
                 <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Poy-ba-9jX">
                 <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Poy-ba-9jX">
                     <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
                     <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
                     <subviews>
                     <subviews>
-                        <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" axis="vertical" alignment="center" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="gOz-rr-CeQ">
+                        <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="780"/>
                             <rect key="frame" x="0.0" y="0.0" width="320" height="780"/>
                             <subviews>
                             <subviews>
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ljm-NP-c4e" customClass="Section" customModule="app">
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ljm-NP-c4e" customClass="Section" customModule="app">

+ 3 - 3
app/Section.swift

@@ -27,13 +27,13 @@ import UIKit
 class Section: UIView {
 class Section: UIView {
 	
 	
 	//The container.
 	//The container.
-	@IBOutlet weak var container: UIView!
+	@IBOutlet var container: UIView!
 	
 	
 	//The section title.
 	//The section title.
-	@IBOutlet weak var title: UITextView!
+	@IBOutlet var title: UITextView!
 	
 	
 	//The content of the section.
 	//The content of the section.
-	@IBOutlet weak var content: UIStackView!
+	@IBOutlet var content: UIStackView!
 	
 	
 	
 	
 	
 	

+ 72 - 0
app/SyncController.swift

@@ -0,0 +1,72 @@
+// Copyright (C) 2016 Inigo Valentin
+//
+// This file is part of the Gasteizko Margolariak IOS app.
+//
+// The Gasteizko Margolariak IOS app is free software: you can
+// redistribute it and/or modify it under the terms of the
+// GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your
+// option) any later version.
+//
+// The Gasteizko Margolariak IOS app is distributed in the
+// hope that it will be useful, but WITHOUT ANY WARRANTY;
+// without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+// Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with the Gasteizko Margolariak IOS app.
+// If not, see <http://www.gnu.org/licenses/>.
+
+import UIKit
+import CoreData
+
+/**
+The view controller of the app.
+*/
+class SyncController: UIViewController{
+	
+	@IBOutlet weak var pb: UIProgressView!
+	@IBOutlet weak var lb: 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?"]
+	
+	
+	/**
+	Run when the app loads.
+	*/
+	override func viewDidLoad() {
+		
+		NSLog(":SYNC:LOG: SyncController shown.")
+		
+		super.viewDidLoad()
+		
+		// Initial setup
+		pb.progress = 0
+		
+		// Start the timer
+		Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(progress), userInfo: nil, repeats: true)
+		
+	}
+	
+	func progress(){
+		
+		if (Int(completion * 100) % 20) == 0 {
+			let rnd = Int(arc4random_uniform(UInt32(messages.count)));
+			lb.text = messages[rnd]
+		}
+		
+		completion = completion + 0.02
+		
+		if completion >= 1.0{
+			completion = 0.0
+		}
+		pb.progress = completion
+		
+		
+		
+	}
+	
+}

+ 20 - 9
app/ViewController.swift

@@ -48,6 +48,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	 Controller initializer.
 	 Controller initializer.
 	*/
 	*/
 	required init?(coder aDecoder: NSCoder) {
 	required init?(coder aDecoder: NSCoder) {
+		NSLog(":CONTROLLER:DEBUG: Init!")
 		super.init(coder: aDecoder)
 		super.init(coder: aDecoder)
 	}
 	}
 	
 	
@@ -107,7 +108,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		else{
 		else{
 			NSLog(":CONTROLLER:DEBUG: Re-populating views and hidding initial sync screen.")
 			NSLog(":CONTROLLER:DEBUG: Re-populating views and hidding initial sync screen.")
 			NSLog(":CONTROLLER:DEBUG: Re-populating disabled: Throws error.")
 			NSLog(":CONTROLLER:DEBUG: Re-populating disabled: Throws error.")
-			//populate()
+			//self.populate()
 			syncSegue?.destination.dismiss(animated: true, completion: nil)
 			syncSegue?.destination.dismiss(animated: true, completion: nil)
 		}
 		}
 	}
 	}
@@ -143,7 +144,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	 Run when the app loads.
 	 Run when the app loads.
 	*/
 	*/
 	override func viewDidLoad() {
 	override func viewDidLoad() {
-				
+						
 		//Hide all sections, except for the first one
 		//Hide all sections, except for the first one
 		self.containerViewLocation.alpha = 0
 		self.containerViewLocation.alpha = 0
 		self.containerViewLablanca.alpha = 0
 		self.containerViewLablanca.alpha = 0
@@ -154,22 +155,32 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		NSLog(":CONTROLLER:LOG: viewDidLoad()")
 		NSLog(":CONTROLLER:LOG: viewDidLoad()")
 		NSLog(":CONTROLLER:DEBUG: Skyp sync")
 		NSLog(":CONTROLLER:DEBUG: Skyp sync")
 		//Sync()
 		//Sync()
-		
-		super.viewDidLoad()
 
 
 		//self.containerViewBlog.setController(controller: self as ViewController)
 		//self.containerViewBlog.setController(controller: self as ViewController)
 		
 		
-		delegate = UIApplication.shared.delegate as! AppDelegate
-		delegate?.controller = self
+		self.delegate = UIApplication.shared.delegate as? AppDelegate
+		self.delegate?.controller = self
+		
+		NSLog(":CONTROLLER:DEBUG: NOT Forcing a call to populate")
+		//self.populate()
+		
+		super.viewDidLoad()
 		
 		
 	}
 	}
 
 
 	func populate(){
 	func populate(){
-		//self.containerViewHome.populate()
+		if (self.containerViewHome != nil){
+			//(self.containerViewHome as HomeView).populate2()
+			let ng = self.containerViewHome.dbgTxt
+			NSLog("AAAAA \(ng)")
+		}
+		else{
+			NSLog("CONTROLLER:ERROR: containerViewHome couldn't be populated: It is nil.")
+		}
 		//self.containerLocation.populate()
 		//self.containerLocation.populate()
 		//self.containerLablanca.populate()
 		//self.containerLablanca.populate()
-		self.containerViewActivities.populate()
-		self.containerViewBlog.populate()
+		//self.containerViewActivities.populate()
+		//self.containerViewBlog.populate()
 		//self.containerGallery.populate()
 		//self.containerGallery.populate()
 	}
 	}