Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ExampleUsage: SimpleAlertDelegate {
- private func configureRestPeriodAlert(lastStimulationTime: Date) -> SimpleAlertViewController {
- let alertStoryboard = UIStoryboard(name: "Alert", bundle: Bundle.main)
- guard let alertViewController = alertStoryboard.instantiateViewController(withIdentifier: "Alert") as? SimpleAlertViewController else { fatalError() }
- alertViewController.modalTransitionStyle = .coverVertical
- alertViewController.modalPresentationStyle = .overCurrentContext
- let viewModel = SimpleAlertViewController.ViewModel()
- viewModel.title.value = NSLocalizedString("RestPeriodAlertTitle", tableName: "", bundle: Bundle.main, value: "Rest Period", comment: "Title for alert which recommends waiting between Neuropriming sessions.")
- 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")
- let messageFunc: (Int) -> (String) = { _ in return String(format: messageTemplate, lastStimulationTime.timeIntervalSinceNow.longStylizedSecondsString()) }
- SafeSignal<Int>.interval(1.0).map(messageFunc).bind(to: viewModel.message)
- viewModel.message.value = messageFunc(0)
- 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.")
- 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.")
- alertViewController.configure(viewModel: viewModel, delegate: self)
- return alertViewController
- }
- func didTapPrimaryButton(alertViewController: SimpleAlertViewController) { /* */ }
- func didTapSecondaryButton(alertViewController: SimpleAlertViewController) { /* */ }
- func didAttemptToStimulate() {
- let lastStimulationTime = Date() //
- self.vc?.present(configureRestPeriodAlert(lastStimulationTime: lastStimulationTime), animated: true, completion: nil)
- }
- }
Add Comment
Please, Sign In to add comment