Commit c4525f8715e07da1592b4c4d3b74f68869d8c367

Authored by nvtu11790@gmail.com
1 parent b94abc619f

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
... ... @@ -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
  1 +{
  2 + "info" : {
  3 + "version" : 1,
  4 + "author" : "xcode"
  5 + }
  6 +}
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
... ... @@ -9,6 +9,7 @@
9 9 #ifndef Entities_h
10 10 #define Entities_h
11 11  
  12 +#import "HistoryObject.h"
12 13 #import "User.h"
13 14  
14 15 #endif /* 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" t