-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
3,696 additions
and
1,267 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import SnapKit | ||
|
||
class AbstractViewController: UIViewController { | ||
let scrollView = UIScrollView() | ||
let contentView = UIView() | ||
let contentStackView = UIStackView() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.initializeScrollView(attachToView: mainView()) | ||
} | ||
|
||
func mainView() -> UIView { | ||
return self.view | ||
} | ||
|
||
func initializeScrollView(attachToView: UIView) { | ||
attachToView.backgroundColor = UIColor(red:0.96, green:0.96, blue:0.97, alpha:1.00) | ||
attachToView.addSubview(self.scrollView) | ||
|
||
self.scrollView.snp.makeConstraints { (make) -> Void in | ||
make.edges.equalTo(attachToView) | ||
} | ||
|
||
self.scrollView.addSubview(self.contentView) | ||
self.contentView.snp.makeConstraints { (make) -> Void in | ||
make.top.bottom.equalTo(self.scrollView) | ||
make.left.right.equalTo(attachToView) | ||
} | ||
|
||
self.createBackgroundView() | ||
|
||
self.contentStackView.axis = .vertical | ||
self.contentStackView.distribution = .fill | ||
self.contentStackView.alignment = .fill | ||
self.contentStackView.spacing = 16 | ||
self.contentStackView.translatesAutoresizingMaskIntoConstraints = false | ||
self.contentView.addSubview(self.contentStackView) | ||
|
||
self.contentStackView.snp.makeConstraints { (make) -> Void in | ||
make.top.equalTo(contentView).offset(8) | ||
make.left.equalTo(contentView).offset(8) | ||
make.right.equalTo(contentView).offset(-8) | ||
make.bottom.equalTo(contentView).offset(-8) | ||
} | ||
} | ||
|
||
func initializeContent() { | ||
self.removeAllViews() | ||
} | ||
|
||
func createBackgroundView(height: Int = 50) { | ||
let view = UIView() | ||
view.backgroundColor = UIColor.primary() | ||
|
||
self.contentView.addSubview(view) | ||
|
||
view.snp.makeConstraints { (make) -> Void in | ||
make.top.equalTo(contentView) | ||
make.left.equalTo(contentView) | ||
make.right.equalTo(contentView) | ||
make.height.equalTo(height) | ||
} | ||
} | ||
|
||
func addView(_ view: UIView) { | ||
self.contentStackView.addArrangedSubview(view) | ||
} | ||
|
||
func removeAllViews() { | ||
for view in self.contentStackView.subviews { | ||
view.removeFromSuperview() | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CompletionRate { | ||
let percentage: Int | ||
let label: String | ||
|
||
init(percentage: Int, label: String) { | ||
self.percentage = percentage | ||
self.label = label | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import Foundation | ||
|
||
class DataEntriesCompanion { | ||
|
||
func getDataEntries(fromDate: Date, | ||
numberOfDays: Int, | ||
repositoryRoutines: [RepositoryRoutine], | ||
workoutChartType: WorkoutChartType | ||
) -> [WorkoutDataEntry] { | ||
var dataEntries: [WorkoutDataEntry] = [] | ||
|
||
let baseLineDay: Date = (Calendar.current as NSCalendar).date( | ||
byAdding: .day, | ||
value: -numberOfDays, | ||
to: fromDate, | ||
options: [] | ||
)! | ||
|
||
for index in 0...numberOfDays { | ||
let date = (Calendar.current as NSCalendar).date( | ||
byAdding: .day, | ||
value: index, | ||
to: baseLineDay, | ||
options: [] | ||
)! | ||
|
||
let routinesForDay = repositoryRoutines.filter({ | ||
return $0.startTime.commonDescription == date.commonDescription | ||
}) | ||
|
||
if let repositoryRoutine = routinesForDay.first { | ||
dataEntries.append( | ||
WorkoutDataEntry( | ||
x: Double(index), | ||
y: self.getValue(repositoryRoutine: repositoryRoutine, workoutChartType: workoutChartType), | ||
title: self.getTitle(repositoryRoutine: repositoryRoutine), | ||
label: self.getLabel(repositoryRoutine: repositoryRoutine, workoutChartType: workoutChartType) | ||
) | ||
) | ||
} else { | ||
dataEntries.append( | ||
WorkoutDataEntry( | ||
x: Double(index), | ||
y: 0, | ||
title: date.description, | ||
label: "No Data" | ||
) | ||
) | ||
} | ||
} | ||
|
||
return dataEntries | ||
} | ||
|
||
private func getValue(repositoryRoutine: RepositoryRoutine, workoutChartType: WorkoutChartType) -> Double { | ||
switch workoutChartType { | ||
case .WorkoutLength: | ||
return RepositoryRoutineCompanion(repositoryRoutine).workoutLengthInMinutes() | ||
case .CompletionRate: | ||
return Double(ListOfRepositoryExercisesCompanion(repositoryRoutine.exercises).completionRate().percentage) | ||
} | ||
} | ||
|
||
private func getTitle(repositoryRoutine: RepositoryRoutine) -> String { | ||
return RepositoryRoutineCompanion(repositoryRoutine).date() | ||
} | ||
|
||
private func getLabel(repositoryRoutine: RepositoryRoutine, workoutChartType: WorkoutChartType) -> String { | ||
switch workoutChartType { | ||
case .WorkoutLength: | ||
return RepositoryRoutineCompanion(repositoryRoutine).workoutLength() | ||
case .CompletionRate: | ||
return ListOfRepositoryExercisesCompanion(repositoryRoutine.exercises).completionRate().label | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
BodyweightFitness/Domain/ListOfRepositoryExercisesCompanion.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import Foundation | ||
import RealmSwift | ||
|
||
class ListOfRepositoryExercisesCompanion { | ||
let repositoryExercises: List<RepositoryExercise> | ||
|
||
init(_ repositoryExercises: List<RepositoryExercise>) { | ||
self.repositoryExercises = repositoryExercises | ||
} | ||
|
||
func numberOfExercises() -> Int { | ||
let filtered = self.repositoryExercises.filter({ | ||
$0.visible | ||
}) | ||
|
||
return filtered.count | ||
} | ||
|
||
func numberOfCompletedExercises() -> Int { | ||
let filtered = self.repositoryExercises.filter({ | ||
$0.visible && RepositoryExerciseCompanion($0).isCompleted() | ||
}) | ||
|
||
return filtered.count | ||
} | ||
|
||
func allExercisesCompleted() -> Bool { | ||
return numberOfCompletedExercises() == numberOfExercises() | ||
} | ||
|
||
func completionRate() -> CompletionRate { | ||
let numberOfExercises = self.numberOfExercises() | ||
let numberOfCompletedExercises = self.numberOfCompletedExercises() | ||
|
||
if (numberOfExercises == 0 || numberOfCompletedExercises == 0) { | ||
return CompletionRate(percentage: 0, label: "0%") | ||
} | ||
|
||
let value = numberOfCompletedExercises * 100 / numberOfExercises | ||
|
||
return CompletionRate(percentage: value, label: "\(value)%") | ||
} | ||
|
||
func notCompletedExercises() -> [RepositoryExercise] { | ||
let filtered = Array(self.repositoryExercises).filter({ | ||
$0.visible && !RepositoryExerciseCompanion($0).isCompleted() | ||
}) | ||
|
||
return filtered | ||
} | ||
|
||
func visibleExercises() -> [RepositoryExercise] { | ||
let filtered = Array(self.repositoryExercises).filter({ | ||
$0.visible | ||
}) | ||
|
||
return filtered | ||
} | ||
|
||
func visibleOrCompletedExercises() -> [RepositoryExercise] { | ||
let filtered = Array(self.repositoryExercises).filter({ | ||
$0.visible || RepositoryExerciseCompanion($0).isCompleted() | ||
}) | ||
|
||
return filtered | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.