Skip to content

Commit a3c5544

Browse files
committed
Fixed countdown cancel action
- Count down cancel button can now abort automatic calling and texting - Fixed issue with automatic double texting - Fixed issue with null emergency contact list upon automatic
1 parent e3a31c1 commit a3c5544

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

iosApp/VC/Controllers/CountdownViewController.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import SwiftUI
1212
class CountdownViewController: UIViewController {
1313

1414
private var countdownTimer: Timer?
15+
public var cancelPressed = false
16+
public var notificationSent = false
1517

1618
override func viewDidLoad() {
1719
super.viewDidLoad()
@@ -62,9 +64,8 @@ class CountdownViewController: UIViewController {
6264
countDownLabel.centerXAnchor.constraint(equalTo: alertController.view.centerXAnchor).isActive = true
6365
countDownLabel.centerYAnchor.constraint(equalTo: alertController.view.centerYAnchor, constant: 60).isActive = true
6466

65-
var cancelPressed = false
6667
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { [weak self] _ in
67-
cancelPressed = true
68+
self?.cancelPressed = true
6869
self?.dismiss(animated: true, completion: nil)
6970
}
7071
alertController.addAction(cancelAction)
@@ -78,21 +79,30 @@ class CountdownViewController: UIViewController {
7879
// Change to text color to red
7980
if countdownSeconds <= 3 {
8081
if let titleString = countDownTitle as? NSString {
81-
let attributes: [NSAttributedString.Key: Any] = [
82-
.foregroundColor: UIColor.red,
83-
.font: UIFont.boldSystemFont(ofSize: 30)
84-
]
85-
let attributedTitle = NSAttributedString(string: titleString as String, attributes: attributes)
86-
alertController.setValue(attributedTitle, forKey: "attributedTitle")
87-
}
82+
let attributes: [NSAttributedString.Key: Any] = [
83+
.foregroundColor: UIColor.red,
84+
.font: UIFont.boldSystemFont(ofSize: 30)
85+
]
86+
let attributedTitle = NSAttributedString(string: titleString as String, attributes: attributes)
87+
alertController.setValue(attributedTitle, forKey: "attributedTitle")
88+
}
8889
countDownLabel.textColor = .red
8990
}
90-
if countdownSeconds == 0 {
91+
92+
// Exit loop
93+
if self.cancelPressed {
94+
countdownSeconds = 0
95+
timer.invalidate()
96+
}
97+
98+
// Notify Emergency Contacts
99+
else if countdownSeconds == 0 {
91100
timer.invalidate()
92-
if !cancelPressed {
101+
if !self.cancelPressed && !self.notificationSent {
93102
let vcContact = VCContactsViewController()
94103
vcContact.textMessageWithTwilio()
95104
vcContact.callWithTwilio()
105+
self.notificationSent = true
96106
}
97107
self.dismiss(animated: true, completion: nil)
98108
}

iosApp/VC/Controllers/VCContactsViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ class VCContactsViewController: UIViewController, UITableViewDataSource, CNConta
375375
request.httpMethod = "POST"
376376
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
377377
request.addValue("Basic " + "\(accountSID):\(authToken)".data(using: .utf8)!.base64EncodedString(), forHTTPHeaderField: "Authorization")
378+
self.getContacts()
378379

379380
for contact in EmergencyContactList {
380381
if let toNumber = contact.contactPhoneNumber {

iosApp/VC/Controllers/VCHomeViewController.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ final class VCHomeViewController: UIViewController, BluetoothManagerDelegate {
8383
dataFromAdafruit.font = UIFont.systemFont(ofSize: 18)
8484
dataFromAdafruit.textColor = UIColor.blue
8585

86-
// delay 3 secs after receiving data for testing
87-
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
88-
self.countdownViewController.showCountdownUI()
86+
// Check cancel isn't pressed from previous runs
87+
if countdownViewController.cancelPressed || countdownViewController.notificationSent {
88+
countdownViewController.cancelPressed = false
89+
countdownViewController.notificationSent = false
8990
}
91+
countdownViewController.showCountdownUI()
9092
}
9193
}

iosApp/VC/Controllers/VCTestingViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import MobileCoreServices
1111

1212
/// Controller to view and change the application's settings
1313
final class VCTestingViewController: UIViewController {
14-
var countdownViewController = CountdownViewController()
14+
private var countdownViewController = CountdownViewController()
1515

1616
override func viewDidLoad() {
1717
super.viewDidLoad()
@@ -68,6 +68,10 @@ final class VCTestingViewController: UIViewController {
6868
}
6969

7070
@objc func countdownButtonTapped() {
71+
if countdownViewController.cancelPressed || countdownViewController.notificationSent {
72+
countdownViewController.cancelPressed = false
73+
countdownViewController.notificationSent = false
74+
}
7175
countdownViewController.showCountdownUI()
7276
}
7377
}

0 commit comments

Comments
 (0)