Skip to content
Permalink
a8cd10a50d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
214 lines (144 sloc) 5.87 KB
//
// GeneratorDisplayViewController.swift
// FitnessApp
//
// Created by Varun Thomas on 20/11/2020.
// Copyright © 2020 Varun Thomas. All rights reserved.
//
//
import UIKit
class GeneratorDisplay: UIViewController {
// titles and textfields for the workout list:
//images and backgrounds
@IBOutlet weak var workoutBackground: UIImageView!
@IBOutlet weak var workoutBackground3: UIImageView!
@IBOutlet weak var workoutBackground2: UIImageView!
//titles
@IBOutlet weak var Day1Calories: UILabel!
@IBOutlet weak var Day2Calories: UILabel!
@IBOutlet weak var Day3Calories: UILabel!
@IBOutlet weak var TotalCalorieTitle: UILabel!
@IBOutlet weak var weeklyCalories: UILabel!
@IBOutlet weak var plan: UILabel!
//textfields:
//day1 display
@IBOutlet weak var c1: UILabel!
@IBOutlet weak var sq1: UILabel!
@IBOutlet weak var sk1: UILabel!
@IBOutlet weak var jj1: UILabel!
@IBOutlet weak var j1: UILabel!
//day2 display
@IBOutlet weak var c2: UILabel!
@IBOutlet weak var sq2: UILabel!
@IBOutlet weak var sk2: UILabel!
@IBOutlet weak var jj2: UILabel!
@IBOutlet weak var j2: UILabel!
//day 3 display
@IBOutlet weak var C3: UILabel!
@IBOutlet weak var sq3: UILabel!
@IBOutlet weak var sk3: UILabel!
@IBOutlet weak var jj3: UILabel!
@IBOutlet weak var j3: UILabel!
//loading up the user interface for Generator Display page
override func viewDidLoad() {
super.viewDidLoad()
UITabBar.appearance().barTintColor = .black
UITabBar.appearance().tintColor = .red
}
// presenting the GenerateSelection page when user clicks button
@IBAction func presentSecondViewController() {
let secondVC = storyboard?.instantiateViewController(identifier: "GenerateSelection") as! GenerateSelection
secondVC.generateDelegate = self
secondVC.modalPresentationStyle = .fullScreen
secondVC.modalTransitionStyle = .crossDissolve
present(secondVC, animated: true, completion: nil)
}
}
// logic to display workouts when user selects and clicks on generate button on the generateSelection page.
extension GeneratorDisplay: userSelectionDelegate {
func generate(kg: String, weeks: String) {
let Day1Array = [c1 , sq1, sk1, jj1, j1]
let Day2Array = [c2, sq2, sk2, jj2, j2]
let Day3Array = [C3, sq3, sk3, jj3, j3]
//calories are calculated
let totalCalories = (Int(kg)! * 7700) / Int(weeks)!
let day1Calories = (40 * totalCalories)/100
let day2Calories = (35 * totalCalories)/100
let day3Calories = (25 * totalCalories)/100
//naming titles
plan.text = "\(kg) kg in \(weeks) weeks"
TotalCalorieTitle.text = "Total Calories: " + String(totalCalories * Int(weeks)!)
weeklyCalories.text = "Weekly Calories: " + String(totalCalories)
Day1Calories.text = "Day1: " + String(day1Calories) + "cal"
Day2Calories.text = "Day2: " + String(day2Calories) + "cal"
Day3Calories.text = "Day3: " + String(day3Calories) + "cal"
// workout list 1
// creating workouts
let workout1 = generateWorkout(day1Calories)
let workout2 = generateWorkout(day2Calories)
let workout3 = generateWorkout(day3Calories)
// assign workouts
displayWorkouts(workout: workout1, display: Day1Array)
displayWorkouts(workout: workout2, display: Day2Array)
displayWorkouts(workout: workout3, display: Day3Array)
//background image
workoutBackground.image = UIImage(named: "WorkoutBackground")
workoutBackground2.image = UIImage(named: "WorkoutBackground")
workoutBackground3.image = UIImage(named: "WorkoutBackground")
}
}
extension GeneratorDisplay {
//FUNCTION which creates the workout list
func generateWorkout(_ cal:Int) -> Array<String> {
var calorie = cal
let exercises = [11:"Jumping Jacks", 12: "Jogging", 10: "Cycling", 8: "Squats", 16: "Skipping"]
let key = [11,12,10,8,16]
//ARRAY OF ALL EXERCISES
var aList = [String]()
//EXERCISES AND REPS
var cycling1 = 0
var squats1 = 0
var skipping1 = 0
var jumpingJacks1 = 0
var jogging1 = 0
//CREATING A NEW WORKOUT PLAN
//DAY 1 -> CREATING A LIST OF ALL EXERCISES IN PLAN A
while (calorie >= 0) {
//generating a random key
var randKey = Int.random(in: 0..<5)
randKey = key[randKey]
//adding the random exercise onto new list
aList.append(exercises[randKey]!)
calorie = calorie - randKey
}
//counting mins for each exercise
for counter in 0...aList.count - 1{
let exercise = aList[counter]
switch exercise{
case "Cycling":
cycling1 += 1
case "Squats":
squats1 += 1
case "Skipping":
skipping1 += 1
case "Jumping Jacks":
jumpingJacks1 += 1
case "Jogging":
jogging1 += 1
default:
print("no exercise present")
}
}
print(cycling1)
// combining both exercise & mins and storing them in an array
let ListOfworkouts = ["Cycling: " + String(cycling1) + " MINS ","Squats: " + String(squats1) + " MINS ", "Skipping: " + String(skipping1) + " MINS","Jumping Jacks: " + String(jumpingJacks1) + " MINS ", "Jogging: " + String(jogging1) + " MINS "]
return ListOfworkouts
}
//function to display the workouts
func displayWorkouts(workout: [String], display: [UILabel?]){
for i in 0...workout.count-1 {
// add code to display
display[i]!.text = workout[i]
}
}
}