diff --git a/ios/SAPTracker/src/xcode/SAPTracker/Main.storyboard b/ios/SAPTracker/src/xcode/SAPTracker/Main.storyboard index 646c328bbd7..7ab719142f5 100644 --- a/ios/SAPTracker/src/xcode/SAPTracker/Main.storyboard +++ b/ios/SAPTracker/src/xcode/SAPTracker/Main.storyboard @@ -318,7 +318,7 @@ - + @@ -456,7 +456,7 @@ - + @@ -647,12 +647,18 @@ - + + + + + + + @@ -868,7 +874,7 @@ - + @@ -1389,7 +1395,7 @@ - + @@ -1489,13 +1495,13 @@ @@ -1521,13 +1527,13 @@ @@ -1553,13 +1559,13 @@ @@ -1585,13 +1591,13 @@ - + + + + + + + @@ -2361,9 +2373,9 @@ + - - + diff --git a/ios/SAPTracker/src/xcode/SAPTracker/RegattaCompetitorViewController.swift b/ios/SAPTracker/src/xcode/SAPTracker/RegattaCompetitorViewController.swift index e7daf17da90..8f45527d6fe 100644 --- a/ios/SAPTracker/src/xcode/SAPTracker/RegattaCompetitorViewController.swift +++ b/ios/SAPTracker/src/xcode/SAPTracker/RegattaCompetitorViewController.swift @@ -101,52 +101,6 @@ class RegattaCompetitorViewController : SessionViewController, UINavigationContr navigationController?.navigationBar.setNeedsLayout() } - // MARK: - Update - - fileprivate func update() { - competitorSessionController.update { [weak self] in - self?.refresh() - } - } - - // MARK: - Refresh - - fileprivate func refresh() { - refreshCompetitor() - refreshTeamImage() - } - - fileprivate func refreshCompetitor() { - competitorNameLabel.text = competitorCheckIn.name - competitorFlagImageView.image = UIImage(named: competitorCheckIn.countryCode) - competitorSailLabel.text = competitorCheckIn.sailID - } - - fileprivate func refreshTeamImage() { - if let imageData = competitorCheckIn.teamImageData { - teamImageView.image = UIImage(data: imageData as Data) - if competitorCheckIn.teamImageRetry { - refreshTeamImageButtons(showAddButton: false, showEditButton: true, showRetryButton: true) - } else { - refreshTeamImageButtons(showAddButton: false, showEditButton: true, showRetryButton: false) - setTeamImageWithURLRequest(urlString: competitorCheckIn.teamImageURL, completion: { (withSuccess) in - self.refreshTeamImageButtons(showAddButton: false, showEditButton: true, showRetryButton: false) - }) - } - } else { - self.refreshTeamImageButtons(showAddButton: true, showEditButton: false, showRetryButton: false) - setTeamImageWithURLRequest(urlString: competitorCheckIn.teamImageURL, completion: { (withSuccess) in - self.refreshTeamImageButtons(showAddButton: !withSuccess, showEditButton: withSuccess, showRetryButton: false) - }) - } - } - - fileprivate func refreshTeamImageButtons(showAddButton: Bool, showEditButton: Bool, showRetryButton: Bool) { - teamImageAddButton.isHidden = !showAddButton - teamImageEditButton.isHidden = !showEditButton - teamImageRetryButton.isHidden = !showRetryButton - } - // MARK: - TeamImage fileprivate func setTeamImageWithURLRequest(urlString: String?, completion: @escaping (_ withSuccess: Bool) -> Void) { @@ -225,36 +179,6 @@ class RegattaCompetitorViewController : SessionViewController, UINavigationContr } } - @IBAction func optionButtonTapped(_ sender: AnyObject) { - let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - if let popoverController = alertController.popoverPresentationController { - popoverController.barButtonItem = sender as? UIBarButtonItem - } - let settingsAction = UIAlertAction(title: Translation.SettingsView.Title.String, style: .default) { [weak self] action in - self?.performSegue(withIdentifier: Segue.Settings, sender: self) - } - let checkOutAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.CheckOutAction.Title.String, style: .default) { [weak self] action in - self?.checkOut() - } - let replaceImageAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.ReplaceImageAction.Title.String, style: .default) { [weak self] action in - self?.showSelectImageAlert() - } - let updateAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.UpdateAction.Title.String, style: .default) { [weak self] action in - self?.update() - } - let aboutAction = UIAlertAction(title: Translation.Common.Info.String, style: .default) { [weak self] action in - self?.performSegue(withIdentifier: Segue.About, sender: alertController) - } - let cancelAction = UIAlertAction(title: Translation.Common.Cancel.String, style: .cancel, handler: nil) - alertController.addAction(settingsAction) - alertController.addAction(checkOutAction) - alertController.addAction(replaceImageAction) - alertController.addAction(updateAction) - alertController.addAction(aboutAction) - alertController.addAction(cancelAction) - present(alertController, animated: true, completion: nil) - } - // MARK: - Alerts fileprivate func showSelectImageAlert() { @@ -298,10 +222,30 @@ class RegattaCompetitorViewController : SessionViewController, UINavigationContr // MARK: - Properties + fileprivate lazy var actionReplaceImage: UIAlertAction = { + return UIAlertAction(title: Translation.CompetitorView.OptionSheet.ReplaceImageAction.Title.String, style: .default) { [weak self] action in + self?.showSelectImageAlert() + } + }() + fileprivate lazy var competitorSessionController: CompetitorSessionController = { return CompetitorSessionController(checkIn: self.competitorCheckIn, coreDataManager: self.regattaCoreDataManager) }() + lazy var regattaCompetitorOptionSheet: UIAlertController = { + let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) + // if let popoverController = alertController.popoverPresentationController { + // popoverController.barButtonItem = sender as? UIBarButtonItem + // } + alertController.addAction(self.actionSettings) + alertController.addAction(self.actionCheckOut) + alertController.addAction(self.actionReplaceImage) + alertController.addAction(self.actionUpdate) + alertController.addAction(self.actionInfo) + alertController.addAction(self.actionCancel) + return alertController + }() + } // MARK: - UIImagePickerControllerDelegate @@ -384,6 +328,46 @@ extension RegattaCompetitorViewController: SessionViewControllerDelegate { var coreDataManager: CoreDataManager { get { return regattaCoreDataManager } } + var optionSheet: UIAlertController { get { return regattaCompetitorOptionSheet } } + var sessionController: SessionController { get { return competitorSessionController } } + // MARK: - Refresh + + func refresh() { + refreshCompetitor() + refreshTeamImage() + } + + fileprivate func refreshCompetitor() { + competitorNameLabel.text = competitorCheckIn.name + competitorFlagImageView.image = UIImage(named: competitorCheckIn.countryCode) + competitorSailLabel.text = competitorCheckIn.sailID + } + + fileprivate func refreshTeamImage() { + if let imageData = competitorCheckIn.teamImageData { + teamImageView.image = UIImage(data: imageData as Data) + if competitorCheckIn.teamImageRetry { + refreshTeamImageButtons(showAddButton: false, showEditButton: true, showRetryButton: true) + } else { + refreshTeamImageButtons(showAddButton: false, showEditButton: true, showRetryButton: false) + setTeamImageWithURLRequest(urlString: competitorCheckIn.teamImageURL, completion: { (withSuccess) in + self.refreshTeamImageButtons(showAddButton: false, showEditButton: true, showRetryButton: false) + }) + } + } else { + self.refreshTeamImageButtons(showAddButton: true, showEditButton: false, showRetryButton: false) + setTeamImageWithURLRequest(urlString: competitorCheckIn.teamImageURL, completion: { (withSuccess) in + self.refreshTeamImageButtons(showAddButton: !withSuccess, showEditButton: withSuccess, showRetryButton: false) + }) + } + } + + fileprivate func refreshTeamImageButtons(showAddButton: Bool, showEditButton: Bool, showRetryButton: Bool) { + teamImageAddButton.isHidden = !showAddButton + teamImageEditButton.isHidden = !showEditButton + teamImageRetryButton.isHidden = !showRetryButton + } + } diff --git a/ios/SAPTracker/src/xcode/SAPTracker/RegattaMarkViewController.swift b/ios/SAPTracker/src/xcode/SAPTracker/RegattaMarkViewController.swift index 0bb2666ecaa..84b9ce1145c 100644 --- a/ios/SAPTracker/src/xcode/SAPTracker/RegattaMarkViewController.swift +++ b/ios/SAPTracker/src/xcode/SAPTracker/RegattaMarkViewController.swift @@ -48,48 +48,6 @@ class RegattaMarkViewController: SessionViewController { navigationController?.navigationBar.setNeedsLayout() } - // MARK: - Update - - fileprivate func update() { - markSessionController.update { [weak self] in - self?.refresh() - } - } - - // MARK: - Refresh - - fileprivate func refresh() { - markNameLabel.text = markCheckIn.name - } - - // MARK: - Actions - - @IBAction func optionButtonTapped(_ sender: AnyObject) { - let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - if let popoverController = alertController.popoverPresentationController { - popoverController.barButtonItem = sender as? UIBarButtonItem - } - let settingsAction = UIAlertAction(title: Translation.SettingsView.Title.String, style: .default) { [weak self] action in - self?.performSegue(withIdentifier: Segue.Settings, sender: self) - } - let checkOutAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.CheckOutAction.Title.String, style: .default) { [weak self] action in - self?.checkOut() - } - let updateAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.UpdateAction.Title.String, style: .default) { [weak self] action in - self?.update() - } - let aboutAction = UIAlertAction(title: Translation.Common.Info.String, style: .default) { [weak self] action in - self?.performSegue(withIdentifier: Segue.About, sender: alertController) - } - let cancelAction = UIAlertAction(title: Translation.Common.Cancel.String, style: .cancel, handler: nil) - alertController.addAction(settingsAction) - alertController.addAction(checkOutAction) - alertController.addAction(updateAction) - alertController.addAction(aboutAction) - alertController.addAction(cancelAction) - present(alertController, animated: true, completion: nil) - } - // MARK: - Segues override func prepare(for segue: UIStoryboardSegue, sender: Any?) { @@ -107,6 +65,19 @@ class RegattaMarkViewController: SessionViewController { return MarkSessionController(checkIn: self.markCheckIn, coreDataManager: self.regattaCoreDataManager) }() + fileprivate lazy var regattaMarkOptionSheet: UIAlertController = { + let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) +// if let popoverController = alertController.popoverPresentationController { +// popoverController.barButtonItem = sender as? UIBarButtonItem +// } + alertController.addAction(self.actionSettings) + alertController.addAction(self.actionCheckOut) + alertController.addAction(self.actionUpdate) + alertController.addAction(self.actionInfo) + alertController.addAction(self.actionCancel) + return alertController + }() + } // MARK: SessionViewControllerDelegate @@ -117,6 +88,14 @@ extension RegattaMarkViewController: SessionViewControllerDelegate { var coreDataManager: CoreDataManager { get { return regattaCoreDataManager } } + var optionSheet: UIAlertController { get { return regattaMarkOptionSheet } } + var sessionController: SessionController { get { return markSessionController } } + // MARK: - Refresh + + func refresh() { + markNameLabel.text = markCheckIn.name + } + } diff --git a/ios/SAPTracker/src/xcode/SAPTracker/SessionViewController.swift b/ios/SAPTracker/src/xcode/SAPTracker/SessionViewController.swift index fc40f9ba6d9..72480402e07 100644 --- a/ios/SAPTracker/src/xcode/SAPTracker/SessionViewController.swift +++ b/ios/SAPTracker/src/xcode/SAPTracker/SessionViewController.swift @@ -14,8 +14,12 @@ protocol SessionViewControllerDelegate: class { var coreDataManager: CoreDataManager { get } + var optionSheet: UIAlertController { get } + var sessionController: SessionController { get } + func refresh() + } class SessionViewController: UIViewController { @@ -55,12 +59,26 @@ class SessionViewController: UIViewController { } } + // MARK: - Update + + func update() { + delegate.sessionController.update { [weak self] in + self?.delegate.refresh() + } + } + // MARK: - CheckOut func checkOut() { showCheckOutAlert() } + // MARK: - Actions + + @IBAction func optionButtonTapped(_ sender: AnyObject) { + present(delegate.optionSheet, animated: true, completion: nil) + } + // MARK: - Alerts fileprivate func showCheckOutAlert() { @@ -128,4 +146,34 @@ class SessionViewController: UIViewController { present(alertController, animated: true, completion: nil) } + // MARK: - Properties + + lazy var actionCancel: UIAlertAction = { + return UIAlertAction(title: Translation.Common.Cancel.String, style: .cancel, handler: nil) + }() + + lazy var actionCheckOut: UIAlertAction = { + return UIAlertAction(title: Translation.CompetitorView.OptionSheet.CheckOutAction.Title.String, style: .default) { [weak self] action in + self?.checkOut() + } + }() + + lazy var actionInfo: UIAlertAction = { + return UIAlertAction(title: Translation.Common.Info.String, style: .default) { [weak self] action in + self?.performSegue(withIdentifier: Segue.About, sender: action) + } + }() + + lazy var actionSettings: UIAlertAction = { + return UIAlertAction(title: Translation.SettingsView.Title.String, style: .default) { [weak self] action in + self?.performSegue(withIdentifier: Segue.Settings, sender: self) + } + }() + + lazy var actionUpdate: UIAlertAction = { + return UIAlertAction(title: Translation.CompetitorView.OptionSheet.UpdateAction.Title.String, style: .default) { [weak self] action in + self?.update() + } + }() + } diff --git a/ios/SAPTracker/src/xcode/SAPTracker/TrainingCompetitorViewController.swift b/ios/SAPTracker/src/xcode/SAPTracker/TrainingCompetitorViewController.swift index a658833246e..332e56c34d7 100644 --- a/ios/SAPTracker/src/xcode/SAPTracker/TrainingCompetitorViewController.swift +++ b/ios/SAPTracker/src/xcode/SAPTracker/TrainingCompetitorViewController.swift @@ -46,48 +46,6 @@ class TrainingCompetitorViewController: SessionViewController { navigationController?.navigationBar.setNeedsLayout() } - // MARK: - Update - - fileprivate func update() { - competitorSessionController.update { [weak self] in - self?.refresh() - } - } - - // MARK: - Refresh - - fileprivate func refresh() { - trainingNameLabel.text = competitorCheckIn.event.name - } - - // MARK: - Actions - - @IBAction func optionButtonTapped(_ sender: AnyObject) { - let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - if let popoverController = alertController.popoverPresentationController { - popoverController.barButtonItem = sender as? UIBarButtonItem - } - let settingsAction = UIAlertAction(title: Translation.SettingsView.Title.String, style: .default) { [weak self] action in - self?.performSegue(withIdentifier: Segue.Settings, sender: self) - } - let checkOutAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.CheckOutAction.Title.String, style: .default) { [weak self] action in - self?.checkOut() - } - let updateAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.UpdateAction.Title.String, style: .default) { [weak self] action in - self?.update() - } - let aboutAction = UIAlertAction(title: Translation.Common.Info.String, style: .default) { [weak self] action in - self?.performSegue(withIdentifier: Segue.About, sender: alertController) - } - let cancelAction = UIAlertAction(title: Translation.Common.Cancel.String, style: .cancel, handler: nil) - alertController.addAction(settingsAction) - alertController.addAction(checkOutAction) - alertController.addAction(updateAction) - alertController.addAction(aboutAction) - alertController.addAction(cancelAction) - present(alertController, animated: true, completion: nil) - } - // MARK: - Segues override func prepare(for segue: UIStoryboardSegue, sender: Any?) { @@ -105,6 +63,19 @@ class TrainingCompetitorViewController: SessionViewController { return CompetitorSessionController(checkIn: self.competitorCheckIn, coreDataManager: self.trainingCoreDataManager) }() + fileprivate lazy var trainingCompetitorOptionSheet: UIAlertController = { + let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) +// if let popoverController = alertController.popoverPresentationController { +// popoverController.barButtonItem = sender as? UIBarButtonItem +// } + alertController.addAction(self.actionSettings) + alertController.addAction(self.actionCheckOut) + alertController.addAction(self.actionUpdate) + alertController.addAction(self.actionInfo) + alertController.addAction(self.actionCancel) + return alertController + }() + } // MARK: - SessionViewControllerDelegate @@ -115,6 +86,14 @@ extension TrainingCompetitorViewController: SessionViewControllerDelegate { var coreDataManager: CoreDataManager { get { return trainingCoreDataManager } } + var optionSheet: UIAlertController { get { return trainingCompetitorOptionSheet } } + var sessionController: SessionController { get { return competitorSessionController } } + // MARK: - Refresh + + func refresh() { + trainingNameLabel.text = competitorCheckIn.event.name + } + } diff --git a/ios/SAPTracker/src/xcode/SAPTracker/TrainingMarkViewController.swift b/ios/SAPTracker/src/xcode/SAPTracker/TrainingMarkViewController.swift index e60c99b4558..652a440c2d8 100644 --- a/ios/SAPTracker/src/xcode/SAPTracker/TrainingMarkViewController.swift +++ b/ios/SAPTracker/src/xcode/SAPTracker/TrainingMarkViewController.swift @@ -46,48 +46,6 @@ class TrainingMarkViewController: SessionViewController { navigationController?.navigationBar.setNeedsLayout() } - // MARK: - Update - - fileprivate func update() { - markSessionController.update { [weak self] in - self?.refresh() - } - } - - // MARK: - Refresh - - fileprivate func refresh() { - trainingNameLabel.text = markCheckIn.event.name - } - - // MARK: - Actions - - @IBAction func optionButtonTapped(_ sender: AnyObject) { - let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - if let popoverController = alertController.popoverPresentationController { - popoverController.barButtonItem = sender as? UIBarButtonItem - } - let settingsAction = UIAlertAction(title: Translation.SettingsView.Title.String, style: .default) { [weak self] action in - self?.performSegue(withIdentifier: Segue.Settings, sender: self) - } - let checkOutAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.CheckOutAction.Title.String, style: .default) { [weak self] action in - self?.checkOut() - } - let updateAction = UIAlertAction(title: Translation.CompetitorView.OptionSheet.UpdateAction.Title.String, style: .default) { [weak self] action in - self?.update() - } - let aboutAction = UIAlertAction(title: Translation.Common.Info.String, style: .default) { [weak self] action in - self?.performSegue(withIdentifier: Segue.About, sender: alertController) - } - let cancelAction = UIAlertAction(title: Translation.Common.Cancel.String, style: .cancel, handler: nil) - alertController.addAction(settingsAction) - alertController.addAction(checkOutAction) - alertController.addAction(updateAction) - alertController.addAction(aboutAction) - alertController.addAction(cancelAction) - present(alertController, animated: true, completion: nil) - } - // MARK: - Segues override func prepare(for segue: UIStoryboardSegue, sender: Any?) { @@ -105,6 +63,19 @@ class TrainingMarkViewController: SessionViewController { return MarkSessionController(checkIn: self.markCheckIn, coreDataManager: self.trainingCoreDataManager) }() + fileprivate lazy var trainingMarkOptionSheet: UIAlertController = { + let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) +// if let popoverController = alertController.popoverPresentationController { +// popoverController.barButtonItem = sender as? UIBarButtonItem +// } + alertController.addAction(self.actionSettings) + alertController.addAction(self.actionCheckOut) + alertController.addAction(self.actionUpdate) + alertController.addAction(self.actionInfo) + alertController.addAction(self.actionCancel) + return alertController + }() + } // MARK: - SessionViewControllerDelegate @@ -115,6 +86,14 @@ extension TrainingMarkViewController: SessionViewControllerDelegate { var coreDataManager: CoreDataManager { get { return trainingCoreDataManager } } + var optionSheet: UIAlertController { get { return trainingMarkOptionSheet } } + var sessionController: SessionController { get { return markSessionController } } + // MARK: - Refresh + + func refresh() { + trainingNameLabel.text = markCheckIn.event.name + } + }