Commit c14347e3 authored by Zach Knox's avatar Zach Knox
Browse files

Merge branch 'persist-alerts' into 'dev-0.0'

Persist alerts

See merge request !22
parents 6b529f18 1072a6c6
......@@ -241,6 +241,7 @@
E09CBA67A9A59A8E148F3FE7 /* [CP] Copy Pods Resources */,
92FF6C7820017E1C00D836AE /* Run Script */,
922C3C1B200306F5008E1146 /* ShellScript */,
92A4237E201190EA00010B73 /* ShellScript */,
);
buildRules = (
);
......@@ -270,7 +271,7 @@
};
CD81F5181DC0334600009FBD = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = K5MMVK2UFR;
DevelopmentTeam = N5GM564QWL;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
};
......@@ -374,6 +375,19 @@
shellPath = /bin/sh;
shellScript = "# This relies on the following program. Alternate app icons WILL NOT WORK without running this (as they're stored in a separate asset catalog)\n# https://github.com/alexaubry/alternate-icons\nif [ \"$CONFIGURATION\" == \"App Store\" ]; then\n embed-alternate-icons\nfi\n";
};
92A4237E201190EA00010B73 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 8;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 1;
shellPath = /bin/sh;
shellScript = "#!/bin/bash\nbuildNumber=$(/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" \"$INFOPLIST_FILE\")\nbuildNumber=$(($buildNumber + 1))\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"$INFOPLIST_FILE\"";
};
92FF6C7820017E1C00D836AE /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
......
......@@ -25,6 +25,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
Fabric.with([Crashlytics.self])
#endif
let defaults = UserDefaults.standard
let alerts = defaults.dictionary(forKey: "alerts")
if alerts == 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")
}
return true
}
......
......@@ -28,15 +28,30 @@
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Checkbox Filter" textLabel="rYu-5q-2u8" style="IBUITableViewCellStyleDefault" id="x5H-BH-cVX" customClass="CheckingTableViewCell" customModule="WhatsOpen" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="Checkbox Filter" id="acT-0Y-66n" customClass="CheckingTableViewCell" customModule="WhatsOpen" customModuleProvider="target">
<rect key="frame" x="0.0" y="99.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="x5H-BH-cVX" id="xf1-yc-ynP">
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="acT-0Y-66n" id="eyW-ce-b3u">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="toSelection" textLabel="y9D-Za-zSF" detailTextLabel="DUJ-JB-MFi" style="IBUITableViewCellStyleValue1" id="AYg-3T-fMg">
<rect key="frame" x="0.0" y="143.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="AYg-3T-fMg" id="b0b-tc-t8O">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Sort By x" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rYu-5q-2u8">
<rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="y9D-Za-zSF">
<rect key="frame" x="16" y="12" width="33.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="DUJ-JB-MFi">
<rect key="frame" x="296" y="12" width="44" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
......@@ -44,10 +59,12 @@
</label>
</subviews>
</tableViewCellContentView>
<color key="tintColor" red="0.0" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
<connections>
<segue destination="yIT-AR-gdn" kind="show" identifier="toSelection" id="lwF-fe-hI5"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="picking" rowHeight="157" id="Qzo-pS-g9l" customClass="PickingTableViewCell" customModule="WhatsOpen" customModuleProvider="target">
<rect key="frame" x="0.0" y="143.5" width="375" height="157"/>
<rect key="frame" x="0.0" y="187.5" width="375" height="157"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Qzo-pS-g9l" id="gyt-MF-bQ2">
<rect key="frame" x="0.0" y="0.0" width="375" height="156.5"/>
......@@ -68,33 +85,6 @@
<outlet property="pickerView" destination="Rpt-Of-2BY" id="ek7-I8-MFW"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="toSelection" textLabel="1gJ-n6-QQk" detailTextLabel="gbn-2b-WZh" style="IBUITableViewCellStyleValue1" id="HkW-HK-Uqf">
<rect key="frame" x="0.0" y="300.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="HkW-HK-Uqf" id="3BF-KX-2nF">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1gJ-n6-QQk">
<rect key="frame" x="16" y="12" width="33.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="gbn-2b-WZh">
<rect key="frame" x="296" y="12" width="44" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="yIT-AR-gdn" kind="show" identifier="toSelection" id="86R-Fz-PuY"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="jkQ-vu-LQa" id="DbO-38-R86"/>
......@@ -145,7 +135,7 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="5t1-ko-HSd" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-8599" y="362"/>
<point key="canvasLocation" x="-8153" y="448"/>
</scene>
<!--What's Open-->
<scene sceneID="w5e-Fb-rsR">
......@@ -376,6 +366,33 @@
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="settingSelection" textLabel="Jpe-0x-5LR" detailTextLabel="x21-Vr-OJr" style="IBUITableViewCellStyleValue1" id="fc0-pe-nJl">
<rect key="frame" x="0.0" y="99.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="fc0-pe-nJl" id="dQS-VU-1IK">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="Jpe-0x-5LR">
<rect key="frame" x="16" y="12" width="33.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="x21-Vr-OJr">
<rect key="frame" x="296" y="12" width="44" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="yIT-AR-gdn" kind="show" identifier="settingSelection" id="FRf-a6-Dgs"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="Lhp-lE-ieb" id="B56-3p-ltP"/>
......@@ -844,5 +861,8 @@
<image name="info" width="266" height="266"/>
<image name="major" width="266" height="266"/>
</resources>
<inferredMetricsTieBreakers>
<segue reference="lwF-fe-hI5"/>
</inferredMetricsTieBreakers>
<color key="tintColor" red="0.0" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
</document>
......@@ -304,7 +304,74 @@ class Utilities: NSObject {
return false
}
}
// MARK - Persistent Alerts
/**
Sets alerts settings in User Defaults
- returns:
true if the alerts was added correctly.
*/
static func setAlertDefaults(_ key: String, value: Bool) -> Bool {
let defaults = UserDefaults.standard
var alerts = defaults.dictionary(forKey: "alerts") as! [String: Bool]?
if alerts != nil {
alerts!.updateValue(value, forKey: key)
defaults.set(alerts, forKey: "alerts")
return true
}
else {
return false
}
}
/**
Sets all alerts settings in User Defaults to true
- returns:
true if the alerts was changed correctly, false if nil was retrieved from User Defaults.
*/
static func setAllAlertDefaults() -> Bool {
let defaults = UserDefaults.standard
var alerts = defaults.dictionary(forKey: "alerts") as! [String: Bool]?
if alerts != nil {
var foundFalse = false
for a in alerts! {
if a.value == false {
foundFalse = true
break
}
}
for alert in alerts! {
alerts!.updateValue(foundFalse, forKey: alert.key)
}
defaults.set(alerts, forKey: "alerts")
return true
}
else {
return false
}
}
/**
Gets alerts settings in User Defaults
- returns:
item stored in User Defaults for key 'alerts'
*/
static func getAlertDefaults() -> [String: Bool] {
let defaults = UserDefaults.standard
let returning = defaults.dictionary(forKey: "alerts") as! [String: Bool]?
if returning == nil {
return [:]
}
else {
return returning!
}
}
}
extension DateFormatter {
......
......@@ -148,12 +148,6 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
return
}
}
for f in filters.showAlerts {
if(f.value != true) {
LeftButton.title = "Filter (On)"
return
}
}
LeftButton.title = "Filter"
return
}
......@@ -278,19 +272,21 @@ 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)!) {
switch alert.urgency {
case "info":
if(filters.showAlerts["Informational"])! {
if(alertFilers!["informational"])! {
shown.append(alert)
}
case "minor":
if(filters.showAlerts["Minor Alerts"])! {
if(alertFilers!["minor alerts"])! {
shown.append(alert)
}
case "major":
if(filters.showAlerts["Major Alerts"])! {
if(alertFilers!["major alerts"])! {
shown.append(alert)
}
default:
......@@ -722,9 +718,12 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
var sectionInsets = LocationsListLayout.sectionInset
if(section != 1 && alertsList.count != 0) {
if(section != 1 && currentAlerts.count != 0) {
sectionInsets.top = 0
}
else if currentAlerts.count == 0 {
sectionInsets.top = 15
}
return sectionInsets
}
......
......@@ -73,7 +73,7 @@ class FilterSelectionTableViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if navigationItem.title == "Alerts" {
if navigationItem.title == "Show 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
......@@ -94,7 +94,7 @@ class FilterSelectionTableViewController: UITableViewController {
res = false
}
_ = selectFunc((tableCell?.textLabel?.text)!.lowercased(), res)
tableView.reloadRows(at: [IndexPath(row: 0, section: 0), indexPath], with: .automatic)
tableView.reloadData()
}
}
......
......@@ -90,7 +90,7 @@ class FiltersTableViewController: UITableViewController {
case 2:
return SortMethod.count
case 3:
return 4
return 3
default:
return 0
}
......@@ -221,22 +221,6 @@ class FiltersTableViewController: UITableViewController {
detail = "\(i) Selected"
}
cell.detailTextLabel?.text = detail
case 3:
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
}
......
......@@ -21,6 +21,10 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
self.dismiss(animated: true, completion: nil)
}
override func viewWillAppear(_ animated: Bool) {
tableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
......@@ -42,8 +46,7 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 3
return 4
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
......@@ -55,6 +58,9 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
return 1
}
else if(section == 2) {
return 1
}
else if(section == 3) {
return 3
}
else {
......@@ -63,15 +69,53 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
switch indexPath.section {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
cell.textLabel!.text = "Are Our Hours Wrong?"
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
cell.textLabel!.text = "Select App Icon"
cell.accessoryType = .disclosureIndicator
return cell
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "settingSelection", for: indexPath)
cell.accessoryType = .disclosureIndicator
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 3:
let cell = tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell
switch indexPath.row {
case 0:
cell.textLabel!.text = "Review on the App Store"
......@@ -83,18 +127,13 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
default:
cell.textLabel!.text = "rip"
}
if indexPath.row == 0 {
}
else if indexPath.row == 1 {
}
return cell
default:
break
}
// Configure the cell...
return cell
return tableView.dequeueReusableCell(withIdentifier: "Setting", for: indexPath) as! SettingTableViewCell // don't let this happen
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
......@@ -126,21 +165,13 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
self.show(vc!, sender: settingcell)
}
else if settingcell.textLabel?.text == "Review on the App Store" {
let appPage = SKStoreProductViewController()
let params = [SKStoreProductParameterITunesItemIdentifier: 1331260366]
appPage.loadProduct(withParameters: params, completionBlock: { (result, err) in
if err == nil && result == true {
self.present(appPage, animated: true)
print("presenting")
}
else {
let alert = UIAlertController(title: "Cound Not Find App in Store", message: "Check your network connection", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .`default`, handler: { _ in
}))
self.present(alert, animated: true)
print("alerting")
}
})
let appId = "1331260366"
let urlString = "itms-apps://itunes.apple.com/us/app/whats-open-at-mason/id\(appId)?action=write-review"
if let url = URL(string: urlString) {
UIApplication.shared.open((url), options: [:], completionHandler: nil)
}
}
else if settingcell.textLabel!.text == "About What's Open" {
let avc = self.storyboard?.instantiateViewController(withIdentifier: "about")
......@@ -206,14 +237,22 @@ class SettingsTableViewController: UITableViewController, MFMailComposeViewContr
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if segue.identifier == "settingSelection" {
let destination = segue.destination as! FilterSelectionTableViewController
destination.navigationItem.title = "Show Alerts"
destination.getFunc = Utilities.getAlertDefaults
destination.selectFunc = Utilities.setAlertDefaults
destination.selectAllFunc = Utilities.setAllAlertDefaults
}
}
*/
}
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