Added alerts and updated option sheets
@@ -19,21 +19,7 @@ class CompetitorSessionViewController: SessionViewController {
|
||||
weak var competitorViewController: CompetitorViewController?
|
||||
|
||||
// MARK: - OptionSheet
|
||||
|
||||
func makeCompetitorOptionSheet() -> UIAlertController {
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
if let popoverController = alertController.popoverPresentationController {
|
||||
popoverController.barButtonItem = self.optionButton
|
||||
}
|
||||
alertController.addAction(self.makeActionCheckOut())
|
||||
//alertController.addAction(self.makeActionReplaceImage())
|
||||
//alertController.addAction(self.makeActionUpdate())
|
||||
alertController.addAction(self.makeActionSettings())
|
||||
alertController.addAction(self.makeActionInfo())
|
||||
alertController.addAction(self.makeActionCancel())
|
||||
return alertController
|
||||
}
|
||||
|
||||
|
||||
fileprivate func makeActionReplaceImage() -> UIAlertAction {
|
||||
return UIAlertAction(title: Translation.CompetitorView.OptionSheet.ReplaceImageAction.Title.String, style: .default) { [weak self] action in
|
||||
self?.competitorViewController?.showSelectImageAlert()
|
||||
|
||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 2.9 KiB |
@@ -17,20 +17,7 @@ class MarkSessionViewController: SessionViewController {
|
||||
weak var markCheckIn: MarkCheckIn!
|
||||
weak var markCoreDataManager: CoreDataManager!
|
||||
weak var markViewController: MarkViewController?
|
||||
|
||||
func makeMarkOptionSheet() -> UIAlertController {
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
if let popoverController = alertController.popoverPresentationController {
|
||||
popoverController.barButtonItem = self.optionButton
|
||||
}
|
||||
alertController.addAction(self.makeActionCheckOut())
|
||||
//alertController.addAction(self.makeActionUpdate())
|
||||
alertController.addAction(self.makeActionSettings())
|
||||
alertController.addAction(self.makeActionInfo())
|
||||
alertController.addAction(self.makeActionCancel())
|
||||
return alertController
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Segues
|
||||
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||
|
||||
@@ -116,15 +116,27 @@ class RegattaCompetitorViewController : CompetitorSessionViewController {
|
||||
// MARK: SessionViewControllerDelegate
|
||||
|
||||
extension RegattaCompetitorViewController: SessionViewControllerDelegate {
|
||||
|
||||
|
||||
var checkIn: CheckIn { get { return competitorCheckIn } }
|
||||
|
||||
|
||||
var checkOutActionTitle: String { get { return Translation.CompetitorView.OptionSheet.CheckOutAction.Title.String } }
|
||||
|
||||
var checkOutAlertMessage: String { get { return Translation.CompetitorView.CheckOutAlert.Message.String } }
|
||||
|
||||
var coreDataManager: CoreDataManager { get { return competitorCoreDataManager } }
|
||||
|
||||
var sessionController: SessionController { get { return competitorSessionController } }
|
||||
|
||||
func makeOptionSheet() -> UIAlertController {
|
||||
return makeCompetitorOptionSheet()
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
if let popoverController = alertController.popoverPresentationController {
|
||||
popoverController.barButtonItem = self.optionButton
|
||||
}
|
||||
alertController.addAction(self.makeActionCheckOut())
|
||||
alertController.addAction(self.makeActionSettings())
|
||||
alertController.addAction(self.makeActionInfo())
|
||||
alertController.addAction(self.makeActionCancel())
|
||||
return alertController
|
||||
}
|
||||
|
||||
func refresh(_ animated: Bool) {
|
||||
|
||||
@@ -50,13 +50,25 @@ class RegattaMarkViewController: MarkSessionViewController {
|
||||
extension RegattaMarkViewController: SessionViewControllerDelegate {
|
||||
|
||||
var checkIn: CheckIn { get { return markCheckIn } }
|
||||
|
||||
|
||||
var checkOutActionTitle: String { get { return Translation.CompetitorView.OptionSheet.CheckOutAction.Title.String } }
|
||||
|
||||
var checkOutAlertMessage: String { get { return Translation.CompetitorView.CheckOutAlert.Message.String } }
|
||||
|
||||
var coreDataManager: CoreDataManager { get { return markCoreDataManager } }
|
||||
|
||||
var sessionController: SessionController { get { return markSessionController } }
|
||||
|
||||
func makeOptionSheet() -> UIAlertController {
|
||||
return makeMarkOptionSheet()
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
if let popoverController = alertController.popoverPresentationController {
|
||||
popoverController.barButtonItem = self.optionButton
|
||||
}
|
||||
alertController.addAction(self.makeActionCheckOut())
|
||||
alertController.addAction(self.makeActionSettings())
|
||||
alertController.addAction(self.makeActionInfo())
|
||||
alertController.addAction(self.makeActionCancel())
|
||||
return alertController
|
||||
}
|
||||
|
||||
func refresh(_ animated: Bool) {
|
||||
|
||||
@@ -11,7 +11,11 @@ import UIKit
|
||||
protocol SessionViewControllerDelegate: class {
|
||||
|
||||
var checkIn: CheckIn { get }
|
||||
|
||||
|
||||
var checkOutActionTitle: String { get }
|
||||
|
||||
var checkOutAlertMessage: String { get }
|
||||
|
||||
var coreDataManager: CoreDataManager { get }
|
||||
|
||||
var sessionController: SessionController { get }
|
||||
@@ -99,7 +103,7 @@ class SessionViewController: UIViewController {
|
||||
}
|
||||
|
||||
func makeActionCheckOut() -> UIAlertAction {
|
||||
return UIAlertAction(title: Translation.CompetitorView.OptionSheet.CheckOutAction.Title.String, style: .default) { [weak self] action in
|
||||
return UIAlertAction(title: delegate?.checkOutActionTitle, style: .default) { [weak self] action in
|
||||
self?.checkOut()
|
||||
}
|
||||
}
|
||||
@@ -162,11 +166,11 @@ class SessionViewController: UIViewController {
|
||||
}
|
||||
|
||||
// MARK: - Alerts
|
||||
|
||||
|
||||
fileprivate func showCheckOutAlert() {
|
||||
let alertController = UIAlertController(
|
||||
title: Translation.Common.Warning.String,
|
||||
message: Translation.CompetitorView.CheckOutAlert.Message.String,
|
||||
message: delegate?.checkOutAlertMessage,
|
||||
preferredStyle: .alert
|
||||
)
|
||||
let yesAction = UIAlertAction(title: Translation.Common.Yes.String, style: .default) { [weak self] action in
|
||||
|
||||
@@ -63,13 +63,25 @@ class TrainingCompetitorViewController: CompetitorSessionViewController {
|
||||
extension TrainingCompetitorViewController: SessionViewControllerDelegate {
|
||||
|
||||
var checkIn: CheckIn { get { return competitorCheckIn } }
|
||||
|
||||
|
||||
var checkOutActionTitle: String { get { return Translation.TrainingView.OptionSheet.CheckOutAction.Title.String } }
|
||||
|
||||
var checkOutAlertMessage: String { get { return Translation.TrainingView.CheckOutAlert.Message.String } }
|
||||
|
||||
var coreDataManager: CoreDataManager { get { return competitorCoreDataManager } }
|
||||
|
||||
var sessionController: SessionController { get { return competitorSessionController } }
|
||||
|
||||
func makeOptionSheet() -> UIAlertController {
|
||||
return makeCompetitorOptionSheet()
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
if let popoverController = alertController.popoverPresentationController {
|
||||
popoverController.barButtonItem = self.optionButton
|
||||
}
|
||||
alertController.addAction(self.makeActionCheckOut())
|
||||
alertController.addAction(self.makeActionSettings())
|
||||
alertController.addAction(self.makeActionInfo())
|
||||
alertController.addAction(self.makeActionCancel())
|
||||
return alertController
|
||||
}
|
||||
|
||||
func refresh(_ animated: Bool) {
|
||||
|
||||
@@ -47,15 +47,27 @@ class TrainingMarkViewController: MarkSessionViewController {
|
||||
extension TrainingMarkViewController: SessionViewControllerDelegate {
|
||||
|
||||
var checkIn: CheckIn { get { return markCheckIn } }
|
||||
|
||||
|
||||
var checkOutActionTitle: String { get { return Translation.TrainingView.OptionSheet.CheckOutAction.Title.String } }
|
||||
|
||||
var checkOutAlertMessage: String { get { return Translation.TrainingView.CheckOutAlert.Message.String } }
|
||||
|
||||
var coreDataManager: CoreDataManager { get { return markCoreDataManager } }
|
||||
|
||||
var sessionController: SessionController { get { return markSessionController } }
|
||||
|
||||
func makeOptionSheet() -> UIAlertController {
|
||||
return makeMarkOptionSheet()
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
if let popoverController = alertController.popoverPresentationController {
|
||||
popoverController.barButtonItem = self.optionButton
|
||||
}
|
||||
alertController.addAction(self.makeActionCheckOut())
|
||||
alertController.addAction(self.makeActionSettings())
|
||||
alertController.addAction(self.makeActionInfo())
|
||||
alertController.addAction(self.makeActionCancel())
|
||||
return alertController
|
||||
}
|
||||
|
||||
|
||||
func refresh(_ animated: Bool) {
|
||||
markViewController?.refresh(animated)
|
||||
trainingViewController?.refresh(animated)
|
||||
|
||||
@@ -165,38 +165,56 @@ class TrainingViewController: UIViewController {
|
||||
SVProgressHUD.show()
|
||||
trainingController.finishTraining(forCheckIn: trainingCheckIn, success: { [weak self] in
|
||||
SVProgressHUD.dismiss()
|
||||
if let strongSelf = self {
|
||||
strongSelf.delegate?.trainingViewControllerDidFinishTraining(strongSelf)
|
||||
}
|
||||
self?.finishTrainingSuccess()
|
||||
}) { [weak self] (error) in
|
||||
SVProgressHUD.dismiss()
|
||||
self?.showAlert(forError: error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fileprivate func finishTrainingSuccess() {
|
||||
let alertController = UIAlertController.init(title: Translation.TrainingView.FinishedAlert.Title.String, message: nil, preferredStyle: .alert)
|
||||
let okAction = UIAlertAction.init(title: Translation.Common.OK.String, style: .default) { [weak self] (action) in
|
||||
if let strongSelf = self {
|
||||
strongSelf.delegate?.trainingViewControllerDidFinishTraining(strongSelf)
|
||||
}
|
||||
}
|
||||
alertController.addAction(okAction)
|
||||
present(alertController, animated: true)
|
||||
}
|
||||
|
||||
fileprivate func reactivateTraining() {
|
||||
SVProgressHUD.show()
|
||||
trainingController.reactivateTraining(forCheckIn: trainingCheckIn, success: { [weak self] in
|
||||
SVProgressHUD.dismiss()
|
||||
if let strongSelf = self {
|
||||
strongSelf.delegate?.trainingViewControllerDidReactivateTraining(strongSelf)
|
||||
}
|
||||
self?.reactivateTrainingSuccess()
|
||||
}) { [weak self] (error) in
|
||||
SVProgressHUD.dismiss()
|
||||
self?.showAlert(forError: error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fileprivate func reactivateTrainingSuccess() {
|
||||
let alertController = UIAlertController.init(title: Translation.TrainingView.ReactivatedAlert.Title.String, message: nil, preferredStyle: .alert)
|
||||
let okAction = UIAlertAction.init(title: Translation.Common.OK.String, style: .default) { [weak self] (action) in
|
||||
if let strongSelf = self {
|
||||
strongSelf.delegate?.trainingViewControllerDidReactivateTraining(strongSelf)
|
||||
}
|
||||
}
|
||||
alertController.addAction(okAction)
|
||||
present(alertController, animated: true)
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func finishTrainingButtonTapped(_ sender: Any) {
|
||||
finishTraining()
|
||||
showFinishAlert()
|
||||
}
|
||||
|
||||
@IBAction func leaderboardButtonTapped(_ sender: Any) {
|
||||
delegate?.trainingViewController(self, leaderboardButtonTapped: sender)
|
||||
}
|
||||
|
||||
|
||||
@IBAction func startTrackingButtonTapped(_ sender: Any) {
|
||||
if isTrainingActive {
|
||||
startTracking(success: {
|
||||
@@ -210,7 +228,22 @@ class TrainingViewController: UIViewController {
|
||||
}
|
||||
|
||||
// MARK: - Alerts
|
||||
|
||||
|
||||
fileprivate func showFinishAlert() {
|
||||
let alertController = UIAlertController(
|
||||
title: Translation.TrainingView.FinishAlert.Title.String,
|
||||
message: Translation.TrainingView.FinishAlert.Message.String,
|
||||
preferredStyle: .alert
|
||||
)
|
||||
let yesAction = UIAlertAction(title: Translation.Common.Yes.String, style: .default) { [weak self] action in
|
||||
self?.finishTraining()
|
||||
}
|
||||
let noAction = UIAlertAction(title: Translation.Common.No.String, style: .cancel, handler: nil)
|
||||
alertController.addAction(yesAction)
|
||||
alertController.addAction(noAction)
|
||||
present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
fileprivate func showReactivateAlert() {
|
||||
let alertController = UIAlertController(
|
||||
title: Translation.TrainingView.ReactivateAlert.Title.String,
|
||||
|
||||
@@ -503,6 +503,18 @@ class Translation: NSObject {
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
struct CheckOutAlert { private static let Key = "\(TrainingView.Key).\(CheckOutAlert.self)"
|
||||
struct Message { private static let Key = "\(CheckOutAlert.Key).\(Message.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
struct OptionSheet { private static let Key = "\(TrainingView.Key).\(OptionSheet.self)"
|
||||
struct CheckOutAction { private static let Key = "\(OptionSheet.Key).\(CheckOutAction.self)"
|
||||
struct Title { private static let Key = "\(CheckOutAction.Key).\(Title.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
struct ReactivateAlert { private static let Key = "\(TrainingView.Key).\(ReactivateAlert.self)"
|
||||
struct Title { private static let Key = "\(ReactivateAlert.Key).\(Title.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
@@ -511,21 +523,36 @@ class Translation: NSObject {
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
struct ReactivatedAlert {
|
||||
static let Key = "\(TrainingView.Key).\(ReactivatedAlert.self)"
|
||||
struct Title { private static let Key = "\(ReactivatedAlert.Key).\(Title.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
struct StartTrackingButton { private static let Key = "\(TrainingView.Key).\(StartTrackingButton.self)"
|
||||
struct Title { private static let Key = "\(StartTrackingButton.Key).\(Title.self)"
|
||||
static let String = CompetitorView.StartTrackingButton.Title.String
|
||||
}
|
||||
}
|
||||
struct StopTrainingAlert { private static let Key = "\(TrainingView.Key).\(StopTrainingAlert.self)"
|
||||
struct Message { private static let Key = "\(StopTrainingAlert.Key).\(Message.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
struct FinishTrainingButton { private static let Key = "\(TrainingView.Key).\(FinishTrainingButton.self)"
|
||||
struct Title { private static let Key = "\(FinishTrainingButton.Key).\(Title.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
struct FinishAlert {
|
||||
static let Key = "\(TrainingView.Key).\(FinishAlert.self)"
|
||||
struct Title { private static let Key = "\(FinishAlert.Key).\(Title.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
struct Message { private static let Key = "\(FinishAlert.Key).\(Message.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
struct FinishedAlert { private static let Key = "\(TrainingView.Key).\(FinishedAlert.self)"
|
||||
struct Title { private static let Key = "\(FinishedAlert.Key).\(Title.self)"
|
||||
static let String = NSLocalizedString(Key, comment: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||