Jelajahi Sumber

No-reporting screen implemented. Increased fetching intervals.

Iñigo Valentin 9 tahun lalu
induk
melakukan
47cca3099b
3 mengubah file dengan 49 tambahan dan 19 penghapusan
  1. 34 17
      app/LocationView.swift
  2. 13 1
      app/LocationView.xib
  3. 2 1
      app/ViewController.swift

+ 34 - 17
app/LocationView.swift

@@ -29,7 +29,9 @@ class LocationView: UIView {
 	
 	@IBOutlet var container: UIView!
 	@IBOutlet weak var map: GMSMapView!
+	@IBOutlet weak var lbTitle: UILabel!
 	@IBOutlet weak var lbDistance: UILabel!
+	@IBOutlet weak var lbNo: UILabel!
 	
 	var controller: ViewController
 	var storyboard: UIStoryboard
@@ -70,7 +72,9 @@ class LocationView: UIView {
 		let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: 42.846399, longitude: -2.673365, zoom: 12.0)
 		map.camera = camera
 		
-		Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(getNewLocation), userInfo: nil, repeats: true)
+		// Schedule location fetches
+		getNewLocation()
+		Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(getNewLocation), userInfo: nil, repeats: true)
 	}
 	
 	
@@ -94,26 +98,39 @@ class LocationView: UIView {
 			let lat = defaults.value(forKey: "GMLocLat") as! Double
 			let lon = defaults.value(forKey: "GMLocLon") as! Double
 			let time = defaults.value(forKey: "GMLocTime") as! Date
-			// TODO compare time
-			let marker = GMSMarker()
-			marker.position = CLLocationCoordinate2D(latitude: lat, longitude: lon)
-			marker.title = "Gasteizko Margolariak"
-			//marker.snippet = "Australia"
-			marker.map = self.map
-			NSLog(":LOCATION:DEBUG: Marker set.")
+			let cTime = Date()
+			let minutes = Calendar.current.dateComponents([.minute], from: time, to: cTime).minute
+			if (minutes! < 30){
+				self.map.isHidden = false
+				self.lbTitle.isHidden = false
+				self.lbDistance.isHidden = false
+				self.lbNo.isHidden = true
+				let marker = GMSMarker()
+				marker.position = CLLocationCoordinate2D(latitude: lat, longitude: lon)
+				marker.title = "Gasteizko Margolariak"
+				//marker.snippet = "Australia"
+				marker.map = self.map
+				NSLog(":LOCATION:DEBUG: Marker set.")
 			
-			let location = self.controller.getLocation()
-			if location != nil {
-				let d: Int = calculateDistance(lat1: location.latitude, lon1: location.longitude, lat2: lat, lon2: lon)
-				NSLog(":LOCATION:LOG: Distance (m): \(d)")
+				let location = self.controller.getLocation()
+				if location != nil {
+					let d: Int = calculateDistance(lat1: location.latitude, lon1: location.longitude, lat2: lat, lon2: lon)
+					NSLog(":LOCATION:LOG: Distance (m): \(d)")
 				
-				if d <= 1000 {
-					self.lbDistance.text = "A \(d) metros de ti."
-				}
-				else{
-					self.lbDistance.text = "A \(Int(d/1000)) kilómetros de ti."
+					if d <= 1000 {
+						self.lbDistance.text = "A \(d) metros de ti."
+					}
+					else{
+						self.lbDistance.text = "A \(Int(d/1000)) kilómetros de ti."
+					}
 				}
 			}
+			else{
+				self.map.isHidden = true
+				self.lbTitle.isHidden = true
+				self.lbDistance.isHidden = true
+				self.lbNo.isHidden = false
+			}
 		}
 		else{
 			NSLog(":LOCATION:DEBUG: No location saved yet.")

+ 13 - 1
app/LocationView.xib

@@ -13,6 +13,8 @@
             <connections>
                 <outlet property="container" destination="iN0-l3-epB" id="HCq-e3-37n"/>
                 <outlet property="lbDistance" destination="lB5-i1-GOe" id="50S-QH-XrM"/>
+                <outlet property="lbNo" destination="hMd-9C-Onm" id="v1m-XE-RIG"/>
+                <outlet property="lbTitle" destination="jwp-Sd-GF5" id="aU9-kg-OHt"/>
                 <outlet property="map" destination="guk-vu-ykd" id="zo6-Wc-NCg"/>
             </connections>
         </placeholder>
@@ -43,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="A X metros de ti." textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lB5-i1-GOe" userLabel="Message">
+                                <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">
                                     <rect key="frame" x="11.5" y="42" width="311" height="21"/>
                                     <constraints>
                                         <constraint firstAttribute="height" constant="21" id="ann-h3-NzS"/>
@@ -52,6 +54,12 @@
                                     <nil key="textColor"/>
                                     <nil key="highlightedColor"/>
                                 </label>
+                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Gasteizko Margolariak no está reportando localización." textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hMd-9C-Onm" userLabel="MessageNo">
+                                    <rect key="frame" x="12" y="10" width="311" height="53"/>
+                                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                    <nil key="textColor"/>
+                                    <nil key="highlightedColor"/>
+                                </label>
                                 <view 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"/>
@@ -72,9 +80,13 @@
                             <constraints>
                                 <constraint firstItem="jwp-Sd-GF5" firstAttribute="centerX" secondItem="3aZ-8G-e8X" secondAttribute="centerX" id="6vZ-Ex-Gdp"/>
                                 <constraint firstItem="lB5-i1-GOe" firstAttribute="centerX" secondItem="3aZ-8G-e8X" secondAttribute="centerX" id="8VC-kx-sMo"/>
+                                <constraint firstItem="hMd-9C-Onm" firstAttribute="top" secondItem="jwp-Sd-GF5" secondAttribute="top" id="DMM-cd-pay"/>
+                                <constraint firstItem="hMd-9C-Onm" firstAttribute="bottom" secondItem="lB5-i1-GOe" secondAttribute="bottom" id="IYr-qB-csg"/>
                                 <constraint firstItem="lB5-i1-GOe" firstAttribute="width" secondItem="3aZ-8G-e8X" secondAttribute="width" constant="-24" id="MQn-K0-SK5"/>
                                 <constraint firstItem="jwp-Sd-GF5" firstAttribute="top" secondItem="3aZ-8G-e8X" secondAttribute="top" constant="10" id="Ni3-zk-KAJ"/>
                                 <constraint firstItem="guk-vu-ykd" firstAttribute="width" secondItem="3aZ-8G-e8X" secondAttribute="width" constant="-20" id="OK6-Tx-KhU"/>
+                                <constraint firstItem="hMd-9C-Onm" firstAttribute="width" secondItem="3aZ-8G-e8X" secondAttribute="width" constant="-24" id="Pg4-Ng-sSd"/>
+                                <constraint firstItem="hMd-9C-Onm" firstAttribute="centerX" secondItem="3aZ-8G-e8X" secondAttribute="centerX" id="Pw4-7b-hDi"/>
                                 <constraint firstItem="guk-vu-ykd" firstAttribute="top" secondItem="lB5-i1-GOe" secondAttribute="bottom" constant="10" id="Q8e-BQ-NFd"/>
                                 <constraint firstItem="lB5-i1-GOe" firstAttribute="top" secondItem="jwp-Sd-GF5" secondAttribute="bottom" constant="10" id="i7u-s7-Fz0"/>
                                 <constraint firstItem="guk-vu-ykd" firstAttribute="centerX" secondItem="3aZ-8G-e8X" secondAttribute="centerX" id="ifj-50-FJg"/>

+ 2 - 1
app/ViewController.swift

@@ -181,7 +181,8 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		self.containerViewGallery.alpha = 0
 		
 		// Start the location schedule
-		self.locationTimer = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(fetchLocation), userInfo: nil, repeats: true)
+		fetchLocation()
+		self.locationTimer = Timer.scheduledTimer(timeInterval: 90, target: self, selector: #selector(fetchLocation), userInfo: nil, repeats: true)
 				
 		NSLog(":CONTROLLER:DEBUG: Don't skyp sync")
 		Sync()