Skip to content

Commit

Permalink
Merge pull request #8 from mazurio/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mazurio committed Apr 21, 2016
2 parents 9c816b8 + 844318a commit a702c47
Show file tree
Hide file tree
Showing 96 changed files with 5,425 additions and 2,999 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
iOSInjectionProject/
.DS_Store
# Xcode
#
Expand All @@ -20,3 +21,4 @@ DerivedData

Carthage/Checkouts
Carthage/Build
Cartfile.resolved
735 changes: 452 additions & 283 deletions BodyweightFitness.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

119 changes: 94 additions & 25 deletions BodyweightFitness/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
import UIKit
import Material
import CoreData
import Fabric
import Crashlytics

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var mask: CALayer?

var sideNavigationViewController: SideNavigationController?

var sideViewController: UIViewController?
var mainViewController: UIViewController?
var calendarViewController: UIViewController?
var supportDeveloperViewController: UIViewController = UINavigationController(rootViewController: SupportDeveloperViewController())
var settingsViewController: UIViewController?
let sideViewController: UIViewController =
SideViewController()

let rootViewController: UINavigationController =
UINavigationController(rootViewController: RootViewController())

let workoutLogViewController =
UINavigationController(rootViewController: WorkoutLogViewController())

let supportDeveloperViewController =
UINavigationController(rootViewController: SupportDeveloperViewController())

let settingsViewController =
UINavigationController(rootViewController: SettingsViewController())

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Fabric.with([Crashlytics.self])

UITabBar.appearance().backgroundColor = UIColor(red:0, green:0.59, blue:0.53, alpha:1)
UITabBar.appearance().tintColor = UIColor(red:0, green:0.59, blue:0.53, alpha:1)

let storyboard = UIStoryboard(name: "Main", bundle: nil)

sideViewController = storyboard.instantiateViewControllerWithIdentifier("SideViewController") as! SideViewController
mainViewController = storyboard.instantiateViewControllerWithIdentifier("MainViewController")
calendarViewController = storyboard.instantiateViewControllerWithIdentifier("CalendarNavigationController")
settingsViewController = storyboard.instantiateViewControllerWithIdentifier("NavigationSettingsController")
self.migrateSchemaIfNeeded()
self.setDefaultSettings()

sideNavigationViewController = SideNavigationController(
rootViewController: mainViewController!,
leftViewController: sideViewController!
self.sideNavigationViewController = SideNavigationController(
rootViewController: self.rootViewController,
leftViewController: self.sideViewController
)

sideNavigationViewController?.setLeftViewWidth(260, hidden: true, animated: false)

window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = sideNavigationViewController!
window?.makeKeyAndVisible()

self.sideNavigationViewController?.setLeftViewWidth(260, hidden: true, animated: false)

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.tintColor = UIColor.primaryDark()
self.window?.backgroundColor = UIColor.primary()
self.window?.rootViewController = self.sideNavigationViewController!
self.window?.makeKeyAndVisible()

return true
}
Expand All @@ -51,5 +53,72 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidBecomeActive(application: UIApplication) {
UIApplication.sharedApplication().idleTimerDisabled = true
}

func setDefaultSettings() {
let defaults = NSUserDefaults.standardUserDefaults()

if(defaults.objectForKey("playAudioWhenTimerStops") == nil) {
defaults.setBool(true, forKey: "playAudioWhenTimerStops")
}
}

func migrateSchemaIfNeeded() {
if (RepositoryStream.sharedInstance.repositoryRoutineForTodayExists()) {
let routine = RoutineStream.sharedInstance.routine
let currentSchema = RepositoryStream.sharedInstance.getRepositoryRoutineForToday()

let (shouldRemoveCurrentSchema, newSchema) = migrateSchemaIfNeeded(routine, currentSchema: currentSchema)

if shouldRemoveCurrentSchema {
let realm = RepositoryStream.sharedInstance.getRealm()

try! realm.write {
realm.add(newSchema, update: false)
realm.delete(currentSchema)
}
}
}
}

func migrateSchemaIfNeeded(routine: Routine, currentSchema: RepositoryRoutine) -> (Bool, RepositoryRoutine) {
if (!isValidSchema(routine, currentSchema: currentSchema)) {
let newSchema = RepositoryStream.sharedInstance.buildRoutine(routine)

newSchema.startTime = currentSchema.startTime
newSchema.lastUpdatedTime = currentSchema.lastUpdatedTime

for exercise in newSchema.exercises {
if let currentExercise = currentSchema.exercises.filter({
$0.exerciseId == exercise.exerciseId
}).first {
exercise.sets.removeAll()

for set in currentExercise.sets {
exercise.sets.append(set)
}
}
}

return (true, newSchema)
}

return (false, currentSchema)
}

func isValidSchema(routine: Routine, currentSchema: RepositoryRoutine) -> Bool {
for exercise in routine.exercises {
if let exercise = exercise as? Exercise {
let containsExercise = currentSchema.exercises.contains({
$0.exerciseId == exercise.exerciseId
})

if (!containsExercise) {
return false
}
}
}

return true
}
}

Loading

0 comments on commit a702c47

Please sign in to comment.