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

Forgot to merge this one in the previous change #38

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8e566bd
Split expresion to workaround swift compiler bug: "Ambiguous use of '…
bamse16 Nov 15, 2017
e55a276
Fixed missing try/throw error
bamse16 Nov 15, 2017
0366ee2
Fixed CalendarViewController scrollingMode, missing delegate
bamse16 Nov 15, 2017
eaa0ee1
Fixed result not used warning
bamse16 Nov 15, 2017
d57bfc2
Set Eureka Swift version to 4.0, to fix NSAttributedStringKey.foregro…
bamse16 Nov 15, 2017
62375d5
Merge remote-tracking branch 'upstream/master'
bamse16 Dec 21, 2017
b74eae5
Fixed home screen background colour
bamse16 Dec 21, 2017
dc340e2
Fixed test failing in other timezones
bamse16 Dec 21, 2017
6327f61
Move canSendMail check to start of function
bamse16 Dec 21, 2017
f58dd62
Moved CSV building to RepositoryRoutineCompanion
bamse16 Dec 21, 2017
cd7708c
Added tests for exercisesAsCSV
bamse16 Dec 21, 2017
8f96fd8
Added method to build emailSubject
bamse16 Dec 21, 2017
3a4b4d9
Added method to build emailBody
bamse16 Dec 21, 2017
8b12240
Compose email using refactored subject/body/csv
bamse16 Dec 21, 2017
8c40017
Added property to generate unique workout csv names
bamse16 Dec 21, 2017
de0c133
Send email even if no exercises are completed
bamse16 Dec 21, 2017
a2b30f3
Return CSV NSData instead of String
bamse16 Dec 21, 2017
3f18936
Fixed extra end (conflict artifact)
bamse16 Dec 21, 2017
39d61fd
Revert "Fixed home screen background colour"
bamse16 Dec 21, 2017
5df6311
Merge remote-tracking branch 'upstream/master'
bamse16 Jan 5, 2018
60e94a4
Fixed wrong csv body passed to email
bamse16 Jan 6, 2018
b6fd1cd
Refactored date extensions to the same file
bamse16 Jan 6, 2018
3c45571
Moved interactions with child VC to WorkoutInteractionDelegate
bamse16 Jan 6, 2018
ea4ec83
Extract logReps as separate function
bamse16 Jan 6, 2018
6e01db1
Refactor printSets to use exercise as param
bamse16 Jan 6, 2018
d7bb4e3
Extract update number of reps
bamse16 Jan 6, 2018
73062ed
Revert "Extract update number of reps"
bamse16 Jan 6, 2018
9371939
Revert "Refactor printSets to use exercise as param"
bamse16 Jan 6, 2018
2c7562a
Revert "Extract logReps as separate function"
bamse16 Jan 6, 2018
03c4e6c
Fixed Issue #26
bamse16 Jan 6, 2018
8c3cc36
Merge branch 'feature/refactoring'
bamse16 Jan 6, 2018
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
80 changes: 80 additions & 0 deletions BodyweightFitness/Date+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,84 @@ extension Date {
//Return Result
return isEqualTo
}

func timeAgo() -> String {
let calendar = Calendar.current
let now = Date()
let unitFlags: NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfYear, .month, .year]
let components = (calendar as NSCalendar).components(unitFlags, from: self, to: now, options: [])

if components.year! >= 2 {
return "\(components.year!) years ago"
}

if components.year! >= 1 {
return "Last year"
}

if components.month! >= 2 {
return "\(components.month!) months ago"
}

if components.month! >= 1 {
return "Last month"
}

if components.weekOfYear! >= 2 {
return "\(components.weekOfYear!) weeks ago"
}

if components.weekOfYear! >= 1 {
return "Last week"
}

if components.day! >= 2 {
return "\(components.day!) days ago"
}

if components.day! >= 1 {
return "Yesterday"
}

if components.hour! >= 2 {
return "\(components.hour!) hours ago"
}

if components.hour! >= 1 {
return "An hour ago"
}

if components.minute! >= 2 {
return "\(components.minute!) minutes ago"
}

if components.minute! >= 1 {
return "A minute ago"
}

if components.second! >= 3 {
return "\(components.second!) seconds ago"
}

return "Just now"
}

static func changeDaysBy(_ days : Int) -> Date {
let startOfDay = Calendar.current.startOfDay(for: Date())

var components = DateComponents()
components.hour = 23
components.minute = 59
components.second = 59

let currentDate = (Calendar.current as NSCalendar).date(
byAdding: components,
to: startOfDay,
options: NSCalendar.Options(rawValue: 0))!

var dateComponents = DateComponents()
dateComponents.day = days
return (Calendar.current as NSCalendar).date(
byAdding: dateComponents, to: currentDate, options: NSCalendar.Options(rawValue: 0))!
}
}
83 changes: 0 additions & 83 deletions BodyweightFitness/Domain/RepositoryStream.swift
Original file line number Diff line number Diff line change
@@ -1,89 +1,6 @@
import Foundation
import RealmSwift

extension Date {
static func changeDaysBy(_ days : Int) -> Date {
let startOfDay = Calendar.current.startOfDay(for: Date())

var components = DateComponents()
components.hour = 23
components.minute = 59
components.second = 59

let currentDate = (Calendar.current as NSCalendar).date(
byAdding: components,
to: startOfDay,
options: NSCalendar.Options(rawValue: 0))!

var dateComponents = DateComponents()
dateComponents.day = days
return (Calendar.current as NSCalendar).date(
byAdding: dateComponents, to: currentDate, options: NSCalendar.Options(rawValue: 0))!
}

static func timeAgoSince(_ date: Date) -> String {
let calendar = Calendar.current
let now = Date()
let unitFlags: NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfYear, .month, .year]
let components = (calendar as NSCalendar).components(unitFlags, from: date, to: now, options: [])

if components.year! >= 2 {
return "\(components.year!) years ago"
}

if components.year! >= 1 {
return "Last year"
}

if components.month! >= 2 {
return "\(components.month!) months ago"
}

if components.month! >= 1 {
return "Last month"
}

if components.weekOfYear! >= 2 {
return "\(components.weekOfYear!) weeks ago"
}

if components.weekOfYear! >= 1 {
return "Last week"
}

if components.day! >= 2 {
return "\(components.day!) days ago"
}

if components.day! >= 1 {
return "Yesterday"
}

if components.hour! >= 2 {
return "\(components.hour!) hours ago"
}

if components.hour! >= 1 {
return "An hour ago"
}

if components.minute! >= 2 {
return "\(components.minute!) minutes ago"
}

if components.minute! >= 1 {
return "A minute ago"
}

if components.second! >= 3 {
return "\(components.second!) seconds ago"
}

return "Just now"

}
}

final class RepositoryStream {
static let sharedInstance = RepositoryStream()

Expand Down
2 changes: 1 addition & 1 deletion BodyweightFitness/Main/CalendarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle
let csv = companion.csv(weightUnit: weightUnit)
let csvName = companion.csvName()

let emailViewController = configuredMailComposeViewController(subject: subject, messageBody: body, csv: data, csvName: csvName)
let emailViewController = configuredMailComposeViewController(subject: subject, messageBody: body, csv: csv, csvName: csvName)
self.present(emailViewController, animated: true, completion: nil)
}

Expand Down
2 changes: 1 addition & 1 deletion BodyweightFitness/Main/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class HomeViewController: AbstractViewController, MFMailComposeViewControllerDel
topRightLabel.textAlignment = .right

if let workout = lastWorkout {
topRightLabel.text = String(Date.timeAgoSince(workout.startTime))
topRightLabel.text = workout.startTime.timeAgo()
} else {
topRightLabel.text = String("Never")
}
Expand Down
13 changes: 7 additions & 6 deletions BodyweightFitness/Workout/RestTimerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class RestTimerViewController: UIViewController, AVAudioPlayerDelegate {

@IBOutlet var previousButton: UIButton!
@IBOutlet var nextButton: UIButton!

var rootViewController: WorkoutViewController? = nil

var delegate: WorkoutInteractionDelegate?

var current: Exercise = RoutineStream.sharedInstance.routine.getFirstExercise()

var audioPlayer: AVAudioPlayer?
Expand Down Expand Up @@ -100,7 +101,7 @@ class RestTimerViewController: UIViewController, AVAudioPlayerDelegate {
seconds -= 1

if(seconds <= 0) {
self.rootViewController?.restTimerStopped()
self.delegate?.restTimerShouldStop()

let defaults = Foundation.UserDefaults.standard
if(defaults.object(forKey: "playAudioWhenTimerStops") != nil) {
Expand Down Expand Up @@ -142,14 +143,14 @@ class RestTimerViewController: UIViewController, AVAudioPlayerDelegate {
}

@IBAction func stopButtonClicked(_ sender: AnyObject) {
self.rootViewController?.restTimerStopped()
self.delegate?.restTimerShouldStop()
}

@IBAction func previousButtonClicked(_ sender: AnyObject) {
self.rootViewController?.previousButtonClicked(sender)
self.delegate?.selectPreviousExercise()
}

@IBAction func nextButtonClicked(_ sender: AnyObject) {
self.rootViewController?.nextButtonClicked(sender)
self.delegate?.selectNextExercise()
}
}
8 changes: 5 additions & 3 deletions BodyweightFitness/Workout/TimedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class TimedViewController: UIViewController, AVAudioPlayerDelegate {

@IBOutlet var previousButton: UIButton!
@IBOutlet var nextButton: UIButton!

var delegate: WorkoutInteractionDelegate?

var rootViewController: WorkoutViewController? = nil
var current: Exercise = RoutineStream.sharedInstance.routine.getFirstExercise()
Expand Down Expand Up @@ -212,7 +214,7 @@ class TimedViewController: UIViewController, AVAudioPlayerDelegate {
}

func showRestTimer() {
self.rootViewController?.restTimerShouldStart()
self.delegate?.restTimerShouldStart()
}

func showNotification(_ seconds: Int) {
Expand Down Expand Up @@ -266,10 +268,10 @@ class TimedViewController: UIViewController, AVAudioPlayerDelegate {


@IBAction func previousButtonClicked(_ sender: AnyObject) {
self.rootViewController?.previousButtonClicked(sender)
self.delegate?.selectPreviousExercise()
}

@IBAction func nextButtonClicked(_ sender: AnyObject) {
self.rootViewController?.nextButtonClicked(sender)
self.delegate?.selectNextExercise()
}
}
13 changes: 8 additions & 5 deletions BodyweightFitness/Workout/WeightedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class WeightedViewController: UIViewController {

@IBOutlet var sets: UILabel!
@IBOutlet var reps: UIButton!


var delegate: WorkoutInteractionDelegate?

var numberOfReps: Int = 5
var rootViewController: WorkoutViewController? = nil
var current: Exercise = RoutineStream.sharedInstance.routine.getFirstExercise()
Expand All @@ -22,7 +24,8 @@ class WeightedViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()


self.numberOfReps = PersistenceManager.getNumberOfReps(self.current.exerciseId)
self.updateLabels()

_ = RoutineStream.sharedInstance.repositoryObservable().subscribe(onNext: { (it) in
Expand Down Expand Up @@ -66,7 +69,7 @@ class WeightedViewController: UIViewController {
}

func showRestTimer() {
self.rootViewController?.restTimerShouldStart()
self.delegate?.restTimerShouldStart()
}

func showNotification(_ set: Int, reps: Int) {
Expand Down Expand Up @@ -127,11 +130,11 @@ class WeightedViewController: UIViewController {
}

@IBAction func previousButtonClicked(_ sender: AnyObject) {
self.rootViewController?.previousButtonClicked(sender)
self.delegate?.selectPreviousExercise()
}

@IBAction func nextButtonClicked(_ sender: AnyObject) {
self.rootViewController?.nextButtonClicked(sender)
self.delegate?.selectNextExercise()
}

@IBAction func increaseRepsClicked(_ sender: AnyObject) {
Expand Down
Loading