Commit c4525f8715e07da1592b4c4d3b74f68869d8c367
1 parent
b94abc619f
Exists in
master
and in
1 other branch
Add API for request history in today with selected type and mode
Showing 19 changed files with 376 additions and 33 deletions Side-by-side Diff
- LifeLog/LifeLog.xcodeproj/project.pbxproj
- LifeLog/LifeLog/Assets.xcassets/History/Contents.json
- LifeLog/LifeLog/Assets.xcassets/History/arrow_back.imageset/Contents.json
- LifeLog/LifeLog/Assets.xcassets/History/arrow_back.imageset/arrow_back.png
- LifeLog/LifeLog/Assets.xcassets/History/arrow_next.imageset/Contents.json
- LifeLog/LifeLog/Assets.xcassets/History/arrow_next.imageset/arrow_next.png
- LifeLog/LifeLog/AutoTransLabel.h
- LifeLog/LifeLog/AutoTransLabel.m
- LifeLog/LifeLog/CollectionView.h
- LifeLog/LifeLog/CollectionView.m
- LifeLog/LifeLog/Entities.h
- LifeLog/LifeLog/HistoryObject.h
- LifeLog/LifeLog/HistoryObject.m
- LifeLog/LifeLog/HistoryViewController.h
- LifeLog/LifeLog/HistoryViewController.m
- LifeLog/LifeLog/HistoryViewController.xib
- LifeLog/LifeLog/Localizable.strings
- LifeLog/LifeLog/ServerAPI.h
- LifeLog/LifeLog/ServerAPI.m
LifeLog/LifeLog.xcodeproj/project.pbxproj
| ... | ... | @@ -44,6 +44,8 @@ |
| 44 | 44 | 9CBDA0FA1F2ECE2C0055DED1 /* BaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CBDA0F91F2ECE2C0055DED1 /* BaseViewController.m */; }; |
| 45 | 45 | 9CBDA0FF1F2F03810055DED1 /* RegisterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CBDA0FD1F2F03810055DED1 /* RegisterViewController.m */; }; |
| 46 | 46 | 9CBDA1001F2F03810055DED1 /* RegisterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9CBDA0FE1F2F03810055DED1 /* RegisterViewController.xib */; }; |
| 47 | + E9373E471F3596940059355A /* AutoTransLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E461F3596940059355A /* AutoTransLabel.m */; }; | |
| 48 | + E9373E4A1F35AA180059355A /* HistoryObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E491F35AA180059355A /* HistoryObject.m */; }; | |
| 47 | 49 | E99E13AB1F336F3600C78787 /* CollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = E99E13AA1F336F3600C78787 /* CollectionView.m */; }; |
| 48 | 50 | E99E13AD1F336F4500C78787 /* CollectionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E99E13AC1F336F4500C78787 /* CollectionView.xib */; }; |
| 49 | 51 | E99E13B11F33720600C78787 /* LabelCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E99E13AF1F33720600C78787 /* LabelCollectionViewCell.m */; }; |
| ... | ... | @@ -137,6 +139,10 @@ |
| 137 | 139 | 9CBDA0FC1F2F03810055DED1 /* RegisterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegisterViewController.h; sourceTree = "<group>"; }; |
| 138 | 140 | 9CBDA0FD1F2F03810055DED1 /* RegisterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegisterViewController.m; sourceTree = "<group>"; }; |
| 139 | 141 | 9CBDA0FE1F2F03810055DED1 /* RegisterViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RegisterViewController.xib; sourceTree = "<group>"; }; |
| 142 | + E9373E451F3596940059355A /* AutoTransLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoTransLabel.h; sourceTree = "<group>"; }; | |
| 143 | + E9373E461F3596940059355A /* AutoTransLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AutoTransLabel.m; sourceTree = "<group>"; }; | |
| 144 | + E9373E481F35AA180059355A /* HistoryObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryObject.h; sourceTree = "<group>"; }; | |
| 145 | + E9373E491F35AA180059355A /* HistoryObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryObject.m; sourceTree = "<group>"; }; | |
| 140 | 146 | E99E13A91F336F3600C78787 /* CollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectionView.h; sourceTree = "<group>"; }; |
| 141 | 147 | E99E13AA1F336F3600C78787 /* CollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CollectionView.m; sourceTree = "<group>"; }; |
| 142 | 148 | E99E13AC1F336F4500C78787 /* CollectionView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CollectionView.xib; sourceTree = "<group>"; }; |
| ... | ... | @@ -208,6 +214,8 @@ |
| 208 | 214 | 6E18CEDA1F2E40F50029891F /* User.h */, |
| 209 | 215 | 6E18CEDB1F2E40F50029891F /* User.m */, |
| 210 | 216 | 6E18CEDD1F2E46570029891F /* Entities.h */, |
| 217 | + E9373E481F35AA180059355A /* HistoryObject.h */, | |
| 218 | + E9373E491F35AA180059355A /* HistoryObject.m */, | |
| 211 | 219 | ); |
| 212 | 220 | name = Model; |
| 213 | 221 | sourceTree = "<group>"; |
| 214 | 222 | |
| ... | ... | @@ -451,9 +459,19 @@ |
| 451 | 459 | name = Pods; |
| 452 | 460 | sourceTree = "<group>"; |
| 453 | 461 | }; |
| 462 | + E9373E441F35966D0059355A /* AutoTranslateView */ = { | |
| 463 | + isa = PBXGroup; | |
| 464 | + children = ( | |
| 465 | + E9373E451F3596940059355A /* AutoTransLabel.h */, | |
| 466 | + E9373E461F3596940059355A /* AutoTransLabel.m */, | |
| 467 | + ); | |
| 468 | + name = AutoTranslateView; | |
| 469 | + sourceTree = "<group>"; | |
| 470 | + }; | |
| 454 | 471 | E99E13A71F336F0C00C78787 /* CustomView */ = { |
| 455 | 472 | isa = PBXGroup; |
| 456 | 473 | children = ( |
| 474 | + E9373E441F35966D0059355A /* AutoTranslateView */, | |
| 457 | 475 | E99E13A81F336F1700C78787 /* CollectionView */, |
| 458 | 476 | ); |
| 459 | 477 | name = CustomView; |
| 460 | 478 | |
| ... | ... | @@ -678,12 +696,14 @@ |
| 678 | 696 | 6E48AF0D1F2F9D3300C1D184 /* CustomTextField.m in Sources */, |
| 679 | 697 | E99E13AB1F336F3600C78787 /* CollectionView.m in Sources */, |
| 680 | 698 | 6E84E3B01F27A975001EB88E /* HomeViewController.m in Sources */, |
| 699 | + E9373E471F3596940059355A /* AutoTransLabel.m in Sources */, | |
| 681 | 700 | 6E84E3791F27A701001EB88E /* AppDelegate.m in Sources */, |
| 682 | 701 | 6E84E3BA1F27A9A0001EB88E /* RankingViewController.m in Sources */, |
| 683 | 702 | 6E7F93441F35872B00EFBC71 /* TPKeyboardAvoidingTableView.m in Sources */, |
| 684 | 703 | E9F73DCC1F338A0F004A3A6F /* HistoryListTableViewCell.m in Sources */, |
| 685 | 704 | 6EDC8BF41F2C68D700765ACC /* CMMotionActivityExtra.m in Sources */, |
| 686 | 705 | 9CBDA0FF1F2F03810055DED1 /* RegisterViewController.m in Sources */, |
| 706 | + E9373E4A1F35AA180059355A /* HistoryObject.m in Sources */, | |
| 687 | 707 | 9CA8AEEA1F31BB4600C5FC74 /* ConfirmForgetPassViewController.m in Sources */, |
| 688 | 708 | E99E13B11F33720600C78787 /* LabelCollectionViewCell.m in Sources */, |
| 689 | 709 | 6EDC8BEE1F2C2FB800765ACC /* Utilities.m in Sources */, |
LifeLog/LifeLog/Assets.xcassets/History/Contents.json
LifeLog/LifeLog/Assets.xcassets/History/arrow_back.imageset/Contents.json
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "idiom" : "universal", | |
| 9 | + "filename" : "arrow_back.png", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "version" : 1, | |
| 19 | + "author" : "xcode" | |
| 20 | + } | |
| 21 | +} |
LifeLog/LifeLog/Assets.xcassets/History/arrow_back.imageset/arrow_back.png
319 Bytes
LifeLog/LifeLog/Assets.xcassets/History/arrow_next.imageset/Contents.json
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "idiom" : "universal", | |
| 9 | + "filename" : "arrow_next.png", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "version" : 1, | |
| 19 | + "author" : "xcode" | |
| 20 | + } | |
| 21 | +} |
LifeLog/LifeLog/Assets.xcassets/History/arrow_next.imageset/arrow_next.png
332 Bytes
LifeLog/LifeLog/AutoTransLabel.h
| 1 | +// | |
| 2 | +// AutoTransLabel.h | |
| 3 | +// LifeLog | |
| 4 | +// | |
| 5 | +// Created by nvtu on 8/5/17. | |
| 6 | +// Copyright ยฉ 2017 PhongNV. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +IB_DESIGNABLE | |
| 12 | + | |
| 13 | +@interface AutoTransLabel : UILabel | |
| 14 | + | |
| 15 | +@property (nonatomic) IBInspectable NSString *localizeKey; | |
| 16 | + | |
| 17 | +@end |
LifeLog/LifeLog/AutoTransLabel.m
| 1 | +// | |
| 2 | +// AutoTransLabel.m | |
| 3 | +// LifeLog | |
| 4 | +// | |
| 5 | +// Created by nvtu on 8/5/17. | |
| 6 | +// Copyright ยฉ 2017 PhongNV. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "AutoTransLabel.h" | |
| 10 | + | |
| 11 | +@implementation AutoTransLabel | |
| 12 | + | |
| 13 | +-(void) awakeFromNib { | |
| 14 | + [super awakeFromNib]; | |
| 15 | + if(![self.localizeKey isEqual: @""]) { | |
| 16 | + self.text = NSLocalizedString(self.localizeKey, nil); | |
| 17 | + } | |
| 18 | +} | |
| 19 | +@end |
LifeLog/LifeLog/CollectionView.h
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | #import <UIKit/UIKit.h> |
| 10 | 10 | |
| 11 | 11 | @interface CollectionView : UIView <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout> { |
| 12 | - int _number; | |
| 12 | + NSInteger _number; | |
| 13 | 13 | int _selectedIndex; |
| 14 | 14 | |
| 15 | 15 | float _spacing; |
| 16 | 16 | |
| ... | ... | @@ -22,10 +22,12 @@ |
| 22 | 22 | NSArray * _arrayTitle; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | +@property (copy) void (^changeCurrentIndex)(int index); | |
| 26 | + | |
| 25 | 27 | @property (weak, nonatomic) IBOutlet UIView *view; |
| 26 | 28 | @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; |
| 27 | 29 | |
| 28 | --(void) setButtonNumber: (int) number; | |
| 30 | +-(void) setButtonNumber: (NSInteger) number; | |
| 29 | 31 | -(void) setSpacing: (float) spacing; |
| 30 | 32 | -(void) setCornerRadius: (float) radius; |
| 31 | 33 | -(void) setSelectedIndex: (int) index; |
| ... | ... | @@ -33,5 +35,6 @@ |
| 33 | 35 | -(void) setArrayTitle: (NSArray *) title; |
| 34 | 36 | |
| 35 | 37 | -(int) getCurrentIndex; |
| 38 | + | |
| 36 | 39 | @end |
LifeLog/LifeLog/CollectionView.m
| ... | ... | @@ -33,7 +33,7 @@ |
| 33 | 33 | [self.collectionView registerNib:[UINib nibWithNibName:@"LabelCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"LabelCell"]; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | --(void) setButtonNumber: (int) number { | |
| 36 | +-(void) setButtonNumber: (NSInteger) number { | |
| 37 | 37 | _number = number; |
| 38 | 38 | } |
| 39 | 39 | |
| ... | ... | @@ -60,7 +60,7 @@ |
| 60 | 60 | _arrayTitle = title; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | --(int) getCurrentIndex { | |
| 63 | +-(int) getCurrentIndex { | |
| 64 | 64 | return _selectedIndex; |
| 65 | 65 | } |
| 66 | 66 | |
| ... | ... | @@ -93,6 +93,7 @@ |
| 93 | 93 | -(void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { |
| 94 | 94 | _selectedIndex = indexPath.row; |
| 95 | 95 | [collectionView reloadData]; |
| 96 | + self.changeCurrentIndex(_selectedIndex); | |
| 96 | 97 | } |
| 97 | 98 | @end |
LifeLog/LifeLog/Entities.h
LifeLog/LifeLog/HistoryObject.h
| 1 | +// | |
| 2 | +// HistoryObject.h | |
| 3 | +// LifeLog | |
| 4 | +// | |
| 5 | +// Created by nvtu on 8/5/17. | |
| 6 | +// Copyright ยฉ 2017 PhongNV. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <Foundation/Foundation.h> | |
| 10 | + | |
| 11 | +@interface HistoryObject : NSObject | |
| 12 | + | |
| 13 | +@property (nonatomic) int step; | |
| 14 | +@property (nonatomic) int missing; | |
| 15 | +@property (nonatomic) int target; | |
| 16 | +@property (nonatomic) float percent; | |
| 17 | +@property (nonatomic) float distance; | |
| 18 | +@property (nonatomic) float calories; | |
| 19 | +@property (nonatomic, strong) NSString * time; | |
| 20 | +@property (nonatomic, strong) NSDate *date; | |
| 21 | + | |
| 22 | +-(id) initWithData : (NSDictionary *) dict; | |
| 23 | + | |
| 24 | +@end |
LifeLog/LifeLog/HistoryObject.m
| 1 | +// | |
| 2 | +// HistoryObject.m | |
| 3 | +// LifeLog | |
| 4 | +// | |
| 5 | +// Created by nvtu on 8/5/17. | |
| 6 | +// Copyright ยฉ 2017 PhongNV. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "HistoryObject.h" | |
| 10 | + | |
| 11 | +@implementation HistoryObject | |
| 12 | + | |
| 13 | +-(id) initWithData : (NSDictionary *) dict { | |
| 14 | + if([dict objectForKey:@"step"] != nil) { | |
| 15 | + self.step = [dict[@"step"] intValue]; | |
| 16 | + } | |
| 17 | + if([dict objectForKey:@"target"] != nil) { | |
| 18 | + self.target = [dict[@"target"] intValue]; | |
| 19 | + } | |
| 20 | + if([dict objectForKey:@"missing"] != nil) { | |
| 21 | + self.missing = [dict[@"missing"] intValue]; | |
| 22 | + } | |
| 23 | + if([dict objectForKey:@"percent"] != nil) { | |
| 24 | + self.percent = [dict[@"percent"] floatValue]; | |
| 25 | + } | |
| 26 | + if([dict objectForKey:@"distance"] != nil) { | |
| 27 | + self.distance = [dict[@"distance"] floatValue]; | |
| 28 | + } | |
| 29 | + if([dict objectForKey:@"kcal"] != nil) { | |
| 30 | + self.calories = [dict[@"kcal"] floatValue]; | |
| 31 | + } | |
| 32 | + if([dict objectForKey:@"time"] != nil) { | |
| 33 | + self.time = dict[@"time"]; | |
| 34 | + } | |
| 35 | + if([dict objectForKey:@"date"] != nil) { | |
| 36 | + NSString *dateString = dict[@"time"]; | |
| 37 | + NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; | |
| 38 | + [dateFormat setDateFormat:@"yyyy-MM-dd"]; | |
| 39 | + self.date = [dateFormat dateFromString:dateString]; | |
| 40 | + } | |
| 41 | + else { | |
| 42 | + self.date = [NSDate date]; | |
| 43 | + } | |
| 44 | + return self; | |
| 45 | +} | |
| 46 | +@end |
LifeLog/LifeLog/HistoryViewController.h
| ... | ... | @@ -11,11 +11,26 @@ |
| 11 | 11 | |
| 12 | 12 | #import "CollectionView.h" |
| 13 | 13 | |
| 14 | -@interface HistoryViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate> | |
| 14 | +#import "Entities.h" | |
| 15 | 15 | |
| 16 | +@interface HistoryViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate> { | |
| 17 | + NSDate * _currentDate; | |
| 18 | + HistoryObject * _currentHistoryObject; | |
| 19 | +} | |
| 20 | + | |
| 16 | 21 | @property (weak, nonatomic) IBOutlet UILabel *lblHeader; |
| 17 | -@property (weak, nonatomic) IBOutlet CollectionView *viewCollectionTime; | |
| 22 | +@property (weak, nonatomic) IBOutlet UILabel *lblCircleStep; | |
| 23 | +@property (weak, nonatomic) IBOutlet UILabel *lblCircleRemain; | |
| 24 | + | |
| 25 | +@property (weak, nonatomic) IBOutlet UILabel *lblStep; | |
| 26 | +@property (weak, nonatomic) IBOutlet UILabel *lblRemaining; | |
| 27 | +@property (weak, nonatomic) IBOutlet UILabel *lblPercent; | |
| 28 | +@property (weak, nonatomic) IBOutlet UILabel *lblCalories; | |
| 29 | +@property (weak, nonatomic) IBOutlet UILabel *lblDistance; | |
| 30 | +@property (weak, nonatomic) IBOutlet UILabel *lblTime; | |
| 31 | + | |
| 18 | 32 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionType; |
| 33 | +@property (weak, nonatomic) IBOutlet CollectionView *viewCollectionMode; | |
| 19 | 34 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionShare; |
| 20 | 35 | |
| 21 | 36 | @property (weak, nonatomic) IBOutlet BarChartView *viewBarChart; |
LifeLog/LifeLog/HistoryViewController.m
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | #import "HistoryViewController.h" |
| 10 | 10 | #import "Utilities.h" |
| 11 | +#import "ServerAPI.h" | |
| 11 | 12 | |
| 12 | 13 | #import "HistoryListTableViewCell.h" |
| 13 | 14 | |
| 14 | 15 | |
| ... | ... | @@ -20,11 +21,16 @@ |
| 20 | 21 | - (void)viewDidLoad { |
| 21 | 22 | [super viewDidLoad]; |
| 22 | 23 | // Do any additional setup after loading the view from its nib. |
| 23 | - self.title = NSLocalizedString(@"lifelog.tapbar.history", nil); | |
| 24 | - self.lblHeader.text = NSLocalizedString(@"lifelog.tapbar.history", nil); | |
| 24 | + self.title = NSLocalizedString(@"lifelog.history.title", nil); | |
| 25 | + self.lblHeader.text = NSLocalizedString(@"lifelog.history.title", nil); | |
| 25 | 26 | |
| 26 | 27 | [self setupView]; |
| 27 | 28 | [self setupChartView]; |
| 29 | + | |
| 30 | + _currentDate = [NSDate date]; | |
| 31 | + | |
| 32 | + [self callRequestToUpdateData]; | |
| 33 | + | |
| 28 | 34 | //register nib for table view |
| 29 | 35 | [self.tableListHistory registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; |
| 30 | 36 | } |
| 31 | 37 | |
| 32 | 38 | |
| 33 | 39 | |
| 34 | 40 | |
| ... | ... | @@ -44,22 +50,40 @@ |
| 44 | 50 | } |
| 45 | 51 | |
| 46 | 52 | - (void)setupView { |
| 47 | - [self.viewCollectionTime setButtonNumber:5]; | |
| 48 | - [self.viewCollectionTime setSpacing:2]; | |
| 49 | - [self.viewCollectionTime setArrayTitle:[NSArray arrayWithObjects:@"1ๆฅ", @"1้ฑ้", @"1ใถๆ", @"3ใถๆ", @"6ใถๆ", nil]]; | |
| 53 | + NSArray *typeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.type.1", nil), NSLocalizedString(@"lifelog.history.type.2", nil), NSLocalizedString(@"lifelog.history.type.3", nil), NSLocalizedString(@"lifelog.history.type.4", nil), NSLocalizedString(@"lifelog.history.type.5", nil), nil]; | |
| 54 | + [self.viewCollectionType setButtonNumber:typeTitle.count]; | |
| 55 | + [self.viewCollectionType setSpacing:2]; | |
| 56 | + [self.viewCollectionType setArrayTitle:typeTitle]; | |
| 57 | + self.viewCollectionType.changeCurrentIndex = ^(int index){ | |
| 58 | + [self callRequestToUpdateData]; | |
| 59 | + }; | |
| 50 | 60 | |
| 51 | - [self.viewCollectionType setButtonNumber:3]; | |
| 52 | - [self.viewCollectionType setSpacing:0]; | |
| 53 | - [self.viewCollectionType setCornerRadius:0]; | |
| 54 | - [self.viewCollectionType setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; | |
| 55 | - [self.viewCollectionType setArrayTitle:[NSArray arrayWithObjects:@"BIKE", @"WALKING", @"RUNNING", nil]]; | |
| 61 | + NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.mode.1", nil), NSLocalizedString(@"lifelog.history.mode.2", nil), NSLocalizedString(@"lifelog.history.mode.3", nil), nil]; | |
| 62 | + [self.viewCollectionMode setButtonNumber:modeTitle.count]; | |
| 63 | + [self.viewCollectionMode setSpacing:0]; | |
| 64 | + [self.viewCollectionMode setCornerRadius:0]; | |
| 65 | + [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; | |
| 66 | + [self.viewCollectionMode setArrayTitle:modeTitle]; | |
| 67 | + self.viewCollectionMode.changeCurrentIndex = ^(int index){ | |
| 68 | + [self callRequestToUpdateData]; | |
| 69 | + }; | |
| 56 | 70 | |
| 57 | - [self.viewCollectionShare setButtonNumber:5]; | |
| 71 | + NSArray *shareTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.share.1", nil), NSLocalizedString(@"lifelog.history.share.2", nil), NSLocalizedString(@"lifelog.history.share.3", nil), NSLocalizedString(@"lifelog.history.share.4", nil), NSLocalizedString(@"lifelog.history.share.5", nil), nil]; | |
| 72 | + [self.viewCollectionShare setButtonNumber:typeTitle.count]; | |
| 58 | 73 | [self.viewCollectionShare setSpacing:3]; |
| 59 | 74 | [self.viewCollectionShare setSelectedIndex:-1]; |
| 60 | - [self.viewCollectionShare setArrayTitle:[NSArray arrayWithObjects:@"facebook", @"twitter", @"line", @"ใกใผใซ", @"ใใฎไป", nil]]; | |
| 75 | + [self.viewCollectionShare setArrayTitle:shareTitle]; | |
| 61 | 76 | } |
| 62 | 77 | |
| 78 | +-(void) updateView { | |
| 79 | + self.lblStep.text = [NSString stringWithFormat:@"%d", _currentHistoryObject.step]; | |
| 80 | + self.lblRemaining.text = [NSString stringWithFormat:@"%d", _currentHistoryObject.missing]; | |
| 81 | + self.lblPercent.text = [NSString stringWithFormat:@"%0.2f", _currentHistoryObject.percent * 100]; | |
| 82 | + self.lblCalories.text = [NSString stringWithFormat:@"%1.0f", _currentHistoryObject.calories]; | |
| 83 | + self.lblDistance.text = [NSString stringWithFormat:@"%0.1f", _currentHistoryObject.distance]; | |
| 84 | + self.lblTime.text = _currentHistoryObject.time; | |
| 85 | +} | |
| 86 | + | |
| 63 | 87 | - (void)setupChartView { |
| 64 | 88 | self.viewBarChart.chartDescription.enabled = NO; |
| 65 | 89 | self.viewBarChart.leftAxis.drawGridLinesEnabled = NO; |
| ... | ... | @@ -110,6 +134,24 @@ |
| 110 | 134 | |
| 111 | 135 | self.viewBarChart.data = data; |
| 112 | 136 | } |
| 137 | +} | |
| 138 | + | |
| 139 | +-(void) callRequestToUpdateData { | |
| 140 | + [[ServerAPI server] requestHistory:[[NSUserDefaults standardUserDefaults] stringForKey:kToken] atDate:_currentDate withType:self.viewCollectionType.getCurrentIndex andMode:self.viewCollectionMode.getCurrentIndex + 1 CompletionHandler:^(HistoryObject *object, NSError *error) { | |
| 141 | + HistoryViewController __weak *weakSelf = self; | |
| 142 | + if(error == nil) { | |
| 143 | + _currentHistoryObject = object; | |
| 144 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 145 | + [self updateView]; | |
| 146 | + }); | |
| 147 | + } | |
| 148 | + else { | |
| 149 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 150 | + NSString *message = [error.userInfo objectForKey:@"message"]; | |
| 151 | + [Utilities showErrorMessage:message withViewController:weakSelf]; | |
| 152 | + }); | |
| 153 | + } | |
| 154 | + }]; | |
| 113 | 155 | } |
| 114 | 156 | |
| 115 | 157 | #pragma mark IBAction |
LifeLog/LifeLog/HistoryViewController.xib
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12118" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | |
| 2 | +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12118" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | |
| 3 | 3 | <device id="retina4_7" orientation="portrait"> |
| 4 | 4 | <adaptation id="fullscreen"/> |
| 5 | 5 | </device> |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | |
| ... | ... | @@ -11,14 +11,22 @@ |
| 11 | 11 | <objects> |
| 12 | 12 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HistoryViewController"> |
| 13 | 13 | <connections> |
| 14 | + <outlet property="lblCalories" destination="dAE-C8-QLr" id="WaS-S3-Qxh"/> | |
| 15 | + <outlet property="lblCircleRemain" destination="Kr7-S0-Fpl" id="UQe-Bt-i0X"/> | |
| 16 | + <outlet property="lblCircleStep" destination="oWg-A8-aCr" id="Q9g-UY-hyv"/> | |
| 17 | + <outlet property="lblDistance" destination="1tR-JC-pyw" id="q4s-Ru-vLO"/> | |
| 14 | 18 | <outlet property="lblHeader" destination="Ht6-rd-JXF" id="SSk-xp-GLP"/> |
| 19 | + <outlet property="lblPercent" destination="8Ru-Jc-Ouv" id="ZHn-Kt-0Qk"/> | |
| 20 | + <outlet property="lblRemaining" destination="1NH-b3-ST8" id="hFc-q9-b0h"/> | |
| 21 | + <outlet property="lblStep" destination="0pf-fX-QXT" id="jK4-9Y-89Q"/> | |
| 22 | + <outlet property="lblTime" destination="PfZ-7x-LAR" id="NQv-fs-rl7"/> | |
| 15 | 23 | <outlet property="scrollView" destination="rey-N3-l8b" id="s3w-fi-n5l"/> |
| 16 | 24 | <outlet property="tableListHistory" destination="FXQ-4O-sRc" id="VNN-sx-9xu"/> |
| 17 | 25 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> |
| 18 | 26 | <outlet property="viewBarChart" destination="VqD-Y3-cYQ" id="RdJ-G5-pPy"/> |
| 27 | + <outlet property="viewCollectionMode" destination="BVv-qD-EHM" id="A6n-32-oxg"/> | |
| 19 | 28 | <outlet property="viewCollectionShare" destination="Iw2-nW-e7g" id="LW3-j0-yEY"/> |
| 20 | - <outlet property="viewCollectionTime" destination="yxY-4d-tB6" id="jp8-TP-N5g"/> | |
| 21 | - <outlet property="viewCollectionType" destination="BVv-qD-EHM" id="0MR-m4-P1Y"/> | |
| 29 | + <outlet property="viewCollectionType" destination="yxY-4d-tB6" id="K1D-Gc-kWV"/> | |
| 22 | 30 | </connections> |
| 23 | 31 | </placeholder> |
| 24 | 32 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> |
| ... | ... | @@ -175,7 +183,7 @@ |
| 175 | 183 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4ix-HE-d9T"> |
| 176 | 184 | <rect key="frame" x="148" y="30" width="219" height="120"/> |
| 177 | 185 | <subviews> |
| 178 | - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="็ฎๆจ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YE6-wh-77T"> | |
| 186 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="็ฎๆจ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YE6-wh-77T" customClass="AutoTransLabel"> | |
| 179 | 187 | <rect key="frame" x="10" y="37.5" width="45" height="15"/> |
| 180 | 188 | <constraints> |
| 181 | 189 | <constraint firstAttribute="width" constant="45" id="6Ce-YE-wbx"/> |
| 182 | 190 | |
| 183 | 191 | |
| 184 | 192 | |
| 185 | 193 | |
| ... | ... | @@ -184,18 +192,27 @@ |
| 184 | 192 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
| 185 | 193 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
| 186 | 194 | <nil key="highlightedColor"/> |
| 195 | + <userDefinedRuntimeAttributes> | |
| 196 | + <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.total"/> | |
| 197 | + </userDefinedRuntimeAttributes> | |
| 187 | 198 | </label> |
| 188 | - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ๆฎๆญฉๆฐ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HOl-Tj-xiT"> | |
| 199 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ๆฎๆญฉๆฐ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HOl-Tj-xiT" customClass="AutoTransLabel"> | |
| 189 | 200 | <rect key="frame" x="10" y="52.5" width="45" height="15"/> |
| 190 | 201 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
| 191 | 202 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
| 192 | 203 | <nil key="highlightedColor"/> |
| 204 | + <userDefinedRuntimeAttributes> | |
| 205 | + <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.remaining"/> | |
| 206 | + </userDefinedRuntimeAttributes> | |
| 193 | 207 | </label> |
| 194 | - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="้ๆ็" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="l0h-qA-2Ai"> | |
| 208 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="้ๆ็" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="l0h-qA-2Ai" customClass="AutoTransLabel"> | |
| 195 | 209 | <rect key="frame" x="10" y="67.5" width="45" height="15"/> |
| 196 | 210 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
| 197 | 211 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
| 198 | 212 | <nil key="highlightedColor"/> |
| 213 | + <userDefinedRuntimeAttributes> | |
| 214 | + <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.percent"/> | |
| 215 | + </userDefinedRuntimeAttributes> | |
| 199 | 216 | </label> |
| 200 | 217 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0pf-fX-QXT"> |
| 201 | 218 | <rect key="frame" x="63" y="37.5" width="118" height="15"/> |
| ... | ... | @@ -252,7 +269,7 @@ |
| 252 | 269 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UwA-5Q-gdv"> |
| 253 | 270 | <rect key="frame" x="0.0" y="0.0" width="111.5" height="35"/> |
| 254 | 271 | <subviews> |
| 255 | - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ๆถ่ฒปใซใญใชใผ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zRU-L6-Ed4"> | |
| 272 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ๆถ่ฒปใซใญใชใผ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zRU-L6-Ed4" customClass="AutoTransLabel"> | |
| 256 | 273 | <rect key="frame" x="0.0" y="0.0" width="111.5" height="18"/> |
| 257 | 274 | <constraints> |
| 258 | 275 | <constraint firstAttribute="height" constant="18" id="Ywp-RA-6am"/> |
| ... | ... | @@ -260,6 +277,9 @@ |
| 260 | 277 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
| 261 | 278 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
| 262 | 279 | <nil key="highlightedColor"/> |
| 280 | + <userDefinedRuntimeAttributes> | |
| 281 | + <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.calories"/> | |
| 282 | + </userDefinedRuntimeAttributes> | |
| 263 | 283 | </label> |
| 264 | 284 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 kcal" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dAE-C8-QLr"> |
| 265 | 285 | <rect key="frame" x="0.0" y="17" width="111.5" height="18"/> |
| ... | ... | @@ -284,7 +304,7 @@ |
| 284 | 304 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVs-KG-fDF"> |
| 285 | 305 | <rect key="frame" x="111.5" y="0.0" width="112" height="35"/> |
| 286 | 306 | <subviews> |
| 287 | - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="่ท้ข" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XGt-pc-sd7"> | |
| 307 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="่ท้ข" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XGt-pc-sd7" customClass="AutoTransLabel"> | |
| 288 | 308 | <rect key="frame" x="0.0" y="0.0" width="112" height="18"/> |
| 289 | 309 | <constraints> |
| 290 | 310 | <constraint firstAttribute="height" constant="18" id="tct-pY-7wo"/> |
| ... | ... | @@ -292,6 +312,9 @@ |
| 292 | 312 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
| 293 | 313 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
| 294 | 314 | <nil key="highlightedColor"/> |
| 315 | + <userDefinedRuntimeAttributes> | |
| 316 | + <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.distance"/> | |
| 317 | + </userDefinedRuntimeAttributes> | |
| 295 | 318 | </label> |
| 296 | 319 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="4.0 KM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1tR-JC-pyw"> |
| 297 | 320 | <rect key="frame" x="0.0" y="17" width="112" height="18"/> |
| ... | ... | @@ -316,7 +339,7 @@ |
| 316 | 339 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="j5h-QD-Igf"> |
| 317 | 340 | <rect key="frame" x="223.5" y="0.0" width="111.5" height="35"/> |
| 318 | 341 | <subviews> |
| 319 | - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ๆ้" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OEO-l8-Ibg"> | |
| 342 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ๆ้" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OEO-l8-Ibg" customClass="AutoTransLabel"> | |
| 320 | 343 | <rect key="frame" x="0.0" y="0.0" width="111.5" height="18"/> |
| 321 | 344 | <constraints> |
| 322 | 345 | <constraint firstAttribute="height" constant="18" id="EVe-qW-qqp"/> |
| ... | ... | @@ -324,6 +347,9 @@ |
| 324 | 347 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
| 325 | 348 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
| 326 | 349 | <nil key="highlightedColor"/> |
| 350 | + <userDefinedRuntimeAttributes> | |
| 351 | + <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.time"/> | |
| 352 | + </userDefinedRuntimeAttributes> | |
| 327 | 353 | </label> |
| 328 | 354 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1:00 ๆ้" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PfZ-7x-LAR"> |
| 329 | 355 | <rect key="frame" x="0.0" y="17" width="111.5" height="18"/> |
LifeLog/LifeLog/Localizable.strings
| ... | ... | @@ -60,4 +60,26 @@ |
| 60 | 60 | "lifelog.today.remaining.other" = "ๆฎๆญฉๆฐ"; |
| 61 | 61 | "lifelog.today.text.percent" = "้ๆ็"; |
| 62 | 62 | "lifelog.today.percent" = "%"; |
| 63 | +// Screen History | |
| 64 | +"lifelog.history.title" = "ๅฑฅๆญด"; | |
| 65 | +"lifelog.history.type.1" = "1ๆฅ"; | |
| 66 | +"lifelog.history.type.2" = "1้ฑ้"; | |
| 67 | +"lifelog.history.type.3" = "1ใถๆ"; | |
| 68 | +"lifelog.history.type.4" = "3ใถๆ"; | |
| 69 | +"lifelog.history.type.5" = "6ใถๆ"; | |
| 70 | +"lifelog.history.mode.1" = "BIKE"; | |
| 71 | +"lifelog.history.mode.2" = "WALKING"; | |
| 72 | +"lifelog.history.mode.3" = "RUNNING"; | |
| 73 | +"lifelog.history.share.1" = "facebook"; | |
| 74 | +"lifelog.history.share.2" = "twitter"; | |
| 75 | +"lifelog.history.share.3" = "line"; | |
| 76 | +"lifelog.history.share.4" = "ใกใผใซ"; | |
| 77 | +"lifelog.history.share.5" = "ใใฎไป"; | |
| 78 | +"lifelog.history.title.total" = "็ฎๆจ"; | |
| 79 | +"lifelog.history.title.remaining" = "ๆฎๆญฉๆฐ"; | |
| 80 | +"lifelog.history.title.percent" = "้ๆ็"; | |
| 81 | +"lifelog.history.title.calories" = "ๆถ่ฒปใซใญใชใผ"; | |
| 82 | +"lifelog.history.title.distance" = "่ท้ข"; | |
| 83 | +"lifelog.history.title.time" = "ๆ้"; | |
| 84 | +"lifelog.history.circle.remaining" = "็ฎๆจใพใงใใจ\n%d stepใงใ"; |
LifeLog/LifeLog/ServerAPI.h
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | #import <Foundation/Foundation.h> |
| 10 | 10 | #import "Entities.h" |
| 11 | + | |
| 11 | 12 | extern NSString *const kServerAddress; |
| 12 | 13 | extern NSString *const kUser; |
| 13 | 14 | extern NSString *const kToken; |
| ... | ... | @@ -20,5 +21,8 @@ |
| 20 | 21 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion; |
| 21 | 22 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion; |
| 22 | 23 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion; |
| 24 | + | |
| 25 | +- (void) requestHistory:(NSString *)token atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, NSError *)) completion; | |
| 26 | + | |
| 23 | 27 | @end |
LifeLog/LifeLog/ServerAPI.m
| ... | ... | @@ -61,7 +61,7 @@ |
| 61 | 61 | // Login |
| 62 | 62 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion |
| 63 | 63 | { |
| 64 | - [self _request:[kServerAddress stringByAppendingFormat: @"login"] method:@"POST" paras:@{@"email":email, @"password": password} completion:^(NSData *data, NSError *error) { | |
| 64 | + [self _request:[kServerAddress stringByAppendingFormat: @"login"] method:@"POST" token:@"" paras:@{@"email":email, @"password": password} completion:^(NSData *data, NSError *error) { | |
| 65 | 65 | |
| 66 | 66 | if (completion == NULL) { |
| 67 | 67 | return ; |
| ... | ... | @@ -116,7 +116,7 @@ |
| 116 | 116 | |
| 117 | 117 | // Register |
| 118 | 118 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion { |
| 119 | - [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" paras:params completion:^(NSData *data, NSError *error) { | |
| 119 | + [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" token:@"" paras:params completion:^(NSData *data, NSError *error) { | |
| 120 | 120 | |
| 121 | 121 | if (completion == NULL) { |
| 122 | 122 | return ; |
| ... | ... | @@ -170,7 +170,7 @@ |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion { |
| 173 | - [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" paras:@{@"email":email} completion:^(NSData *data, NSError *error) { | |
| 173 | + [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" token:@"" paras:@{@"email":email} completion:^(NSData *data, NSError *error) { | |
| 174 | 174 | |
| 175 | 175 | if (completion == NULL) { |
| 176 | 176 | return ; |
| ... | ... | @@ -197,7 +197,7 @@ |
| 197 | 197 | }]; |
| 198 | 198 | } |
| 199 | 199 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion { |
| 200 | - [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) { | |
| 200 | + [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" token:@"" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) { | |
| 201 | 201 | |
| 202 | 202 | if (completion == NULL) { |
| 203 | 203 | return ; |
| ... | ... | @@ -233,7 +233,7 @@ |
| 233 | 233 | else { |
| 234 | 234 | dict = @{@"img": base64Encoded}; |
| 235 | 235 | } |
| 236 | - [self _request:[kServerAddress stringByAppendingFormat: @"upload-image"] method:@"POST" paras:dict completion:^(NSData *data, NSError *error) { | |
| 236 | + [self _request:[kServerAddress stringByAppendingFormat: @"upload-image"] method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { | |
| 237 | 237 | |
| 238 | 238 | if (completion == NULL) { |
| 239 | 239 | return ; |
| ... | ... | @@ -252,6 +252,58 @@ |
| 252 | 252 | }]; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | +-(NSString *) convertIntToString : (int) type { | |
| 256 | + switch (type) { | |
| 257 | + case 1: | |
| 258 | + return @"week"; | |
| 259 | + break; | |
| 260 | + case 2: | |
| 261 | + return @"oneMonth"; | |
| 262 | + break; | |
| 263 | + case 3: | |
| 264 | + return @"threeMonth"; | |
| 265 | + break; | |
| 266 | + case 4: | |
| 267 | + return @"sixMonth"; | |
| 268 | + break; | |
| 269 | + default: | |
| 270 | + return @"today"; | |
| 271 | + break; | |
| 272 | + } | |
| 273 | +} | |
| 274 | + | |
| 275 | +#pragma mark - History Screen Function | |
| 276 | +- (void) requestHistory:(NSString *)token atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, NSError *)) completion { | |
| 277 | + NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/%@/%d", [self convertIntToString:type], mode]; | |
| 278 | + NSLog(@"requestHistory link %@", url); | |
| 279 | + [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | |
| 280 | + | |
| 281 | + if (completion == NULL) { | |
| 282 | + return ; | |
| 283 | + } | |
| 284 | + | |
| 285 | + if (error == nil) | |
| 286 | + { | |
| 287 | + NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | |
| 288 | + NSLog(@"%@", dataResult); | |
| 289 | + int status = [dataResult[@"status"] intValue]; | |
| 290 | + if (status == 1) { // status = 1 success | |
| 291 | + HistoryObject * object = [[HistoryObject alloc] initWithData:dataResult[@"result"]]; | |
| 292 | + completion(object, nil); | |
| 293 | + } | |
| 294 | + else { | |
| 295 | + NSString *message = dataResult[@"message"]; | |
| 296 | + NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | |
| 297 | + completion(nil, errorObject); | |
| 298 | + } | |
| 299 | + } | |
| 300 | + else | |
| 301 | + { | |
| 302 | + completion(nil, error); | |
| 303 | + } | |
| 304 | + }]; | |
| 305 | +} | |
| 306 | + | |
| 255 | 307 | #pragma mark - Private Function |
| 256 | 308 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary |
| 257 | 309 | { |
| 258 | 310 | |
| ... | ... | @@ -267,12 +319,15 @@ |
| 267 | 319 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; |
| 268 | 320 | } |
| 269 | 321 | |
| 270 | -- (void) _request:(NSString *)address method:(NSString *)method paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion | |
| 322 | +- (void) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion | |
| 271 | 323 | { |
| 272 | 324 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; |
| 273 | 325 | request.HTTPMethod = method; |
| 274 | 326 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; |
| 275 | 327 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; |
| 328 | + if(token != nil && ![token isEqual: @""]) { | |
| 329 | + [request setValue: token forHTTPHeaderField: @"token"]; | |
| 330 | + } | |
| 276 | 331 | [request setTimeoutInterval:self.timeOutInterval]; |
| 277 | 332 | |
| 278 | 333 | if (paras != nil) |