diff --git a/logU.xcodeproj/project.pbxproj b/logU.xcodeproj/project.pbxproj index d4b7b37..0481b59 100644 --- a/logU.xcodeproj/project.pbxproj +++ b/logU.xcodeproj/project.pbxproj @@ -19,6 +19,8 @@ B55E02481C6457C200DBACF6 /* LogLift.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55E02471C6457C200DBACF6 /* LogLift.swift */; }; B56863DC1C58374B0065D641 /* DashData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56863DB1C58374B0065D641 /* DashData.swift */; }; B56863E01C59A1A70065D641 /* SignUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56863DF1C59A1A70065D641 /* SignUpViewController.swift */; }; + B5787C371C7AA2B400694C44 /* JsonData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5787C361C7AA2B400694C44 /* JsonData.swift */; }; + B5787C391C7AA36D00694C44 /* DeleteAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5787C381C7AA36D00694C44 /* DeleteAccount.swift */; }; B58E938F1C6EDFED00CFC8CA /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58E938E1C6EDFED00CFC8CA /* Theme.swift */; }; B5C6F1041C4F25F70016B70E /* logUTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F1031C4F25F70016B70E /* logUTests.swift */; }; B5C6F10F1C4F25F70016B70E /* logUUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F10E1C4F25F70016B70E /* logUUITests.swift */; }; @@ -30,7 +32,6 @@ B5C6F12F1C4F26480016B70E /* GraphData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F1211C4F26480016B70E /* GraphData.swift */; }; B5C6F1301C4F26480016B70E /* GraphViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F1221C4F26480016B70E /* GraphViewController.swift */; }; B5C6F1311C4F26480016B70E /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B5C6F1231C4F26480016B70E /* Info.plist */; }; - B5C6F1321C4F26480016B70E /* JsonData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F1241C4F26480016B70E /* JsonData.swift */; }; B5C6F1331C4F26480016B70E /* LiftTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F1251C4F26480016B70E /* LiftTableViewCell.swift */; }; B5C6F1341C4F26480016B70E /* LoginVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F1261C4F26480016B70E /* LoginVC.swift */; }; B5C6F1361C4F26480016B70E /* SquatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F1281C4F26480016B70E /* SquatViewController.swift */; }; @@ -44,7 +45,6 @@ B5C6F15E1C4F45240016B70E /* MaxesTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F15D1C4F45240016B70E /* MaxesTableViewCell.swift */; }; B5C6F1681C557ACD0016B70E /* PoundageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F1671C557ACD0016B70E /* PoundageTableViewCell.swift */; }; B5C6F16C1C557B4E0016B70E /* PoundageTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C6F16B1C557B4E0016B70E /* PoundageTableViewController.swift */; }; - B5E812521C72A30100FA2DBC /* DeleteAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E812511C72A30100FA2DBC /* DeleteAccount.swift */; }; B5F5D8981C6FA23B0037B51B /* GraphSegmented.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F5D8971C6FA23B0037B51B /* GraphSegmented.swift */; }; B5F5D89D1C6FA3110037B51B /* SegmentedControlParentVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F5D89C1C6FA3110037B51B /* SegmentedControlParentVC.swift */; }; /* End PBXBuildFile section */ @@ -142,6 +142,8 @@ B55E02471C6457C200DBACF6 /* LogLift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogLift.swift; sourceTree = ""; }; B56863DB1C58374B0065D641 /* DashData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashData.swift; sourceTree = ""; }; B56863DF1C59A1A70065D641 /* SignUpViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = ""; }; + B5787C361C7AA2B400694C44 /* JsonData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JsonData.swift; sourceTree = ""; }; + B5787C381C7AA36D00694C44 /* DeleteAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeleteAccount.swift; sourceTree = ""; }; B58E938E1C6EDFED00CFC8CA /* Theme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = ""; }; B5C6F0EB1C4F25F70016B70E /* logU.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = logU.app; sourceTree = BUILT_PRODUCTS_DIR; }; B5C6F0FF1C4F25F70016B70E /* logUTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = logUTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -158,7 +160,6 @@ B5C6F1211C4F26480016B70E /* GraphData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphData.swift; sourceTree = ""; }; B5C6F1221C4F26480016B70E /* GraphViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphViewController.swift; sourceTree = ""; }; B5C6F1231C4F26480016B70E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - B5C6F1241C4F26480016B70E /* JsonData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JsonData.swift; sourceTree = ""; }; B5C6F1251C4F26480016B70E /* LiftTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiftTableViewCell.swift; sourceTree = ""; }; B5C6F1261C4F26480016B70E /* LoginVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginVC.swift; sourceTree = ""; }; B5C6F1281C4F26480016B70E /* SquatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SquatViewController.swift; sourceTree = ""; }; @@ -171,7 +172,6 @@ B5C6F15D1C4F45240016B70E /* MaxesTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaxesTableViewCell.swift; sourceTree = ""; }; B5C6F1671C557ACD0016B70E /* PoundageTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoundageTableViewCell.swift; sourceTree = ""; }; B5C6F16B1C557B4E0016B70E /* PoundageTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoundageTableViewController.swift; sourceTree = ""; }; - B5E812511C72A30100FA2DBC /* DeleteAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeleteAccount.swift; path = ../DeleteAccount.swift; sourceTree = ""; }; B5F5D8971C6FA23B0037B51B /* GraphSegmented.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphSegmented.swift; sourceTree = ""; }; B5F5D89C1C6FA3110037B51B /* SegmentedControlParentVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedControlParentVC.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -235,12 +235,13 @@ B5C6F0ED1C4F25F70016B70E /* logU */ = { isa = PBXGroup; children = ( - B5E812511C72A30100FA2DBC /* DeleteAccount.swift */, + B5787C381C7AA36D00694C44 /* DeleteAccount.swift */, B56863DF1C59A1A70065D641 /* SignUpViewController.swift */, B56863DB1C58374B0065D641 /* DashData.swift */, B505D02A1C55CEDB00C09549 /* Settings.swift */, B505D0241C55B5AE00C09549 /* SettingsTableViewController.swift */, B505D0281C55C27500C09549 /* SettingsTableViewCell.swift */, + B5787C361C7AA2B400694C44 /* JsonData.swift */, B5C6F1671C557ACD0016B70E /* PoundageTableViewCell.swift */, B5C6F16B1C557B4E0016B70E /* PoundageTableViewController.swift */, B5C6F1571C4F3A9E0016B70E /* StatsTableViewController.swift */, @@ -260,7 +261,6 @@ B5C6F1211C4F26480016B70E /* GraphData.swift */, B5C6F1221C4F26480016B70E /* GraphViewController.swift */, B5C6F1231C4F26480016B70E /* Info.plist */, - B5C6F1241C4F26480016B70E /* JsonData.swift */, B5C6F1251C4F26480016B70E /* LiftTableViewCell.swift */, B5C6F1261C4F26480016B70E /* LoginVC.swift */, B5C6F1281C4F26480016B70E /* SquatViewController.swift */, @@ -492,13 +492,14 @@ B52FFA561C62F16A00C5F481 /* StatsData.swift in Sources */, B5F5D89D1C6FA3110037B51B /* SegmentedControlParentVC.swift in Sources */, B5C6F12A1C4F26480016B70E /* AppDelegate.swift in Sources */, - B5C6F1321C4F26480016B70E /* JsonData.swift in Sources */, 8BB596DB1C513968003B98BA /* ConnectionTest.swift in Sources */, B5C6F12C1C4F26480016B70E /* BenchViewController.swift in Sources */, B5F5D8981C6FA23B0037B51B /* GraphSegmented.swift in Sources */, + B5787C391C7AA36D00694C44 /* DeleteAccount.swift in Sources */, B5C6F15E1C4F45240016B70E /* MaxesTableViewCell.swift in Sources */, 8BB596E21C514449003B98BA /* OfflineRequest.swift in Sources */, B5C6F12D1C4F26480016B70E /* DashTableViewController.swift in Sources */, + B5787C371C7AA2B400694C44 /* JsonData.swift in Sources */, B5C6F15A1C4F3AFE0016B70E /* StatsTableViewCell.swift in Sources */, B5C6F1581C4F3A9E0016B70E /* StatsTableViewController.swift in Sources */, B5C6F16C1C557B4E0016B70E /* PoundageTableViewController.swift in Sources */, @@ -509,7 +510,6 @@ B505D0251C55B5AE00C09549 /* SettingsTableViewController.swift in Sources */, B56863DC1C58374B0065D641 /* DashData.swift in Sources */, 8BB596E01C513BE8003B98BA /* LiftDataModel.xcdatamodeld in Sources */, - B5E812521C72A30100FA2DBC /* DeleteAccount.swift in Sources */, B5C6F1331C4F26480016B70E /* LiftTableViewCell.swift in Sources */, B505D02B1C55CEDB00C09549 /* Settings.swift in Sources */, B55E02481C6457C200DBACF6 /* LogLift.swift in Sources */, diff --git a/logU/.DS_Store b/logU/.DS_Store index cc29a05..40d6bdb 100644 Binary files a/logU/.DS_Store and b/logU/.DS_Store differ diff --git a/logU/.gitignore b/logU/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/logU/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/logU/Assets.xcassets/AppIcon.appiconset/Contents.json b/logU/Assets.xcassets/AppIcon.appiconset/Contents.json index 1593889..0e2917a 100644 --- a/logU/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/logU/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -33,13 +33,21 @@ { "size" : "57x57", "idiom" : "iphone", +<<<<<<< HEAD + "filename" : "Icon-60@2x-2.png", +======= "filename" : "Icon-60@2x-3.png", +>>>>>>> release "scale" : "1x" }, { "size" : "57x57", "idiom" : "iphone", +<<<<<<< HEAD + "filename" : "Icon-60@2x-3.png", +======= "filename" : "Icon-60@2x-2.png", +>>>>>>> release "scale" : "2x" }, { diff --git a/logU/Assets.xcassets/Clear Filters.imageset/Clear Filters.png b/logU/Assets.xcassets/Clear Filters.imageset/Clear Filters.png new file mode 100644 index 0000000..ca01464 Binary files /dev/null and b/logU/Assets.xcassets/Clear Filters.imageset/Clear Filters.png differ diff --git a/logU/Assets.xcassets/Clear Filters.imageset/Contents.json b/logU/Assets.xcassets/Clear Filters.imageset/Contents.json new file mode 100644 index 0000000..09a7b5e --- /dev/null +++ b/logU/Assets.xcassets/Clear Filters.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "Clear Filters.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/logU/Assets.xcassets/Filter.imageset/Contents.json b/logU/Assets.xcassets/Filter.imageset/Contents.json new file mode 100644 index 0000000..f652f3e --- /dev/null +++ b/logU/Assets.xcassets/Filter.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "Filter.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/logU/Assets.xcassets/Filter.imageset/Filter.png b/logU/Assets.xcassets/Filter.imageset/Filter.png new file mode 100644 index 0000000..ccc8a89 Binary files /dev/null and b/logU/Assets.xcassets/Filter.imageset/Filter.png differ diff --git a/logU/Base.lproj/Main.storyboard b/logU/Base.lproj/Main.storyboard index 2007181..c5ac5bf 100644 --- a/logU/Base.lproj/Main.storyboard +++ b/logU/Base.lproj/Main.storyboard @@ -107,20 +107,40 @@ + + + + + + + + + + + + + + + + + - - - - + + + + + + + - + @@ -153,13 +173,33 @@ + + + + + + + + + + + + + + + + + - - - - + + + + + + + @@ -168,6 +208,7 @@ + @@ -199,13 +240,33 @@ + + + + + + + + + + + + + + + + + - - - - + + + + + + + @@ -214,6 +275,7 @@ + @@ -464,10 +526,10 @@ - - - - + + + + @@ -1134,7 +1196,9 @@ This data will not be collected, transmitted, or used with anybody or anything o + + @@ -1184,8 +1248,10 @@ This data will not be collected, transmitted, or used with anybody or anything o + + diff --git a/logU/BenchViewController.swift b/logU/BenchViewController.swift index fea7ecd..b500e16 100644 --- a/logU/BenchViewController.swift +++ b/logU/BenchViewController.swift @@ -13,6 +13,9 @@ var dataBench: Array> = [] class BenchViewController: UIViewController { + var setsTextField: UITextField? + var repsTextField: UITextField? + let url_to_post:String = "https://loguapp.com/swift4.php" var graphLift : [String]! = [] @@ -25,10 +28,102 @@ class BenchViewController: UIViewController { saveGraph() } + @IBOutlet weak var reloadButton: UIBarButtonItem! + + @IBAction func reloadGraph(sender: UIBarButtonItem) { + + reloadButton.enabled = false + setsTextField = nil + repsTextField = nil + + if Reachability.isConnectedToNetwork() { + dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { + GraphData().dataOfLifting(self.url_to_post, completion: { jsonString in + dataBench = jsonString + dispatch_async(dispatch_get_main_queue(), { + self.loadAfter(dataBench) + }) + + }) + } + } + + } + + @IBAction func filterGraph(sender: UIBarButtonItem) { + + let actionSheetController: UIAlertController = UIAlertController(title: "Filter Graph", message: "Please enter sets and reps to filter by:", preferredStyle: .Alert) + let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in + //Do some stuff + } + + let submitAction: UIAlertAction = UIAlertAction(title: "Filter", style: .Default) { action -> Void in + //Do some stuff + + if Reachability.isConnectedToNetwork() { + dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { + GraphData().dataOfLiftingFiltered("https://loguapp.com/swift_filter_graph.php", sets: self.setsTextField!.text!, reps: self.repsTextField!.text!, lift: "Bench", completion: { jsonString in + dataBench = jsonString + + if dataBench.count != 0 { + dispatch_async(dispatch_get_main_queue(), { + self.loadAfter(dataBench) + }) + } else { + + let actionSheetController: UIAlertController = UIAlertController(title: "Filter Graph Failed", message: "Data for this set/rep combo doesn't exist!", preferredStyle: .Alert) + let cancelAction: UIAlertAction = UIAlertAction(title: "Dismiss", style: .Cancel) { action -> Void in + //Do some stuff + } + actionSheetController.addAction(cancelAction) + self.presentViewController(actionSheetController, animated: true, completion: nil) + } + }) + } + self.reloadButton.enabled = true + } + + } + + actionSheetController.addTextFieldWithConfigurationHandler { (setsField) in + + setsField.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged) + + setsField.placeholder = "Sets" + setsField.keyboardType = UIKeyboardType.NumberPad + self.setsTextField = setsField + + } + actionSheetController.addTextFieldWithConfigurationHandler { (repsField) in + + repsField.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged) + + repsField.placeholder = "Reps" + repsField.keyboardType = UIKeyboardType.NumberPad + self.repsTextField = repsField + } + + actionSheetController.addAction(cancelAction) + actionSheetController.addAction(submitAction) + submitAction.enabled = false + + self.presentViewController(actionSheetController, animated: true, completion: nil) + + } + + func textChanged(sender:AnyObject) { + let tf = sender as! UITextField + var resp : UIResponder = tf + while !(resp is UIAlertController) { resp = resp.nextResponder()! } + let alert = resp as! UIAlertController + (alert.actions[1] as UIAlertAction).enabled = (setsTextField?.text != "" && repsTextField?.text != "" && setsTextField?.text?.hasPrefix("0") == false && repsTextField?.text?.hasPrefix("0") == false) + } + override func viewDidLoad() { super.viewDidLoad() self.automaticallyAdjustsScrollViewInsets = false; + reloadButton.enabled = false if Reachability.isConnectedToNetwork() { dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { @@ -57,12 +152,12 @@ class BenchViewController: UIViewController { }) } } - shouldUpdateBench = false } } func loadAfter(object: Array>) { + var label: String! dataBench = object graphLift = [] @@ -74,7 +169,19 @@ class BenchViewController: UIViewController { } Date = graphLift - setLineChart(graphLift, values: graphWeight) + + if setsTextField == nil || repsTextField == nil { + label = "" + } else { + label = setsTextField!.text! + "x" + repsTextField!.text! + } + + if shouldUpdateBench { + label = "" + } + shouldUpdateBench = false + + setLineChart(graphLift, values: graphWeight, label: label) } override func didReceiveMemoryWarning() { @@ -82,7 +189,7 @@ class BenchViewController: UIViewController { // Dispose of any resources that can be recreated. } - func setLineChart(dataPoints: [String], values: [Double]) { + func setLineChart(dataPoints: [String], values: [Double], label: String) { if graphLift.count == 0 || graphWeight.count == 0 { benchChartView.isEmpty() @@ -101,7 +208,7 @@ class BenchViewController: UIViewController { dataEntries.append(dataEntry) } - let chartDataSet = LineChartDataSet(yVals: dataEntries, label: "Bench") + let chartDataSet = LineChartDataSet(yVals: dataEntries, label: label + " " + "Bench") chartDataSet.drawCubicEnabled = true chartDataSet.drawFilledEnabled = true chartDataSet.drawCirclesEnabled = false diff --git a/logU/DeadliftViewController.swift b/logU/DeadliftViewController.swift index ae1192b..7b7d47a 100644 --- a/logU/DeadliftViewController.swift +++ b/logU/DeadliftViewController.swift @@ -13,6 +13,9 @@ var dataDeadlift: Array> = [] class DeadliftViewController: UIViewController { + var setsTextField: UITextField? + var repsTextField: UITextField? + let url_to_post:String = "https://loguapp.com/swift5.php" var graphLift : [String]! = [] @@ -25,10 +28,105 @@ class DeadliftViewController: UIViewController { saveGraph() } + @IBOutlet weak var reloadButton: UIBarButtonItem! + + @IBAction func reloadGraph(sender: UIBarButtonItem) { + + reloadButton.enabled = false + setsTextField = nil + repsTextField = nil + + if Reachability.isConnectedToNetwork() { + dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { + GraphData().dataOfLifting(self.url_to_post, completion: { jsonString in + dataDeadlift = jsonString + dispatch_async(dispatch_get_main_queue(), { + self.loadAfter(dataDeadlift) + }) + + }) + } + } + + } + + @IBAction func filterGraph(sender: UIBarButtonItem) { + let actionSheetController: UIAlertController = UIAlertController(title: "Filter Graph", message: "Please enter sets and reps to filter by:", preferredStyle: .Alert) + let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in + //Do some stuff + } + + let submitAction: UIAlertAction = UIAlertAction(title: "Filter", style: .Default) { action -> Void in + //Do some stuff + + if Reachability.isConnectedToNetwork() { + dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { + GraphData().dataOfLiftingFiltered("https://loguapp.com/swift_filter_graph.php", sets: self.setsTextField!.text!, reps: self.repsTextField!.text!, lift: "Deadlift", completion: { jsonString in + dataDeadlift = jsonString + + if dataDeadlift.count != 0 { + dispatch_async(dispatch_get_main_queue(), { + self.loadAfter(dataDeadlift) + }) + } else { + + let actionSheetController: UIAlertController = UIAlertController(title: "Filter Graph Failed", message: "Data for this set/rep combo doesn't exist!", preferredStyle: .Alert) + let cancelAction: UIAlertAction = UIAlertAction(title: "Dismiss", style: .Cancel) { action -> Void in + //Do some stuff + } + actionSheetController.addAction(cancelAction) + self.presentViewController(actionSheetController, animated: true, completion: nil) + } + }) + } + self.reloadButton.enabled = true + + } + + + } + + actionSheetController.addTextFieldWithConfigurationHandler { (setsField) in + + setsField.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged) + + + setsField.placeholder = "Sets" + setsField.keyboardType = UIKeyboardType.NumberPad + self.setsTextField = setsField + + } + actionSheetController.addTextFieldWithConfigurationHandler { (repsField) in + + repsField.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged) + + + repsField.placeholder = "Reps" + repsField.keyboardType = UIKeyboardType.NumberPad + self.repsTextField = repsField + } + + actionSheetController.addAction(cancelAction) + actionSheetController.addAction(submitAction) + submitAction.enabled = false + + self.presentViewController(actionSheetController, animated: true, completion: nil) + + } + + func textChanged(sender:AnyObject) { + let tf = sender as! UITextField + var resp : UIResponder = tf + while !(resp is UIAlertController) { resp = resp.nextResponder()! } + let alert = resp as! UIAlertController + (alert.actions[1] as UIAlertAction).enabled = (setsTextField?.text != "" && repsTextField?.text != "" && setsTextField?.text?.hasPrefix("0") == false && repsTextField?.text?.hasPrefix("0") == false) + } + override func viewDidLoad() { super.viewDidLoad() self.automaticallyAdjustsScrollViewInsets = false; + reloadButton.enabled = false if Reachability.isConnectedToNetwork() { dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { @@ -57,11 +155,11 @@ class DeadliftViewController: UIViewController { }) } } - shouldUpdateDeadlift = false } } func loadAfter(object: Array>) { + var label: String! dataDeadlift = object graphLift = [] @@ -73,7 +171,19 @@ class DeadliftViewController: UIViewController { } Date = graphLift - setLineChart(graphLift, values: graphWeight) + + if setsTextField == nil || repsTextField == nil { + label = "" + } else { + label = setsTextField!.text! + "x" + repsTextField!.text! + } + + if shouldUpdateDeadlift { + label = "" + } + shouldUpdateDeadlift = false + + setLineChart(graphLift, values: graphWeight, label: label) } @@ -82,7 +192,7 @@ class DeadliftViewController: UIViewController { // Dispose of any resources that can be recreated. } - func setLineChart(dataPoints: [String], values: [Double]) { + func setLineChart(dataPoints: [String], values: [Double], label: String) { if graphLift.count == 0 || graphWeight.count == 0 { deadliftChartView.isEmpty() @@ -101,7 +211,7 @@ class DeadliftViewController: UIViewController { dataEntries.append(dataEntry) } - let chartDataSet = LineChartDataSet(yVals: dataEntries, label: "Deadlift") + let chartDataSet = LineChartDataSet(yVals: dataEntries, label: label + " " + "Deadlift") chartDataSet.drawCubicEnabled = true chartDataSet.drawFilledEnabled = true chartDataSet.drawCirclesEnabled = false diff --git a/DeleteAccount.swift b/logU/DeleteAccount.swift similarity index 100% rename from DeleteAccount.swift rename to logU/DeleteAccount.swift diff --git a/logU/GraphData.swift b/logU/GraphData.swift index a368bde..79ab43b 100644 --- a/logU/GraphData.swift +++ b/logU/GraphData.swift @@ -46,4 +46,40 @@ class GraphData { }); task.resume() } + + func dataOfLiftingFiltered(url: String, sets: String, reps: String, lift: String, completion: (Array>) -> ()) { + + let urlName:NSURL = NSURL(string: url)! + let session = NSURLSession.sharedSession() + let data = NSData(contentsOfURL: NSURL(string: url)!) + let user = "username=\(NSUserDefaults.standardUserDefaults().valueForKey("USERNAME")!)&sets=\(sets)&reps=\(reps)&lift=\(lift)" + print(user) + let queryParam = user.dataUsingEncoding(NSUTF8StringEncoding) + let request:NSMutableURLRequest = NSMutableURLRequest(URL: urlName) + request.HTTPMethod = "POST" + request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData + + let task = session.uploadTaskWithRequest(request, fromData: queryParam!, completionHandler: + {(data,response,error) in + + guard let _:NSData = data, let _:NSURLResponse = response where error == nil else { + print("error") + return + } + var myData: Array> = [] + do { + let jsonArray = try NSJSONSerialization.JSONObjectWithData(data!, options: [NSJSONReadingOptions.MutableContainers, NSJSONReadingOptions.AllowFragments]) as? Array> + if jsonArray != nil { + myData = jsonArray! + } + + } catch let error as NSError { + print(error.localizedDescription) + } + completion(Array>(myData)) + + }); + task.resume() + } + } \ No newline at end of file diff --git a/logU/Info.plist b/logU/Info.plist index 4e3fda1..5b787f1 100644 --- a/logU/Info.plist +++ b/logU/Info.plist @@ -15,11 +15,15 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.1 CFBundleSignature ???? CFBundleVersion +<<<<<<< HEAD + 6 +======= 2 +>>>>>>> release LSRequiresIPhoneOS UILaunchStoryboardName diff --git a/logU/JSonData.swift b/logU/JSonData.swift deleted file mode 100644 index 31a3a82..0000000 --- a/logU/JSonData.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// jsonData.swift -// logU -// -// Created by Brett on 1/15/16. -// Copyright © 2016 Brett. All rights reserved. -// - -import Foundation - -class JsonData { - - var myData: Array> = [] - - var Lifts: [String] = [] - var Dates: [String] = [] - var Weights: [String] = [] - var Sets: [String] = [] - var Reps: [String] = [] - var Ids: [String] = [] - - func passValues(data: Array>) { - - myData = data - } - - func dataOfLift(completion: (Array>) -> ()) {//url: String) -> ([String], [String], [String], [String], [String], [String])? { - - let urlName:NSURL = NSURL(string: "https:loguapp.com/swift6.php")! - let session = NSURLSession.sharedSession() - - let data = NSData(contentsOfURL: NSURL(string: "https:/loguapp.com/swift6.php")!) - let user = "username=\(NSUserDefaults.standardUserDefaults().valueForKey("USERNAME")!)" - let queryParam = user.dataUsingEncoding(NSUTF8StringEncoding) - let userData:NSData = user.dataUsingEncoding(NSASCIIStringEncoding)! - - let request:NSMutableURLRequest = NSMutableURLRequest(URL: urlName) - request.HTTPMethod = "POST" - request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData - - let task = session.uploadTaskWithRequest(request, fromData: queryParam!, completionHandler: - {(data,response,error) in - - guard let _:NSData = data, let _:NSURLResponse = response where error == nil else { - print("error") - return - } - - var myData: Array> = [] - do { - let jsonArray = try NSJSONSerialization.JSONObjectWithData(data!, options: [NSJSONReadingOptions.MutableContainers, NSJSONReadingOptions.AllowFragments]) as? Array> - - myData = jsonArray! - - } catch let error as NSError { - print(error.localizedDescription) - } - completion(Array>(myData)) - }); - task.resume() - } - -} diff --git a/logU/LogLift.swift b/logU/LogLift.swift index b9a0114..fdba016 100644 --- a/logU/LogLift.swift +++ b/logU/LogLift.swift @@ -91,7 +91,7 @@ class LogLift: FormViewController { <<< PickerInlineRow("Lift") { (row : PickerInlineRow) -> Void in row.title = "Lift" - row.options = ["Squat", "Pause Squat", "Front Squat", "Bench", "Close Grip Bench", "Incline Bench", "Pause Bench", "Floor Press", "Deadlift", "Deficit Deadlift", "Pause Deadlift", "Snatch Grip Deadlift", "Overhead Press", "Sots Press", "Pullups", "Dips", "Bent Over Rows", "Kroc Rows", "Straight Bar Bicep Curls", "EZ Bar Bicep Curls", "Barbell Bicep Curls", "Snatch", "Clean and Jerk", "Power Clean", "Power Snatch", "Hang Clean", "Hang Snatch"] + row.options = ["Squat", "Pause Squat", "Front Squat", "Bench", "Close Grip Bench", "Incline Bench", "Decline Bench", "Pause Bench", "Floor Press", "Deadlift", "Deficit Deadlift", "Pause Deadlift", "Snatch Grip Deadlift", "Overhead Press", "Sots Press", "Pullups", "Dips", "Bent Over Rows", "Kroc Rows", "Upright Rows", "Straight Bar Bicep Curls", "EZ Bar Bicep Curls", "Barbell Bicep Curls", "Hammer Curls", "Snatch", "Clean and Jerk", "Power Clean", "Power Snatch", "Hang Clean", "Hang Snatch", "Leg Press", "Leg Extension", "Leg Curl", "Chest Fly", "Lat Pulldown", "Shoulder Fly", "Lateral Raise", "Shoulder Shrug", "Tricep Extension", "Dumbbell Bench", "Dumbbell Press", "Skullcrushers", "21's", "Hack Squat", "Zerker Squat"] row.value = row.options[0] } diff --git a/logU/LoginVC.swift b/logU/LoginVC.swift index 8737d0b..07c9c3f 100644 --- a/logU/LoginVC.swift +++ b/logU/LoginVC.swift @@ -18,27 +18,51 @@ class LoginVC: UIViewController { var lifting = [NSManagedObject]() var indicator: UIActivityIndicatorView! + @IBOutlet weak var txtUsername: UITextField! + @IBOutlet weak var txtPassword: UITextField! + @IBOutlet weak var loginButton: UIButton! + @IBOutlet weak var signUpButton: UIButton! + override func viewDidLoad() { + var prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults() addDoneButton() - loginButton.enabled = true - signUpButton.enabled = true - txtUsername.enabled = true - txtPassword.enabled = true + if prefs.valueForKey("ISLOGGEDIN") != nil { + if String((prefs.valueForKey("ISLOGGEDIN"))!) == "1" { + + loginButton.enabled = false + signUpButton.enabled = false + txtUsername.enabled = false + txtPassword.enabled = false + + dispatch_async(dispatch_get_main_queue(), { + self.performSegueWithIdentifier("Dashboard", sender: self) + }) + + globalUser = String((prefs.valueForKey("USERNAME"))!) + Settings().getUnit(globalUser! as String, completion: { jsonString in + prefs.setInteger(Int(jsonString[0]["unit"]!)!, forKey: "Unit") + prefs.setValue(String(jsonString[0]["gender"]!), forKey: "Gender") + prefs.setValue(Double(jsonString[0]["bodyweight"]!)!, forKey: "Bodyweight") + }) + + } + } else { + + loginButton.enabled = true + signUpButton.enabled = true + txtUsername.enabled = true + txtPassword.enabled = true - if Reachability.isConnectedToNetwork() { - OfflineRequest().OfflineFetchSubmit() - OfflineRequest().OfflineFetchDelete() + if Reachability.isConnectedToNetwork() { + OfflineRequest().OfflineFetchSubmit() + OfflineRequest().OfflineFetchDelete() + } } } - @IBOutlet weak var txtUsername: UITextField! - @IBOutlet weak var txtPassword: UITextField! - @IBOutlet weak var loginButton: UIButton! - @IBOutlet weak var signUpButton: UIButton! - @IBAction func unwindToLogin(unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) { } @@ -131,6 +155,7 @@ class LoginVC: UIViewController { var prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults() prefs.setObject(username, forKey: "USERNAME") prefs.setInteger(1, forKey: "ISLOGGEDIN") + prefs.setObject("1", forKey: "ISLOGGED") prefs.synchronize() globalUser = String(prefs.valueForKey("USERNAME")) diff --git a/logU/SettingsTableViewController.swift b/logU/SettingsTableViewController.swift index c650522..d689d9e 100644 --- a/logU/SettingsTableViewController.swift +++ b/logU/SettingsTableViewController.swift @@ -104,6 +104,9 @@ class SettingsTableViewController: FormViewController { performSegueWithIdentifier("loggingOut", sender: nil) self.navigationController?.navigationBarHidden = true globalUser = "" + defaults.setObject("", forKey: "USERNAME") + defaults.setValue(0, forKey: "ISLOGGEDIN") + defaults.synchronize() } func viewPrivacy(cell: ButtonCellOf, row: ButtonRow) { @@ -127,6 +130,10 @@ class SettingsTableViewController: FormViewController { DeleteAccount().delete_request(globalUser!) globalUser = "" + self.defaults.setObject("", forKey: "USERNAME") + self.defaults.setValue(0, forKey: "ISLOGGEDIN") + self.defaults.synchronize() + self.performSegueWithIdentifier("loggingOut", sender: nil) self.navigationController?.navigationBarHidden = true diff --git a/logU/SquatViewController.swift b/logU/SquatViewController.swift index 516b64f..efb6bb7 100644 --- a/logU/SquatViewController.swift +++ b/logU/SquatViewController.swift @@ -13,6 +13,9 @@ var dataSquat: Array> = [] class SquatViewController: UIViewController { + var setsTextField: UITextField? + var repsTextField: UITextField? + let url_to_post:String = "https://loguapp.com/swift3.php" var graphLift : [String]! = [] @@ -25,10 +28,100 @@ class SquatViewController: UIViewController { saveGraph() } + @IBOutlet weak var reloadButton: UIBarButtonItem! + + @IBAction func reloadGraph(sender: UIBarButtonItem) { + + reloadButton.enabled = false + setsTextField = nil + repsTextField = nil + + if Reachability.isConnectedToNetwork() { + dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { + GraphData().dataOfLifting(self.url_to_post, completion: { jsonString in + dataSquat = jsonString + dispatch_async(dispatch_get_main_queue(), { + self.loadAfter(dataSquat) + }) + + }) + } + } + } + + @IBAction func filterGraph(sender: UIBarButtonItem) { + let actionSheetController: UIAlertController = UIAlertController(title: "Filter Graph", message: "Please enter sets and reps to filter by:", preferredStyle: .Alert) + let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in + //Do some stuff + } + + let submitAction: UIAlertAction = UIAlertAction(title: "Filter", style: .Default) { action -> Void in + //Do some stuff + + if Reachability.isConnectedToNetwork() { + dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { + GraphData().dataOfLiftingFiltered("https://loguapp.com/swift_filter_graph.php", sets: self.setsTextField!.text!, reps: self.repsTextField!.text!, lift: "Squat", completion: { jsonString in + dataSquat = jsonString + + if dataSquat.count != 0 { + dispatch_async(dispatch_get_main_queue(), { + self.loadAfter(dataSquat) + }) + } else { + + let actionSheetController: UIAlertController = UIAlertController(title: "Filter Graph Failed", message: "Data for this set/rep combo doesn't exist!", preferredStyle: .Alert) + let cancelAction: UIAlertAction = UIAlertAction(title: "Dismiss", style: .Cancel) { action -> Void in + //Do some stuff + } + actionSheetController.addAction(cancelAction) + self.presentViewController(actionSheetController, animated: true, completion: nil) + } + }) + } + self.reloadButton.enabled = true + } + + } + + actionSheetController.addTextFieldWithConfigurationHandler { (setsField) in + + setsField.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged) + + setsField.placeholder = "Sets" + setsField.keyboardType = UIKeyboardType.NumberPad + self.setsTextField = setsField + + } + actionSheetController.addTextFieldWithConfigurationHandler { (repsField) in + + repsField.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged) + + repsField.placeholder = "Reps" + repsField.keyboardType = UIKeyboardType.NumberPad + self.repsTextField = repsField + } + + actionSheetController.addAction(cancelAction) + actionSheetController.addAction(submitAction) + submitAction.enabled = false + + self.presentViewController(actionSheetController, animated: true, completion: nil) + + } + + func textChanged(sender:AnyObject) { + let tf = sender as! UITextField + var resp : UIResponder = tf + while !(resp is UIAlertController) { resp = resp.nextResponder()! } + let alert = resp as! UIAlertController + (alert.actions[1] as UIAlertAction).enabled = (setsTextField?.text != "" && repsTextField?.text != "" && setsTextField?.text?.hasPrefix("0") == false && repsTextField?.text?.hasPrefix("0") == false) + } + override func viewDidLoad() { super.viewDidLoad() self.automaticallyAdjustsScrollViewInsets = false; + reloadButton.enabled = false if Reachability.isConnectedToNetwork() { dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { @@ -50,6 +143,7 @@ class SquatViewController: UIViewController { dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { GraphData().dataOfLifting(self.url_to_post, completion: { jsonString in dataSquat = jsonString + dispatch_async(dispatch_get_main_queue(), { self.loadAfter(dataSquat) }) @@ -57,12 +151,13 @@ class SquatViewController: UIViewController { }) } } - shouldUpdateSquat = false } } func loadAfter(object: Array>) { + var label: String! dataSquat = object + print(dataSquat.count) graphLift = [] graphWeight = [] @@ -73,7 +168,20 @@ class SquatViewController: UIViewController { } Date = graphLift - setLineChart(graphLift, values: graphWeight) + + if setsTextField == nil || repsTextField == nil { + label = "" + } else { + label = setsTextField!.text! + "x" + repsTextField!.text! + } + + if shouldUpdateSquat { + label = "" + } + + setLineChart(graphLift, values: graphWeight, label: label) + + shouldUpdateSquat = false } override func didReceiveMemoryWarning() { @@ -81,7 +189,7 @@ class SquatViewController: UIViewController { // Dispose of any resources that can be recreated. } - func setLineChart(dataPoints: [String], values: [Double]) { + func setLineChart(dataPoints: [String], values: [Double], label: String) { if graphLift.count == 0 || graphWeight.count == 0 { squatChartView.isEmpty() @@ -100,7 +208,7 @@ class SquatViewController: UIViewController { dataEntries.append(dataEntry) } - let chartDataSet = LineChartDataSet(yVals: dataEntries, label: "Squat") + let chartDataSet = LineChartDataSet(yVals: dataEntries, label: label + " " + "Squat") chartDataSet.drawCubicEnabled = true chartDataSet.drawFilledEnabled = true chartDataSet.drawCirclesEnabled = false diff --git a/logU/jsonData.swift b/logU/jsonData.swift index 3970cc6..31a3a82 100644 --- a/logU/jsonData.swift +++ b/logU/jsonData.swift @@ -24,7 +24,7 @@ class JsonData { myData = data } - func dataOfLift(completion: (Array>) -> ()) { + func dataOfLift(completion: (Array>) -> ()) {//url: String) -> ([String], [String], [String], [String], [String], [String])? { let urlName:NSURL = NSURL(string: "https:loguapp.com/swift6.php")! let session = NSURLSession.sharedSession()