ViewControllerHealth

class ViewControllerHealth : UIViewController, UITableViewDataSource, UITableViewDelegate, tableCellDelegate

Controls all UI elements within the health domain. This includes illness and stress entry, favouriting system, managing the day log and filtering.

  • Stores index of selected cell to allow expanding to show more info when selected

    Declaration

    Swift

    private var selectedCellIndexPath: [IndexPath?]
  • Height for a cell which has been selected and expanded

    Declaration

    Swift

    private let selectedCellHeight: CGFloat
  • Height for an unselected and contracted cell

    Declaration

    Swift

    private let unselectedCellHeight: CGFloat
  • Tracks whether to show favourites or log and updates table to show that

    Declaration

    Swift

    private var showFavouritesHealth: Bool { get set }
  • Allows user to choose previous 7, 30 or 60 days to view, adjusts button colours to show selection and updates the table

    Declaration

    Swift

    private var daysToShow: String { get set }
  • Variable to store whether to filter by Hypos and updates the table

    Declaration

    Swift

    private var filterHypo: Bool { get set }
  • Variable to store whether to filter by Exercise and updates the table

    Declaration

    Swift

    private var filterExercise: Bool { get set }
  • Variable to store whether to filter by Hyper and updates the table

    Declaration

    Swift

    private var filterHyper: Bool { get set }
  • Variable to store whether to filter by Stress and updates the table

    Declaration

    Swift

    private var filterStress: Bool { get set }
  • Variable to store whether to filter by Illness and updates the table

    Declaration

    Swift

    private var filterIllness: Bool { get set }
  • Stores an array of fetched Day objects to display in table

    Declaration

    Swift

    private var loggedDays: [Day]
  • Tracks start times of stress tracking to allow storing of stress logs with duration

    Declaration

    Swift

    private var stressStart: Date?
  • Tracks start times of illness tracking to allow storing of illness logs with duration

    Declaration

    Swift

    private var illnessStart: Date?
  • Tracks date set by graph and hides data entry fields when not on current day

    Declaration

    Swift

    private var currentDay: Date { get set }
  • viewDidLoad override to set: Button colours, Initial filtering settings, Stress and Illness default state, Observers to act on current graph day changing,

    Declaration

    Swift

    override func viewDidLoad()
  • Updates the currentDay variable with a date provided via notification from ViewControllerGraph

    Declaration

    Swift

    @objc
    private func updateDay(notification: Notification)
  • Sets filtering to previous 7 days

    Declaration

    Swift

    @IBAction
    private func sevenDaysButton(_ sender: UIButton)
  • Sets filtering to previous 30 days

    Declaration

    Swift

    @IBAction
    private func thirtyDaysButton(_ sender: UIButton)
  • Sets filtering to previous 60 days

    Declaration

    Swift

    @IBAction
    private func sixtyDaysButton(_ sender: UIButton)
  • Toggles filtering by Hypos

    Declaration

    Swift

    @IBAction
    private func filterHypoButton(_ sender: Any)
  • Toggles filtering by Hypers

    Declaration

    Swift

    @IBAction
    private func filterHyperButton(_ sender: Any)
  • Toggles filtering by Exercise

    Declaration

    Swift

    @IBAction
    private func filterExerciseButton(_ sender: Any)
  • Toggles filtering by Stress

    Declaration

    Swift

    @IBAction
    private func filterStressButton(_ sender: Any)
  • Toggles filtering by Illness

    Declaration

    Swift

    @IBAction
    private func filterIllnessButton(_ sender: Any)
  • Stress switch: When turned on, stores start date When turned off, adds start and end date to a stress log

    Declaration

    Swift

    @IBAction
    private func stressSwitchButton(_ sender: Any)
  • Illness switch: When turned on, stores start date When turned off, adds start and end date to a illness log

    Declaration

    Swift

    @IBAction
    private func illnessSwitchButton(_ sender: Any)
  • Toggle between favourite and daily log views

    Declaration

    Swift

    @IBAction
    private func toggleFavourites(_ sender: Any)
  • Delegate function to toggle whether a day is favourited

    Declaration

    Swift

    func didPressButton(_ tag: Int)
  • When pressed in log, sends a notification with that day, which is picked up by graph and set as shown day

    Declaration

    Swift

    func didPressViewDayButton(_ tag: Int)
  • Table funcion to set number of rows equal to total loggedDays

    Declaration

    Swift

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
  • Provides setup for table cells, setting each label

    Declaration

    Swift

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
  • Updates the table by re-fetching and filtering the returned array of days, or the user’s favourites

    Declaration

    Swift

    private func updateTable()
  • Allows selecting a favourite to add to daily log if showing favourites, else toggles expanding of cell

    Declaration

    Swift

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
  • Allows expanding of cells by changing cell height for specific rows

    Declaration

    Swift

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat