Unverified Commit 358dbe6e authored by Zach Knox's avatar Zach Knox
Browse files

alert filters

parent 9b7b4243
......@@ -17,7 +17,7 @@ class Filters {
var sortBy = SortMethod.alphabetical
var openFirst = true
var showAlerts = ["info":true, "minor":true, "major":true]
var showAlerts = ["Informational":true, "Minor Alerts":true, "Major Alerts":true]
var onlyFromLocations = [String: Bool]() // Locations to show, could simply use Location objects instead if you wanted
var onlyFromCategories = [String: Bool]() //same as above, but for Categories, not Locations
......
......@@ -138,6 +138,12 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
return
}
}
for f in filters.showAlerts {
if(f.value != true) {
LeftButton.title = "Filter (On)"
return
}
}
LeftButton.title = "Filter"
return
}
......@@ -252,7 +258,22 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
let now = Date()
for alert in alertsList {
if now.isGreaterThanDate(dateToCompare: formatter.date(from: alert.startDate)!) && now.isLessThanDate(dateToCompare: formatter.date(from: alert.endDate)!) {
shown.append(alert)
switch alert.urgency {
case "info":
if(filters.showAlerts["Informational"])! {
shown.append(alert)
}
case "minor":
if(filters.showAlerts["Minor Alerts"])! {
shown.append(alert)
}
case "major":
if(filters.showAlerts["Major Alerts"])! {
shown.append(alert)
}
default:
shown.append(alert)
}
}
}
currentAlerts = shown
......@@ -483,7 +504,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if(section == 1 || alertsList.count == 0) {
if(section == 1 || currentAlerts.count == 0) {
return shownFacilities.count
}
else {
......@@ -495,7 +516,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (indexPath.section == 1 || alertsList.count == 0) {
if (indexPath.section == 1 || currentAlerts.count == 0) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) as! FacilityCollectionViewCell
/*
let windowRect = self.view.window!.frame
......@@ -594,7 +615,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if(indexPath.section == 1 || alertsList.count == 0) {
if(indexPath.section == 1 || currentAlerts.count == 0) {
let height = LocationsListLayout.itemSize.height
let width: CGFloat
......
......@@ -78,6 +78,13 @@ class FilterSelectionTableViewController: UITableViewController {
return cell
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if navigationItem.title == "Alerts" {
return "Emergency Alerts are always enabled in the app for your safety. We will never send a notification to your device without your consent."
}
return nil
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if(indexPath.row == 0) {
selectAllFunc()
......
......@@ -90,7 +90,7 @@ class FiltersTableViewController: UITableViewController {
case 2:
return SortMethod.count
case 3:
return 2
return 3
default:
return 0
}
......@@ -205,6 +205,22 @@ class FiltersTableViewController: UITableViewController {
detail = "\(i) Selected"
}
cell.detailTextLabel?.text = detail
case 2:
cell.textLabel?.text = "Alerts"
var i = 0
for c in filters.showAlerts {
if(c.value == true) {
i += 1
}
}
var detail: String
if(i == filters.showAlerts.count) {
detail = "All Selected"
}
else {
detail = "\(i) Selected"
}
cell.detailTextLabel?.text = detail
default:
return cell
}
......@@ -292,10 +308,14 @@ class FiltersTableViewController: UITableViewController {
let destination = segue.destination as! FilterSelectionTableViewController
destination.navigationItem.title = (sender as! UITableViewCell).textLabel?.text!
func get() -> [String: Bool] {
if((sender as! UITableViewCell).textLabel?.text! == "Categories") {
return filters.onlyFromCategories
}
else if(sender as! UITableViewCell).textLabel?.text! == "Alerts" {
return filters.showAlerts
}
else {
return filters.onlyFromLocations
}
......@@ -304,6 +324,9 @@ class FiltersTableViewController: UITableViewController {
if((sender as! UITableViewCell).textLabel?.text! == "Categories") {
filters.onlyFromCategories[key] = value
}
else if(sender as! UITableViewCell).textLabel?.text! == "Alerts" {
filters.showAlerts[key] = value
}
else {
filters.onlyFromLocations[key] = value
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment