Unverified Commit 979fa063 authored by Zach Knox's avatar Zach Knox
Browse files

getting things prepared for persistent campus filters—not there yet

parent 74a1f621
...@@ -34,6 +34,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -34,6 +34,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
setAlerts.updateValue(true, forKey: "major alerts") setAlerts.updateValue(true, forKey: "major alerts")
defaults.set(setAlerts, forKey: "alerts") defaults.set(setAlerts, forKey: "alerts")
} }
let campuses = defaults.dictionary(forKey: "campuses")
if campuses == nil {
defaults.set([String: Bool](), forKey: "alerts")
}
return true return true
} }
......
...@@ -264,6 +264,24 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, ...@@ -264,6 +264,24 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
// Facilities // Facilities
filteredFacilities = filters.applyFiltersOnFacilities(facilitiesArray) filteredFacilities = filters.applyFiltersOnFacilities(facilitiesArray)
let defaults = UserDefaults.standard
// Campuses
// By the time you've called reloadWithFilters(), the defaults list should already be updated to include
// all campuses via updateFilterLists
let campusFilters = defaults.dictionary(forKey: "campuses") as! [String: Bool]?
let filteredByCampus = List<Facility>()
for facility in filteredFacilities {
if campusFilters![(facility.facilityLocation?.campus.lowercased())!]! {
filteredByCampus.append(facility)
}
}
filteredFacilities = filteredByCampus
shownFacilities = filteredFacilities shownFacilities = filteredFacilities
favoritesControlChanges(self) favoritesControlChanges(self)
...@@ -272,7 +290,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, ...@@ -272,7 +290,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
let formatter = ISO8601DateFormatter() let formatter = ISO8601DateFormatter()
formatter.timeZone = TimeZone(identifier: "America/New_York") formatter.timeZone = TimeZone(identifier: "America/New_York")
let now = Date() let now = Date()
let defaults = UserDefaults.standard
let alertFilers = defaults.dictionary(forKey: "alerts") as! [String: Bool]? let alertFilers = defaults.dictionary(forKey: "alerts") as! [String: Bool]?
for alert in alertsList { for alert in alertsList {
if now.isGreaterThanDate(dateToCompare: formatter.date(from: alert.startDate)!) && now.isLessThanDate(dateToCompare: formatter.date(from: alert.endDate)!) { if now.isGreaterThanDate(dateToCompare: formatter.date(from: alert.startDate)!) && now.isLessThanDate(dateToCompare: formatter.date(from: alert.endDate)!) {
...@@ -413,6 +430,8 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, ...@@ -413,6 +430,8 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
func updateFiltersLists() { func updateFiltersLists() {
// Add locations and categories to filters // Add locations and categories to filters
let defaults = UserDefaults.standard
var campusFilters = defaults.dictionary(forKey: "campuses") as! [String: Bool]?
for f in facilitiesArray { for f in facilitiesArray {
if(!filters.onlyFromCategories.keys.contains((f.category?.categoryName)!)) { if(!filters.onlyFromCategories.keys.contains((f.category?.categoryName)!)) {
filters.onlyFromCategories.updateValue(true, forKey: (f.category?.categoryName)!.lowercased()) filters.onlyFromCategories.updateValue(true, forKey: (f.category?.categoryName)!.lowercased())
...@@ -420,10 +439,11 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, ...@@ -420,10 +439,11 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
if(!filters.onlyFromLocations.keys.contains((f.facilityLocation?.building)!)) { if(!filters.onlyFromLocations.keys.contains((f.facilityLocation?.building)!)) {
filters.onlyFromLocations.updateValue(true, forKey: (f.facilityLocation?.building)!.lowercased()) filters.onlyFromLocations.updateValue(true, forKey: (f.facilityLocation?.building)!.lowercased())
} }
if(!filters.onlyFromCampuses.keys.contains((f.facilityLocation?.campus)!)) { if(!campusFilters!.keys.contains((f.facilityLocation?.campus)!)) {
filters.onlyFromCampuses.updateValue(true, forKey: (f.facilityLocation?.campus)!.lowercased()) campusFilters!.updateValue(true, forKey: (f.facilityLocation?.campus)!.lowercased())
} }
} }
defaults.set(campusFilters, forKey: "campuses")
} }
/* /*
......
...@@ -58,7 +58,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr ...@@ -58,7 +58,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
return 1 return 1
} }
else if(section == 2) { else if(section == 2) {
return 1 return 2
} }
else if(section == 3) { else if(section == 3) {
return 3 return 3
...@@ -84,36 +84,47 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr ...@@ -84,36 +84,47 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
let cell = tableView.dequeueReusableCell(withIdentifier: "settingSelection", for: indexPath) let cell = tableView.dequeueReusableCell(withIdentifier: "settingSelection", for: indexPath)
cell.accessoryType = .disclosureIndicator cell.accessoryType = .disclosureIndicator
cell.textLabel?.text = "Show Alerts" switch indexPath.row {
case 0:
/* cell.textLabel?.text = "Show Alerts"
let defaults = UserDefaults.standard let alerts = Utilities.getAlertDefaults()
let alertsFromDefaults = defaults.dictionary(forKey: "alerts")
if alertsFromDefaults == nil {
var setAlerts = [String: Bool]()
setAlerts.updateValue(true, forKey: "Informational")
setAlerts.updateValue(true, forKey: "Minor Alerts")
setAlerts.updateValue(true, forKey: "Major Alerts")
defaults.set(setAlerts, forKey: "alerts")
}
*/
let alerts = Utilities.getAlertDefaults()
var i = 0 var i = 0
for c in alerts { for c in alerts {
if(c.value == true) { if(c.value == true) {
i += 1 i += 1
} }
} }
var detail: String var detail: String
if(i == alerts.count) { if(i == alerts.count) {
detail = "All Selected" detail = "All Selected"
} }
else { else {
detail = "\(i) Selected" detail = "\(i) Selected"
} }
cell.detailTextLabel?.text = detail cell.detailTextLabel?.text = detail
return cell return cell
case 1:
cell.textLabel?.text = "Show Campuses"
let alerts = Utilities.getAlertDefaults()
var i = 0
for c in alerts {
if(c.value == true) {
i += 1
}
}
var detail: String
if(i == alerts.count) {
detail = "All Selected"
}
else {
detail = "\(i) Selected"
}
cell.detailTextLabel?.text = detail
return cell
default:
return UITableViewCell() // don't do this
}
case 3: case 3:
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
switch indexPath.row { switch indexPath.row {
......
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