Skip to content

Commit

Permalink
Swift 3 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
mazurio authored Oct 10, 2017
1 parent dddf9ad commit 5fee73b
Show file tree
Hide file tree
Showing 108 changed files with 3,921 additions and 6,838 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Podfile.lock
Pods/
iOSInjectionProject/
.DS_Store
# Xcode
Expand Down
402 changes: 177 additions & 225 deletions BodyweightFitness.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions BodyweightFitness.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 22 additions & 66 deletions BodyweightFitness/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,50 @@ import CoreData
import Fabric
import Crashlytics

class TabBarController: UITabBarController {
let homeViewController = HomeViewController()
let workoutLogViewController = WorkoutLogViewController()
let supportDeveloperViewController = SupportDeveloperViewController()
let settingsViewController = SettingsViewController()

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

self.tabBar.tintColor = UIColor.primary()
self.tabBar.barTintColor = UIColor.whiteColor()

self.homeViewController.tabBarItem = UITabBarItem(
title: "Home",
image: UIImage(named: "tab_home"),
selectedImage: UIImage(named: "tab_home"))

self.workoutLogViewController.tabBarItem = UITabBarItem(
title: "Workout Log",
image: UIImage(named: "tab_workout_log"),
selectedImage: UIImage(named: "tab_workout_log"))

self.supportDeveloperViewController.tabBarItem = UITabBarItem(
title: "Support Developer",
image: UIImage(named: "tab_support_developer"),
selectedImage: UIImage(named: "tab_support_developer"))

self.settingsViewController.tabBarItem = UITabBarItem(
title: "Settings",
image: UIImage(named: "tab_settings"),
selectedImage: UIImage(named: "tab_settings"))

self.viewControllers = [
self.homeViewController,
self.workoutLogViewController,
self.supportDeveloperViewController,
self.settingsViewController]
}
}

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

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

Fabric.with([Crashlytics.self])

self.migrateSchemaIfNeeded()
self.setDefaultSettings()

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


return true
}

func applicationDidEnterBackground(application: UIApplication) {
UIApplication.sharedApplication().idleTimerDisabled = false
func applicationDidEnterBackground(_ application: UIApplication) {
UIApplication.shared.isIdleTimerDisabled = false
}

func applicationDidBecomeActive(application: UIApplication) {
UIApplication.sharedApplication().idleTimerDisabled = true
func applicationDidBecomeActive(_ application: UIApplication) {
UIApplication.shared.isIdleTimerDisabled = true
}

func setDefaultSettings() {
let defaults = NSUserDefaults.standardUserDefaults()
let defaults = Foundation.UserDefaults.standard

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

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

if(defaults.objectForKey("showRestTimerAfterWarmup") == nil) {
defaults.setBool(false, forKey: "showRestTimerAfterWarmup")
if(defaults.object(forKey: "showRestTimerAfterWarmup") == nil) {
defaults.set(false, forKey: "showRestTimerAfterWarmup")
}

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

if(defaults.objectForKey("showRestTimerAfterFlexibilityExercises") == nil) {
defaults.setBool(false, forKey: "showRestTimerAfterFlexibilityExercises")
if(defaults.object(forKey: "showRestTimerAfterFlexibilityExercises") == nil) {
defaults.set(false, forKey: "showRestTimerAfterFlexibilityExercises")
}
}

Expand All @@ -112,7 +68,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

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

Expand All @@ -137,10 +93,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return (false, currentSchema)
}

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

Expand Down
10 changes: 6 additions & 4 deletions BodyweightFitness/Bodyweight Fitness.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Bodyweight Fitness</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -15,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.1</string>
<string>1.6.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>151</string>
<string>161</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand All @@ -38,14 +40,14 @@
<true/>
<key>NSCameraUsageDescription</key>
<string>This app does not require access to the camera.</string>
<key>NSMainNibFile</key>
<string>Window</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app does not require access to the microphone.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app does not require access to the photo library.</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
172 changes: 172 additions & 0 deletions BodyweightFitness/Controller/Cell/CellView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import UIKit
import JTAppleCalendar

class CellView: JTAppleCell {
@IBInspectable var todayColor: UIColor!// = UIColor(red: 254.0/255.0, green: 73.0/255.0, blue: 64.0/255.0, alpha: 0.3)
@IBInspectable var normalDayColor: UIColor! //UIColor(white: 0.0, alpha: 0.1)

@IBOutlet var selectedView: AnimationView!
@IBOutlet var dot: UIView!
@IBOutlet var dayLabel: UILabel!

lazy var todayDate : String = {
[weak self] in
let aString = self!.c.string(from: Date())
return aString
}()

lazy var c : DateFormatter = {
let f = DateFormatter()
f.dateFormat = "yyyy-MM-dd"

return f
}()

func setupCellBeforeDisplay(_ cellState: CellState, date: Date) {
let routines = RepositoryStream.sharedInstance.getRoutinesForDate(cellState.date)

if (routines.count > 0) {
self.dot.isHidden = false
} else {
self.dot.isHidden = true
}

self.dot.layer.cornerRadius = self.dot.frame.width / 2
self.selectedView.layer.cornerRadius = self.selectedView.frame.width / 2

// Setup Cell text
self.dayLabel.text = cellState.text

// Mark todays date
if (c.string(from: date) == todayDate) {
selectedView.backgroundColor = UIColor.primaryDark()
} else {
selectedView.backgroundColor = UIColor.white
}

configureTextColor(cellState)

delayRunOnMainThread(0.0) {
self.configureViewIntoBubbleView(cellState)
}

configureVisibility(cellState)
}

func delayRunOnMainThread(_ delay: Double, closure: @escaping () -> ()) {
DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() +
Double(Int64(delay * Double(NSEC_PER_SEC))) /
Double(NSEC_PER_SEC), execute: closure)
}

func configureVisibility(_ cellState: CellState) {
self.isHidden = false
}

func configureTextColor(_ cellState: CellState) {
if cellState.isSelected {
if (c.string(from: cellState.date as Date) == todayDate) {
dayLabel.textColor = UIColor.white
} else {
dayLabel.textColor = UIColor.black
}
} else if cellState.dateBelongsTo == .thisMonth {
dayLabel.textColor = UIColor.black
} else {
dayLabel.textColor = UIColor.primaryDark()
}
}

func cellSelectionChanged(_ cellState: CellState) {
if cellState.isSelected == true {
if selectedView.isHidden == true {
configureViewIntoBubbleView(cellState)
selectedView.animateWithBounceEffect(withCompletionHandler: nil)
}
} else {
configureViewIntoBubbleView(cellState, animateDeselection: true)
}
}

fileprivate func configureViewIntoBubbleView(_ cellState: CellState, animateDeselection: Bool = false) {
if cellState.isSelected {
self.selectedView.layer.cornerRadius = self.selectedView.frame.width / 2
self.selectedView.isHidden = false
self.dot.isHidden = true

self.configureTextColor(cellState)
} else {
if animateDeselection {
self.configureTextColor(cellState)

if self.selectedView.isHidden == false {
self.selectedView.animateWithFadeEffect(withCompletionHandler: { () -> Void in
self.selectedView.isHidden = true
self.selectedView.alpha = 1
})
}
} else {
self.selectedView.isHidden = true
}

let routines = RepositoryStream.sharedInstance.getRoutinesForDate(cellState.date)

if (routines.count > 0) {
self.dot.isHidden = false
} else {
self.dot.isHidden = true
}
}
}
}
import UIKit

class AnimationView: UIView {
func animateWithBounceEffect(withCompletionHandler completionHandler:(() -> Void)?) {
let viewAnimation = AnimationClass.BounceEffect()
viewAnimation(self) { _ in
completionHandler?()
}
}

func animateWithFadeEffect(withCompletionHandler completionHandler:(() -> Void)?) {
let viewAnimation = AnimationClass.fadeOutEffect()
viewAnimation(self) { _ in
completionHandler?()
}
}
}

class AnimationClass {
class func BounceEffect() -> (UIView, @escaping (Bool) -> Void) -> () {
return {
view, completion in
view.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(
withDuration: 0.5,
delay: 0, usingSpringWithDamping: 0.3,
initialSpringVelocity: 0.1,
options: UIViewAnimationOptions.beginFromCurrentState,
animations: {
view.transform = CGAffineTransform(scaleX: 1, y: 1)
},
completion: completion
)
}
}

class func fadeOutEffect() -> (UIView, @escaping (Bool) -> Void) -> () {
return {
view, completion in
UIView.animate(withDuration: 0.6,
delay: 0, usingSpringWithDamping: 0.6,
initialSpringVelocity: 0,
options: [],
animations: {
view.alpha = 0
},
completion: completion)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DashboardCategoryCell: UITableViewCell {

}

override func setSelected(selected: Bool, animated: Bool) {
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
Loading

0 comments on commit 5fee73b

Please sign in to comment.