Skip to content

Commit

Permalink
Merge pull request #7 from jhrcook/precommit
Browse files Browse the repository at this point in the history
Pre-commit hooks
  • Loading branch information
jhrcook authored Nov 16, 2020
2 parents 10370c2 + fc8a409 commit 850c98d
Show file tree
Hide file tree
Showing 42 changed files with 398 additions and 522 deletions.
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
args: ['--maxkb=80000']
- repo: https://github.com/nicklockwood/SwiftFormat
rev: 0.47.3
hooks:
- id: swiftformat
name: SwiftFormat
types: [swift]
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

**An Apple Watch App that randomly selects quick exercises.**

![Swift](https://img.shields.io/badge/Swift-Swift_Project-FA7343.svg?style=flat&logo=swift)
![iOS](https://img.shields.io/badge/watchOS-App-999999.svg?style=flat&logo=apple)
[![jhc github](https://img.shields.io/badge/GitHub-jhrcook-181717.svg?style=flat&logo=github)](https://github.com/jhrcook)
[![jhc twitter](https://img.shields.io/badge/[email protected]?style=flat&logo=twitter)](https://twitter.com/JoshDoesa)
[![jhc website](https://img.shields.io/badge/Website-Joshua_Cook-5087B2.svg?style=flat&logo=telegram)](https://joshuacook.netlify.com)
![Swift](https://img.shields.io/badge/Swift-App-FA7343.svg?style=flat&logo=swift)
![iOS](https://img.shields.io/badge/watchOS-App-999999.svg?style=flat&logo=apple&logoColor=white)

<img src="demos/01-spinner.png" width="25%">
<img src="demos/02-start.png" width="25%">
<img src="demos/03-workout.png" width="25%">

<img src="demos/demo.gif" width="35%">

---

[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![SwiftFormat](https://img.shields.io/badge/SwfitFormat-enabled-A166E6)](https://github.com/nicklockwood/SwiftFormat)
[![jhc github](https://img.shields.io/badge/GitHub-jhrcook-181717.svg?style=flat&logo=github)](https://github.com/jhrcook)
[![jhc twitter](https://img.shields.io/badge/[email protected]?style=flat&logo=twitter)](https://twitter.com/JoshDoesa)
[![jhc website](https://img.shields.io/badge/Website-Joshua_Cook-5087B2.svg?style=flat&logo=telegram)](https://joshuacook.netlify.com)
4 changes: 2 additions & 2 deletions Workout Spinner WatchKit App/Base.lproj/Interface.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<!--Hosting Controller-->
<scene sceneID="RUd-og-cv4">
<objects>
<hostingController id="NBu-mt-KyX" customClass="HostingController"
customModuleProvider="target"/>
<hostingController id="NBu-mt-KyX" customClass="HostingController"
customModuleProvider="target"/>
</objects>
<point key="canvasLocation" x="187" y="141"/>
</scene>
Expand Down
39 changes: 18 additions & 21 deletions Workout Spinner WatchKit Extension/ComplicationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,46 @@

import ClockKit


class ComplicationController: NSObject, CLKComplicationDataSource {

// MARK: - Timeline Configuration
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {

func getSupportedTimeTravelDirections(for _: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
handler([.forward, .backward])
}
func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {

func getTimelineStartDate(for _: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(nil)
}
func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {

func getTimelineEndDate(for _: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(nil)
}
func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {

func getPrivacyBehavior(for _: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {
handler(.showOnLockScreen)
}

// MARK: - Timeline Population
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {

func getCurrentTimelineEntry(for _: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
// Call the handler with the current timeline entry
handler(nil)
}
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {

func getTimelineEntries(for _: CLKComplication, before _: Date, limit _: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries prior to the given date
handler(nil)
}
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {

func getTimelineEntries(for _: CLKComplication, after _: Date, limit _: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries after to the given date
handler(nil)
}

// MARK: - Placeholder Templates
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {

func getLocalizableSampleTemplate(for _: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
handler(nil)
}

}
2 changes: 0 additions & 2 deletions Workout Spinner WatchKit Extension/ExtensionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import WatchKit

class ExtensionDelegate: NSObject, WKExtensionDelegate {

func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
}
Expand Down Expand Up @@ -52,5 +51,4 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,34 @@
import SwiftUI

extension Color {

init(red: Int, green: Int, blue: Int) {
func f(_ x: Int) -> Double {
return Double(x) / 255.0
}
self.init(red: f(red), green: f(green), blue: f(blue))
}

static func randomPastelColor() -> Color {
let pastelRange = 140...255
let pastelRange = 140 ... 255
return Color(red: Int.random(in: pastelRange), green: Int.random(in: pastelRange), blue: Int.random(in: pastelRange))
}
}


struct CustomColors_Previews: PreviewProvider {

static var customColors: [Color] = [.workoutGreen, .darkGray, .deepRed, .deepRed2, .pastelDarkRed, .pastelDarkRed2]

static var previews: some View {
Group {
ForEach(0..<10) { _ in
ForEach(0 ..< 10) { _ in
Color.randomPastelColor().previewLayout(.fixed(width: 50, height: 50))
}
ForEach(0..<CustomColors_Previews.customColors.count) { i in
ForEach(0 ..< CustomColors_Previews.customColors.count) { i in
CustomColors_Previews.customColors[i].previewLayout(.fixed(width: 50, height: 50))
}
}
}
}


extension Color {
static let workoutGreen = Color(red: 194, green: 255, blue: 60)
static let workoutRed = Color(red: 214, green: 26, blue: 82)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import SwiftUI

extension GeometryProxy {
var minSize: CGFloat{
var minSize: CGFloat {
return min(size.width, size.height)
}
}
2 changes: 1 addition & 1 deletion Workout Spinner WatchKit Extension/HostingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright © 2020 Joshua Cook. All rights reserved.
//

import WatchKit
import Foundation
import SwiftUI
import WatchKit

class HostingController: WKHostingController<ContentView> {
override var body: ContentView {
Expand Down
27 changes: 10 additions & 17 deletions Workout Spinner WatchKit Extension/Models/BodyPartSelections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import SwiftUI


struct BodyPartSelection: Identifiable {
let bodypart: ExerciseBodyPart
var enabled: Bool
Expand All @@ -17,55 +16,49 @@ struct BodyPartSelection: Identifiable {
}
}


class BodyPartSelections: ObservableObject {

@Published var bodyparts = [BodyPartSelection]()

/// Extract the body parts from exeristing exercise information.
/// - Parameter exerciseInfo: The exercise information.
init(fromExerciseInfo exerciseInfo: ExerciseInfo) {
self.bodyparts = ExerciseBodyPart.allCases
bodyparts = ExerciseBodyPart.allCases
.sorted { $0.rawValue < $1.rawValue }
.map { BodyPartSelection(bodypart: $0, enabled: exerciseInfo.bodyParts.contains($0)) }
}



/// Initialize with specificed body parts.
init(bodyparts: [BodyPartSelection]) {
self.bodyparts = bodyparts
}



enum DefaultBodyPartsSelection {
case none, all, userDefaults
}

/// Initialize with some default selection of body parts.
/// - Parameter selection: The section of body parts to use.
init(with selection: DefaultBodyPartsSelection) {
if selection == .userDefaults {
let userDefaultsData = BodyPartSelections.readUserDefaults()
self.bodyparts = ExerciseBodyPart.allCases
bodyparts = ExerciseBodyPart.allCases
.sorted { $0.rawValue < $1.rawValue }
.map{ BodyPartSelection(bodypart: $0, enabled: userDefaultsData[$0.rawValue] ?? true) }
.map { BodyPartSelection(bodypart: $0, enabled: userDefaultsData[$0.rawValue] ?? true) }
} else {
self.bodyparts = ExerciseBodyPart.allCases
bodyparts = ExerciseBodyPart.allCases
.sorted { $0.rawValue < $1.rawValue }
.map { BodyPartSelection(bodypart: $0, enabled: selection == .all) }
}
}



static func readUserDefaults() -> [String: Bool] {
if let data = UserDefaults.standard.dictionary(forKey: UserDefaultsKeys.activeBodyParts.rawValue) as? [String: Bool] {
return data
} else {
return [String: Bool]()
}
}



func saveDataToUserDefaults() {
var data = [String: Bool]()
for bp in bodyparts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,51 @@ import Foundation
class CrownVelocityCalculator {
private var history = [Double]()
var currentVelocity: Double = 0.0

var velocityThreshold: Double = 500.0
private(set) var didPassThreshold: Bool = false

var memory: Int = 10

init() {}

init(memory: Int) {
self.memory = memory
}

init(velocityThreshold: Double) {
self.velocityThreshold = velocityThreshold
}

init(velocityThreshold: Double, memory: Int) {
self.velocityThreshold = velocityThreshold
self.memory = memory
}

func update(newValue x: Double) {
self.history.append(x)
history.append(x)
if history.count < memory { return }

if history.count > memory {
history = history.suffix(memory)
}

var diffs: Double = 0.0
for i in 0..<(history.count - 1) {
diffs += history[i+1] - history[i]
for i in 0 ..< (history.count - 1) {
diffs += history[i + 1] - history[i]
}

currentVelocity = diffs / Double(history.count - 1)
checkThreshold()
}

func checkThreshold() {
if !didPassThreshold {
didPassThreshold = abs(currentVelocity) > velocityThreshold
}
}

func resetThreshold() {
didPassThreshold = false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ func == (lhs: ExerciseIntensity, rhs: ExerciseIntensity) -> Bool {
return lhs.rawValue == rhs.rawValue
}


enum ExerciseType: String, Codable, CaseIterable {
case count, time
}


enum ExerciseBodyPart: String, Codable, CaseIterable {
case arms, core, legs, back, cardio, neck
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ExerciseInfo: Identifiable, Codable, Equatable {
let bodyParts: [ExerciseBodyPart]
let workoutValue: [String: Float]
var active: Bool = true

static func == (lhs: ExerciseInfo, rhs: ExerciseInfo) -> Bool {
return lhs.id == rhs.id
}
Expand Down
Loading

0 comments on commit 850c98d

Please sign in to comment.