Kaynağa Gözat

Home section reloaded after initial sync (or any sync).

Iñigo Valentin 9 yıl önce
ebeveyn
işleme
937efa9aa8
2 değiştirilmiş dosya ile 39 ekleme ve 22 silme
  1. 30 21
      app/HomeView.swift
  2. 9 1
      app/ViewController.swift

+ 30 - 21
app/HomeView.swift

@@ -40,6 +40,10 @@ class HomeView: UIView {
 	@IBOutlet weak var gallerySection: Section!
 	@IBOutlet weak var pastActivitiesSection: Section!
 	@IBOutlet weak var socialSection: Section!
+
+	let lang: String
+	let moc: NSManagedObjectContext
+	let appDelegate: AppDelegate
 	
 	override init(frame: CGRect){
 		super.init(frame: frame)
@@ -58,7 +62,6 @@ class HomeView: UIView {
 		container.frame = self.bounds
 		
 
-		
 		//Set titles for each section
 		locationSection.setTitle(text: "Encuentranos")
 		lablancaSection.setTitle(text: "La Blanca")
@@ -69,32 +72,38 @@ class HomeView: UIView {
 		socialSection.setTitle(text: "Siguenos")
 		
 		//Get info to populate sections
-		let moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
-		
-		let appDelegate = UIApplication.shared.delegate as! AppDelegate
-		moc.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator
-		let lang : String = getLanguage()
+		self.moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
+		self.appDelegate = UIApplication.shared.delegate as! AppDelegate
+		self.moc.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator
+		self.lang = getLanguage()
 		
 		//Populate sections
-		setUpPastActivities(context: moc, delegate: appDelegate, lang: lang, parent: pastActivitiesSection.getContentStack())
-		setUpBlog(context: moc, delegate: appDelegate, lang: lang, parent: blogSection.getContentStack())
-		setUpFutureActivities(context: moc, delegate: appDelegate, lang: lang, parent: futureActivitiesSection.getContentStack())
-		setUpSocial(parent: socialSection.getContentStack())
-		setUpGallery(context: moc, delegate: appDelegate, parent: gallerySection.getContentStack())
-		
-		
-		pastActivitiesSection.expandSection()
+		self.populate()
 		
 		
 		//Always at the end: update scrollview
-		var h: Int = 0
-		for view in scrollView.subviews {
-			//contentRect = contentRect.union(view.frame);
-			h = h + Int(view.frame.height) + 30 //Why 30?
-			print("curh: \(h)")
-		}
+		//var h: Int = 0
+		//for view in scrollView.subviews {
+		//	//contentRect = contentRect.union(view.frame);
+		//	h = h + Int(view.frame.height) + 30 //Why 30?
+		//	print("curh: \(h)")
+		//}
 		// TODO: Calculate at the end
-		self.scrollView.contentSize.height = 1300// CGFloat(h);
+		//self.scrollView.contentSize.height = 1300// CGFloat(h);
+	}
+
+	/**
+	 Triggers a reloading (or initial loading) of all sections.
+	*/
+	func populate(){
+		
+		//Populate sections
+		self.setUpPastActivities(context: self.moc, delegate: appDelegate, lang: self.lang, parent: self.pastActivitiesSection.getContentStack())
+		self.setUpBlog(context: self.moc, delegate: self.appDelegate, lang: self.lang, parent: self.blogSection.getContentStack())
+		self.setUpFutureActivities(context: self.moc, delegate: self.appDelegate, lang: self.lang, parent: self.futureActivitiesSection.getContentStack())
+		self.setUpSocial(parent: self.socialSection.getContentStack())
+		self.setUpGallery(context: self.moc, delegate: self.appDelegate, parent: self.gallerySection.getContentStack())
+		self.pastActivitiesSection.expandSection()
 	}
 	
 	func getLanguage() -> String{

+ 9 - 1
app/ViewController.swift

@@ -160,7 +160,15 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		delegate = UIApplication.shared.delegate as! AppDelegate
 		delegate?.controller = self
 		
-		
+	}
+
+	func populate(){
+		self.containerViewHome.populate()
+		//self.containerLocation.populate()
+		//self.containerLablanca.populate()
+		//self.containerActivities.populate()
+		//self.containerBlog.populate()
+		//self.containerGallery.populate()
 	}
 	
 	/**