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 {
setAlerts.updateValue(true, forKey: "major alerts")
defaults.set(setAlerts, forKey: "alerts")
}
let campuses = defaults.dictionary(forKey: "campuses")
if campuses == nil {
defaults.set([String: Bool](), forKey: "alerts")
}
return true
}
......
......@@ -264,6 +264,24 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
// Facilities
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
favoritesControlChanges(self)
......@@ -272,7 +290,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
let formatter = ISO8601DateFormatter()
formatter.timeZone = TimeZone(identifier: "America/New_York")
let now = Date()
let defaults = UserDefaults.standard
let alertFilers = defaults.dictionary(forKey: "alerts") as! [String: Bool]?
for alert in alertsList {
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,
func updateFiltersLists() {
// Add locations and categories to filters
let defaults = UserDefaults.standard
var campusFilters = defaults.dictionary(forKey: "campuses") as! [String: Bool]?
for f in facilitiesArray {
if(!filters.onlyFromCategories.keys.contains((f.category?.categoryName)!)) {
filters.onlyFromCategories.updateValue(true, forKey: (f.category?.categoryName)!.lowercased())
......@@ -420,10 +439,11 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
if(!filters.onlyFromLocations.keys.contains((f.facilityLocation?.building)!)) {
filters.onlyFromLocations.updateValue(true, forKey: (f.facilityLocation?.building)!.lowercased())
}
if(!filters.onlyFromCampuses.keys.contains((f.facilityLocation?.campus)!)) {
filters.onlyFromCampuses.updateValue(true, forKey: (f.facilityLocation?.campus)!.lowercased())
if(!campusFilters!.keys.contains((f.facilityLocation?.campus)!)) {
campusFilters!.updateValue(true, forKey: (f.facilityLocation?.campus)!.lowercased())
}
}
defaults.set(campusFilters, forKey: "campuses")
}
/*
......
......@@ -58,7 +58,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
return 1
}
else if(section == 2) {
return 1
return 2
}
else if(section == 3) {
return 3
......@@ -84,20 +84,27 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
let cell = tableView.dequeueReusableCell(withIdentifier: "settingSelection", for: indexPath)
cell.accessoryType = .disclosureIndicator
switch indexPath.row {
case 0:
cell.textLabel?.text = "Show Alerts"
/*
let defaults = UserDefaults.standard
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
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
case 1:
cell.textLabel?.text = "Show Campuses"
let alerts = Utilities.getAlertDefaults()
var i = 0
for c in alerts {
......@@ -114,6 +121,10 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
}
cell.detailTextLabel?.text = detail
return cell
default:
return UITableViewCell() // don't do this
}
case 3:
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
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