Unverified Commit 23c1cdb1 authored by Zach Knox's avatar Zach Knox
Browse files

notifications work—still work to do but it's progress

also updated pods
parent fa006df2
......@@ -35,7 +35,7 @@ class FilterSelectionTableViewController: UITableViewController {
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
if navigationItem.title = "Alert Notifications" {
if navigationItem.title == "Alert Notifications" {
return 2
}
return 1
......@@ -55,7 +55,7 @@ class FilterSelectionTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section != 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "filterSelection", for: indexPath)
cell.accessoryType = .detailButton
cell.accessoryType = .disclosureIndicator
cell.textLabel?.text = "Open Notifications Settings"
return cell
}
......@@ -95,8 +95,8 @@ class FilterSelectionTableViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if section != 0 {
return "The above settings will only apply if you have notifications enabled for What's Open in Settings."
if section != 0 && navigationItem.title == "Alert Notifications" {
return "The above settings will only apply if you have notifications enabled for What's Open in Settings.\n\nBackground App Refresh is required in order to recieve notifications."
}
if navigationItem.title == "Show Alerts" {
......@@ -110,7 +110,9 @@ class FilterSelectionTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section != 0 {
UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!, completionHandler: nil)
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, completionHandler: nil)
let tableCell = tableView.cellForRow(at: indexPath)
tableCell?.isSelected = false
return
}
......
......@@ -76,9 +76,11 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
var favoriteFacilites = List<WOPFacility>()
// add the facility to favorites list if it is a favorite
favoriteFacilites = filteredFacilities.filter({ (facility: WOPFacility) -> Bool in
return WOPUtilities.isFavoriteFacility(facility)
})
for facility in filteredFacilities {
if WOPUtilities.isFavoriteFacility(facility) {
favoriteFacilites.append(facility)
}
}
return favoriteFacilites
}
......@@ -442,17 +444,17 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
List of filtered facilities. Facilities whose names, buildings, or categories match the search text are included.
*/
func filterFacilitiesForSearchText(_ searchText: String) -> List<WOPFacility> {
var filtered: List<WOPFacility>
var filtered = List<WOPFacility>()
if searchText == "" {
filtered = shownFacilities
LocationsList.reloadData()
return shownFacilities
}
filtered = filteredFacilities.filter({(facility: WOPFacility) -> Bool in
for facility in filteredFacilities {
let hasName = facility.facilityName.lowercased().contains(searchText.lowercased())
let hasBuilding = facility.facilityLocation?.building.lowercased().contains(searchText.lowercased()) ?? false
let hasAbbreviation = facility.facilityLocation?.abbreviation.lowercased().contains(searchText.lowercased()) ?? false
let hasAbbreviation = facility.facilityLocation?.abbreviation.lowercased().contains(searchText.lowercased()) ?? false
let hasCategory = facility.category?.categoryName.lowercased().contains(searchText.lowercased()) ?? false
var hasTag = false
for tag in facility.facilityTags! {
......@@ -472,8 +474,10 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
hasLabel = true
}
}
return hasName || hasBuilding || hasCategory || hasTag || hasAbbreviation
})
if hasName || hasBuilding || hasCategory || hasTag || hasAbbreviation {
filtered.append(facility)
}
}
LocationsList.reloadData()
return filtered
......
......@@ -47,7 +47,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 4
return 5
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
......@@ -62,6 +62,9 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
return 2
}
else if(section == 3) {
return 1
}
else if(section == 4) {
return 3
}
else {
......@@ -142,6 +145,11 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
}
case 3:
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
cell.textLabel!.text = "Alert Notifications"
cell.accessoryType = .disclosureIndicator
return cell
case 4:
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
switch indexPath.row {
case 0:
......@@ -186,6 +194,14 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
else {
present(mailvc, animated: true)
}
} else if settingcell.textLabel?.text == "Alert Notifications" {
let destination = self.storyboard?.instantiateViewController(withIdentifier: "filtersVC") as! FilterSelectionTableViewController
destination.navigationItem.title = "Alert Notifications"
destination.getFunc = WOPUtilities.getAlertNotificationDefaults
destination.selectFunc = WOPUtilities.setAlertNotificationDefaults
destination.selectAllFunc = WOPUtilities.setAllAlertNotificationDefaults
destination.updateFacilities = updateFacilities
self.show(destination, sender: self)
}
else if settingcell.textLabel?.text == "Select App Icon" {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "setAppIcon")
......@@ -285,14 +301,6 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
destination.selectAllFunc = WOPUtilities.setAllAlertDefaults
destination.updateFacilities = updateFacilities
}
else if (sender as! UITableViewCell).textLabel?.text == "Alert Notifications" {
let destination = segue.destination as! FilterSelectionTableViewController
destination.navigationItem.title = "Alert Notifications"
destination.getFunc = WOPUtilities.getCampusDefaults
destination.selectFunc = WOPUtilities.setCampusDefaults
destination.selectAllFunc = WOPUtilities.setAllCampusDefaults
destination.updateFacilities = updateFacilities
}
else if (sender as! UITableViewCell).textLabel?.text == "Show Campuses" {
let destination = segue.destination as! FilterSelectionTableViewController
destination.navigationItem.title = "Show Campuses"
......
......@@ -41,7 +41,9 @@ public class WOPDownloadController: NSObject {
})
// This is where completion is called
// Right after the array is done mapping all facility objects
completion(List(facilities))
let list = List<WOPFacility>()
list.append(objectsIn: facilities)
completion(list)
}
}
}
......@@ -80,7 +82,9 @@ public class WOPDownloadController: NSObject {
})
// This is where completion is called
// Right after the array is done mapping all facility objects
completion(List(alerts))
let list = List<WOPAlert>()
list.append(objectsIn: alerts)
completion(list)
}
}
}
......
......@@ -255,9 +255,12 @@ public class WOPUtilities: NSObject {
let now = Date()
if(facility.specialSchedules != nil) {
for schedule in facility.specialSchedules! {
if schedule.validStart == "" {
dump(schedule)
}
let start = formatter.date(from: schedule.validStart)
let end = formatter.date(from: schedule.validEnd)
if start! < now && end! > now {
return schedule
}
......@@ -476,6 +479,8 @@ public class WOPUtilities: NSObject {
true if the option was changed correctly.
*/
public static func setAlertNotificationDefaults(_ key: String, value: Bool) -> Bool {
var returning = false
if value == true {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.getNotificationSettings { (settings) in
......@@ -486,11 +491,13 @@ public class WOPUtilities: NSObject {
var alerts = defaults.dictionary(forKey: "notificationDefaults") as! [String: Bool]?
if alerts != nil {
alerts!.updateValue(value, forKey: key)
defaults.set(alerts, forKey: "alerts")
return true
defaults.set(alerts, forKey: "notificationDefaults")
returning = true
return
}
else {
return false
returning = false
return
}
} else {
return
......@@ -504,16 +511,30 @@ public class WOPUtilities: NSObject {
var alerts = defaults.dictionary(forKey: "notificationDefaults") as! [String: Bool]?
if alerts != nil {
alerts!.updateValue(value, forKey: key)
defaults.set(alerts, forKey: "alerts")
return true
defaults.set(alerts, forKey: "notificationDefaults")
returning = true
return
}
else {
return false
returning = false
return
}
}
}
} else {
let defaults = WOPDatabaseController.getDefaults()
var alerts = defaults.dictionary(forKey: "notificationDefaults") as! [String: Bool]?
if alerts != nil {
alerts!.updateValue(value, forKey: key)
defaults.set(alerts, forKey: "notificationDefaults")
returning = true
}
else {
returning = false
}
}
return returning
}
/**
......@@ -537,7 +558,7 @@ public class WOPUtilities: NSObject {
for alert in alerts! {
alerts!.updateValue(foundFalse, forKey: alert.key)
}
defaults.set(alerts, forKey: "alerts")
defaults.set(alerts, forKey: "notificationDefaults")
return true
}
else {
......@@ -551,7 +572,7 @@ public class WOPUtilities: NSObject {
- returns:
item stored in User Defaults for key 'notificationDefaults'
*/
public static func getAlertDefaults() -> [String: Bool] {
public static func getAlertNotificationDefaults() -> [String: Bool] {
let defaults = WOPDatabaseController.getDefaults()
let returning = defaults.dictionary(forKey: "notificationDefaults") as! [String: Bool]?
if returning == nil {
......
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