RVS_SetTimerAmbiaMara_ViewController

class RVS_SetTimerAmbiaMara_ViewController : RVS_AmbiaMara_BaseViewController
extension RVS_SetTimerAmbiaMara_ViewController: UIPickerViewDataSource
extension RVS_SetTimerAmbiaMara_ViewController: UIPickerViewDelegate
extension RVS_SetTimerAmbiaMara_ViewController: UIPickerViewAccessibilityDelegate
extension RVS_SetTimerAmbiaMara_ViewController: UIPopoverPresentationControllerDelegate

This is the view controller for the setup screen, where the timer is set, and started.

Time Sections Enum

  • The timer setup is accomplished via a picker control, with three sections: Hours (left), Minutes (center), and Seconds (right). You can have up to 99 hours, and/or 59 minutes, and/or 59 seconds.

    See more

    Declaration

    Swift

    enum PickerComponents : Int

Screen State Enum

  • These enums determine the state of this screen

    See more

    Declaration

    Swift

    enum States : Int
  • The ID for the segue, to show the about screen.

    Declaration

    Swift

    private static let _aboutViewSegueID: String
  • The ID for the segue, to start the timer.

    Declaration

    Swift

    private static let _startTimerSegueID: String
  • The size of the two settings popovers.

    Declaration

    Swift

    private static let _settingsPopoverWidthInDisplayUnits: CGFloat
  • The period that we use for the “fade in” animation.

    Declaration

    Swift

    private static let _fadeInAnimationPeriodInSeconds: CGFloat
  • The period that we use for the selection fade animation.

    Declaration

    Swift

    private static let _selectionFadeAnimationPeriodInSeconds: CGFloat
  • The period that we use for the add timer animation.

    Declaration

    Swift

    private static let _addTimerAnimationPeriodInSeconds: CGFloat
  • The starting alpha for our settings items, in the initial animation.

    Declaration

    Swift

    private static let _initialSettingsItemAlpha: CGFloat
  • The size of the picker font

    Declaration

    Swift

    private static let _pickerFont: UIFont
  • The size of the picker selection corner radius.

    Declaration

    Swift

    private static let _pickerCornerRadiusInDisplayUnits: CGFloat
  • The ranges that we use to populate the picker (default).

    Declaration

    Swift

    private static let _defaultPickerViewDataRanges: [Range<Int>]
  • The maximum number of timers we can have.

    Declaration

    Swift

    private static let _maximumNumberOfTimers: Int
  • The current screen state.

    Declaration

    Swift

    private var _state: States { get set }
  • This will provide haptic/audio feedback for subtle events.

    Declaration

    Swift

    private var _selectionFeedbackGenerator: UISelectionFeedbackGenerator?
  • This will provide haptic/audio feedback for more significant events.

    Declaration

    Swift

    private var _impactFeedbackGenerator: UIImpactFeedbackGenerator?
  • If a popover is being displayed, we reference it here (so we put it away, when we ned to).

    Declaration

    Swift

    weak var currentDisplayedPopover: UIViewController?

Overall Items

  • The “startup” logo that we fade out.

    Declaration

    Swift

    @IBOutlet
    weak var startupLogo: UIImageView?
  • This is an “overall container” view. It mainly exists to fix an issue with the toolbar, but also makes the fade in more convenient.

    Declaration

    Swift

    @IBOutlet
    weak var containerView: UIView?

Bar Button Items

  • The set alarm popover bar button item.

    Declaration

    Swift

    @IBOutlet
    weak var alarmSetBarButtonItem: UIBarButtonItem?
  • The settings popover bar button item.

    Declaration

    Swift

    @IBOutlet
    weak var settingsBarButtonItem: UIBarButtonItem?

Timer Settings Area

  • This contains the central timer setting area.

    Declaration

    Swift

    @IBOutlet
    weak var setupContainerView: UIView?
  • The view that contains the four labels at the top of the settings area. It has a background color that changes for the state.

    Declaration

    Swift

    @IBOutlet
    weak var topLabelContainerView: UIView?

Top Labels

  • The state label, at the top of the settings area.

    Declaration

    Swift

    @IBOutlet
    weak var stateLabel: UILabel?
  • The label over the hours wheel

    Declaration

    Swift

    @IBOutlet
    weak var hoursLabel: UILabel?
  • The label over the minutes wheel

    Declaration

    Swift

    @IBOutlet
    weak var minutesLabel: UILabel?
  • The label over the seconds wheel

    Declaration

    Swift

    @IBOutlet
    weak var secondsLabel: UILabel?

Time Setting

  • The timer set picker control.

    Declaration

    Swift

    @IBOutlet
    weak var setTimePickerView: UIPickerView?
  • The button that sets the timer back to zero, and appears when there is a value in the picker.

    Declaration

    Swift

    @IBOutlet
    weak var clearButton: UIButton?

State/Start Buttons

  • The button to select the start time set state.

    Declaration

    Swift

    @IBOutlet
    weak var startSetButton: UIButton?
  • The button to select the warning time set state.

    Declaration

    Swift

    @IBOutlet
    weak var warnSetButton: UIButton?
  • The button to select the final time set state.

    Declaration

    Swift

    @IBOutlet
    weak var finalSetButton: UIButton?
  • This is the triangle button that starts the timer.

    Declaration

    Swift

    @IBOutlet
    weak var startButton: UIButton?

Toolbar

  • This is the toolbar on the bottom, with the timers.

    Declaration

    Swift

    @IBOutlet
    weak var bottomToolbar: UIToolbar?
  • This is the leftmost button, the trash icon.

    Declaration

    Swift

    @IBOutlet
    weak var trashBarButtonItem: UIBarButtonItem?
  • This is the rightmost button, the add button.

    Declaration

    Swift

    @IBOutlet
    weak var addBarButtonItem: UIBarButtonItem?

Gesture Recognizers

  • This is the left swipe (previous timer) gesture recognizer, applied to the main view.

    Declaration

    Swift

    @IBOutlet
    weak var backgroundLeftSwipeGestureRecognizer: UISwipeGestureRecognizer?
  • This is the right swipe (next timer) gesture recognizer, applied to the main view.

    Declaration

    Swift

    @IBOutlet
    weak var backgroundRightSwipeGestureRecognizer: UISwipeGestureRecognizer?

Computed Properties

  • The current timer, routed from the settings.

    Declaration

    Swift

    private var _currentTimer: RVS_AmbiaMara_Settings.TimerSettings { get set }
  • This will list our timer toolbar items.

    Declaration

    Swift

    private var _timerBarItems: [UIBarButtonItem] { get }
  • Declaration

    Swift

    private var _nextTimerIndex: Int? { get }

    Return Value

    The index of the following timer. Nil, if no following timer. This “circles around,” so the last timer points to the first timer.

  • Declaration

    Swift

    private var _previousTimerIndex: Int? { get }

    Return Value

    The index of the previous timer. Nil, if no previous timer. This “circles around,” so the first timer points to the last timer.

  • The ranges that we use to populate the picker. The picker will display Integers between the range endpoints.

    Declaration

    Swift

    private var _pickerViewData: [Range<Int>] { get }
  • This is the number of seconds currently represented by the picker. Setting it, sets the picker.

    Declaration

    Swift

    var pickerTime: Int { get set }

Private Instance Methods

  • Returns the currently limited value (warn can’t be higher than start, and final can’t be higher than either warn or start).

    Declaration

    Swift

    private func _stateTime(from inTime: Int = -1) -> Int

    Parameters

    from

    The time being checked (in seconds). It is optional. leaving it out, fetches the time from the picker.

    Return Value

    The normalized time (clipped, if necessary).

Base Class Overrides

  • Called when the view hierarchy is set up. We use this to set our localizations and accessibility.

    Declaration

    Swift

    override func viewDidLoad()
  • Called when the view is about to appear. We use this to start the “fade in” animation.

    Declaration

    Swift

    override func viewWillAppear(_ inIsAnimated: Bool)

    Parameters

    inIsAnimated

    True, if the transition is to be animated (ignored, but sent to the superclass).

  • This allows Catalyst apps to use the keyboard to control the timer, like gestures.

    Declaration

    Swift

    override func pressesBegan(_ inKeyPresses: Set<UIPress>, with inEvent: UIPressesEvent?)

    Parameters

    inKeyPresses

    The pressed keys.

    with

    The event, creating the keypresses.

Instance Methods

  • This sets up the toolbar, by adding all the timers.

    Declaration

    Swift

    func setUpToolbar()
  • This sets up the buttons and the picker to the current state.

    Declaration

    Swift

    func setUpButtons()

Callbacks

  • The user swiped the timer. If there are multiple timers, it selects the next/previous one. If there is only one timer, the gesture is ignored.

    Declaration

    Swift

    @IBAction
    func swipeGestureReceived(_ inGestureRecognizer: UISwipeGestureRecognizer)

    Parameters

    inGestureRecognizer

    The swipe gesture recognizer.

  • The clear button was hit.

    Declaration

    Swift

    @IBAction
    func clearButtonHit(_ inClearButton: UIButton)

    Parameters

    inClearButton

    the clear button instance.

  • Called when one of the state buttons is hit. It sets the screen state.

    Declaration

    Swift

    @IBAction
    func setButtonHit(_ inButton: UIButton)

    Parameters

    inButton

    The button that was hit.

  • Called when the trash bar button item has been hit. This puts up a confirmation screen, asking if the user is sure they want to delete the timer.

    Declaration

    Swift

    @IBAction
    func trashHit(_: Any)
  • Called when the add bar button item has been hit.

    Declaration

    Swift

    @IBAction
    func addHit(_: Any)
  • The timer start button was hit.

    Declaration

    Swift

    @IBAction
    func startButtonHit(_: Any! = nil)
  • This is called, when someone selects the Alarm Set Bar Button. It displays a popover, with tools to select the audible (or vibratory) alarm.

    Declaration

    Swift

    @IBAction
    func displayAlarmSetupPopover(_ inButtonItem: UIBarButtonItem)

    Parameters

    inButtonItem

    the bar button item.

  • This is called, when someone selects the Settings Bar Button. It displays a popover, with various app settings.

    Declaration

    Swift

    @IBAction
    func displaySettingsPopover(_ inButtonItem: UIBarButtonItem)

    Parameters

    inButtonItem

    the bar button item.

  • Called when the add bar button item has been hit.

    Declaration

    Swift

    @objc
    func selectToolbarItem(_ inToolbarButton: UIBarButtonItem)
  • This makes sure the alarm icon at the top, is the correct one.

    Declaration

    Swift

    func setAlarmIcon()
  • This shows the about screen.

    Declaration

    Swift

    func showAboutScreen()

UIPickerViewDataSource Conformance

  • Declaration

    Swift

    func numberOfComponents(in: UIPickerView) -> Int

    Parameters

    in

    The picker view (ignored).

  • Declaration

    Swift

    func pickerView(_: UIPickerView, numberOfRowsInComponent inComponent: Int) -> Int

    Parameters

    numberOfRowsInComponent

    The 0-based index of the component we are querying.

UIPickerViewDelegate Conformance

  • All picker rows are the same height.

    Declaration

    Swift

    func pickerView(_ inPickerView: UIPickerView, rowHeightForComponent: Int) -> CGFloat

    Parameters

    inPickerView

    The picker instance.

    rowHeightForComponent

    ignored (the component we’re checking).

  • This is called when a row is selected. It verifies that the value is OK, and may change the selection, if not.

    Declaration

    Swift

    func pickerView(_ inPickerView: UIPickerView, didSelectRow inRow: Int, inComponent: Int)

    Parameters

    inPickerView

    The picker instance.

    didSelectRow

    The 0-based row index, in the component.

    inComponent

    The component that contains the selected row (0-based index).

  • This returns the view to display for the picker row.

    Declaration

    Swift

    func pickerView(_ inPickerView: UIPickerView, viewForRow inRow: Int, forComponent inComponent: Int, reusing inReusingView: UIView?) -> UIView

    Parameters

    inPickerView

    The picker instance.

    viewForRow

    The 0-based row index to be displayed.

    forComponent

    The 0-based component index for the row.

    reusing

    If a row has been previously created, we use that, instead.

    Return Value

    A new view, containing the row. If it is selected, it is displayed as reversed.

UIPickerViewAccessibilityDelegate Conformance

  • This returns the accessibility label for the picker component.

    Declaration

    Swift

    func pickerView(_ inPickerView: UIPickerView, accessibilityHintForComponent inComponent: Int) -> String?

    Parameters

    inPickerView

    The picker instance.

    accessibilityHintForComponent

    The 0-based component index for the label.

    Return Value

    An accessibility string for the component.

UIPopoverPresentationControllerDelegate Conformance

  • Called to ask if there’s any possibility of this being displayed in another way.

    Declaration

    Swift

    func adaptivePresentationStyle(for: UIPresentationController) -> UIModalPresentationStyle

    Parameters

    for

    The presentation controller we’re talking about.

    Return Value

    No way, Jose.

  • Called to ask if there’s any possibility of this being displayed in another way (when the screen is rotated).

    Declaration

    Swift

    func adaptivePresentationStyle(for: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle

    Parameters

    for

    The presentation controller we’re talking about.

    traitCollection

    The traits, describing the new orientation.

    Return Value

    No way, Jose.