Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HistoryGrip Update #12

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
<entity name="HistoryGrip" representedClassName="HistoryGrip" syncable="YES">
<attribute name="breakMinutes" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="breakSeconds" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="customRestSeconds" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromDataTransformerName" customClassName="[Int]"/>
<attribute name="customWorkSeconds" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromDataTransformerName" customClassName="[Int]"/>
<attribute name="decrementSets" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="edgeSize" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="gripTypeName" attributeType="String"/>
<attribute name="hasCustomDurations" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="lastBreakMinutes" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="lastBreakSeconds" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="repCount" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
Expand Down
20 changes: 20 additions & 0 deletions CountDown/CoreData/HistoryGrip+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ extension HistoryGrip {
@NSManaged public var breakSeconds: Int16
@NSManaged public var lastBreakMinutes: Int16
@NSManaged public var lastBreakSeconds: Int16
@NSManaged public var decrementSets: Bool
@NSManaged public var hasCustomDurations: Bool
@NSManaged public var edgeSize: Int16
@NSManaged public var sequenceNum: Int16
@NSManaged public var workoutHistory: WorkoutHistory?
@NSManaged public var customWorkSeconds: [Int]?
@NSManaged public var customRestSeconds: [Int]?

public var unwrappedBreakMinutes: Int {
Int(breakMinutes)
Expand Down Expand Up @@ -72,6 +76,22 @@ extension HistoryGrip {
public var unwrappedGripTypeName: String {
gripTypeName ?? "Unknown Grip Type"
}

public var unwrappedDecrementSets: Bool {
decrementSets
}

public var unwrappedHasCustomDurations: Bool {
hasCustomDurations
}

public var unwrappedCustomWork: [Int] {
customWorkSeconds ?? [Int](repeating: 7, count: maxNumberOfReps)
}

public var unwrappedCustomRest: [Int] {
customRestSeconds ?? [Int](repeating: 3, count: maxNumberOfReps)
}

}

Expand Down
4 changes: 4 additions & 0 deletions CountDown/ViewModels/WorkoutHistoryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ struct WorkoutHistoryViewModel {
historyGrip.breakSeconds = grip.breakSeconds
historyGrip.lastBreakMinutes = grip.lastBreakMinutes
historyGrip.lastBreakSeconds = grip.lastBreakSeconds
historyGrip.decrementSets = grip.decrementSets
historyGrip.hasCustomDurations = grip.hasCustomDurations
historyGrip.customWorkSeconds = grip.customWorkSeconds
historyGrip.customRestSeconds = grip.customRestSeconds
historyGrip.edgeSize = grip.edgeSize
historyGrip.sequenceNum = grip.sequenceNum
}
Expand Down
24 changes: 22 additions & 2 deletions CountDown/Views/History/HistoryGripCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct HistoryGripCardView: View {
}
Spacer()
VStack(alignment: .leading) {
Text("Work: \(historyGrip.unwrappedWorkSeconds)s")
Text("Rest: \(historyGrip.unwrappedRestSeconds)s")
Text("Work: \(workSecondsString)")
Text("Rest: \(restSecondsString)")
}
Spacer()
VStack(alignment: .leading) {
Expand All @@ -41,6 +41,26 @@ struct HistoryGripCardView: View {
}
}
}

/// Shows the work seconds or a message if history grip has custom durations
private var workSecondsString: String {
if historyGrip.hasCustomDurations {
return customDurationsString(
customSeconds: historyGrip.unwrappedCustomWork,
range: historyGrip.unwrappedRepCount)
}
return "\(historyGrip.unwrappedWorkSeconds)s"
}

/// Shows the rest seconds or a message if history grip has custom durations
private var restSecondsString: String {
if historyGrip.hasCustomDurations {
return customDurationsString(
customSeconds: historyGrip.unwrappedCustomRest,
range: historyGrip.unwrappedRepCount - 1)
}
return "\(historyGrip.unwrappedRestSeconds)s"
}
}

struct HistoryGripCardView_Previews: PreviewProvider {
Expand Down
11 changes: 11 additions & 0 deletions CountDownTests/CoreData/HistoryGripPropertiesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ final class HistoryGripPropertiesTest: XCTestCase {
historyGrip.breakSeconds = 30
historyGrip.lastBreakMinutes = 1
historyGrip.lastBreakSeconds = 30
historyGrip.hasCustomDurations = true
historyGrip.customWorkSeconds = [3, 6, 9, 12]
historyGrip.customRestSeconds = [30, 35, 40, 45]
historyGrip.edgeSize = 18
historyGrip.sequenceNum = 2

Expand All @@ -61,6 +64,9 @@ final class HistoryGripPropertiesTest: XCTestCase {
XCTAssertEqual(historyGrip.unwrappedBreakSeconds, 30)
XCTAssertEqual(historyGrip.unwrappedLastBreakMinutes, 1)
XCTAssertEqual(historyGrip.unwrappedLastBreakSeconds, 30)
XCTAssertEqual(historyGrip.unwrappedHasCustomDurations, true)
XCTAssertEqual(historyGrip.unwrappedCustomWork, [3, 6, 9, 12])
XCTAssertEqual(historyGrip.unwrappedCustomRest, [30, 35, 40, 45])
XCTAssertEqual(historyGrip.unwrappedEdgeSize, 18)
XCTAssertEqual(historyGrip.unwrappedSequenceNum, 2)
XCTAssertEqual(historyGrip.unwrappedGripTypeName, "Full Crimp")
Expand All @@ -78,6 +84,11 @@ final class HistoryGripPropertiesTest: XCTestCase {
XCTAssertEqual(historyGrip.unwrappedBreakSeconds, 0)
XCTAssertEqual(historyGrip.unwrappedLastBreakMinutes, 0)
XCTAssertEqual(historyGrip.unwrappedLastBreakSeconds, 0)
XCTAssertEqual(historyGrip.unwrappedHasCustomDurations, false)
XCTAssertEqual(historyGrip.unwrappedCustomWork.count, maxNumberOfReps)
XCTAssertEqual(historyGrip.unwrappedCustomWork.first, 7)
XCTAssertEqual(historyGrip.unwrappedCustomRest.count, maxNumberOfReps)
XCTAssertEqual(historyGrip.unwrappedCustomRest.first, 3)
XCTAssertNil(historyGrip.unwrappedEdgeSize)
XCTAssertEqual(historyGrip.unwrappedSequenceNum, 0)
XCTAssertEqual(historyGrip.unwrappedGripTypeName, "Unknown Grip Type")
Expand Down
7 changes: 7 additions & 0 deletions CountDownTests/ViewModels/WorkoutHistoryViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ final class WorkoutHistoryViewModelTests: XCTestCase {
grip2.breakSeconds = 45
grip2.lastBreakMinutes = 1
grip2.lastBreakSeconds = 45
grip2.hasCustomDurations = true
grip2.customWorkSeconds = [7, 7, 7, 7, 7]
grip2.customRestSeconds = [3, 3, 3, 3, 3]
grip2.edgeSize = 16
grip2.sequenceNum = 2
grip2.gripType = gripType2
Expand Down Expand Up @@ -86,6 +89,7 @@ final class WorkoutHistoryViewModelTests: XCTestCase {
XCTAssertEqual(savedHistory?.gripArray[0].breakSeconds, 30)
XCTAssertEqual(savedHistory?.gripArray[0].lastBreakMinutes, 1)
XCTAssertEqual(savedHistory?.gripArray[0].lastBreakSeconds, 30)
XCTAssertFalse(savedHistory!.gripArray[0].hasCustomDurations)
XCTAssertEqual(savedHistory?.gripArray[0].edgeSize, 18)
XCTAssertEqual(savedHistory?.gripArray[0].sequenceNum, 1)
XCTAssertEqual(savedHistory?.gripArray[0].gripTypeName, "Full Crimp")
Expand All @@ -98,6 +102,9 @@ final class WorkoutHistoryViewModelTests: XCTestCase {
XCTAssertEqual(savedHistory?.gripArray[1].breakSeconds, 45)
XCTAssertEqual(savedHistory?.gripArray[1].lastBreakMinutes, 1)
XCTAssertEqual(savedHistory?.gripArray[1].lastBreakSeconds, 45)
XCTAssertTrue(savedHistory!.gripArray[1].hasCustomDurations)
XCTAssertEqual(savedHistory?.gripArray[1].customWorkSeconds, [7, 7, 7, 7, 7])
XCTAssertEqual(savedHistory?.gripArray[1].customRestSeconds, [3, 3, 3, 3, 3])
XCTAssertEqual(savedHistory?.gripArray[1].edgeSize, 16)
XCTAssertEqual(savedHistory?.gripArray[1].sequenceNum, 2)
XCTAssertEqual(savedHistory?.gripArray[1].gripTypeName, "Half Crimp")
Expand Down
Loading