Przeglądaj źródła

Fixed a bug while calculating the day of festival events.

Iñigo Valentin 9 lat temu
rodzic
commit
8b00700f3c
3 zmienionych plików z 34 dodań i 20 usunięć
  1. 1 1
      app/HomeView.swift
  2. 24 7
      app/ScheduleViewController.swift
  3. 9 12
      app/Sync.swift

+ 1 - 1
app/HomeView.swift

@@ -193,7 +193,7 @@ class HomeView: UIView {
 		
 		let defaults = UserDefaults.standard
 		if (defaults.value(forKey: "festivals") != nil){
-			let festivals = defaults.value(forKey: "festivals") as! Int
+			let festivals = Int(defaults.value(forKey: "festivals") as! String)
 			if festivals == 1{
 				
 				// Set tap recognizer

+ 24 - 7
app/ScheduleViewController.swift

@@ -105,11 +105,17 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 	*/
 	public func loadSchedule(margolari: Bool){
 		
+		NSLog("IVV Loading schedule START")
+		
+		// TODO: if/else for margolari/city
+		
 		self.context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		self.delegate = UIApplication.shared.delegate as? AppDelegate
 		self.delegate?.scheduleController = self
 		self.lang = getLanguage()
 		self.context?.persistentStoreCoordinator = self.delegate?.persistentStoreCoordinator
+		
+		NSLog("IVV Loading schedule 1")
 
 		// Get days
 		// TODO: Get current year
@@ -121,23 +127,28 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 		let sDate = dateFormatter.date(from: dateString)
 		dateString = "\(year)-12-31"
 		let eDate = dateFormatter.date(from: dateString)
-		let dayFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Festival_event")
+		let dayFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Festival_event_gm")
 		dayFetchRequest.propertiesToFetch = ["day"]
-		if self.margolari == true{
-			dayFetchRequest.predicate = NSPredicate(format: "(gm = %i) AND (start >= %@) AND (start <= %@)", argumentArray: [1, sDate!, eDate!])
-		}
-		else{
-			dayFetchRequest.predicate = NSPredicate(format: "(gm = %i) AND (start >= %@) AND (start <= %@)", argumentArray: [0, sDate!, eDate!])
-		}
+		
+		NSLog("IVV Loading schedule 2")
+		
+		dayFetchRequest.predicate = NSPredicate(format: "(start >= %@) AND (start <= %@)", argumentArray: [sDate!, eDate!])
+		
+		NSLog("IVV Loading schedule 3")
+		
 
 		dayFetchRequest.returnsDistinctResults = true
 		let sortDayDescriptor = NSSortDescriptor(key: "start", ascending: true)
 		let sortDayDescriptors = [sortDayDescriptor]
 		dayFetchRequest.sortDescriptors = sortDayDescriptors
+		
+		NSLog("IVV Loading schedule 4")
 
 		do {
 			let results = try self.context?.fetch(dayFetchRequest)
 			
+			NSLog("IVV Loading schedule 5")
+			
 			for r in results as! [NSManagedObject] {
 				let day: NSDate = r.value(forKey: "day") as! NSDate
 				// Don't add duplicates
@@ -145,6 +156,8 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 					self.days.append(day)
 				}
 			}
+			
+			NSLog("IVV Loading schedule 6")
 		}
 		catch let err as NSError {
 			NSLog(":SCHEDULECONTROLLER:ERROR: Error getting day list: \(err)")
@@ -161,8 +174,12 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 		let tapRecognizerNextDay = UITapGestureRecognizer(target: self, action: #selector(nextDay(_:)))
 		self.btNext.isUserInteractionEnabled = true
 		self.btNext.addGestureRecognizer(tapRecognizerNextDay)
+		
+		NSLog("IVV Loading schedule 7")
 
 		loadDay()
+		
+		NSLog("IVV Loading schedule END")
 	}
 
 

+ 9 - 12
app/Sync.swift

@@ -245,7 +245,9 @@ class Sync{
 					}
 					
 					// Special case: "festivl_event_citiy" and "festival_event_gm" have a special column: "day"
-					if (table == "festival_event_city" || table == "festival_event_gm") && (column == "start" || (column == "end" && value != "ul")) {
+					if (table == "festival_event_city" || table == "festival_event_gm") && column == "start" {
+						
+						NSLog("IVV Getting day")
 						
 						dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
 						dateFormatter.calendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.ISO8601)! as Calendar
@@ -265,14 +267,9 @@ class Sync{
 							day = Calendar.current.date(byAdding: .day, value: -1, to: day)!
 						}
 						query.setValue(day, forKey: "day")
-						
 					}
-					
-					
-					
 				}
 				
-				
 				let start: Int = row.indexOf(target: ",\"")! + 2
 				let end: Int = row.length
 				if (start == end){
@@ -285,7 +282,7 @@ class Sync{
 			}
 			
 			do{
-				// Save the setting
+				// Save the row
 				try context.save()
 			}
 			catch let error as NSError {
@@ -322,8 +319,8 @@ class Sync{
 			row = "\(row),\""
 			
 			while (row.indexOf(target: ",\"") != nil){
-				tuple = row.subStr(start: 0, end: row.indexOf(target: ",\"")! - 1)
 				
+				tuple = row.subStr(start: 0, end: row.indexOf(target: ",\"")! - 1)
 				column = tuple.subStr(start: 1, end: tuple.indexOf(target: "\":")! - 1)
 				value = tuple.subStr(start: column.length + 4, end: tuple.length - 2)
 				
@@ -335,13 +332,13 @@ class Sync{
 				}
 				
 				
-				let start: Int = row.indexOf(target: ",\"")! + 2
-				let end: Int = row.length
+				let start: Int = row.indexOf(target: ",\"")! + 1
+				let end: Int = row.length - 1
 				if (start == end){
 					row = ""
 				}
 				else{
-					row = row.subStr(start: row.indexOf(target: ",\"")! + 2, end: row.length - 1)
+					row = row.subStr(start: start, end: end)
 				}
 				
 			}
@@ -405,7 +402,7 @@ class Sync{
 							query.setValue(Int(version), forKey: "version")
 						}
 						
-						// Save the setting
+						// Save the row
 						try context.save()
 					}
 					catch let error as NSError  {