Guest User

Untitled

a guest
Feb 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. class ExampleUsage: SimpleAlertDelegate {
  2.  
  3. private func configureRestPeriodAlert(lastStimulationTime: Date) -> SimpleAlertViewController {
  4. let alertStoryboard = UIStoryboard(name: "Alert", bundle: Bundle.main)
  5. guard let alertViewController = alertStoryboard.instantiateViewController(withIdentifier: "Alert") as? SimpleAlertViewController else { fatalError() }
  6. alertViewController.modalTransitionStyle = .coverVertical
  7. alertViewController.modalPresentationStyle = .overCurrentContext
  8.  
  9. let viewModel = SimpleAlertViewController.ViewModel()
  10. viewModel.title.value = NSLocalizedString("RestPeriodAlertTitle", tableName: "", bundle: Bundle.main, value: "Rest Period", comment: "Title for alert which recommends waiting between Neuropriming sessions.")
  11. let messageTemplate = NSLocalizedString("RestPeriodAlertMessage", tableName: "", bundle: Bundle.main, value: "Research supports a rest period of at least 8 hours between Neuropriming sessions.\n\nTime since last session:\n%@", comment: "Message for alert which recommends waiting between Neuropriming sessions. Argument is the time that has passed since the end of the last session, formatted as hh:mm:ss")
  12. let messageFunc: (Int) -> (String) = { _ in return String(format: messageTemplate, lastStimulationTime.timeIntervalSinceNow.longStylizedSecondsString()) }
  13.  
  14. SafeSignal<Int>.interval(1.0).map(messageFunc).bind(to: viewModel.message)
  15. viewModel.message.value = messageFunc(0)
  16.  
  17. viewModel.primaryButtonTitle.value = NSLocalizedString("RestPeriodAlertCancelButtonTitle", tableName: "", bundle: Bundle.main, value: "Wait", comment: "Title for alert button which indicates that the user will wait instead of proceeding with a new session.")
  18. viewModel.secondaryButtonTitle.value = NSLocalizedString("RestPeriodAlertContinueButtonTitle", tableName: "", bundle: Bundle.main, value: "Continue", comment: "Title for alert button which indicates that the user will proceed with a new session despite the recommendation to wait.")
  19. alertViewController.configure(viewModel: viewModel, delegate: self)
  20.  
  21. return alertViewController
  22. }
  23.  
  24. func didTapPrimaryButton(alertViewController: SimpleAlertViewController) { /* */ }
  25. func didTapSecondaryButton(alertViewController: SimpleAlertViewController) { /* */ }
  26.  
  27. func didAttemptToStimulate() {
  28. let lastStimulationTime = Date() //
  29. self.vc?.present(configureRestPeriodAlert(lastStimulationTime: lastStimulationTime), animated: true, completion: nil)
  30. }
  31. }
Add Comment
Please, Sign In to add comment