Skip to content

Commit

Permalink
Tweak accuracy and add spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
stlk committed Jan 11, 2020
1 parent 2a22e5a commit 21132f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<outlet property="delegate" destination="M4Y-Lb-cyx" id="D9r-Zq-OAh"/>
</connections>
</tableView>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" hidesWhenStopped="YES" style="large" translatesAutoresizingMaskIntoConstraints="NO" id="HZo-NX-9uC">
<rect key="frame" x="150" y="17" width="20" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</activityIndicatorView>
</subviews>
<constraints>
<constraint firstItem="vh5-hX-TAF" firstAttribute="bottom" secondItem="ssy-KU-ocm" secondAttribute="bottom" id="0nf-C2-ExO"/>
Expand All @@ -62,6 +66,7 @@
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<size key="freeformSize" width="320" height="37"/>
<connections>
<outlet property="spinner" destination="HZo-NX-9uC" id="wlz-Jx-Jhr"/>
<outlet property="table" destination="vh5-hX-TAF" id="rV9-2e-7yq"/>
</connections>
</viewController>
Expand Down
21 changes: 7 additions & 14 deletions app/Departures/TodayWidgetDepartures/TodayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class TodayViewController: UIViewController, UITableViewDelegate, UITableViewDat
fileprivate let kCellHeight : CGFloat = 30
lazy private var locManager = CLLocationManager()
private var departuresSections : [Section] = []
@IBOutlet weak var spinner: UIActivityIndicatorView!


override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -47,15 +49,15 @@ class TodayViewController: UIViewController, UITableViewDelegate, UITableViewDat
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

locManager.desiredAccuracy = kCLLocationAccuracyBest
locManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locManager.requestWhenInUseAuthorization()
locManager.requestLocation()
}


func getDepartures(latitude: String, longitude: String) {
if let url = URL(string: "https://departures.stlk.now.sh/api/departures?latitude=" + latitude + "&longitude=" + longitude) {

spinner.startAnimating()
if let url = URL(string: "https://departures.now.sh/api/departures?latitude=" + latitude + "&longitude=" + longitude) {
let request = NSMutableURLRequest(url: url)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
data, response, error in
Expand All @@ -72,6 +74,7 @@ class TodayViewController: UIViewController, UITableViewDelegate, UITableViewDat
})
print(self.departuresSections)
DispatchQueue.main.sync(execute: {
self.spinner.stopAnimating()
self.table.reloadData()
self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
})
Expand All @@ -90,15 +93,11 @@ class TodayViewController: UIViewController, UITableViewDelegate, UITableViewDat
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.departuresSections.count == 0
{
return 1
}
return self.departuresSections[section].collapsed ? 0: self.departuresSections[section].departures.count
}

func numberOfSections(in tableView: UITableView) -> Int {
self.departuresSections.count
return self.departuresSections.count
}

// Not needed for collapsible section header
Expand All @@ -108,12 +107,6 @@ class TodayViewController: UIViewController, UITableViewDelegate, UITableViewDat

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
if self.departuresSections.count == 0
{
cell.textLabel?.text = "loading..."
return cell
}

let departure = self.departuresSections[indexPath.section].departures[indexPath.row]

cell.textLabel?.text = departure.route_short_name + " - " + departure.trip_headsign
Expand Down

0 comments on commit 21132f3

Please sign in to comment.