Skip to content

Commit

Permalink
sorting works for alphabetical and number of free spots
Browse files Browse the repository at this point in the history
See #1 and #37
  • Loading branch information
kiliankoe committed Mar 19, 2015
1 parent 60a4265 commit 557d182
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions ParkenDD/ServerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ServerController {
lotState = lotstate.closed
default:
lotState = lotstate.nodata
lotFree = -1
}

// hehe, lotLat is an awesome name for a variable
Expand Down
21 changes: 19 additions & 2 deletions ParkenDD/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
// Store the single parking lots once they're retrieved from the server
// a single subarray for each section
var parkinglots: [Parkinglot] = []
var defaultSortedParkinglots: [Parkinglot] = []
var sectionNames: [String] = []

override func viewDidLoad() {
Expand Down Expand Up @@ -56,6 +57,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
}

override func viewWillAppear(animated: Bool) {
sortLots()
tableView.reloadData()
}

Expand Down Expand Up @@ -103,6 +105,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
} else if let secNames = secNames, plotList = plotList {
self.sectionNames = secNames
self.parkinglots = plotList
self.defaultSortedParkinglots = plotList
self.sortLots()

// Reload the tableView on the main thread, otherwise it will only update once the user interacts with it
Expand All @@ -126,7 +129,21 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
}

func sortLots() {

let sortingType = NSUserDefaults.standardUserDefaults().stringForKey("SortingType")
switch sortingType! {
case "location":
println("sorting after location")
case "alphabetical":
parkinglots.sort({
$0.name < $1.name
})
case "free":
parkinglots.sort({
$0.free > $1.free
})
default:
parkinglots = defaultSortedParkinglots
}
}

// MARK: - IBActions
Expand Down Expand Up @@ -196,7 +213,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
}

// Maybe a future version of the scraper will be able to read the tendency as well
if thisLot.state == lotstate.nodata && thisLot.free == 0 {
if thisLot.state == lotstate.nodata && thisLot.free == -1 {
cell.parkinglotTendencyLabel.text = NSLocalizedString("UNKNOWN_LOAD", comment: "unknown")
} else if thisLot.state == lotstate.closed {
cell.parkinglotTendencyLabel.text = NSLocalizedString("CLOSED", comment: "closed")
Expand Down

0 comments on commit 557d182

Please sign in to comment.