PodSetupCompleteViewController.swift 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // PodSetupCompleteViewController.swift
  3. // OmniKitUI
  4. //
  5. // Created by Pete Schwamb on 9/18/18.
  6. // Copyright © 2018 Pete Schwamb. All rights reserved.
  7. //
  8. import UIKit
  9. import LoopKitUI
  10. import OmniKit
  11. class PodSetupCompleteViewController: SetupTableViewController {
  12. @IBOutlet weak var expirationReminderDateCell: ExpirationReminderDateTableViewCell!
  13. var pumpManager: OmnipodPumpManager! {
  14. didSet {
  15. if let expirationReminderDate = pumpManager.expirationReminderDate, let podState = pumpManager.state.podState {
  16. expirationReminderDateCell.date = expirationReminderDate
  17. expirationReminderDateCell.datePicker.maximumDate = podState.expiresAt?.addingTimeInterval(-Pod.expirationReminderAlertMinTimeBeforeExpiration)
  18. expirationReminderDateCell.datePicker.minimumDate = podState.expiresAt?.addingTimeInterval(-Pod.expirationReminderAlertMaxTimeBeforeExpiration)
  19. }
  20. }
  21. }
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. self.padFooterToBottom = false
  25. self.navigationItem.hidesBackButton = true
  26. self.navigationItem.rightBarButtonItem = nil
  27. expirationReminderDateCell.datePicker.datePickerMode = .dateAndTime
  28. #if swift(>=5.2)
  29. if #available(iOS 14.0, *) {
  30. expirationReminderDateCell.datePicker.preferredDatePickerStyle = .wheels
  31. }
  32. #endif
  33. expirationReminderDateCell.titleLabel.text = LocalizedString("Expiration Reminder", comment: "The title of the cell showing the pod expiration reminder date")
  34. expirationReminderDateCell.datePicker.minuteInterval = 1
  35. expirationReminderDateCell.delegate = self
  36. }
  37. override func continueButtonPressed(_ sender: Any) {
  38. if let setupVC = navigationController as? OmnipodPumpManagerSetupViewController {
  39. setupVC.finishedSetup()
  40. }
  41. if let replaceVC = navigationController as? PodReplacementNavigationController {
  42. replaceVC.completeSetup()
  43. }
  44. if pumpManager.confirmationBeeps {
  45. pumpManager.setConfirmationBeeps(enabled: true, completion: { (error) in
  46. if let error = error {
  47. DispatchQueue.main.async {
  48. let title = LocalizedString("Error emitting completion confirmation beep", comment: "The alert title for emitting completion beep error")
  49. self.present(UIAlertController(with: error, title: title), animated: true)
  50. }
  51. }
  52. })
  53. }
  54. }
  55. override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
  56. tableView.beginUpdates()
  57. return indexPath
  58. }
  59. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  60. tableView.deselectRow(at: indexPath, animated: true)
  61. tableView.endUpdates()
  62. }
  63. }
  64. extension PodSetupCompleteViewController: DatePickerTableViewCellDelegate {
  65. func datePickerTableViewCellDidUpdateDate(_ cell: DatePickerTableViewCell) {
  66. pumpManager.expirationReminderDate = cell.date
  67. }
  68. }