Compare View

switch
from
...
to
 
Commits (3)

Changes

Showing 22 changed files Inline Diff

LifeLog/LifeLog/Assets.xcassets/History/arrow_decre.imageset/Contents.json
File was created 1 {
2 "images" : [
3 {
4 "idiom" : "universal",
5 "scale" : "1x"
6 },
7 {
8 "idiom" : "universal",
9 "filename" : "arrow_decre.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_decre.imageset/arrow_decre.png

1.33 KB

LifeLog/LifeLog/Assets.xcassets/History/arrow_incre.imageset/Contents.json
File was created 1 {
2 "images" : [
3 {
4 "idiom" : "universal",
5 "scale" : "1x"
6 },
7 {
8 "idiom" : "universal",
9 "filename" : "arrow_incre.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_incre.imageset/arrow_incre.png

1.49 KB

LifeLog/LifeLog/BaseTableViewController.h
1 // 1 //
2 // BaseTableViewController.h 2 // BaseTableViewController.h
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/11/17. 5 // Created by nvtu on 8/11/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
10 10
11 @interface BaseTableViewController : UIViewController<UITableViewDelegate, UITableViewDataSource> { 11 @interface BaseTableViewController : UIViewController<UITableViewDelegate, UITableViewDataSource> {
12 NSMutableArray * _curDataList; 12 NSMutableArray * _curDataList;
13 BOOL _firstTime; 13 BOOL _firstTime;
14 BOOL _isLoading; 14 BOOL _isLoading;
15 BOOL _isEndOfResult; 15 BOOL _isEndOfResult;
16 BOOL _isDisableLoadMore;
16 int _curPage; 17 int _curPage;
17 } 18 }
18 19
19 @property (weak, nonatomic) IBOutlet UITableView *tableBase; 20 @property (weak, nonatomic) IBOutlet UITableView *tableBase;
20 @property (strong, nonatomic) UIRefreshControl *refreshControl; 21 @property (strong, nonatomic) UIRefreshControl *refreshControl;
21 22
22 -(void) callRequestToUpdateData; 23 -(void) callRequestToUpdateData;
23 -(void) updateTableData : (NSArray *) array error: (NSError *) error; 24 -(void) updateTableData : (NSArray *) array error: (NSError *) error;
24 -(void) resetData; 25 -(void) resetData;
25 @end 26 @end
26 27
LifeLog/LifeLog/BaseTableViewController.m
1 // 1 //
2 // BaseTableViewController.m 2 // BaseTableViewController.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/11/17. 5 // Created by nvtu on 8/11/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "BaseTableViewController.h" 9 #import "BaseTableViewController.h"
10 #import "Utilities.h" 10 #import "Utilities.h"
11 11
12 @interface BaseTableViewController () 12 @interface BaseTableViewController ()
13 13
14 @end 14 @end
15 15
16 @implementation BaseTableViewController 16 @implementation BaseTableViewController
17 17
18 - (void)viewDidLoad { 18 - (void)viewDidLoad {
19 [super viewDidLoad]; 19 [super viewDidLoad];
20 _firstTime = false; 20 _firstTime = false;
21 _curPage = 1; 21 _curPage = 1;
22 _isEndOfResult = false; 22 _isEndOfResult = false;
23 _isDisableLoadMore = false;
23 _curDataList = [[NSMutableArray alloc] init]; 24 _curDataList = [[NSMutableArray alloc] init];
24 self.refreshControl = [[UIRefreshControl alloc] init]; 25 self.refreshControl = [[UIRefreshControl alloc] init];
25 [self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged]; 26 [self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];
26 [self.tableBase addSubview:self.refreshControl]; 27 [self.tableBase addSubview:self.refreshControl];
27 // Do any additional setup after loading the view. 28 // Do any additional setup after loading the view.
28 } 29 }
29 30
30 - (void)didReceiveMemoryWarning { 31 - (void)didReceiveMemoryWarning {
31 [super didReceiveMemoryWarning]; 32 [super didReceiveMemoryWarning];
32 // Dispose of any resources that can be recreated. 33 // Dispose of any resources that can be recreated.
33 } 34 }
34 35
35 -(void) callRequestToUpdateData { 36 -(void) callRequestToUpdateData {
36 _isLoading = true; 37 _isLoading = true;
37 } 38 }
38 39
39 -(void) resetData { 40 -(void) resetData {
40 _isLoading = false; 41 _isLoading = false;
41 _isEndOfResult = false; 42 _isEndOfResult = false;
42 _firstTime = false; 43 _firstTime = false;
43 _curPage = 1; 44 _curPage = 1;
44 [_curDataList removeAllObjects]; 45 [_curDataList removeAllObjects];
45 [self.tableBase reloadData]; 46 [self.tableBase reloadData];
46 [self callRequestToUpdateData]; 47 [self callRequestToUpdateData];
47 } 48 }
48 49
49 -(void) refreshTable { 50 -(void) refreshTable {
50 [self resetData]; 51 [self resetData];
51 } 52 }
52 53
53 -(void) updateTableData : (NSArray *) array error: (NSError *) error { 54 -(void) updateTableData : (NSArray *) array error: (NSError *) error {
54 BaseTableViewController __weak *weakSelf = self; 55 BaseTableViewController __weak *weakSelf = self;
55 _isLoading = false; 56 _isLoading = false;
56 _firstTime = true; 57 _firstTime = true;
57 if(self.refreshControl != nil) { 58 if(self.refreshControl != nil) {
58 dispatch_async(dispatch_get_main_queue(), ^{ 59 dispatch_async(dispatch_get_main_queue(), ^{
59 [self.refreshControl endRefreshing]; 60 [self.refreshControl endRefreshing];
60 }); 61 });
61 } 62 }
62 if(error == nil) { 63 if(error == nil) {
63 if(array.count != 0) { 64 if(array.count != 0) {
64 if(_curPage == 1) { 65 if(_curPage == 1) {
65 [_curDataList removeAllObjects]; 66 [_curDataList removeAllObjects];
66 } 67 }
67 [_curDataList addObjectsFromArray:array]; 68 [_curDataList addObjectsFromArray:array];
68 dispatch_async(dispatch_get_main_queue(), ^{ 69 dispatch_async(dispatch_get_main_queue(), ^{
69 [weakSelf.tableBase reloadData]; 70 [weakSelf.tableBase reloadData];
70 }); 71 });
71 } 72 }
72 else { 73 else {
73 if(_curPage != 1) { 74 if(_curPage != 1) {
74 _isEndOfResult = true; 75 _isEndOfResult = true;
75 _curPage -= 1; 76 _curPage -= 1;
76 } 77 }
77 else { 78 else {
78 dispatch_async(dispatch_get_main_queue(), ^{ 79 dispatch_async(dispatch_get_main_queue(), ^{
79 [weakSelf.tableBase reloadData]; 80 [weakSelf.tableBase reloadData];
80 }); 81 });
81 } 82 }
82 } 83 }
83 } 84 }
84 else { 85 else {
85 _curPage = MAX(1, _curPage - 1); 86 _curPage = MAX(1, _curPage - 1);
86 dispatch_async(dispatch_get_main_queue(), ^{ 87 dispatch_async(dispatch_get_main_queue(), ^{
87 NSString *message = [error.userInfo objectForKey:@"message"]; 88 NSString *message = [error.userInfo objectForKey:@"message"];
88 [Utilities showErrorMessage:message withViewController:weakSelf]; 89 [Utilities showErrorMessage:message withViewController:weakSelf];
89 }); 90 });
90 } 91 }
91 } 92 }
92 93
93 #pragma mark UITableView Delegate 94 #pragma mark UITableView Delegate
94 - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { 95 - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
95 if((_curDataList == nil || _curDataList.count == 0) && _firstTime) { 96 if((_curDataList == nil || _curDataList.count == 0) && _firstTime) {
96 UILabel * noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)]; 97 UILabel * noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)];
97 noDataLabel.text = @"No data available"; 98 noDataLabel.text = @"No data available";
98 noDataLabel.backgroundColor = [UIColor clearColor]; 99 noDataLabel.backgroundColor = [UIColor clearColor];
99 noDataLabel.textColor = [UIColor whiteColor]; 100 noDataLabel.textColor = [UIColor whiteColor];
100 noDataLabel.textAlignment = NSTextAlignmentCenter; 101 noDataLabel.textAlignment = NSTextAlignmentCenter;
101 tableView.backgroundView = noDataLabel; 102 tableView.backgroundView = noDataLabel;
102 tableView.backgroundView.layer.zPosition -= 1; 103 tableView.backgroundView.layer.zPosition -= 1;
103 return 0; 104 return 0;
104 } 105 }
105 tableView.backgroundView = nil; 106 tableView.backgroundView = nil;
106 return 1; 107 return 1;
107 } 108 }
108 109
109 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 110 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
110 return _curDataList.count; 111 return _curDataList.count;
111 } 112 }
112 113
113 - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 114 - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
114 NSInteger lastRowIndex = [tableView numberOfRowsInSection:0] - 1; 115 NSInteger lastRowIndex = [tableView numberOfRowsInSection:0] - 1;
115 if (indexPath.row == lastRowIndex) { 116 if (indexPath.row == lastRowIndex) {
116 // This is the last cell 117 // This is the last cell
117 if(!_isLoading) { 118 if(!_isLoading && !_isDisableLoadMore) {
118 _curPage += 1; 119 _curPage += 1;
119 [self callRequestToUpdateData]; 120 [self callRequestToUpdateData];
120 } 121 }
121 } 122 }
122 } 123 }
123 @end 124 @end
124 125
LifeLog/LifeLog/GroupDetailViewController.m
1 // 1 //
2 // GroupDetailViewController.m 2 // GroupDetailViewController.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/13/17. 5 // Created by nvtu on 8/13/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "GroupDetailViewController.h" 9 #import "GroupDetailViewController.h"
10 #import <SDWebImage/UIImageView+WebCache.h> 10 #import <SDWebImage/UIImageView+WebCache.h>
11 11
12 #import "Utilities.h" 12 #import "Utilities.h"
13 #import "ServerAPI.h" 13 #import "ServerAPI.h"
14 #import "SNSRecentTopicTableViewCell.h" 14 #import "SNSRecentTopicTableViewCell.h"
15 15
16 @interface GroupDetailViewController () 16 @interface GroupDetailViewController ()
17 17
18 @end 18 @end
19 19
20 @implementation GroupDetailViewController 20 @implementation GroupDetailViewController
21 21
22 - (void)viewDidLoad { 22 - (void)viewDidLoad {
23 [super viewDidLoad]; 23 [super viewDidLoad];
24 isMemberList = false; 24 isMemberList = false;
25 //register nib for table view 25 //register nib for table view
26 [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; 26 [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"];
27 if(_curGroup != nil) { 27 if(_curGroup != nil) {
28 [self requestGroupDetail]; 28 [self requestGroupDetail];
29 } 29 }
30 // Do any additional setup after loading the view from its nib. 30 // Do any additional setup after loading the view from its nib.
31 } 31 }
32 32
33 - (void)didReceiveMemoryWarning { 33 - (void)didReceiveMemoryWarning {
34 [super didReceiveMemoryWarning]; 34 [super didReceiveMemoryWarning];
35 // Dispose of any resources that can be recreated. 35 // Dispose of any resources that can be recreated.
36 } 36 }
37 37
38 - (void) setGroup : (GroupObject *) object { 38 - (void) setGroup : (GroupObject *) object {
39 _curGroup = object; 39 _curGroup = object;
40 } 40 }
41 41
42 - (void)setupView { 42 - (void)setupView {
43 if(_curGroup != nil) { 43 if(_curGroup != nil) {
44 if(self.imgAva != nil && _curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) { 44 if(self.imgAva != nil && _curGroup.avatar && ![_curGroup.avatar isKindOfClass:[NSNull class]]) {
45 [self.imgAva sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:_curGroup.avatar]]]; 45 [self.imgAva sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:_curGroup.avatar]]];
46 } 46 }
47 if(self.lblGrpName != nil) { 47 if(self.lblGrpName != nil) {
48 [self.lblGrpName setText:_curGroup.name]; 48 [self.lblGrpName setText:_curGroup.name];
49 } 49 }
50 if(self.btJoinGrp != nil) { 50 if(self.btJoinGrp != nil) {
51 [self.btJoinGrp setHidden:false]; 51 [self.btJoinGrp setHidden:false];
52 } 52 }
53 NSString *mode = @""; 53 NSString *mode = @"";
54 NSString *goalText = [NSString stringWithFormat:@"%@\n", _curGroup.goal]; 54 NSString *goalText = [NSString stringWithFormat:@"%@\n", _curGroup.goal];
55 if(_curGroup.runMode || _curGroup.walkMode || _curGroup.bikeMode) { 55 if(_curGroup.runMode || _curGroup.walkMode || _curGroup.bikeMode) {
56 goalText = [goalText stringByAppendingString:@"1日 目標 "]; 56 goalText = [goalText stringByAppendingString:@"1日 目標 "];
57 } 57 }
58 if(_curGroup.runMode) { 58 if(_curGroup.runMode) {
59 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.running", nil)]; 59 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.running", nil)];
60 mode = [mode stringByAppendingString:@"\n"]; 60 mode = [mode stringByAppendingString:@"\n"];
61 goalText = [goalText stringByAppendingFormat:@"RUN %dm, ", _curGroup.runGoal]; 61 goalText = [goalText stringByAppendingFormat:@"RUN %dm, ", _curGroup.runGoal];
62 } 62 }
63 if(_curGroup.walkMode) { 63 if(_curGroup.walkMode) {
64 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.walking", nil)]; 64 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.walking", nil)];
65 mode = [mode stringByAppendingString:@"\n"]; 65 mode = [mode stringByAppendingString:@"\n"];
66 goalText = [goalText stringByAppendingFormat:@"WALK %dm, ", _curGroup.walkGoal]; 66 goalText = [goalText stringByAppendingFormat:@"WALK %dm, ", _curGroup.walkGoal];
67 } 67 }
68 if(_curGroup.bikeMode) { 68 if(_curGroup.bikeMode) {
69 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.bike", nil)]; 69 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.bike", nil)];
70 mode = [mode stringByAppendingString:@"\n"]; 70 mode = [mode stringByAppendingString:@"\n"];
71 goalText = [goalText stringByAppendingFormat:@"BIKE %dm, ", _curGroup.bikeGoal]; 71 goalText = [goalText stringByAppendingFormat:@"BIKE %dm, ", _curGroup.bikeGoal];
72 } 72 }
73 if(_curGroup.stepMode) { 73 if(_curGroup.stepMode) {
74 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.step", nil)]; 74 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.step", nil)];
75 mode = [mode stringByAppendingString:@"\n"]; 75 mode = [mode stringByAppendingString:@"\n"];
76 } 76 }
77 if(_curGroup.beginMode) { 77 if(_curGroup.beginMode) {
78 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.begin", nil)]; 78 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.begin", nil)];
79 mode = [mode stringByAppendingString:@"\n"]; 79 mode = [mode stringByAppendingString:@"\n"];
80 } 80 }
81 if(_curGroup.gymMode) { 81 if(_curGroup.gymMode) {
82 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.gym", nil)]; 82 mode = [mode stringByAppendingString:NSLocalizedString(@"lifelog.grDetail.mode.gym", nil)];
83 mode = [mode stringByAppendingString:@"\n"]; 83 mode = [mode stringByAppendingString:@"\n"];
84 } 84 }
85 NSRange range = [mode rangeOfString:@"\n" options:NSBackwardsSearch]; 85 NSRange range = [mode rangeOfString:@"\n" options:NSBackwardsSearch];
86 if(range.length > 0) { 86 if(range.length > 0) {
87 mode = [mode stringByReplacingOccurrencesOfString:@"\n" withString:@"" options:NSBackwardsSearch range:range]; 87 mode = [mode stringByReplacingOccurrencesOfString:@"\n" withString:@"" options:NSBackwardsSearch range:range];
88 } 88 }
89 range = [goalText rangeOfString:@", " options:NSBackwardsSearch]; 89 range = [goalText rangeOfString:@", " options:NSBackwardsSearch];
90 if(range.length > 0) { 90 if(range.length > 0) {
91 goalText = [goalText stringByReplacingOccurrencesOfString:@", " withString:@"" options:NSBackwardsSearch range:range]; 91 goalText = [goalText stringByReplacingOccurrencesOfString:@", " withString:@"" options:NSBackwardsSearch range:range];
92 } 92 }
93 [self.lbbGrpActiveMode setText:mode]; 93 [self.lbbGrpActiveMode setText:mode];
94 [self.lblGrpGoal setText:goalText]; 94 [self.lblGrpGoal setText:goalText];
95 } 95 }
96 } 96 }
97 97
98 - (void) requestGroupDetail { 98 - (void) requestGroupDetail {
99 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; 99 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
100 MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; 100 MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
101 [[ServerAPI server] getGroupDetail:token withGroupID:_curGroup.groupID CompletionHandler:^(GroupObject *object, NSError *error) { 101 [[ServerAPI server] getGroupDetail:token withGroupID:_curGroup.groupID CompletionHandler:^(GroupObject *object, NSError *error) {
102 GroupDetailViewController __weak *weakSelf = self; 102 GroupDetailViewController __weak *weakSelf = self;
103 [_curGroup updateDate:object]; 103 [_curGroup updateDate:object];
104 dispatch_async(dispatch_get_main_queue(), ^{ 104 dispatch_async(dispatch_get_main_queue(), ^{
105 [hudView hideAnimated:true]; 105 [hudView hideAnimated:true];
106 [weakSelf setupView]; 106 [weakSelf setupView];
107 [weakSelf callRequestToUpdateData]; 107 [weakSelf callRequestToUpdateData];
108 }); 108 });
109 }]; 109 }];
110 } 110 }
111 111
112 #pragma mark IBAction 112 #pragma mark IBAction
113 113
114 - (IBAction)clickBack:(id)sender { 114 - (IBAction)clickBack:(id)sender {
115 [self.navigationController popViewControllerAnimated:true]; 115 [self.navigationController popViewControllerAnimated:true];
116 } 116 }
117 117
118 - (IBAction)clickSwitch:(AutoTransButton *)sender { 118 - (IBAction)clickSwitch:(AutoTransButton *)sender {
119 isMemberList = !isMemberList; 119 isMemberList = !isMemberList;
120 if(isMemberList) { 120 if(isMemberList) {
121 [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; 121 [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal];
122 } 122 }
123 else { 123 else {
124 [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; 124 [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal];
125 } 125 }
126 [sender setUserInteractionEnabled:false]; 126 [sender setUserInteractionEnabled:false];
127 [self resetData]; 127 [self resetData];
128 } 128 }
129 129
130 - (IBAction)clickJoin:(AutoTransButton *)sender { 130 - (IBAction)clickJoin:(AutoTransButton *)sender {
131 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; 131 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
132 MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; 132 MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
133 [[ServerAPI server] requestJoinGroup:token groupID:_curGroup.groupID CompletionHandler:^(NSError *error){ 133 [[ServerAPI server] requestJoinGroup:token groupID:_curGroup.groupID CompletionHandler:^(NSError *error){
134 GroupDetailViewController __weak *weakSelf = self; 134 GroupDetailViewController __weak *weakSelf = self;
135 dispatch_async(dispatch_get_main_queue(), ^{ 135 dispatch_async(dispatch_get_main_queue(), ^{
136 [hudView hideAnimated:true]; 136 [hudView hideAnimated:true];
137 if(error == nil) { 137 if(error == nil) {
138 _curGroup.isJoin = true; 138 _curGroup.isJoin = true;
139 [weakSelf.btJoinGrp setHidden:_curGroup.isJoin]; 139 [weakSelf.btJoinGrp setHidden:_curGroup.isJoin];
140 [Utilities showMessage:@"Join successfully" withViewController:weakSelf]; 140 [Utilities showMessage:@"Join successfully" withViewController:weakSelf];
141 } 141 }
142 }); 142 });
143 }]; 143 }];
144 144
145 } 145 }
146 146
147 147
148 148
149 #pragma mark UITableView Delegate 149 #pragma mark UITableView Delegate
150 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 150 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
151 SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; 151 SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"];
152 if(isMemberList) { 152 if(isMemberList) {
153 MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; 153 MemberObject *object = [_curDataList objectAtIndex:indexPath.row];
154 [cell setMemberData:object]; 154 [cell setMemberData:object];
155 }
156 else {
157 TweetObject *object = [_curDataList objectAtIndex:indexPath.row];
158 [cell setTweetsData:object];
159 }
160
161 return cell;
162 }
163
164 #pragma mark Private Function
165
166 -(void) callRequestToUpdateData { 155 }
167 [super callRequestToUpdateData]; 156 else {
168 157 TweetObject *object = [_curDataList objectAtIndex:indexPath.row];
169 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; 158 [cell setTweetsData:object];
170 MBProgressHUD *hudView = nil;
171 if(_curPage == 1 && !self.refreshControl.isRefreshing) {
172 hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
173 }
174 if(isMemberList) {
175 [[ServerAPI server] requestMemberList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){
176 dispatch_async(dispatch_get_main_queue(), ^{
177 if(hudView != nil) {
178 [hudView hideAnimated:true];
179 }
180 });
181 GroupDetailViewController __weak *weakSelf = self; 159 }
182 [weakSelf updateTableData:array error:error]; 160
183 [weakSelf.btSwitch setUserInteractionEnabled:true]; 161 return cell;
184 }]; 162 }
185 } 163
186 else { 164 #pragma mark Private Function
187 [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ 165
188 dispatch_async(dispatch_get_main_queue(), ^{ 166 -(void) callRequestToUpdateData {
189 if(hudView != nil) { 167 [super callRequestToUpdateData];
190 [hudView hideAnimated:true]; 168
191 } 169 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
192 }); 170 MBProgressHUD *hudView = nil;
193 GroupDetailViewController __weak *weakSelf = self; 171 if(_curPage == 1 && !self.refreshControl.isRefreshing) {
194 [weakSelf updateTableData:array error:error]; 172 hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
195 [weakSelf.btSwitch setUserInteractionEnabled:true]; 173 }
196 }]; 174 if(isMemberList) {
197 } 175 [[ServerAPI server] requestMemberList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){
198 } 176 dispatch_async(dispatch_get_main_queue(), ^{
199 177 if(hudView != nil) {
200 @end 178 [hudView hideAnimated:true];
201 179 }
LifeLog/LifeLog/HistoryListTableViewCell.h
1 // 1 //
2 // HistoryListTableViewCell.h 2 // HistoryListTableViewCell.h
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/3/17. 5 // Created by nvtu on 8/3/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
10 10
11 @interface HistoryListTableViewCell : UITableViewCell 11 @interface HistoryListTableViewCell : UITableViewCell
12 12
13 @property (weak, nonatomic) IBOutlet UIImageView *imgArrow;
14
13 @property (weak, nonatomic) IBOutlet UILabel *lblTitle; 15 @property (weak, nonatomic) IBOutlet UILabel *lblTitle;
14 @property (weak, nonatomic) IBOutlet UILabel *lblStep; 16 @property (weak, nonatomic) IBOutlet UILabel *lblStep;
17 @property (weak, nonatomic) IBOutlet UILabel *lblDiff;
15 @property (weak, nonatomic) IBOutlet UILabel *lblDistance; 18 @property (weak, nonatomic) IBOutlet UILabel *lblDistance;
16 @property (weak, nonatomic) IBOutlet UILabel *lblPower; 19 @property (weak, nonatomic) IBOutlet UILabel *lblPower;
17 @property (weak, nonatomic) IBOutlet UILabel *lblDuration; 20 @property (weak, nonatomic) IBOutlet UILabel *lblDuration;
18 21
19 @end 22 @end
20 23
LifeLog/LifeLog/HistoryListTableViewCell.xib
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
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"> 2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait"> 3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/> 4 <adaptation id="fullscreen"/>
5 </device> 5 </device>
6 <dependencies> 6 <dependencies>
7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/> 7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
8 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> 8 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9 </dependencies> 9 </dependencies>
10 <objects> 10 <objects>
11 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> 11 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
12 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> 12 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
13 <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="HistoryListCell" rowHeight="100" id="KGk-i7-Jjw" customClass="HistoryListTableViewCell"> 13 <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="HistoryListCell" rowHeight="100" id="KGk-i7-Jjw" customClass="HistoryListTableViewCell">
14 <rect key="frame" x="0.0" y="0.0" width="320" height="188"/> 14 <rect key="frame" x="0.0" y="0.0" width="320" height="188"/>
15 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> 15 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
16 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM"> 16 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
17 <rect key="frame" x="0.0" y="0.0" width="320" height="188"/> 17 <rect key="frame" x="0.0" y="0.0" width="320" height="188"/>
18 <autoresizingMask key="autoresizingMask"/> 18 <autoresizingMask key="autoresizingMask"/>
19 <subviews> 19 <subviews>
20 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="l97-iI-4Nl"> 20 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="l97-iI-4Nl">
21 <rect key="frame" x="0.0" y="0.0" width="320" height="35"/> 21 <rect key="frame" x="0.0" y="0.0" width="320" height="35"/>
22 <subviews> 22 <subviews>
23 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1日(月 )" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zW0-JI-PIE"> 23 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1日(月 )" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zW0-JI-PIE">
24 <rect key="frame" x="4" y="0.0" width="80" height="30"/> 24 <rect key="frame" x="4" y="0.0" width="80" height="30"/>
25 <constraints> 25 <constraints>
26 <constraint firstAttribute="width" constant="80" id="2SR-JF-W5T"/> 26 <constraint firstAttribute="width" constant="80" id="2SR-JF-W5T"/>
27 </constraints> 27 </constraints>
28 <fontDescription key="fontDescription" type="system" pointSize="13"/> 28 <fontDescription key="fontDescription" type="system" pointSize="13"/>
29 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 29 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
30 <nil key="highlightedColor"/> 30 <nil key="highlightedColor"/>
31 </label> 31 </label>
32 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qgK-8d-giH"> 32 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qgK-8d-giH">
33 <rect key="frame" x="240" y="0.0" width="80" height="30"/> 33 <rect key="frame" x="240" y="0.0" width="80" height="30"/>
34 <constraints> 34 <constraints>
35 <constraint firstAttribute="width" constant="80" id="efJ-dz-Eyh"/> 35 <constraint firstAttribute="width" constant="80" id="efJ-dz-Eyh"/>
36 </constraints> 36 </constraints>
37 <fontDescription key="fontDescription" type="system" pointSize="13"/> 37 <fontDescription key="fontDescription" type="system" pointSize="13"/>
38 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 38 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
39 <nil key="highlightedColor"/> 39 <nil key="highlightedColor"/>
40 </label> 40 </label>
41 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 step" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Eop-bg-Dy9"> 41 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 step" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Eop-bg-Dy9">
42 <rect key="frame" x="84" y="0.0" width="156" height="30"/> 42 <rect key="frame" x="84" y="0.0" width="156" height="30"/>
43 <fontDescription key="fontDescription" type="system" pointSize="13"/> 43 <fontDescription key="fontDescription" type="system" pointSize="13"/>
44 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 44 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
45 <nil key="highlightedColor"/> 45 <nil key="highlightedColor"/>
46 </label> 46 </label>
47 <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="arrow_incre" translatesAutoresizingMaskIntoConstraints="NO" id="uC9-bK-F7u">
48 <rect key="frame" x="229" y="2" width="21" height="25"/>
49 <constraints>
50 <constraint firstAttribute="width" constant="21" id="Mml-ka-nwr"/>
51 <constraint firstAttribute="height" constant="25" id="OUH-L1-Don"/>
52 </constraints>
53 </imageView>
47 </subviews> 54 </subviews>
48 <color key="backgroundColor" red="0.36078431372549019" green="0.36078431372549019" blue="0.36078431372549019" alpha="1" colorSpace="calibratedRGB"/> 55 <color key="backgroundColor" red="0.36078431372549019" green="0.36078431372549019" blue="0.36078431372549019" alpha="1" colorSpace="calibratedRGB"/>
49 <constraints> 56 <constraints>
50 <constraint firstAttribute="trailing" secondItem="qgK-8d-giH" secondAttribute="trailing" id="4eG-yY-bgS"/> 57 <constraint firstAttribute="trailing" secondItem="qgK-8d-giH" secondAttribute="trailing" id="4eG-yY-bgS"/>
51 <constraint firstItem="qgK-8d-giH" firstAttribute="top" secondItem="l97-iI-4Nl" secondAttribute="top" id="8YS-4x-HVg"/> 58 <constraint firstItem="qgK-8d-giH" firstAttribute="top" secondItem="l97-iI-4Nl" secondAttribute="top" id="8YS-4x-HVg"/>
52 <constraint firstAttribute="height" constant="35" id="R67-hu-UQW"/> 59 <constraint firstAttribute="height" constant="35" id="R67-hu-UQW"/>
53 <constraint firstItem="Eop-bg-Dy9" firstAttribute="leading" secondItem="zW0-JI-PIE" secondAttribute="trailing" id="Rh3-lL-CfE"/> 60 <constraint firstItem="Eop-bg-Dy9" firstAttribute="leading" secondItem="zW0-JI-PIE" secondAttribute="trailing" id="Rh3-lL-CfE"/>
54 <constraint firstAttribute="bottom" secondItem="zW0-JI-PIE" secondAttribute="bottom" constant="5" id="W55-gD-NIx"/> 61 <constraint firstAttribute="bottom" secondItem="zW0-JI-PIE" secondAttribute="bottom" constant="5" id="W55-gD-NIx"/>
55 <constraint firstAttribute="bottom" secondItem="Eop-bg-Dy9" secondAttribute="bottom" constant="5" id="Wor-Tc-WPf"/> 62 <constraint firstAttribute="bottom" secondItem="Eop-bg-Dy9" secondAttribute="bottom" constant="5" id="Wor-Tc-WPf"/>
56 <constraint firstItem="zW0-JI-PIE" firstAttribute="leading" secondItem="l97-iI-4Nl" secondAttribute="leading" constant="4" id="ZBL-QQ-0jD"/> 63 <constraint firstItem="zW0-JI-PIE" firstAttribute="leading" secondItem="l97-iI-4Nl" secondAttribute="leading" constant="4" id="ZBL-QQ-0jD"/>
57 <constraint firstAttribute="bottom" secondItem="qgK-8d-giH" secondAttribute="bottom" constant="5" id="cyO-Tr-6Md"/> 64 <constraint firstAttribute="bottom" secondItem="qgK-8d-giH" secondAttribute="bottom" constant="5" id="cyO-Tr-6Md"/>
65 <constraint firstItem="qgK-8d-giH" firstAttribute="leading" secondItem="uC9-bK-F7u" secondAttribute="trailing" constant="-10" id="e8q-Pv-h1j"/>
58 <constraint firstItem="zW0-JI-PIE" firstAttribute="top" secondItem="l97-iI-4Nl" secondAttribute="top" id="iDg-dJ-y0S"/> 66 <constraint firstItem="zW0-JI-PIE" firstAttribute="top" secondItem="l97-iI-4Nl" secondAttribute="top" id="iDg-dJ-y0S"/>
59 <constraint firstItem="qgK-8d-giH" firstAttribute="leading" secondItem="Eop-bg-Dy9" secondAttribute="trailing" id="vhm-kx-gmg"/> 67 <constraint firstItem="qgK-8d-giH" firstAttribute="leading" secondItem="Eop-bg-Dy9" secondAttribute="trailing" id="vhm-kx-gmg"/>
60 <constraint firstItem="Eop-bg-Dy9" firstAttribute="top" secondItem="l97-iI-4Nl" secondAttribute="top" id="xli-4P-Kun"/> 68 <constraint firstItem="Eop-bg-Dy9" firstAttribute="top" secondItem="l97-iI-4Nl" secondAttribute="top" id="xli-4P-Kun"/>
69 <constraint firstItem="uC9-bK-F7u" firstAttribute="centerY" secondItem="l97-iI-4Nl" secondAttribute="centerY" constant="-3" id="zqt-y0-dLW"/>
61 </constraints> 70 </constraints>
62 <userDefinedRuntimeAttributes> 71 <userDefinedRuntimeAttributes>
63 <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> 72 <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
64 <integer key="value" value="5"/> 73 <integer key="value" value="5"/>
65 </userDefinedRuntimeAttribute> 74 </userDefinedRuntimeAttribute>
66 </userDefinedRuntimeAttributes> 75 </userDefinedRuntimeAttributes>
67 </view> 76 </view>
68 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yAb-sD-Uf2"> 77 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yAb-sD-Uf2">
69 <rect key="frame" x="0.0" y="30" width="320" height="158"/> 78 <rect key="frame" x="0.0" y="30" width="320" height="158"/>
70 <subviews> 79 <subviews>
71 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="距離" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pTa-iM-GGE"> 80 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="距離" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pTa-iM-GGE">
72 <rect key="frame" x="10" y="8" width="45" height="15"/> 81 <rect key="frame" x="10" y="8" width="45" height="15"/>
73 <constraints> 82 <constraints>
74 <constraint firstAttribute="height" constant="15" id="FsR-rA-SoL"/> 83 <constraint firstAttribute="height" constant="15" id="FsR-rA-SoL"/>
75 <constraint firstAttribute="width" constant="45" id="GEl-5g-KCw"/> 84 <constraint firstAttribute="width" constant="45" id="GEl-5g-KCw"/>
76 </constraints> 85 </constraints>
77 <fontDescription key="fontDescription" type="system" pointSize="10"/> 86 <fontDescription key="fontDescription" type="system" pointSize="10"/>
78 <nil key="highlightedColor"/> 87 <nil key="highlightedColor"/>
79 </label> 88 </label>
80 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="カロリー" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JCF-ib-9hs"> 89 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="カロリー" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JCF-ib-9hs">
81 <rect key="frame" x="10" y="23" width="45" height="15"/> 90 <rect key="frame" x="10" y="23" width="45" height="15"/>
82 <fontDescription key="fontDescription" type="system" pointSize="10"/> 91 <fontDescription key="fontDescription" type="system" pointSize="10"/>
83 <nil key="highlightedColor"/> 92 <nil key="highlightedColor"/>
84 </label> 93 </label>
85 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="距離" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6g7-qJ-zHF"> 94 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="距離" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6g7-qJ-zHF">
86 <rect key="frame" x="10" y="38" width="45" height="15"/> 95 <rect key="frame" x="10" y="38" width="45" height="15"/>
87 <fontDescription key="fontDescription" type="system" pointSize="10"/> 96 <fontDescription key="fontDescription" type="system" pointSize="10"/>
88 <nil key="highlightedColor"/> 97 <nil key="highlightedColor"/>
89 </label> 98 </label>
90 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 km" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="f2Y-XG-L6g"> 99 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 km" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="f2Y-XG-L6g">
91 <rect key="frame" x="63" y="8" width="219" height="15"/> 100 <rect key="frame" x="63" y="8" width="219" height="15"/>
92 <constraints> 101 <constraints>
93 <constraint firstAttribute="height" constant="15" id="kWm-bt-xfO"/> 102 <constraint firstAttribute="height" constant="15" id="kWm-bt-xfO"/>
94 </constraints> 103 </constraints>
95 <fontDescription key="fontDescription" type="system" pointSize="10"/> 104 <fontDescription key="fontDescription" type="system" pointSize="10"/>
96 <nil key="highlightedColor"/> 105 <nil key="highlightedColor"/>
97 </label> 106 </label>
98 <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="Yy6-cn-agT"> 107 <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="Yy6-cn-agT">
99 <rect key="frame" x="63" y="23" width="219" height="15"/> 108 <rect key="frame" x="63" y="23" width="219" height="15"/>
100 <fontDescription key="fontDescription" type="system" pointSize="10"/> 109 <fontDescription key="fontDescription" type="system" pointSize="10"/>
101 <nil key="highlightedColor"/> 110 <nil key="highlightedColor"/>
102 </label> 111 </label>
103 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0:50:11" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lmZ-T8-ABg"> 112 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0:50:11" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lmZ-T8-ABg">
104 <rect key="frame" x="63" y="38" width="219" height="15"/> 113 <rect key="frame" x="63" y="38" width="219" height="15"/>
105 <fontDescription key="fontDescription" type="system" pointSize="10"/> 114 <fontDescription key="fontDescription" type="system" pointSize="10"/>
106 <nil key="highlightedColor"/> 115 <nil key="highlightedColor"/>
107 </label> 116 </label>
108 </subviews> 117 </subviews>
109 <color key="backgroundColor" red="0.93333333333333335" green="0.93333333333333335" blue="0.93333333333333335" alpha="1" colorSpace="calibratedRGB"/> 118 <color key="backgroundColor" red="0.93333333333333335" green="0.93333333333333335" blue="0.93333333333333335" alpha="1" colorSpace="calibratedRGB"/>
110 <constraints> 119 <constraints>
111 <constraint firstItem="Yy6-cn-agT" firstAttribute="leading" secondItem="f2Y-XG-L6g" secondAttribute="leading" id="2Ee-SX-8go"/> 120 <constraint firstItem="Yy6-cn-agT" firstAttribute="leading" secondItem="f2Y-XG-L6g" secondAttribute="leading" id="2Ee-SX-8go"/>
112 <constraint firstItem="lmZ-T8-ABg" firstAttribute="height" secondItem="f2Y-XG-L6g" secondAttribute="height" id="2nz-Eq-Wuy"/> 121 <constraint firstItem="lmZ-T8-ABg" firstAttribute="height" secondItem="f2Y-XG-L6g" secondAttribute="height" id="2nz-Eq-Wuy"/>
113 <constraint firstItem="Yy6-cn-agT" firstAttribute="leading" secondItem="f2Y-XG-L6g" secondAttribute="leading" id="5GH-Il-KeE"/> 122 <constraint firstItem="Yy6-cn-agT" firstAttribute="leading" secondItem="f2Y-XG-L6g" secondAttribute="leading" id="5GH-Il-KeE"/>
114 <constraint firstItem="JCF-ib-9hs" firstAttribute="leading" secondItem="pTa-iM-GGE" secondAttribute="leading" id="9hV-iQ-0Bo"/> 123 <constraint firstItem="JCF-ib-9hs" firstAttribute="leading" secondItem="pTa-iM-GGE" secondAttribute="leading" id="9hV-iQ-0Bo"/>
115 <constraint firstItem="lmZ-T8-ABg" firstAttribute="top" secondItem="Yy6-cn-agT" secondAttribute="bottom" id="Aam-YG-wSE"/> 124 <constraint firstItem="lmZ-T8-ABg" firstAttribute="top" secondItem="Yy6-cn-agT" secondAttribute="bottom" id="Aam-YG-wSE"/>
116 <constraint firstItem="lmZ-T8-ABg" firstAttribute="width" secondItem="f2Y-XG-L6g" secondAttribute="width" id="ETo-YC-5aI"/> 125 <constraint firstItem="lmZ-T8-ABg" firstAttribute="width" secondItem="f2Y-XG-L6g" secondAttribute="width" id="ETo-YC-5aI"/>
117 <constraint firstItem="Yy6-cn-agT" firstAttribute="height" secondItem="f2Y-XG-L6g" secondAttribute="height" id="Es4-R8-oEa"/> 126 <constraint firstItem="Yy6-cn-agT" firstAttribute="height" secondItem="f2Y-XG-L6g" secondAttribute="height" id="Es4-R8-oEa"/>
118 <constraint firstItem="Yy6-cn-agT" firstAttribute="top" secondItem="f2Y-XG-L6g" secondAttribute="bottom" id="Jgb-7C-kb9"/> 127 <constraint firstItem="Yy6-cn-agT" firstAttribute="top" secondItem="f2Y-XG-L6g" secondAttribute="bottom" id="Jgb-7C-kb9"/>
119 <constraint firstItem="pTa-iM-GGE" firstAttribute="leading" secondItem="yAb-sD-Uf2" secondAttribute="leading" constant="10" id="LVc-pD-XW4"/> 128 <constraint firstItem="pTa-iM-GGE" firstAttribute="leading" secondItem="yAb-sD-Uf2" secondAttribute="leading" constant="10" id="LVc-pD-XW4"/>
120 <constraint firstItem="Yy6-cn-agT" firstAttribute="width" secondItem="f2Y-XG-L6g" secondAttribute="width" id="Qxi-If-K2Y"/> 129 <constraint firstItem="Yy6-cn-agT" firstAttribute="width" secondItem="f2Y-XG-L6g" secondAttribute="width" id="Qxi-If-K2Y"/>
121 <constraint firstItem="JCF-ib-9hs" firstAttribute="top" secondItem="pTa-iM-GGE" secondAttribute="bottom" id="Sob-0k-rC4"/> 130 <constraint firstItem="JCF-ib-9hs" firstAttribute="top" secondItem="pTa-iM-GGE" secondAttribute="bottom" id="Sob-0k-rC4"/>
122 <constraint firstItem="6g7-qJ-zHF" firstAttribute="width" secondItem="pTa-iM-GGE" secondAttribute="width" id="UwK-Ej-eer"/> 131 <constraint firstItem="6g7-qJ-zHF" firstAttribute="width" secondItem="pTa-iM-GGE" secondAttribute="width" id="UwK-Ej-eer"/>
123 <constraint firstItem="6g7-qJ-zHF" firstAttribute="top" secondItem="JCF-ib-9hs" secondAttribute="bottom" id="VSr-9F-5cc"/> 132 <constraint firstItem="6g7-qJ-zHF" firstAttribute="top" secondItem="JCF-ib-9hs" secondAttribute="bottom" id="VSr-9F-5cc"/>
124 <constraint firstItem="JCF-ib-9hs" firstAttribute="height" secondItem="pTa-iM-GGE" secondAttribute="height" id="Yhh-Zn-2tX"/> 133 <constraint firstItem="JCF-ib-9hs" firstAttribute="height" secondItem="pTa-iM-GGE" secondAttribute="height" id="Yhh-Zn-2tX"/>
125 <constraint firstItem="pTa-iM-GGE" firstAttribute="top" secondItem="yAb-sD-Uf2" secondAttribute="top" constant="8" id="hUP-mB-2dz"/> 134 <constraint firstItem="pTa-iM-GGE" firstAttribute="top" secondItem="yAb-sD-Uf2" secondAttribute="top" constant="8" id="hUP-mB-2dz"/>
126 <constraint firstItem="lmZ-T8-ABg" firstAttribute="leading" secondItem="f2Y-XG-L6g" secondAttribute="leading" id="hto-gS-Mz2"/> 135 <constraint firstItem="lmZ-T8-ABg" firstAttribute="leading" secondItem="f2Y-XG-L6g" secondAttribute="leading" id="hto-gS-Mz2"/>
127 <constraint firstItem="lmZ-T8-ABg" firstAttribute="leading" secondItem="f2Y-XG-L6g" secondAttribute="leading" id="i7D-G9-PPF"/> 136 <constraint firstItem="lmZ-T8-ABg" firstAttribute="leading" secondItem="f2Y-XG-L6g" secondAttribute="leading" id="i7D-G9-PPF"/>
128 <constraint firstItem="f2Y-XG-L6g" firstAttribute="top" secondItem="yAb-sD-Uf2" secondAttribute="top" constant="8" id="jmU-mq-AaY"/> 137 <constraint firstItem="f2Y-XG-L6g" firstAttribute="top" secondItem="yAb-sD-Uf2" secondAttribute="top" constant="8" id="jmU-mq-AaY"/>
129 <constraint firstItem="6g7-qJ-zHF" firstAttribute="height" secondItem="pTa-iM-GGE" secondAttribute="height" id="mvT-lk-mcd"/> 138 <constraint firstItem="6g7-qJ-zHF" firstAttribute="height" secondItem="pTa-iM-GGE" secondAttribute="height" id="mvT-lk-mcd"/>
130 <constraint firstAttribute="trailing" secondItem="f2Y-XG-L6g" secondAttribute="trailing" constant="38" id="pFC-Zy-Ydq"/> 139 <constraint firstAttribute="trailing" secondItem="f2Y-XG-L6g" secondAttribute="trailing" constant="38" id="pFC-Zy-Ydq"/>
131 <constraint firstItem="f2Y-XG-L6g" firstAttribute="leading" secondItem="pTa-iM-GGE" secondAttribute="trailing" constant="8" id="svF-aI-4pu"/> 140 <constraint firstItem="f2Y-XG-L6g" firstAttribute="leading" secondItem="pTa-iM-GGE" secondAttribute="trailing" constant="8" id="svF-aI-4pu"/>
132 <constraint firstItem="JCF-ib-9hs" firstAttribute="width" secondItem="pTa-iM-GGE" secondAttribute="width" id="v8t-01-PGN"/> 141 <constraint firstItem="JCF-ib-9hs" firstAttribute="width" secondItem="pTa-iM-GGE" secondAttribute="width" id="v8t-01-PGN"/>
133 <constraint firstItem="6g7-qJ-zHF" firstAttribute="leading" secondItem="pTa-iM-GGE" secondAttribute="leading" id="zgT-uC-I9l"/> 142 <constraint firstItem="6g7-qJ-zHF" firstAttribute="leading" secondItem="pTa-iM-GGE" secondAttribute="leading" id="zgT-uC-I9l"/>
134 </constraints> 143 </constraints>
135 </view> 144 </view>
136 </subviews> 145 </subviews>
137 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 146 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
138 <constraints> 147 <constraints>
139 <constraint firstItem="yAb-sD-Uf2" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="65T-wN-9af"/> 148 <constraint firstItem="yAb-sD-Uf2" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="65T-wN-9af"/>
140 <constraint firstItem="yAb-sD-Uf2" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="30" id="7y1-zF-cRh"/> 149 <constraint firstItem="yAb-sD-Uf2" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="30" id="7y1-zF-cRh"/>
141 <constraint firstAttribute="trailing" secondItem="l97-iI-4Nl" secondAttribute="trailing" id="DF1-YD-2mu"/> 150 <constraint firstAttribute="trailing" secondItem="l97-iI-4Nl" secondAttribute="trailing" id="DF1-YD-2mu"/>
142 <constraint firstItem="l97-iI-4Nl" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="WNb-sn-9xi"/> 151 <constraint firstItem="l97-iI-4Nl" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="WNb-sn-9xi"/>
143 <constraint firstAttribute="trailing" secondItem="yAb-sD-Uf2" secondAttribute="trailing" id="mbU-jM-lKI"/> 152 <constraint firstAttribute="trailing" secondItem="yAb-sD-Uf2" secondAttribute="trailing" id="mbU-jM-lKI"/>
144 <constraint firstItem="l97-iI-4Nl" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="rgY-N8-3mT"/> 153 <constraint firstItem="l97-iI-4Nl" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="rgY-N8-3mT"/>
145 <constraint firstAttribute="bottom" secondItem="yAb-sD-Uf2" secondAttribute="bottom" id="tgk-Kq-NYY"/> 154 <constraint firstAttribute="bottom" secondItem="yAb-sD-Uf2" secondAttribute="bottom" id="tgk-Kq-NYY"/>
146 </constraints> 155 </constraints>
147 </tableViewCellContentView> 156 </tableViewCellContentView>
148 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 157 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
149 <connections> 158 <connections>
159 <outlet property="imgArrow" destination="uC9-bK-F7u" id="0pM-jI-nwl"/>
160 <outlet property="lblDiff" destination="qgK-8d-giH" id="8e8-ew-yEX"/>
150 <outlet property="lblDistance" destination="f2Y-XG-L6g" id="gwM-yJ-wWM"/> 161 <outlet property="lblDistance" destination="f2Y-XG-L6g" id="gwM-yJ-wWM"/>
151 <outlet property="lblDuration" destination="lmZ-T8-ABg" id="ioM-85-tg7"/> 162 <outlet property="lblDuration" destination="lmZ-T8-ABg" id="ioM-85-tg7"/>
152 <outlet property="lblPower" destination="Yy6-cn-agT" id="6KD-eN-oTW"/> 163 <outlet property="lblPower" destination="Yy6-cn-agT" id="6KD-eN-oTW"/>
153 <outlet property="lblStep" destination="Eop-bg-Dy9" id="JII-VL-w0n"/> 164 <outlet property="lblStep" destination="Eop-bg-Dy9" id="JII-VL-w0n"/>
154 <outlet property="lblTitle" destination="zW0-JI-PIE" id="RaR-hQ-48q"/> 165 <outlet property="lblTitle" destination="zW0-JI-PIE" id="RaR-hQ-48q"/>
155 </connections> 166 </connections>
156 <point key="canvasLocation" x="26" y="124"/> 167 <point key="canvasLocation" x="26" y="124"/>
157 </tableViewCell> 168 </tableViewCell>
158 </objects> 169 </objects>
170 <resources>
171 <image name="arrow_incre" width="10" height="12"/>
172 </resources>
159 </document> 173 </document>
160 174
LifeLog/LifeLog/HistoryObject.h
1 // 1 //
2 // HistoryObject.h 2 // HistoryObject.h
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/5/17. 5 // Created by nvtu on 8/5/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 10
11 @interface HistoryObject : NSObject 11 @interface HistoryObject : NSObject
12 12
13 @property (nonatomic) int step; 13 @property (nonatomic) int step;
14 @property (nonatomic) int step_diff;
14 @property (nonatomic) int missing; 15 @property (nonatomic) int missing;
15 @property (nonatomic) int target; 16 @property (nonatomic) int target;
17 @property (nonatomic) int time;
16 @property (nonatomic) int time; 18 @property (nonatomic) float percent;
17 @property (nonatomic) float percent; 19 @property (nonatomic) float distance;
18 @property (nonatomic) float distance; 20 @property (nonatomic) float calories;
19 @property (nonatomic) float calories;
20 @property (nonatomic, strong) NSDate *date; 21 @property (nonatomic, strong) NSDate *date;
21 @property (nonatomic, strong) NSMutableArray *dataGraph; 22 @property (nonatomic, strong) NSMutableArray *dataGraph;
22 23
23 -(id) initWithData : (NSDictionary *) dict; 24 -(id) initWithData : (NSDictionary *) dict;
24 25
25 @end 26 @end
LifeLog/LifeLog/HistoryObject.m
1 // 1 //
2 // HistoryObject.m 2 // HistoryObject.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/5/17. 5 // Created by nvtu on 8/5/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "HistoryObject.h" 9 #import "HistoryObject.h"
10 #import "Utilities.h"
10 11
11 @implementation HistoryObject 12 @implementation HistoryObject
12 13
13 -(id) initWithData : (NSDictionary *) dict { 14 -(id) initWithData : (NSDictionary *) dict {
14 if([dict objectForKey:@"steps"] != nil) { 15 if([dict objectForKey:@"steps"] != nil) {
15 self.step = [dict[@"steps"] intValue]; 16 self.step = [dict[@"steps"] intValue];
17 }
18 if([dict objectForKey:@"step_diff"] != nil) {
19 self.step_diff = [dict[@"step_diff"] intValue];
16 } 20 }
17 if([dict objectForKey:@"target"] != nil) { 21 if([dict objectForKey:@"target"] != nil) {
18 self.target = [dict[@"target"] intValue]; 22 self.target = [dict[@"target"] intValue];
19 } 23 }
20 if([dict objectForKey:@"step_remain"] != nil) { 24 if([dict objectForKey:@"step_remain"] != nil) {
21 self.missing = [dict[@"step_remain"] intValue]; 25 self.missing = [dict[@"step_remain"] intValue];
22 } 26 }
23 if([dict objectForKey:@"complete_percent"] != nil) { 27 if([dict objectForKey:@"complete_percent"] != nil) {
24 self.percent = [dict[@"complete_percent"] floatValue]; 28 self.percent = [dict[@"complete_percent"] floatValue];
25 } 29 }
26 if([dict objectForKey:@"distance"] != nil) { 30 if([dict objectForKey:@"distance"] != nil) {
27 if([dict[@"distance"] isKindOfClass:[NSString class]]) { 31 if([dict[@"distance"] isKindOfClass:[NSString class]]) {
28 NSString *distance = dict[@"distance"]; 32 NSString *distance = dict[@"distance"];
29 self.distance = [distance floatValue]; 33 self.distance = [distance floatValue];
30 } 34 }
31 else { 35 else {
32 self.distance = [dict[@"distance"] floatValue]; 36 self.distance = [dict[@"distance"] floatValue];
33 } 37 }
34 } 38 }
35 if([dict objectForKey:@"kcal"] != nil) { 39 if([dict objectForKey:@"kcal"] != nil) {
36 self.calories = [dict[@"kcal"] floatValue]; 40 self.calories = [dict[@"kcal"] floatValue];
37 } 41 }
38 if([dict objectForKey:@"time"] != nil) { 42 if([dict objectForKey:@"time"] != nil) {
39 self.time = [dict[@"time"] intValue]; 43 self.time = [dict[@"time"] intValue];
40 }
41 if([dict objectForKey:@"date"] != nil) {
42 NSString *dateString = dict[@"date"];
43 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
44 [dateFormat setDateFormat:@"yyyy-MM-dd"];
45 self.date = [dateFormat dateFromString:dateString]; 44 }
46 } 45 if([dict objectForKey:@"date"] != nil) {
47 else { 46 NSString *dateString = dict[@"date"];
48 self.date = [NSDate date]; 47 self.date = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd"];
49 }
50 if([dict objectForKey:@"data_chart"] != nil) {
51 self.dataGraph = [[NSMutableArray alloc] init]; 48 }
52 NSDictionary * graph = [dict objectForKey:@"data_chart"]; 49 else {
53 if([graph count] == 24) { 50 self.date = [NSDate date];
54 for(int i = 0; i < 24; i++) { 51 }
55 [self.dataGraph addObject:[graph objectForKey:[NSString stringWithFormat:@"%d", i]]]; 52 if([dict objectForKey:@"data_chart"] != nil) {
56 } 53 self.dataGraph = [[NSMutableArray alloc] init];
57 } 54 NSDictionary * graph = [dict objectForKey:@"data_chart"];
58 } 55 if([graph count] == 24) {
59 return self; 56 for(int i = 0; i < 24; i++) {
60 } 57 [self.dataGraph addObject:[graph objectForKey:[NSString stringWithFormat:@"%d", i]]];
LifeLog/LifeLog/HistoryViewController.h
1 // 1 //
2 // HistoryViewController.h 2 // HistoryViewController.h
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by Nguyen Van Phong on 7/25/17. 5 // Created by Nguyen Van Phong on 7/25/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
10 #import <Charts/Charts-Swift.h> 10 #import <Charts/Charts-Swift.h>
11 11
12 #import "BaseTableViewController.h" 12 #import "BaseTableViewController.h"
13 #import "CollectionView.h" 13 #import "CollectionView.h"
14 14
15 #import "Entities.h" 15 #import "Entities.h"
16 16
17 @interface HistoryViewController : BaseTableViewController <UIScrollViewDelegate> { 17 @interface HistoryViewController : BaseTableViewController <UIScrollViewDelegate> {
18 NSDate * _startDate; 18 NSDate * _startDate;
19 NSDate * _endDate; 19 NSDate * _endDate;
20 NSArray * _curHisArray; 20 NSArray * _curHisArray;
21 NSArray * _curListArray;
21 } 22 }
22 @property (weak, nonatomic) IBOutlet UILabel *lblDatetime; 23 @property (weak, nonatomic) IBOutlet UILabel *lblDatetime;
23 24
24 @property (weak, nonatomic) IBOutlet UILabel *lblCircleStep; 25 @property (weak, nonatomic) IBOutlet UILabel *lblCircleStep;
25 @property (weak, nonatomic) IBOutlet UILabel *lblCircleRemain; 26 @property (weak, nonatomic) IBOutlet UILabel *lblCircleRemain;
26 27
27 @property (weak, nonatomic) IBOutlet UILabel *lblStep; 28 @property (weak, nonatomic) IBOutlet UILabel *lblStep;
28 @property (weak, nonatomic) IBOutlet UILabel *lblRemaining; 29 @property (weak, nonatomic) IBOutlet UILabel *lblRemaining;
29 @property (weak, nonatomic) IBOutlet UILabel *lblPercent; 30 @property (weak, nonatomic) IBOutlet UILabel *lblPercent;
30 @property (weak, nonatomic) IBOutlet UILabel *lblCalories; 31 @property (weak, nonatomic) IBOutlet UILabel *lblCalories;
31 @property (weak, nonatomic) IBOutlet UILabel *lblDistance; 32 @property (weak, nonatomic) IBOutlet UILabel *lblDistance;
32 @property (weak, nonatomic) IBOutlet UILabel *lblTime; 33 @property (weak, nonatomic) IBOutlet UILabel *lblTime;
33 34
34 @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionType; 35 @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionType;
35 @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionMode; 36 @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionMode;
36 @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionShare; 37 @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionShare;
37 38
38 @property (weak, nonatomic) IBOutlet BarChartView *viewBarChart; 39 @property (weak, nonatomic) IBOutlet BarChartView *viewBarChart;
39 40
40 @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; 41 @property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
41 42
42 - (IBAction)swipeAction:(UISwipeGestureRecognizer *)sender; 43 - (IBAction)swipeAction:(UISwipeGestureRecognizer *)sender;
43 - (IBAction)clickBackward:(UIButton *)sender; 44 - (IBAction)clickBackward:(UIButton *)sender;
44 - (IBAction)clickForward:(UIButton *)sender; 45 - (IBAction)clickForward:(UIButton *)sender;
45 46
46 @end 47 @end
47 48
LifeLog/LifeLog/HistoryViewController.m
1 // 1 //
2 // HistoryViewController.m 2 // HistoryViewController.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by Nguyen Van Phong on 7/25/17. 5 // Created by Nguyen Van Phong on 7/25/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "HistoryViewController.h" 9 #import "HistoryViewController.h"
10 #import "Utilities.h" 10 #import "Utilities.h"
11 #import "ServerAPI.h" 11 #import "ServerAPI.h"
12 12
13 #import "HistoryListTableViewCell.h" 13 #import "HistoryListTableViewCell.h"
14 14
15 @interface HistoryViewController () 15 @interface HistoryViewController ()
16 16
17 @end 17 @end
18 18
19 @implementation HistoryViewController 19 @implementation HistoryViewController
20 20
21 - (void)viewDidLoad { 21 - (void)viewDidLoad {
22 [super viewDidLoad]; 22 [super viewDidLoad];
23 // Do any additional setup after loading the view from its nib. 23 // Do any additional setup after loading the view from its nib.
24 self.title = NSLocalizedString(@"lifelog.history.title", nil); 24 self.title = NSLocalizedString(@"lifelog.history.title", nil);
25 25
26 _isDisableLoadMore = true;
27
26 [self setupView]; 28 [self setupView];
27 [self setupChartView]; 29 [self setupChartView];
28 30
29 _startDate = [NSDate date]; 31 _startDate = [NSDate date];
30 _endDate = _startDate; 32 _endDate = _startDate;
31 33
32 self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; 34 self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"];
33 35
34 [self checkRequestData]; 36 [self checkRequestData];
35 37
36 //register nib for table view 38 //register nib for table view
37 [self.tableBase registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; 39 [self.tableBase registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"];
38 } 40 }
39 41
40 - (void)viewDidAppear:(BOOL) animated 42 - (void)viewDidAppear:(BOOL) animated
41 { 43 {
42 [super viewDidAppear:animated]; 44 [super viewDidAppear:animated];
43 self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 400); 45 self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 400);
44 [self.scrollView setNeedsLayout]; 46 [self.scrollView setNeedsLayout];
45 [self.scrollView setNeedsUpdateConstraints]; 47 [self.scrollView setNeedsUpdateConstraints];
46 48
47 } 49 }
48 50
49 - (void)didReceiveMemoryWarning { 51 - (void)didReceiveMemoryWarning {
50 [super didReceiveMemoryWarning]; 52 [super didReceiveMemoryWarning];
51 // Dispose of any resources that can be recreated. 53 // Dispose of any resources that can be recreated.
52 } 54 }
53 55
54 - (void)setupView { 56 - (void)setupView {
55 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]; 57 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];
56 [self.viewCollectionType setButtonNumber:typeTitle.count]; 58 [self.viewCollectionType setButtonNumber:typeTitle.count];
57 [self.viewCollectionType setSpacing:2]; 59 [self.viewCollectionType setSpacing:2];
58 [self.viewCollectionType setArrayTitle:typeTitle]; 60 [self.viewCollectionType setArrayTitle:typeTitle];
59 self.viewCollectionType.changeCurrentIndex = ^(int index){ 61 self.viewCollectionType.changeCurrentIndex = ^(int index){
60 [self changeDate]; 62 [self changeDate];
61 }; 63 };
62 64
63 NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.mode.1", nil), NSLocalizedString(@"lifelog.history.mode.2", nil), NSLocalizedString(@"lifelog.history.mode.3", nil), nil]; 65 NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.mode.1", nil), NSLocalizedString(@"lifelog.history.mode.2", nil), NSLocalizedString(@"lifelog.history.mode.3", nil), nil];
64 [self.viewCollectionMode setButtonNumber:modeTitle.count]; 66 [self.viewCollectionMode setButtonNumber:modeTitle.count];
65 [self.viewCollectionMode setSpacing:0]; 67 [self.viewCollectionMode setSpacing:0];
66 [self.viewCollectionMode setCornerRadius:0]; 68 [self.viewCollectionMode setCornerRadius:0];
67 [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; 69 [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]];
68 [self.viewCollectionMode setArrayTitle:modeTitle]; 70 [self.viewCollectionMode setArrayTitle:modeTitle];
69 self.viewCollectionMode.changeCurrentIndex = ^(int index){ 71 self.viewCollectionMode.changeCurrentIndex = ^(int index){
70 [self updateView]; 72 if(self.tableBase.alpha == 0.0) {
73 [self updateView];
74 }
75 else {
76 NSArray * list = [_curListArray objectAtIndex:index];
77 [self updateTableData:list error:nil];
78 }
71 }; 79 };
72 80
73 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]; 81 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];
74 [self.viewCollectionShare setButtonNumber:typeTitle.count]; 82 [self.viewCollectionShare setButtonNumber:typeTitle.count];
75 [self.viewCollectionShare setSpacing:3]; 83 [self.viewCollectionShare setSpacing:3];
76 [self.viewCollectionShare setArrayTitle:shareTitle]; 84 [self.viewCollectionShare setArrayTitle:shareTitle];
77 [self.viewCollectionShare disableSelection]; 85 [self.viewCollectionShare disableSelection];
78 86
79 //add tap gesture for enable tap on gesture on CollectionView in ScrollView 87 //add tap gesture for enable tap on gesture on CollectionView in ScrollView
80 UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; 88 UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)];
81 [recognizer setNumberOfTapsRequired:1]; 89 [recognizer setNumberOfTapsRequired:1];
82 self.scrollView.userInteractionEnabled = YES; 90 self.scrollView.userInteractionEnabled = YES;
83 [self.scrollView addGestureRecognizer:recognizer]; 91 [self.scrollView addGestureRecognizer:recognizer];
84 } 92 }
85 93
86 - (void)setupChartView { 94 - (void)setupChartView {
87 self.viewBarChart.chartDescription.enabled = NO; 95 self.viewBarChart.chartDescription.enabled = NO;
88 self.viewBarChart.leftAxis.drawGridLinesEnabled = NO; 96 self.viewBarChart.leftAxis.drawGridLinesEnabled = NO;
89 self.viewBarChart.rightAxis.drawGridLinesEnabled = NO; 97 self.viewBarChart.rightAxis.drawGridLinesEnabled = NO;
90 self.viewBarChart.legend.enabled = NO; 98 self.viewBarChart.legend.enabled = NO;
91 99
92 ChartXAxis *xAxis = self.viewBarChart.xAxis; 100 ChartXAxis *xAxis = self.viewBarChart.xAxis;
93 xAxis.labelPosition = XAxisLabelPositionBottom; 101 xAxis.labelPosition = XAxisLabelPositionBottom;
94 xAxis.drawGridLinesEnabled = NO; 102 xAxis.drawGridLinesEnabled = NO;
95 xAxis.drawAxisLineEnabled = NO; 103 xAxis.drawAxisLineEnabled = NO;
96 xAxis.drawLabelsEnabled = YES; 104 xAxis.drawLabelsEnabled = YES;
97 xAxis.labelPosition = XAxisLabelPositionBottom; 105 xAxis.labelPosition = XAxisLabelPositionBottom;
98 xAxis.labelFont = [UIFont systemFontOfSize:10.f]; 106 xAxis.labelFont = [UIFont systemFontOfSize:10.f];
99 xAxis.labelTextColor = [UIColor whiteColor]; 107 xAxis.labelTextColor = [UIColor whiteColor];
100 xAxis.granularity = 1.0; // only intervals of 1 day 108 xAxis.granularity = 1.0; // only intervals of 1 day
101 xAxis.labelCount = 8; 109 xAxis.labelCount = 8;
102 110
103 self.viewBarChart.leftAxis.drawAxisLineEnabled = NO; 111 self.viewBarChart.leftAxis.drawAxisLineEnabled = NO;
104 self.viewBarChart.rightAxis.drawAxisLineEnabled = NO; 112 self.viewBarChart.rightAxis.drawAxisLineEnabled = NO;
105 } 113 }
106 114
107 -(void) updateView { 115 -(void) updateView {
108 HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; 116 HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex];
109 self.lblStep.text = [NSString stringWithFormat:@"%d step", obj.step]; 117 self.lblStep.text = [NSString stringWithFormat:@"%d step", obj.step];
110 self.lblCircleStep.text = self.lblStep.text; 118 self.lblCircleStep.text = self.lblStep.text;
111 self.lblRemaining.text = [NSString stringWithFormat:@"%d step", obj.missing]; 119 self.lblRemaining.text = [NSString stringWithFormat:@"%d step", obj.missing];
112 self.lblCircleRemain.text = [NSString stringWithFormat:@"目標まであと\n%d stepです", obj.missing]; 120 self.lblCircleRemain.text = [NSString stringWithFormat:@"目標まであと\n%d stepです", obj.missing];
113 self.lblPercent.text = [NSString stringWithFormat:@"%0.2f%%", obj.percent]; 121 self.lblPercent.text = [NSString stringWithFormat:@"%0.2f%%", obj.percent];
114 self.lblCalories.text = [NSString stringWithFormat:@"%0.2f kcal", obj.calories]; 122 self.lblCalories.text = [NSString stringWithFormat:@"%0.2f kcal", obj.calories];
123 self.lblDistance.text = [NSString stringWithFormat:@"%0.1f KM", obj.distance];
124 self.lblTime.text = [Utilities convertSecondToShortTime:obj.time];
115 self.lblDistance.text = [NSString stringWithFormat:@"%0.1f KM", obj.distance]; 125 [self updateGraphView];
116 self.lblTime.text = [Utilities convertSecondToShortTime:obj.time]; 126 }
117 [self updateGraphView]; 127
118 } 128 -(void) updateGraphView {
119 129 HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex];
120 -(void) updateGraphView { 130
121 HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; 131 NSMutableArray *yVals = [[NSMutableArray alloc] init];
122 132 for (int i = 0; i < obj.dataGraph.count; i++)
123 NSMutableArray *yVals = [[NSMutableArray alloc] init]; 133 {
124 for (int i = 0; i < obj.dataGraph.count; i++) 134 [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:[[obj.dataGraph objectAtIndex:i] doubleValue]]];
125 { 135 }
126 [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:[[obj.dataGraph objectAtIndex:i] doubleValue]]]; 136
127 } 137 BarChartDataSet *set1 = nil;
128 138 if (self.viewBarChart.data.dataSetCount > 0)
129 BarChartDataSet *set1 = nil; 139 {
130 if (self.viewBarChart.data.dataSetCount > 0) 140 set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0];
131 { 141 set1.values = yVals;
132 set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0]; 142 [self.viewBarChart.data notifyDataChanged];
133 set1.values = yVals; 143 [self.viewBarChart notifyDataSetChanged];
134 [self.viewBarChart.data notifyDataChanged]; 144 }
135 [self.viewBarChart notifyDataSetChanged]; 145 else
136 } 146 {
137 else 147 set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""];
138 { 148 [set1 setColor:[UIColor whiteColor]];
139 set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""]; 149
140 [set1 setColor:[UIColor whiteColor]]; 150 NSMutableArray *dataSets = [[NSMutableArray alloc] init];
141 151 [dataSets addObject:set1];
142 NSMutableArray *dataSets = [[NSMutableArray alloc] init]; 152
143 [dataSets addObject:set1]; 153 BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];
144 154 data.barWidth = 0.5f;
145 BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets]; 155
146 data.barWidth = 0.5f; 156 self.viewBarChart.data = data;
147 157 }
148 self.viewBarChart.data = data; 158 }
149 } 159
150 } 160 -(void) checkRequestData {
151 161 if(self.tableBase.alpha == 0.0) {
152 -(void) checkRequestData { 162 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
153 if(self.tableBase.alpha == 0.0) { 163 MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
154 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; 164 [[ServerAPI server] requestHistory:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) {
155 MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; 165 HistoryViewController __weak *weakSelf = self;
156 [[ServerAPI server] requestHistory:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) { 166 dispatch_async(dispatch_get_main_queue(), ^{
157 HistoryViewController __weak *weakSelf = self; 167 if(hudView != nil) {
158 dispatch_async(dispatch_get_main_queue(), ^{ 168 [hudView hideAnimated:true];
159 if(hudView != nil) { 169 }
160 [hudView hideAnimated:true]; 170 });
161 } 171 if(error == nil) {
162 }); 172 _curHisArray = array;
163 if(error == nil) { 173 dispatch_async(dispatch_get_main_queue(), ^{
164 _curHisArray = array; 174 [weakSelf updateView];
165 dispatch_async(dispatch_get_main_queue(), ^{ 175 });
166 [weakSelf updateView]; 176 }
167 }); 177 else {
168 } 178 dispatch_async(dispatch_get_main_queue(), ^{
169 else { 179 NSString *message = [error.userInfo objectForKey:@"message"];
170 dispatch_async(dispatch_get_main_queue(), ^{ 180 [Utilities showErrorMessage:message withViewController:weakSelf];
171 NSString *message = [error.userInfo objectForKey:@"message"]; 181 });
172 [Utilities showErrorMessage:message withViewController:weakSelf]; 182 }
173 }); 183 }];
174 } 184 }
175 }]; 185 else {
176 } 186 [self resetData];
177 else { 187 }
178 [self resetData]; 188 }
179 } 189
180 } 190 -(void) callRequestToUpdateData {
181 191 [super callRequestToUpdateData];
182 -(void) callRequestToUpdateData { 192 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
183 [super callRequestToUpdateData];
184 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
185 int type = self.viewCollectionType.getCurrentIndex; 193
186 int mode = self.viewCollectionMode.getCurrentIndex + 1; 194 MBProgressHUD *hudView = nil;
187 195 if(_curPage == 1 && !self.refreshControl.isRefreshing) {
188 MBProgressHUD *hudView = nil; 196 hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
189 if(_curPage == 1 && !self.refreshControl.isRefreshing) { 197 }
190 hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; 198 [[ServerAPI server] requestHistoryList:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) {
191 } 199 dispatch_async(dispatch_get_main_queue(), ^{
192 [[ServerAPI server] requestHistoryList:token withType:type andMode:mode AtPage:_curPage CompletionHandler:^(NSArray *array, NSError *error) { 200 if(hudView != nil) {
193 dispatch_async(dispatch_get_main_queue(), ^{ 201 [hudView hideAnimated:true];
194 if(hudView != nil) { 202 }
195 [hudView hideAnimated:true]; 203 });
196 } 204 HistoryViewController __weak *weakSelf = self;
197 }); 205 if(error == nil) {
206 _curListArray = array;
207 NSArray * list = [array objectAtIndex:weakSelf.viewCollectionMode.getCurrentIndex];
208 [weakSelf updateTableData:list error:error];
209 }
210 else {
211 [weakSelf updateTableData:array error:error];
212 }
198 HistoryViewController __weak *weakSelf = self; 213 }];
199 [weakSelf updateTableData:array error:error]; 214 }
200 }]; 215
201 } 216 - (void) changeDate {
202 217 switch (self.viewCollectionType.getCurrentIndex) {
203 - (void) changeDate { 218 case 1:
204 switch (self.viewCollectionType.getCurrentIndex) { 219 _startDate = [_endDate dateByAddingTimeInterval:-86400 * 7];
205 case 1: 220 break;
206 _startDate = [_endDate dateByAddingTimeInterval:-86400 * 7]; 221 case 2:
207 break; 222 _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30];
208 case 2: 223 break;
209 _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30]; 224 case 3:
210 break; 225 _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 3];
211 case 3: 226 break;
212 _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 3]; 227 case 4:
213 break; 228 _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 6];
214 case 4: 229 break;
215 _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 6]; 230 default:
216 break; 231 _startDate = _endDate;
217 default: 232 break;
218 _startDate = _endDate; 233 }
234 if(_startDate == _endDate) {
235 self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"];
236 }
237 else {
238 NSString * startDateString = [Utilities stringFromDate:_startDate withFormat:@"YYYY年MM月dd日" locale:@"ja_JP"];
239 NSString * endDateString = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日" locale:@"ja_JP"];
240 self.lblDatetime.text = [NSString stringWithFormat:@"%@-%@", startDateString, endDateString];
241 }
219 break; 242 [self checkRequestData];
220 } 243 }
221 [self checkRequestData]; 244
222 } 245 #pragma mark IBAction
223 246 -(void) swipeAction:(UISwipeGestureRecognizer *)sender {
224 #pragma mark IBAction 247 bool alphaValue = self.scrollView.alpha == 1.0 ? 1.0 : 0.0;
225 -(void) swipeAction:(UISwipeGestureRecognizer *)sender { 248 [UIView animateWithDuration:0.5 animations:^{
226 bool alphaValue = self.scrollView.alpha == 1.0 ? 1.0 : 0.0; 249 self.tableBase.alpha = alphaValue;
227 [UIView animateWithDuration:0.5 animations:^{ 250 self.scrollView.alpha = 1.0 - alphaValue;
228 self.tableBase.alpha = alphaValue; 251 } completion:^(BOOL completed) {
229 self.scrollView.alpha = 1.0 - alphaValue; 252 [self checkRequestData];
230 } completion:^(BOOL completed) { 253 }];
231 [self checkRequestData]; 254 }
232 }]; 255
233 } 256 - (IBAction)clickBackward:(UIButton *)sender {
234 257 _endDate = [_endDate dateByAddingTimeInterval:-86400];
235 - (IBAction)clickBackward:(UIButton *)sender {
236 _endDate = [_endDate dateByAddingTimeInterval:-86400]; 258 [self changeDate];
237 self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; 259 }
238 [self changeDate]; 260
239 } 261 - (IBAction)clickForward:(UIButton *)sender {
240 262 _endDate = [_endDate dateByAddingTimeInterval:86400];
241 - (IBAction)clickForward:(UIButton *)sender {
242 _endDate = [_endDate dateByAddingTimeInterval:86400]; 263 [self changeDate];
243 self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; 264 }
244 [self changeDate]; 265
245 } 266 -(void)gestureAction:(UITapGestureRecognizer *) sender
246 267 {
247 -(void)gestureAction:(UITapGestureRecognizer *) sender 268 CGPoint touchLocation = [sender locationOfTouch:0 inView:self.viewCollectionShare];
248 { 269 NSIndexPath *indexPath = [self.viewCollectionShare.collectionView indexPathForItemAtPoint:touchLocation];
249 CGPoint touchLocation = [sender locationOfTouch:0 inView:self.viewCollectionShare]; 270 NSString * content = @"Finish 500 steps";
250 NSIndexPath *indexPath = [self.viewCollectionShare.collectionView indexPathForItemAtPoint:touchLocation]; 271 HistoryViewController __weak *weakSelf = self;
251 NSString * content = @"Finish 500 steps"; 272 if(indexPath != NULL) {
252 HistoryViewController __weak *weakSelf = self; 273 switch (indexPath.row) {
253 if(indexPath != NULL) { 274 case 0: //share facebook
254 switch (indexPath.row) { 275 [Utilities shareFacebook:content withViewController:weakSelf];
255 case 0: //share facebook 276 break;
256 [Utilities shareFacebook:content withViewController:weakSelf]; 277 case 1: //share twitter
257 break; 278 [Utilities shareTwitter:content withViewController:weakSelf];
258 case 1: //share twitter 279 break;
259 [Utilities shareTwitter:content withViewController:weakSelf]; 280 case 2 : //share line
260 break; 281 [Utilities shareLine:content withViewController:weakSelf];
261 case 2 : //share line 282 break;
262 [Utilities shareLine:content withViewController:weakSelf]; 283 case 3: // share email
263 break; 284 [Utilities shareEmail:content withViewController:weakSelf];
264 case 3: // share email 285 break;
265 [Utilities shareEmail:content withViewController:weakSelf]; 286 default: //share other
287 [Utilities shareOther:content withViewController:weakSelf];
266 break; 288 break;
267 default: //share other 289 }
268 [Utilities shareOther:content withViewController:weakSelf]; 290 }
269 break; 291 }
270 } 292
271 } 293 #pragma mark UITableView Delegate
272 } 294 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
273 295 HistoryListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryListCell"];
274 #pragma mark UITableView Delegate 296 HistoryObject * obj = [_curDataList objectAtIndex:indexPath.row];
297 cell.lblTitle.text = [Utilities stringFromDate:obj.date withFormat:@"dd日 (EEEE)" locale:@"ja_JP"];
275 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 298 cell.lblStep.text = [NSString stringWithFormat:@"%d", obj.step];
299 cell.lblDiff.text = [NSString stringWithFormat:@"%d", obj.step_diff];
300 cell.imgArrow.image = (obj.step_diff > 0) ? [UIImage imageNamed:@"arrow_incre"] : [UIImage imageNamed:@"arrow_decre"];
276 HistoryListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryListCell"]; 301 cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories];
277 HistoryObject * obj = [_curDataList objectAtIndex:indexPath.row]; 302 cell.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance];
278 cell.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; 303 cell.lblDuration.text = [Utilities convertSecondToShortTime:obj.time];
279 cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; 304 return cell;
LifeLog/LifeLog/HistoryViewController.xib
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" 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="12121" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait"> 3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/> 4 <adaptation id="fullscreen"/>
5 </device> 5 </device>
6 <dependencies> 6 <dependencies>
7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/> 7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
8 <capability name="Aspect ratio constraints" minToolsVersion="5.1"/> 8 <capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> 9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10 </dependencies> 10 </dependencies>
11 <objects> 11 <objects>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HistoryViewController"> 12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HistoryViewController">
13 <connections> 13 <connections>
14 <outlet property="lblCalories" destination="dAE-C8-QLr" id="WaS-S3-Qxh"/> 14 <outlet property="lblCalories" destination="dAE-C8-QLr" id="WaS-S3-Qxh"/>
15 <outlet property="lblCircleRemain" destination="Kr7-S0-Fpl" id="UQe-Bt-i0X"/> 15 <outlet property="lblCircleRemain" destination="Kr7-S0-Fpl" id="UQe-Bt-i0X"/>
16 <outlet property="lblCircleStep" destination="oWg-A8-aCr" id="Q9g-UY-hyv"/> 16 <outlet property="lblCircleStep" destination="oWg-A8-aCr" id="Q9g-UY-hyv"/>
17 <outlet property="lblDatetime" destination="EM7-vA-s1e" id="0fK-4u-TaK"/> 17 <outlet property="lblDatetime" destination="EM7-vA-s1e" id="0fK-4u-TaK"/>
18 <outlet property="lblDistance" destination="1tR-JC-pyw" id="q4s-Ru-vLO"/> 18 <outlet property="lblDistance" destination="1tR-JC-pyw" id="q4s-Ru-vLO"/>
19 <outlet property="lblPercent" destination="8Ru-Jc-Ouv" id="ZHn-Kt-0Qk"/> 19 <outlet property="lblPercent" destination="8Ru-Jc-Ouv" id="ZHn-Kt-0Qk"/>
20 <outlet property="lblRemaining" destination="1NH-b3-ST8" id="hFc-q9-b0h"/> 20 <outlet property="lblRemaining" destination="1NH-b3-ST8" id="hFc-q9-b0h"/>
21 <outlet property="lblStep" destination="0pf-fX-QXT" id="jK4-9Y-89Q"/> 21 <outlet property="lblStep" destination="0pf-fX-QXT" id="jK4-9Y-89Q"/>
22 <outlet property="lblTime" destination="PfZ-7x-LAR" id="NQv-fs-rl7"/> 22 <outlet property="lblTime" destination="PfZ-7x-LAR" id="NQv-fs-rl7"/>
23 <outlet property="scrollView" destination="rey-N3-l8b" id="s3w-fi-n5l"/> 23 <outlet property="scrollView" destination="rey-N3-l8b" id="s3w-fi-n5l"/>
24 <outlet property="tableBase" destination="FXQ-4O-sRc" id="UHy-Nk-f7u"/> 24 <outlet property="tableBase" destination="FXQ-4O-sRc" id="UHy-Nk-f7u"/>
25 <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> 25 <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
26 <outlet property="viewBarChart" destination="VqD-Y3-cYQ" id="RdJ-G5-pPy"/> 26 <outlet property="viewBarChart" destination="VqD-Y3-cYQ" id="RdJ-G5-pPy"/>
27 <outlet property="viewCollectionMode" destination="BVv-qD-EHM" id="A6n-32-oxg"/> 27 <outlet property="viewCollectionMode" destination="BVv-qD-EHM" id="A6n-32-oxg"/>
28 <outlet property="viewCollectionShare" destination="Iw2-nW-e7g" id="LW3-j0-yEY"/> 28 <outlet property="viewCollectionShare" destination="Iw2-nW-e7g" id="LW3-j0-yEY"/>
29 <outlet property="viewCollectionType" destination="yxY-4d-tB6" id="K1D-Gc-kWV"/> 29 <outlet property="viewCollectionType" destination="yxY-4d-tB6" id="K1D-Gc-kWV"/>
30 </connections> 30 </connections>
31 </placeholder> 31 </placeholder>
32 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> 32 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
33 <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> 33 <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
34 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> 34 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
35 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> 35 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
36 <subviews> 36 <subviews>
37 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="clL-JG-rbd" userLabel="ViewHeader"> 37 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="clL-JG-rbd" userLabel="ViewHeader">
38 <rect key="frame" x="0.0" y="0.0" width="375" height="46"/> 38 <rect key="frame" x="0.0" y="0.0" width="375" height="46"/>
39 <subviews> 39 <subviews>
40 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="履歴" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ht6-rd-JXF" customClass="AutoTransLabel"> 40 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="履歴" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ht6-rd-JXF" customClass="AutoTransLabel">
41 <rect key="frame" x="0.0" y="0.0" width="375" height="46"/> 41 <rect key="frame" x="0.0" y="0.0" width="375" height="46"/>
42 <fontDescription key="fontDescription" type="system" pointSize="17"/> 42 <fontDescription key="fontDescription" type="system" pointSize="17"/>
43 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 43 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
44 <nil key="highlightedColor"/> 44 <nil key="highlightedColor"/>
45 <userDefinedRuntimeAttributes> 45 <userDefinedRuntimeAttributes>
46 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title"/> 46 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title"/>
47 </userDefinedRuntimeAttributes> 47 </userDefinedRuntimeAttributes>
48 </label> 48 </label>
49 <button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ytc-zM-ZGC"> 49 <button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ytc-zM-ZGC">
50 <rect key="frame" x="0.0" y="5" width="70" height="36"/> 50 <rect key="frame" x="0.0" y="5" width="70" height="36"/>
51 <constraints> 51 <constraints>
52 <constraint firstAttribute="width" constant="70" id="xAE-oP-WEf"/> 52 <constraint firstAttribute="width" constant="70" id="xAE-oP-WEf"/>
53 </constraints> 53 </constraints>
54 <state key="normal" image="today_back_button"/> 54 <state key="normal" image="today_back_button"/>
55 </button> 55 </button>
56 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="CFx-sO-MAH"> 56 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="CFx-sO-MAH">
57 <rect key="frame" x="330" y="0.0" width="45" height="46"/> 57 <rect key="frame" x="330" y="0.0" width="45" height="46"/>
58 <constraints> 58 <constraints>
59 <constraint firstAttribute="width" constant="45" id="V0g-Ii-pNQ"/> 59 <constraint firstAttribute="width" constant="45" id="V0g-Ii-pNQ"/>
60 </constraints> 60 </constraints>
61 <state key="normal" image="icon_menu"/> 61 <state key="normal" image="icon_menu"/>
62 </button> 62 </button>
63 </subviews> 63 </subviews>
64 <color key="backgroundColor" red="0.098039215686274508" green="0.098039215686274508" blue="0.098039215686274508" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> 64 <color key="backgroundColor" red="0.098039215686274508" green="0.098039215686274508" blue="0.098039215686274508" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
65 <constraints> 65 <constraints>
66 <constraint firstAttribute="trailing" secondItem="Ht6-rd-JXF" secondAttribute="trailing" id="Fr9-Yj-q5e"/> 66 <constraint firstAttribute="trailing" secondItem="Ht6-rd-JXF" secondAttribute="trailing" id="Fr9-Yj-q5e"/>
67 <constraint firstItem="ytc-zM-ZGC" firstAttribute="leading" secondItem="clL-JG-rbd" secondAttribute="leading" id="LDb-Pq-Z5k"/> 67 <constraint firstItem="ytc-zM-ZGC" firstAttribute="leading" secondItem="clL-JG-rbd" secondAttribute="leading" id="LDb-Pq-Z5k"/>
68 <constraint firstAttribute="trailing" secondItem="CFx-sO-MAH" secondAttribute="trailing" id="PTh-vI-2DI"/> 68 <constraint firstAttribute="trailing" secondItem="CFx-sO-MAH" secondAttribute="trailing" id="PTh-vI-2DI"/>
69 <constraint firstItem="Ht6-rd-JXF" firstAttribute="top" secondItem="clL-JG-rbd" secondAttribute="top" id="URG-nj-C2r"/> 69 <constraint firstItem="Ht6-rd-JXF" firstAttribute="top" secondItem="clL-JG-rbd" secondAttribute="top" id="URG-nj-C2r"/>
70 <constraint firstItem="CFx-sO-MAH" firstAttribute="top" secondItem="clL-JG-rbd" secondAttribute="top" id="Uxg-Wl-DlF"/> 70 <constraint firstItem="CFx-sO-MAH" firstAttribute="top" secondItem="clL-JG-rbd" secondAttribute="top" id="Uxg-Wl-DlF"/>
71 <constraint firstAttribute="bottom" secondItem="CFx-sO-MAH" secondAttribute="bottom" id="X9D-m3-QXF"/> 71 <constraint firstAttribute="bottom" secondItem="CFx-sO-MAH" secondAttribute="bottom" id="X9D-m3-QXF"/>
72 <constraint firstAttribute="bottom" secondItem="ytc-zM-ZGC" secondAttribute="bottom" constant="5" id="hWb-ga-1wm"/> 72 <constraint firstAttribute="bottom" secondItem="ytc-zM-ZGC" secondAttribute="bottom" constant="5" id="hWb-ga-1wm"/>
73 <constraint firstAttribute="bottom" secondItem="Ht6-rd-JXF" secondAttribute="bottom" id="iqI-Bi-QI1"/> 73 <constraint firstAttribute="bottom" secondItem="Ht6-rd-JXF" secondAttribute="bottom" id="iqI-Bi-QI1"/>
74 <constraint firstItem="Ht6-rd-JXF" firstAttribute="leading" secondItem="clL-JG-rbd" secondAttribute="leading" id="uzc-SO-7mw"/> 74 <constraint firstItem="Ht6-rd-JXF" firstAttribute="leading" secondItem="clL-JG-rbd" secondAttribute="leading" id="uzc-SO-7mw"/>
75 <constraint firstItem="ytc-zM-ZGC" firstAttribute="top" secondItem="clL-JG-rbd" secondAttribute="top" constant="5" id="vFt-FE-klC"/> 75 <constraint firstItem="ytc-zM-ZGC" firstAttribute="top" secondItem="clL-JG-rbd" secondAttribute="top" constant="5" id="vFt-FE-klC"/>
76 <constraint firstAttribute="height" constant="46" id="xGd-BD-bgs"/> 76 <constraint firstAttribute="height" constant="46" id="xGd-BD-bgs"/>
77 </constraints> 77 </constraints>
78 </view> 78 </view>
79 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cf1-lP-zbB" userLabel="ViewTime"> 79 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cf1-lP-zbB" userLabel="ViewTime">
80 <rect key="frame" x="10" y="46" width="355" height="35"/> 80 <rect key="frame" x="10" y="46" width="355" height="35"/>
81 <subviews> 81 <subviews>
82 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6T2-M9-9wV"> 82 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6T2-M9-9wV">
83 <rect key="frame" x="0.0" y="0.0" width="35" height="35"/> 83 <rect key="frame" x="0.0" y="0.0" width="35" height="35"/>
84 <constraints> 84 <constraints>
85 <constraint firstAttribute="width" secondItem="6T2-M9-9wV" secondAttribute="height" multiplier="1:1" id="RlM-6u-eer"/> 85 <constraint firstAttribute="width" secondItem="6T2-M9-9wV" secondAttribute="height" multiplier="1:1" id="RlM-6u-eer"/>
86 </constraints> 86 </constraints>
87 <state key="normal" backgroundImage="arrow_back"/> 87 <state key="normal" backgroundImage="arrow_back"/>
88 <connections> 88 <connections>
89 <action selector="clickBackward:" destination="-1" eventType="touchUpInside" id="pwN-yT-qyp"/> 89 <action selector="clickBackward:" destination="-1" eventType="touchUpInside" id="pwN-yT-qyp"/>
90 </connections> 90 </connections>
91 </button> 91 </button>
92 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Cwb-8M-pDi"> 92 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Cwb-8M-pDi">
93 <rect key="frame" x="320" y="0.0" width="35" height="35"/> 93 <rect key="frame" x="320" y="0.0" width="35" height="35"/>
94 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 94 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
95 <state key="normal" backgroundImage="arrow_next"/> 95 <state key="normal" backgroundImage="arrow_next"/>
96 <connections> 96 <connections>
97 <action selector="clickForward:" destination="-1" eventType="touchUpInside" id="1NC-km-Lfe"/> 97 <action selector="clickForward:" destination="-1" eventType="touchUpInside" id="1NC-km-Lfe"/>
98 </connections> 98 </connections>
99 </button> 99 </button>
100 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2017年1月1日 日曜日" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EM7-vA-s1e"> 100 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2017年1月1日 日曜日" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EM7-vA-s1e">
101 <rect key="frame" x="40" y="2" width="275" height="31"/> 101 <rect key="frame" x="40" y="2" width="275" height="31"/>
102 <fontDescription key="fontDescription" type="system" pointSize="17"/> 102 <fontDescription key="fontDescription" type="system" pointSize="15"/>
103 <nil key="textColor"/> 103 <nil key="textColor"/>
104 <nil key="highlightedColor"/> 104 <nil key="highlightedColor"/>
105 </label> 105 </label>
106 </subviews> 106 </subviews>
107 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 107 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
108 <constraints> 108 <constraints>
109 <constraint firstItem="Cwb-8M-pDi" firstAttribute="top" secondItem="Cf1-lP-zbB" secondAttribute="top" id="4Jr-r7-y6d"/> 109 <constraint firstItem="Cwb-8M-pDi" firstAttribute="top" secondItem="Cf1-lP-zbB" secondAttribute="top" id="4Jr-r7-y6d"/>
110 <constraint firstAttribute="bottom" secondItem="6T2-M9-9wV" secondAttribute="bottom" id="8bU-NI-m32"/> 110 <constraint firstAttribute="bottom" secondItem="6T2-M9-9wV" secondAttribute="bottom" id="8bU-NI-m32"/>
111 <constraint firstItem="EM7-vA-s1e" firstAttribute="leading" secondItem="6T2-M9-9wV" secondAttribute="trailing" constant="5" id="9G1-I6-nSV"/> 111 <constraint firstItem="EM7-vA-s1e" firstAttribute="leading" secondItem="6T2-M9-9wV" secondAttribute="trailing" constant="5" id="9G1-I6-nSV"/>
112 <constraint firstItem="EM7-vA-s1e" firstAttribute="top" secondItem="Cf1-lP-zbB" secondAttribute="top" constant="2" id="9Yk-sv-gkx"/> 112 <constraint firstItem="EM7-vA-s1e" firstAttribute="top" secondItem="Cf1-lP-zbB" secondAttribute="top" constant="2" id="9Yk-sv-gkx"/>
113 <constraint firstItem="Cwb-8M-pDi" firstAttribute="leading" secondItem="EM7-vA-s1e" secondAttribute="trailing" constant="5" id="JQI-18-cWP"/> 113 <constraint firstItem="Cwb-8M-pDi" firstAttribute="leading" secondItem="EM7-vA-s1e" secondAttribute="trailing" constant="5" id="JQI-18-cWP"/>
114 <constraint firstAttribute="height" constant="35" id="Pdg-IR-g8y"/> 114 <constraint firstAttribute="height" constant="35" id="Pdg-IR-g8y"/>
115 <constraint firstItem="6T2-M9-9wV" firstAttribute="leading" secondItem="Cf1-lP-zbB" secondAttribute="leading" id="Pgh-zZ-vrG"/> 115 <constraint firstItem="6T2-M9-9wV" firstAttribute="leading" secondItem="Cf1-lP-zbB" secondAttribute="leading" id="Pgh-zZ-vrG"/>
116 <constraint firstAttribute="bottom" secondItem="Cwb-8M-pDi" secondAttribute="bottom" id="WWs-Ey-osm"/> 116 <constraint firstAttribute="bottom" secondItem="Cwb-8M-pDi" secondAttribute="bottom" id="WWs-Ey-osm"/>
117 <constraint firstItem="Cwb-8M-pDi" firstAttribute="width" secondItem="Cwb-8M-pDi" secondAttribute="height" multiplier="1:1" id="YHa-MU-GKi"/> 117 <constraint firstItem="Cwb-8M-pDi" firstAttribute="width" secondItem="Cwb-8M-pDi" secondAttribute="height" multiplier="1:1" id="YHa-MU-GKi"/>
118 <constraint firstItem="6T2-M9-9wV" firstAttribute="top" secondItem="Cf1-lP-zbB" secondAttribute="top" id="fiM-o3-Us0"/> 118 <constraint firstItem="6T2-M9-9wV" firstAttribute="top" secondItem="Cf1-lP-zbB" secondAttribute="top" id="fiM-o3-Us0"/>
119 <constraint firstAttribute="trailing" secondItem="Cwb-8M-pDi" secondAttribute="trailing" id="oCE-RP-EmX"/> 119 <constraint firstAttribute="trailing" secondItem="Cwb-8M-pDi" secondAttribute="trailing" id="oCE-RP-EmX"/>
120 <constraint firstAttribute="bottom" secondItem="EM7-vA-s1e" secondAttribute="bottom" constant="2" id="oOd-ip-MZy"/> 120 <constraint firstAttribute="bottom" secondItem="EM7-vA-s1e" secondAttribute="bottom" constant="2" id="oOd-ip-MZy"/>
121 </constraints> 121 </constraints>
122 </view> 122 </view>
123 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yxY-4d-tB6" customClass="CollectionView"> 123 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yxY-4d-tB6" customClass="CollectionView">
124 <rect key="frame" x="2" y="96" width="371" height="40"/> 124 <rect key="frame" x="2" y="96" width="371" height="40"/>
125 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 125 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
126 <constraints> 126 <constraints>
127 <constraint firstAttribute="height" constant="40" id="U7Q-wa-CDi"/> 127 <constraint firstAttribute="height" constant="40" id="U7Q-wa-CDi"/>
128 </constraints> 128 </constraints>
129 </view> 129 </view>
130 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVv-qD-EHM" customClass="CollectionView"> 130 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVv-qD-EHM" customClass="CollectionView">
131 <rect key="frame" x="0.0" y="577" width="375" height="40"/> 131 <rect key="frame" x="0.0" y="577" width="375" height="40"/>
132 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 132 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
133 <constraints> 133 <constraints>
134 <constraint firstAttribute="height" constant="40" id="6wc-NQ-UAH"/> 134 <constraint firstAttribute="height" constant="40" id="6wc-NQ-UAH"/>
135 </constraints> 135 </constraints>
136 </view> 136 </view>
137 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FLa-rV-Aas" userLabel="ViewContent"> 137 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FLa-rV-Aas" userLabel="ViewContent">
138 <rect key="frame" x="0.0" y="151" width="375" height="421"/> 138 <rect key="frame" x="0.0" y="151" width="375" height="421"/>
139 <subviews> 139 <subviews>
140 <tableView clipsSubviews="YES" alpha="0.0" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="100" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="FXQ-4O-sRc"> 140 <tableView clipsSubviews="YES" alpha="0.0" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="100" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="FXQ-4O-sRc">
141 <rect key="frame" x="5" y="0.0" width="365" height="421"/> 141 <rect key="frame" x="5" y="0.0" width="365" height="421"/>
142 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 142 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
143 <connections> 143 <connections>
144 <outlet property="dataSource" destination="-1" id="GQy-lg-1Af"/> 144 <outlet property="dataSource" destination="-1" id="GQy-lg-1Af"/>
145 <outlet property="delegate" destination="-1" id="Jka-Ij-zNq"/> 145 <outlet property="delegate" destination="-1" id="Jka-Ij-zNq"/>
146 </connections> 146 </connections>
147 </tableView> 147 </tableView>
148 <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="rey-N3-l8b"> 148 <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="rey-N3-l8b">
149 <rect key="frame" x="0.0" y="0.0" width="375" height="421"/> 149 <rect key="frame" x="0.0" y="0.0" width="375" height="421"/>
150 <subviews> 150 <subviews>
151 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cam-ML-IEO"> 151 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cam-ML-IEO">
152 <rect key="frame" x="0.0" y="0.0" width="375" height="421"/> 152 <rect key="frame" x="0.0" y="0.0" width="375" height="421"/>
153 <subviews> 153 <subviews>
154 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Kzk-mN-AOf"> 154 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Kzk-mN-AOf">
155 <rect key="frame" x="20" y="30" width="120" height="120"/> 155 <rect key="frame" x="20" y="30" width="120" height="120"/>
156 <subviews> 156 <subviews>
157 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oWg-A8-aCr"> 157 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oWg-A8-aCr">
158 <rect key="frame" x="18" y="35" width="82" height="21"/> 158 <rect key="frame" x="18" y="35" width="82" height="21"/>
159 <constraints> 159 <constraints>
160 <constraint firstAttribute="height" constant="21" id="zOX-0d-IVv"/> 160 <constraint firstAttribute="height" constant="21" id="zOX-0d-IVv"/>
161 </constraints> 161 </constraints>
162 <fontDescription key="fontDescription" type="system" pointSize="17"/> 162 <fontDescription key="fontDescription" type="system" pointSize="17"/>
163 <nil key="textColor"/> 163 <nil key="textColor"/>
164 <nil key="highlightedColor"/> 164 <nil key="highlightedColor"/>
165 </label> 165 </label>
166 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kr7-S0-Fpl"> 166 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kr7-S0-Fpl">
167 <rect key="frame" x="20" y="61" width="80" height="42"/> 167 <rect key="frame" x="20" y="61" width="80" height="42"/>
168 <constraints> 168 <constraints>
169 <constraint firstAttribute="width" constant="80" id="IOc-sB-dA2"/> 169 <constraint firstAttribute="width" constant="80" id="IOc-sB-dA2"/>
170 <constraint firstAttribute="height" constant="42" id="zRP-Fu-qZ9"/> 170 <constraint firstAttribute="height" constant="42" id="zRP-Fu-qZ9"/>
171 </constraints> 171 </constraints>
172 <string key="text">目標まであと 172 <string key="text">目標まであと
173 0 stepです</string> 173 0 stepです</string>
174 <fontDescription key="fontDescription" type="system" pointSize="11"/> 174 <fontDescription key="fontDescription" type="system" pointSize="11"/>
175 <nil key="textColor"/> 175 <nil key="textColor"/>
176 <nil key="highlightedColor"/> 176 <nil key="highlightedColor"/>
177 </label> 177 </label>
178 </subviews> 178 </subviews>
179 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 179 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
180 <constraints> 180 <constraints>
181 <constraint firstItem="Kr7-S0-Fpl" firstAttribute="top" secondItem="oWg-A8-aCr" secondAttribute="bottom" constant="5" id="2KK-Lm-h74"/> 181 <constraint firstItem="Kr7-S0-Fpl" firstAttribute="top" secondItem="oWg-A8-aCr" secondAttribute="bottom" constant="5" id="2KK-Lm-h74"/>
182 <constraint firstItem="oWg-A8-aCr" firstAttribute="leading" secondItem="Kzk-mN-AOf" secondAttribute="leading" constant="18" id="CdG-qa-ud5"/> 182 <constraint firstItem="oWg-A8-aCr" firstAttribute="leading" secondItem="Kzk-mN-AOf" secondAttribute="leading" constant="18" id="CdG-qa-ud5"/>
183 <constraint firstAttribute="width" constant="120" id="E48-cC-dsc"/> 183 <constraint firstAttribute="width" constant="120" id="E48-cC-dsc"/>
184 <constraint firstAttribute="height" constant="120" id="SlY-sr-tR9"/> 184 <constraint firstAttribute="height" constant="120" id="SlY-sr-tR9"/>
185 <constraint firstItem="Kr7-S0-Fpl" firstAttribute="centerX" secondItem="Kzk-mN-AOf" secondAttribute="centerX" id="jJV-RH-pk1"/> 185 <constraint firstItem="Kr7-S0-Fpl" firstAttribute="centerX" secondItem="Kzk-mN-AOf" secondAttribute="centerX" id="jJV-RH-pk1"/>
186 <constraint firstItem="oWg-A8-aCr" firstAttribute="top" secondItem="Kzk-mN-AOf" secondAttribute="top" constant="35" id="oBl-zo-td5"/> 186 <constraint firstItem="oWg-A8-aCr" firstAttribute="top" secondItem="Kzk-mN-AOf" secondAttribute="top" constant="35" id="oBl-zo-td5"/>
187 <constraint firstAttribute="trailing" secondItem="oWg-A8-aCr" secondAttribute="trailing" constant="20" id="xgh-d4-jOF"/> 187 <constraint firstAttribute="trailing" secondItem="oWg-A8-aCr" secondAttribute="trailing" constant="20" id="xgh-d4-jOF"/>
188 </constraints> 188 </constraints>
189 <userDefinedRuntimeAttributes> 189 <userDefinedRuntimeAttributes>
190 <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> 190 <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
191 <integer key="value" value="60"/> 191 <integer key="value" value="60"/>
192 </userDefinedRuntimeAttribute> 192 </userDefinedRuntimeAttribute>
193 </userDefinedRuntimeAttributes> 193 </userDefinedRuntimeAttributes>
194 </view> 194 </view>
195 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4ix-HE-d9T"> 195 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4ix-HE-d9T">
196 <rect key="frame" x="148" y="30" width="219" height="120"/> 196 <rect key="frame" x="148" y="30" width="219" height="120"/>
197 <subviews> 197 <subviews>
198 <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"> 198 <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">
199 <rect key="frame" x="10" y="38" width="45" height="15"/> 199 <rect key="frame" x="10" y="38" width="45" height="15"/>
200 <constraints> 200 <constraints>
201 <constraint firstAttribute="width" constant="45" id="6Ce-YE-wbx"/> 201 <constraint firstAttribute="width" constant="45" id="6Ce-YE-wbx"/>
202 <constraint firstAttribute="height" constant="15" id="eFR-Ao-75U"/> 202 <constraint firstAttribute="height" constant="15" id="eFR-Ao-75U"/>
203 </constraints> 203 </constraints>
204 <fontDescription key="fontDescription" type="system" pointSize="12"/> 204 <fontDescription key="fontDescription" type="system" pointSize="12"/>
205 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 205 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
206 <nil key="highlightedColor"/> 206 <nil key="highlightedColor"/>
207 <userDefinedRuntimeAttributes> 207 <userDefinedRuntimeAttributes>
208 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.total"/> 208 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.total"/>
209 </userDefinedRuntimeAttributes> 209 </userDefinedRuntimeAttributes>
210 </label> 210 </label>
211 <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"> 211 <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">
212 <rect key="frame" x="10" y="53" width="45" height="15"/> 212 <rect key="frame" x="10" y="53" width="45" height="15"/>
213 <fontDescription key="fontDescription" type="system" pointSize="12"/> 213 <fontDescription key="fontDescription" type="system" pointSize="12"/>
214 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 214 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
215 <nil key="highlightedColor"/> 215 <nil key="highlightedColor"/>
216 <userDefinedRuntimeAttributes> 216 <userDefinedRuntimeAttributes>
217 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.remaining"/> 217 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.remaining"/>
218 </userDefinedRuntimeAttributes> 218 </userDefinedRuntimeAttributes>
219 </label> 219 </label>
220 <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"> 220 <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">
221 <rect key="frame" x="10" y="68" width="45" height="15"/> 221 <rect key="frame" x="10" y="68" width="45" height="15"/>
222 <fontDescription key="fontDescription" type="system" pointSize="12"/> 222 <fontDescription key="fontDescription" type="system" pointSize="12"/>
223 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 223 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
224 <nil key="highlightedColor"/> 224 <nil key="highlightedColor"/>
225 <userDefinedRuntimeAttributes> 225 <userDefinedRuntimeAttributes>
226 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.percent"/> 226 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.percent"/>
227 </userDefinedRuntimeAttributes> 227 </userDefinedRuntimeAttributes>
228 </label> 228 </label>
229 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0pf-fX-QXT"> 229 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0pf-fX-QXT">
230 <rect key="frame" x="63" y="38" width="118" height="15"/> 230 <rect key="frame" x="63" y="38" width="118" height="15"/>
231 <constraints> 231 <constraints>
232 <constraint firstAttribute="height" constant="15" id="Z6o-LI-Eu9"/> 232 <constraint firstAttribute="height" constant="15" id="Z6o-LI-Eu9"/>
233 </constraints> 233 </constraints>
234 <fontDescription key="fontDescription" type="system" pointSize="12"/> 234 <fontDescription key="fontDescription" type="system" pointSize="12"/>
235 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 235 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
236 <nil key="highlightedColor"/> 236 <nil key="highlightedColor"/>
237 </label> 237 </label>
238 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1NH-b3-ST8"> 238 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1NH-b3-ST8">
239 <rect key="frame" x="63" y="53" width="118" height="15"/> 239 <rect key="frame" x="63" y="53" width="118" height="15"/>
240 <fontDescription key="fontDescription" type="system" pointSize="12"/> 240 <fontDescription key="fontDescription" type="system" pointSize="12"/>
241 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 241 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
242 <nil key="highlightedColor"/> 242 <nil key="highlightedColor"/>
243 </label> 243 </label>
244 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 %" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8Ru-Jc-Ouv"> 244 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 %" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8Ru-Jc-Ouv">
245 <rect key="frame" x="63" y="68" width="118" height="15"/> 245 <rect key="frame" x="63" y="68" width="118" height="15"/>
246 <fontDescription key="fontDescription" type="system" pointSize="12"/> 246 <fontDescription key="fontDescription" type="system" pointSize="12"/>
247 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 247 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
248 <nil key="highlightedColor"/> 248 <nil key="highlightedColor"/>
249 </label> 249 </label>
250 </subviews> 250 </subviews>
251 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 251 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
252 <constraints> 252 <constraints>
253 <constraint firstItem="l0h-qA-2Ai" firstAttribute="top" secondItem="HOl-Tj-xiT" secondAttribute="bottom" id="0dv-3h-eHs"/> 253 <constraint firstItem="l0h-qA-2Ai" firstAttribute="top" secondItem="HOl-Tj-xiT" secondAttribute="bottom" id="0dv-3h-eHs"/>
254 <constraint firstItem="l0h-qA-2Ai" firstAttribute="leading" secondItem="YE6-wh-77T" secondAttribute="leading" id="7z3-ph-BM4"/> 254 <constraint firstItem="l0h-qA-2Ai" firstAttribute="leading" secondItem="YE6-wh-77T" secondAttribute="leading" id="7z3-ph-BM4"/>
255 <constraint firstItem="1NH-b3-ST8" firstAttribute="leading" secondItem="0pf-fX-QXT" secondAttribute="leading" id="ACu-BV-ieg"/> 255 <constraint firstItem="1NH-b3-ST8" firstAttribute="leading" secondItem="0pf-fX-QXT" secondAttribute="leading" id="ACu-BV-ieg"/>
256 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="top" secondItem="1NH-b3-ST8" secondAttribute="bottom" id="Abh-FK-4X7"/> 256 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="top" secondItem="1NH-b3-ST8" secondAttribute="bottom" id="Abh-FK-4X7"/>
257 <constraint firstItem="1NH-b3-ST8" firstAttribute="top" secondItem="0pf-fX-QXT" secondAttribute="bottom" id="B3I-n2-Oks"/> 257 <constraint firstItem="1NH-b3-ST8" firstAttribute="top" secondItem="0pf-fX-QXT" secondAttribute="bottom" id="B3I-n2-Oks"/>
258 <constraint firstItem="1NH-b3-ST8" firstAttribute="height" secondItem="0pf-fX-QXT" secondAttribute="height" id="BAn-7O-jBX"/> 258 <constraint firstItem="1NH-b3-ST8" firstAttribute="height" secondItem="0pf-fX-QXT" secondAttribute="height" id="BAn-7O-jBX"/>
259 <constraint firstItem="0pf-fX-QXT" firstAttribute="leading" secondItem="YE6-wh-77T" secondAttribute="trailing" constant="8" id="G20-xx-HEH"/> 259 <constraint firstItem="0pf-fX-QXT" firstAttribute="leading" secondItem="YE6-wh-77T" secondAttribute="trailing" constant="8" id="G20-xx-HEH"/>
260 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="leading" secondItem="0pf-fX-QXT" secondAttribute="leading" id="NIm-Zw-fnf"/> 260 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="leading" secondItem="0pf-fX-QXT" secondAttribute="leading" id="NIm-Zw-fnf"/>
261 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="height" secondItem="0pf-fX-QXT" secondAttribute="height" id="PdQ-qd-Sqc"/> 261 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="height" secondItem="0pf-fX-QXT" secondAttribute="height" id="PdQ-qd-Sqc"/>
262 <constraint firstItem="HOl-Tj-xiT" firstAttribute="width" secondItem="YE6-wh-77T" secondAttribute="width" id="WpC-o9-bDa"/> 262 <constraint firstItem="HOl-Tj-xiT" firstAttribute="width" secondItem="YE6-wh-77T" secondAttribute="width" id="WpC-o9-bDa"/>
263 <constraint firstItem="l0h-qA-2Ai" firstAttribute="height" secondItem="YE6-wh-77T" secondAttribute="height" id="bR8-Ki-lS1"/> 263 <constraint firstItem="l0h-qA-2Ai" firstAttribute="height" secondItem="YE6-wh-77T" secondAttribute="height" id="bR8-Ki-lS1"/>
264 <constraint firstItem="HOl-Tj-xiT" firstAttribute="height" secondItem="YE6-wh-77T" secondAttribute="height" id="c0u-hz-5O9"/> 264 <constraint firstItem="HOl-Tj-xiT" firstAttribute="height" secondItem="YE6-wh-77T" secondAttribute="height" id="c0u-hz-5O9"/>
265 <constraint firstItem="1NH-b3-ST8" firstAttribute="leading" secondItem="0pf-fX-QXT" secondAttribute="leading" id="chf-kb-ClX"/> 265 <constraint firstItem="1NH-b3-ST8" firstAttribute="leading" secondItem="0pf-fX-QXT" secondAttribute="leading" id="chf-kb-ClX"/>
266 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="leading" secondItem="0pf-fX-QXT" secondAttribute="leading" id="din-4T-V5w"/> 266 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="leading" secondItem="0pf-fX-QXT" secondAttribute="leading" id="din-4T-V5w"/>
267 <constraint firstItem="l0h-qA-2Ai" firstAttribute="width" secondItem="YE6-wh-77T" secondAttribute="width" id="eo0-xw-d1f"/> 267 <constraint firstItem="l0h-qA-2Ai" firstAttribute="width" secondItem="YE6-wh-77T" secondAttribute="width" id="eo0-xw-d1f"/>
268 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="width" secondItem="0pf-fX-QXT" secondAttribute="width" id="gjt-3e-Pkx"/> 268 <constraint firstItem="8Ru-Jc-Ouv" firstAttribute="width" secondItem="0pf-fX-QXT" secondAttribute="width" id="gjt-3e-Pkx"/>
269 <constraint firstItem="1NH-b3-ST8" firstAttribute="width" secondItem="0pf-fX-QXT" secondAttribute="width" id="kOM-6S-Amv"/> 269 <constraint firstItem="1NH-b3-ST8" firstAttribute="width" secondItem="0pf-fX-QXT" secondAttribute="width" id="kOM-6S-Amv"/>
270 <constraint firstItem="HOl-Tj-xiT" firstAttribute="leading" secondItem="YE6-wh-77T" secondAttribute="leading" id="oOc-TB-k4j"/> 270 <constraint firstItem="HOl-Tj-xiT" firstAttribute="leading" secondItem="YE6-wh-77T" secondAttribute="leading" id="oOc-TB-k4j"/>
271 <constraint firstItem="1NH-b3-ST8" firstAttribute="centerY" secondItem="HOl-Tj-xiT" secondAttribute="centerY" id="pGW-dw-56G"/> 271 <constraint firstItem="1NH-b3-ST8" firstAttribute="centerY" secondItem="HOl-Tj-xiT" secondAttribute="centerY" id="pGW-dw-56G"/>
272 <constraint firstItem="HOl-Tj-xiT" firstAttribute="top" secondItem="YE6-wh-77T" secondAttribute="bottom" id="s6n-mU-Sp6"/> 272 <constraint firstItem="HOl-Tj-xiT" firstAttribute="top" secondItem="YE6-wh-77T" secondAttribute="bottom" id="s6n-mU-Sp6"/>
273 <constraint firstItem="HOl-Tj-xiT" firstAttribute="centerY" secondItem="4ix-HE-d9T" secondAttribute="centerY" id="vB9-RR-pao"/> 273 <constraint firstItem="HOl-Tj-xiT" firstAttribute="centerY" secondItem="4ix-HE-d9T" secondAttribute="centerY" id="vB9-RR-pao"/>
274 <constraint firstAttribute="trailing" secondItem="0pf-fX-QXT" secondAttribute="trailing" constant="38" id="xiP-fg-Ozi"/> 274 <constraint firstAttribute="trailing" secondItem="0pf-fX-QXT" secondAttribute="trailing" constant="38" id="xiP-fg-Ozi"/>
275 <constraint firstItem="YE6-wh-77T" firstAttribute="leading" secondItem="4ix-HE-d9T" secondAttribute="leading" constant="10" id="xj6-In-ihz"/> 275 <constraint firstItem="YE6-wh-77T" firstAttribute="leading" secondItem="4ix-HE-d9T" secondAttribute="leading" constant="10" id="xj6-In-ihz"/>
276 </constraints> 276 </constraints>
277 </view> 277 </view>
278 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iEh-Ze-suq"> 278 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iEh-Ze-suq">
279 <rect key="frame" x="20" y="158" width="335" height="35"/> 279 <rect key="frame" x="20" y="158" width="335" height="35"/>
280 <subviews> 280 <subviews>
281 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UwA-5Q-gdv"> 281 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UwA-5Q-gdv">
282 <rect key="frame" x="0.0" y="0.0" width="111.5" height="35"/> 282 <rect key="frame" x="0.0" y="0.0" width="111.5" height="35"/>
283 <subviews> 283 <subviews>
284 <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"> 284 <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">
285 <rect key="frame" x="0.0" y="0.0" width="111.5" height="18"/> 285 <rect key="frame" x="0.0" y="0.0" width="111.5" height="18"/>
286 <constraints> 286 <constraints>
287 <constraint firstAttribute="height" constant="18" id="Ywp-RA-6am"/> 287 <constraint firstAttribute="height" constant="18" id="Ywp-RA-6am"/>
288 </constraints> 288 </constraints>
289 <fontDescription key="fontDescription" type="system" pointSize="12"/> 289 <fontDescription key="fontDescription" type="system" pointSize="12"/>
290 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 290 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
291 <nil key="highlightedColor"/> 291 <nil key="highlightedColor"/>
292 <userDefinedRuntimeAttributes> 292 <userDefinedRuntimeAttributes>
293 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.calories"/> 293 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.calories"/>
294 </userDefinedRuntimeAttributes> 294 </userDefinedRuntimeAttributes>
295 </label> 295 </label>
296 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 kcal" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dAE-C8-QLr"> 296 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 kcal" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dAE-C8-QLr">
297 <rect key="frame" x="0.0" y="17" width="111.5" height="18"/> 297 <rect key="frame" x="0.0" y="17" width="111.5" height="18"/>
298 <constraints> 298 <constraints>
299 <constraint firstAttribute="height" constant="18" id="r0d-xi-3u7"/> 299 <constraint firstAttribute="height" constant="18" id="r0d-xi-3u7"/>
300 </constraints> 300 </constraints>
301 <fontDescription key="fontDescription" type="system" pointSize="12"/> 301 <fontDescription key="fontDescription" type="system" pointSize="12"/>
302 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 302 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
303 <nil key="highlightedColor"/> 303 <nil key="highlightedColor"/>
304 </label> 304 </label>
305 </subviews> 305 </subviews>
306 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 306 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
307 <constraints> 307 <constraints>
308 <constraint firstItem="zRU-L6-Ed4" firstAttribute="leading" secondItem="UwA-5Q-gdv" secondAttribute="leading" id="Zbe-7f-cuR"/> 308 <constraint firstItem="zRU-L6-Ed4" firstAttribute="leading" secondItem="UwA-5Q-gdv" secondAttribute="leading" id="Zbe-7f-cuR"/>
309 <constraint firstAttribute="bottom" secondItem="dAE-C8-QLr" secondAttribute="bottom" id="aZH-zh-M1V"/> 309 <constraint firstAttribute="bottom" secondItem="dAE-C8-QLr" secondAttribute="bottom" id="aZH-zh-M1V"/>
310 <constraint firstItem="zRU-L6-Ed4" firstAttribute="top" secondItem="UwA-5Q-gdv" secondAttribute="top" id="bsw-KU-Tcu"/> 310 <constraint firstItem="zRU-L6-Ed4" firstAttribute="top" secondItem="UwA-5Q-gdv" secondAttribute="top" id="bsw-KU-Tcu"/>
311 <constraint firstAttribute="trailing" secondItem="zRU-L6-Ed4" secondAttribute="trailing" id="iMB-ch-u4B"/> 311 <constraint firstAttribute="trailing" secondItem="zRU-L6-Ed4" secondAttribute="trailing" id="iMB-ch-u4B"/>
312 <constraint firstItem="dAE-C8-QLr" firstAttribute="leading" secondItem="UwA-5Q-gdv" secondAttribute="leading" id="qNu-WH-Jjj"/> 312 <constraint firstItem="dAE-C8-QLr" firstAttribute="leading" secondItem="UwA-5Q-gdv" secondAttribute="leading" id="qNu-WH-Jjj"/>
313 <constraint firstAttribute="trailing" secondItem="dAE-C8-QLr" secondAttribute="trailing" id="wRF-1x-XC1"/> 313 <constraint firstAttribute="trailing" secondItem="dAE-C8-QLr" secondAttribute="trailing" id="wRF-1x-XC1"/>
314 </constraints> 314 </constraints>
315 </view> 315 </view>
316 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVs-KG-fDF"> 316 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVs-KG-fDF">
317 <rect key="frame" x="111.5" y="0.0" width="112" height="35"/> 317 <rect key="frame" x="111.5" y="0.0" width="112" height="35"/>
318 <subviews> 318 <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="XGt-pc-sd7" customClass="AutoTransLabel"> 319 <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">
320 <rect key="frame" x="0.0" y="0.0" width="112" height="18"/> 320 <rect key="frame" x="0.0" y="0.0" width="112" height="18"/>
321 <constraints> 321 <constraints>
322 <constraint firstAttribute="height" constant="18" id="tct-pY-7wo"/> 322 <constraint firstAttribute="height" constant="18" id="tct-pY-7wo"/>
323 </constraints> 323 </constraints>
324 <fontDescription key="fontDescription" type="system" pointSize="12"/> 324 <fontDescription key="fontDescription" type="system" pointSize="12"/>
325 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 325 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
326 <nil key="highlightedColor"/> 326 <nil key="highlightedColor"/>
327 <userDefinedRuntimeAttributes> 327 <userDefinedRuntimeAttributes>
328 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.distance"/> 328 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.distance"/>
329 </userDefinedRuntimeAttributes> 329 </userDefinedRuntimeAttributes>
330 </label> 330 </label>
331 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0.0 KM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1tR-JC-pyw"> 331 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0.0 KM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1tR-JC-pyw">
332 <rect key="frame" x="0.0" y="17" width="112" height="18"/> 332 <rect key="frame" x="0.0" y="17" width="112" height="18"/>
333 <constraints> 333 <constraints>
334 <constraint firstAttribute="height" constant="18" id="sNT-xl-BKH"/> 334 <constraint firstAttribute="height" constant="18" id="sNT-xl-BKH"/>
335 </constraints> 335 </constraints>
336 <fontDescription key="fontDescription" type="system" pointSize="12"/> 336 <fontDescription key="fontDescription" type="system" pointSize="12"/>
337 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 337 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
338 <nil key="highlightedColor"/> 338 <nil key="highlightedColor"/>
339 </label> 339 </label>
340 </subviews> 340 </subviews>
341 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 341 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
342 <constraints> 342 <constraints>
343 <constraint firstItem="XGt-pc-sd7" firstAttribute="leading" secondItem="BVs-KG-fDF" secondAttribute="leading" id="Bd8-ZX-shc"/> 343 <constraint firstItem="XGt-pc-sd7" firstAttribute="leading" secondItem="BVs-KG-fDF" secondAttribute="leading" id="Bd8-ZX-shc"/>
344 <constraint firstAttribute="trailing" secondItem="1tR-JC-pyw" secondAttribute="trailing" id="Mrw-gb-r3n"/> 344 <constraint firstAttribute="trailing" secondItem="1tR-JC-pyw" secondAttribute="trailing" id="Mrw-gb-r3n"/>
345 <constraint firstAttribute="trailing" secondItem="XGt-pc-sd7" secondAttribute="trailing" id="cTc-te-Pc1"/> 345 <constraint firstAttribute="trailing" secondItem="XGt-pc-sd7" secondAttribute="trailing" id="cTc-te-Pc1"/>
346 <constraint firstItem="XGt-pc-sd7" firstAttribute="top" secondItem="BVs-KG-fDF" secondAttribute="top" id="cs1-A7-e5C"/> 346 <constraint firstItem="XGt-pc-sd7" firstAttribute="top" secondItem="BVs-KG-fDF" secondAttribute="top" id="cs1-A7-e5C"/>
347 <constraint firstAttribute="bottom" secondItem="1tR-JC-pyw" secondAttribute="bottom" id="vsZ-FE-X5m"/> 347 <constraint firstAttribute="bottom" secondItem="1tR-JC-pyw" secondAttribute="bottom" id="vsZ-FE-X5m"/>
348 <constraint firstItem="1tR-JC-pyw" firstAttribute="leading" secondItem="BVs-KG-fDF" secondAttribute="leading" id="xOd-ZK-rZn"/> 348 <constraint firstItem="1tR-JC-pyw" firstAttribute="leading" secondItem="BVs-KG-fDF" secondAttribute="leading" id="xOd-ZK-rZn"/>
349 </constraints> 349 </constraints>
350 </view> 350 </view>
351 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="j5h-QD-Igf"> 351 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="j5h-QD-Igf">
352 <rect key="frame" x="223.5" y="0.0" width="111.5" height="35"/> 352 <rect key="frame" x="223.5" y="0.0" width="111.5" height="35"/>
353 <subviews> 353 <subviews>
354 <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"> 354 <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">
355 <rect key="frame" x="0.0" y="0.0" width="111.5" height="18"/> 355 <rect key="frame" x="0.0" y="0.0" width="111.5" height="18"/>
356 <constraints> 356 <constraints>
357 <constraint firstAttribute="height" constant="18" id="EVe-qW-qqp"/> 357 <constraint firstAttribute="height" constant="18" id="EVe-qW-qqp"/>
358 </constraints> 358 </constraints>
359 <fontDescription key="fontDescription" type="system" pointSize="12"/> 359 <fontDescription key="fontDescription" type="system" pointSize="12"/>
360 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 360 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
361 <nil key="highlightedColor"/> 361 <nil key="highlightedColor"/>
362 <userDefinedRuntimeAttributes> 362 <userDefinedRuntimeAttributes>
363 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.time"/> 363 <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.time"/>
364 </userDefinedRuntimeAttributes> 364 </userDefinedRuntimeAttributes>
365 </label> 365 </label>
366 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PfZ-7x-LAR"> 366 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PfZ-7x-LAR">
367 <rect key="frame" x="0.0" y="17" width="111.5" height="18"/> 367 <rect key="frame" x="0.0" y="17" width="111.5" height="18"/>
368 <constraints> 368 <constraints>
369 <constraint firstAttribute="height" constant="18" id="lno-Dx-ZNm"/> 369 <constraint firstAttribute="height" constant="18" id="lno-Dx-ZNm"/>
370 </constraints> 370 </constraints>
371 <fontDescription key="fontDescription" type="system" pointSize="12"/> 371 <fontDescription key="fontDescription" type="system" pointSize="12"/>
372 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 372 <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
373 <nil key="highlightedColor"/> 373 <nil key="highlightedColor"/>
374 </label> 374 </label>
375 </subviews> 375 </subviews>
376 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 376 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
377 <constraints> 377 <constraints>
378 <constraint firstAttribute="trailing" secondItem="PfZ-7x-LAR" secondAttribute="trailing" id="3Ir-mZ-xmI"/> 378 <constraint firstAttribute="trailing" secondItem="PfZ-7x-LAR" secondAttribute="trailing" id="3Ir-mZ-xmI"/>
379 <constraint firstItem="OEO-l8-Ibg" firstAttribute="leading" secondItem="j5h-QD-Igf" secondAttribute="leading" id="5oW-CQ-vWi"/> 379 <constraint firstItem="OEO-l8-Ibg" firstAttribute="leading" secondItem="j5h-QD-Igf" secondAttribute="leading" id="5oW-CQ-vWi"/>
380 <constraint firstItem="PfZ-7x-LAR" firstAttribute="leading" secondItem="j5h-QD-Igf" secondAttribute="leading" id="Qur-SO-10d"/> 380 <constraint firstItem="PfZ-7x-LAR" firstAttribute="leading" secondItem="j5h-QD-Igf" secondAttribute="leading" id="Qur-SO-10d"/>
381 <constraint firstAttribute="trailing" secondItem="OEO-l8-Ibg" secondAttribute="trailing" id="WQn-Gv-plQ"/> 381 <constraint firstAttribute="trailing" secondItem="OEO-l8-Ibg" secondAttribute="trailing" id="WQn-Gv-plQ"/>
382 <constraint firstItem="OEO-l8-Ibg" firstAttribute="top" secondItem="j5h-QD-Igf" secondAttribute="top" id="lt7-Qt-rBM"/> 382 <constraint firstItem="OEO-l8-Ibg" firstAttribute="top" secondItem="j5h-QD-Igf" secondAttribute="top" id="lt7-Qt-rBM"/>
383 <constraint firstAttribute="bottom" secondItem="PfZ-7x-LAR" secondAttribute="bottom" id="qcA-M9-NYS"/> 383 <constraint firstAttribute="bottom" secondItem="PfZ-7x-LAR" secondAttribute="bottom" id="qcA-M9-NYS"/>
384 </constraints> 384 </constraints>
385 </view> 385 </view>
386 </subviews> 386 </subviews>
387 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 387 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
388 <constraints> 388 <constraints>
389 <constraint firstAttribute="bottom" secondItem="j5h-QD-Igf" secondAttribute="bottom" id="IsO-UX-w9t"/> 389 <constraint firstAttribute="bottom" secondItem="j5h-QD-Igf" secondAttribute="bottom" id="IsO-UX-w9t"/>
390 <constraint firstItem="j5h-QD-Igf" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="top" id="Msr-oS-nFH"/> 390 <constraint firstItem="j5h-QD-Igf" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="top" id="Msr-oS-nFH"/>
391 <constraint firstItem="BVs-KG-fDF" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="top" id="Ohk-mJ-oCK"/> 391 <constraint firstItem="BVs-KG-fDF" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="top" id="Ohk-mJ-oCK"/>
392 <constraint firstItem="UwA-5Q-gdv" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="top" id="Pue-sC-wfB"/> 392 <constraint firstItem="UwA-5Q-gdv" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="top" id="Pue-sC-wfB"/>
393 <constraint firstAttribute="height" constant="35" id="WDe-uC-4Qb"/> 393 <constraint firstAttribute="height" constant="35" id="WDe-uC-4Qb"/>
394 <constraint firstItem="BVs-KG-fDF" firstAttribute="leading" secondItem="UwA-5Q-gdv" secondAttribute="trailing" id="f8Q-F0-hjc"/> 394 <constraint firstItem="BVs-KG-fDF" firstAttribute="leading" secondItem="UwA-5Q-gdv" secondAttribute="trailing" id="f8Q-F0-hjc"/>
395 <constraint firstItem="BVs-KG-fDF" firstAttribute="width" secondItem="UwA-5Q-gdv" secondAttribute="width" id="fdz-YH-1kJ"/> 395 <constraint firstItem="BVs-KG-fDF" firstAttribute="width" secondItem="UwA-5Q-gdv" secondAttribute="width" id="fdz-YH-1kJ"/>
396 <constraint firstAttribute="bottom" secondItem="UwA-5Q-gdv" secondAttribute="bottom" id="gxD-wy-TgL"/> 396 <constraint firstAttribute="bottom" secondItem="UwA-5Q-gdv" secondAttribute="bottom" id="gxD-wy-TgL"/>
397 <constraint firstItem="j5h-QD-Igf" firstAttribute="width" secondItem="UwA-5Q-gdv" secondAttribute="width" id="i3o-n4-fZN"/> 397 <constraint firstItem="j5h-QD-Igf" firstAttribute="width" secondItem="UwA-5Q-gdv" secondAttribute="width" id="i3o-n4-fZN"/>
398 <constraint firstAttribute="trailing" secondItem="j5h-QD-Igf" secondAttribute="trailing" id="nT6-nS-H9z"/> 398 <constraint firstAttribute="trailing" secondItem="j5h-QD-Igf" secondAttribute="trailing" id="nT6-nS-H9z"/>
399 <constraint firstAttribute="bottom" secondItem="BVs-KG-fDF" secondAttribute="bottom" id="nqB-N3-F3F"/> 399 <constraint firstAttribute="bottom" secondItem="BVs-KG-fDF" secondAttribute="bottom" id="nqB-N3-F3F"/>
400 <constraint firstItem="UwA-5Q-gdv" firstAttribute="leading" secondItem="iEh-Ze-suq" secondAttribute="leading" id="oV9-IH-tYC"/> 400 <constraint firstItem="UwA-5Q-gdv" firstAttribute="leading" secondItem="iEh-Ze-suq" secondAttribute="leading" id="oV9-IH-tYC"/>
401 <constraint firstItem="j5h-QD-Igf" firstAttribute="leading" secondItem="BVs-KG-fDF" secondAttribute="trailing" id="zOb-WE-3CI"/> 401 <constraint firstItem="j5h-QD-Igf" firstAttribute="leading" secondItem="BVs-KG-fDF" secondAttribute="trailing" id="zOb-WE-3CI"/>
402 </constraints> 402 </constraints>
403 </view> 403 </view>
404 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VqD-Y3-cYQ" customClass="BarChartView" customModule="Charts"> 404 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VqD-Y3-cYQ" customClass="BarChartView" customModule="Charts">
405 <rect key="frame" x="0.0" y="201" width="375" height="100"/> 405 <rect key="frame" x="0.0" y="201" width="375" height="100"/>
406 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 406 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
407 <constraints> 407 <constraints>
408 <constraint firstAttribute="height" constant="100" id="aQR-hf-MhR"/> 408 <constraint firstAttribute="height" constant="100" id="aQR-hf-MhR"/>
409 </constraints> 409 </constraints>
410 </view> 410 </view>
411 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Iw2-nW-e7g" customClass="CollectionView"> 411 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Iw2-nW-e7g" customClass="CollectionView">
412 <rect key="frame" x="20" y="316" width="335" height="50"/> 412 <rect key="frame" x="20" y="316" width="335" height="50"/>
413 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 413 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
414 <constraints> 414 <constraints>
415 <constraint firstAttribute="height" constant="50" id="Yzh-hD-r0n"/> 415 <constraint firstAttribute="height" constant="50" id="Yzh-hD-r0n"/>
416 </constraints> 416 </constraints>
417 </view> 417 </view>
418 </subviews> 418 </subviews>
419 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 419 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
420 <constraints> 420 <constraints>
421 <constraint firstItem="VqD-Y3-cYQ" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="bottom" constant="8" id="0BA-6p-JLT"/> 421 <constraint firstItem="VqD-Y3-cYQ" firstAttribute="top" secondItem="iEh-Ze-suq" secondAttribute="bottom" constant="8" id="0BA-6p-JLT"/>
422 <constraint firstItem="Iw2-nW-e7g" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="2lH-sF-Mp0"/> 422 <constraint firstItem="Iw2-nW-e7g" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="2lH-sF-Mp0"/>
423 <constraint firstItem="iEh-Ze-suq" firstAttribute="top" secondItem="4ix-HE-d9T" secondAttribute="bottom" constant="8" id="9Sm-IQ-feL"/> 423 <constraint firstItem="iEh-Ze-suq" firstAttribute="top" secondItem="4ix-HE-d9T" secondAttribute="bottom" constant="8" id="9Sm-IQ-feL"/>
424 <constraint firstItem="VqD-Y3-cYQ" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" id="Gbd-bD-rFf"/> 424 <constraint firstItem="VqD-Y3-cYQ" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" id="Gbd-bD-rFf"/>
425 <constraint firstItem="4ix-HE-d9T" firstAttribute="top" secondItem="Cam-ML-IEO" secondAttribute="top" constant="30" id="JyQ-KD-MhR"/> 425 <constraint firstItem="4ix-HE-d9T" firstAttribute="top" secondItem="Cam-ML-IEO" secondAttribute="top" constant="30" id="JyQ-KD-MhR"/>
426 <constraint firstAttribute="trailing" secondItem="iEh-Ze-suq" secondAttribute="trailing" constant="20" id="RcZ-yN-56e"/> 426 <constraint firstAttribute="trailing" secondItem="iEh-Ze-suq" secondAttribute="trailing" constant="20" id="RcZ-yN-56e"/>
427 <constraint firstAttribute="trailing" secondItem="Iw2-nW-e7g" secondAttribute="trailing" constant="20" id="Xso-Or-Fgf"/> 427 <constraint firstAttribute="trailing" secondItem="Iw2-nW-e7g" secondAttribute="trailing" constant="20" id="Xso-Or-Fgf"/>
428 <constraint firstItem="Kzk-mN-AOf" firstAttribute="top" secondItem="Cam-ML-IEO" secondAttribute="top" constant="30" id="YzU-Mb-veC"/> 428 <constraint firstItem="Kzk-mN-AOf" firstAttribute="top" secondItem="Cam-ML-IEO" secondAttribute="top" constant="30" id="YzU-Mb-veC"/>
429 <constraint firstAttribute="trailing" secondItem="4ix-HE-d9T" secondAttribute="trailing" constant="8" id="del-xz-Tos"/> 429 <constraint firstAttribute="trailing" secondItem="4ix-HE-d9T" secondAttribute="trailing" constant="8" id="del-xz-Tos"/>
430 <constraint firstItem="4ix-HE-d9T" firstAttribute="height" secondItem="Kzk-mN-AOf" secondAttribute="height" id="duV-wT-9wp"/> 430 <constraint firstItem="4ix-HE-d9T" firstAttribute="height" secondItem="Kzk-mN-AOf" secondAttribute="height" id="duV-wT-9wp"/>
431 <constraint firstItem="Iw2-nW-e7g" firstAttribute="top" secondItem="VqD-Y3-cYQ" secondAttribute="bottom" constant="15" id="ekR-kS-L5v"/> 431 <constraint firstItem="Iw2-nW-e7g" firstAttribute="top" secondItem="VqD-Y3-cYQ" secondAttribute="bottom" constant="15" id="ekR-kS-L5v"/>
432 <constraint firstItem="Kzk-mN-AOf" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="hFq-WM-gLq"/> 432 <constraint firstItem="Kzk-mN-AOf" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="hFq-WM-gLq"/>
433 <constraint firstItem="4ix-HE-d9T" firstAttribute="leading" secondItem="Kzk-mN-AOf" secondAttribute="trailing" constant="8" id="hzO-hA-cNG"/> 433 <constraint firstItem="4ix-HE-d9T" firstAttribute="leading" secondItem="Kzk-mN-AOf" secondAttribute="trailing" constant="8" id="hzO-hA-cNG"/>
434 <constraint firstAttribute="trailing" secondItem="VqD-Y3-cYQ" secondAttribute="trailing" id="ptF-2O-CNR"/> 434 <constraint firstAttribute="trailing" secondItem="VqD-Y3-cYQ" secondAttribute="trailing" id="ptF-2O-CNR"/>
435 <constraint firstItem="iEh-Ze-suq" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="u5o-P4-qkL"/> 435 <constraint firstItem="iEh-Ze-suq" firstAttribute="leading" secondItem="Cam-ML-IEO" secondAttribute="leading" constant="20" id="u5o-P4-qkL"/>
436 </constraints> 436 </constraints>
437 </view> 437 </view>
438 </subviews> 438 </subviews>
439 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 439 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
440 <constraints> 440 <constraints>
441 <constraint firstItem="Cam-ML-IEO" firstAttribute="centerY" secondItem="rey-N3-l8b" secondAttribute="centerY" id="0WD-1q-SWm"/> 441 <constraint firstItem="Cam-ML-IEO" firstAttribute="centerY" secondItem="rey-N3-l8b" secondAttribute="centerY" id="0WD-1q-SWm"/>
442 <constraint firstItem="Cam-ML-IEO" firstAttribute="width" secondItem="rey-N3-l8b" secondAttribute="width" id="LbF-3h-cxa"/> 442 <constraint firstItem="Cam-ML-IEO" firstAttribute="width" secondItem="rey-N3-l8b" secondAttribute="width" id="LbF-3h-cxa"/>
443 <constraint firstAttribute="trailing" secondItem="Cam-ML-IEO" secondAttribute="trailing" id="UHb-6d-wF8"/> 443 <constraint firstAttribute="trailing" secondItem="Cam-ML-IEO" secondAttribute="trailing" id="UHb-6d-wF8"/>
444 <constraint firstItem="Cam-ML-IEO" firstAttribute="leading" secondItem="rey-N3-l8b" secondAttribute="leading" id="Y4U-kD-V28"/> 444 <constraint firstItem="Cam-ML-IEO" firstAttribute="leading" secondItem="rey-N3-l8b" secondAttribute="leading" id="Y4U-kD-V28"/>
445 <constraint firstItem="Cam-ML-IEO" firstAttribute="top" secondItem="rey-N3-l8b" secondAttribute="top" id="ohS-iH-IIM"/> 445 <constraint firstItem="Cam-ML-IEO" firstAttribute="top" secondItem="rey-N3-l8b" secondAttribute="top" id="ohS-iH-IIM"/>
446 <constraint firstAttribute="bottom" secondItem="Cam-ML-IEO" secondAttribute="bottom" id="th8-dH-zv1"/> 446 <constraint firstAttribute="bottom" secondItem="Cam-ML-IEO" secondAttribute="bottom" id="th8-dH-zv1"/>
447 </constraints> 447 </constraints>
448 <connections> 448 <connections>
449 <outlet property="delegate" destination="-1" id="3Fl-Qy-gjm"/> 449 <outlet property="delegate" destination="-1" id="3Fl-Qy-gjm"/>
450 </connections> 450 </connections>
451 </scrollView> 451 </scrollView>
452 </subviews> 452 </subviews>
453 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> 453 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
454 <constraints> 454 <constraints>
455 <constraint firstAttribute="trailing" secondItem="FXQ-4O-sRc" secondAttribute="trailing" constant="5" id="5y0-NC-rHp"/> 455 <constraint firstAttribute="trailing" secondItem="FXQ-4O-sRc" secondAttribute="trailing" constant="5" id="5y0-NC-rHp"/>
456 <constraint firstItem="FXQ-4O-sRc" firstAttribute="leading" secondItem="FLa-rV-Aas" secondAttribute="leading" constant="5" id="C0U-21-SKl"/> 456 <constraint firstItem="FXQ-4O-sRc" firstAttribute="leading" secondItem="FLa-rV-Aas" secondAttribute="leading" constant="5" id="C0U-21-SKl"/>
457 <constraint firstItem="FXQ-4O-sRc" firstAttribute="top" secondItem="FLa-rV-Aas" secondAttribute="top" id="CB0-VD-h5m"/> 457 <constraint firstItem="FXQ-4O-sRc" firstAttribute="top" secondItem="FLa-rV-Aas" secondAttribute="top" id="CB0-VD-h5m"/>
458 <constraint firstAttribute="bottom" secondItem="FXQ-4O-sRc" secondAttribute="bottom" id="FbP-FY-h1E"/> 458 <constraint firstAttribute="bottom" secondItem="FXQ-4O-sRc" secondAttribute="bottom" id="FbP-FY-h1E"/>
459 <constraint firstAttribute="trailing" secondItem="rey-N3-l8b" secondAttribute="trailing" id="KFD-f5-xci"/> 459 <constraint firstAttribute="trailing" secondItem="rey-N3-l8b" secondAttribute="trailing" id="KFD-f5-xci"/>
460 <constraint firstItem="rey-N3-l8b" firstAttribute="top" secondItem="FLa-rV-Aas" secondAttribute="top" id="SpB-31-H3a"/> 460 <constraint firstItem="rey-N3-l8b" firstAttribute="top" secondItem="FLa-rV-Aas" secondAttribute="top" id="SpB-31-H3a"/>
461 <constraint firstItem="rey-N3-l8b" firstAttribute="leading" secondItem="FLa-rV-Aas" secondAttribute="leading" id="YvS-I2-8Dg"/> 461 <constraint firstItem="rey-N3-l8b" firstAttribute="leading" secondItem="FLa-rV-Aas" secondAttribute="leading" id="YvS-I2-8Dg"/>
462 <constraint firstAttribute="bottom" secondItem="rey-N3-l8b" secondAttribute="bottom" id="enX-7g-Eib"/> 462 <constraint firstAttribute="bottom" secondItem="rey-N3-l8b" secondAttribute="bottom" id="enX-7g-Eib"/>
463 </constraints> 463 </constraints>
464 <connections> 464 <connections>
465 <outletCollection property="gestureRecognizers" destination="Qjg-St-rCc" appends="YES" id="egt-sX-aBC"/> 465 <outletCollection property="gestureRecognizers" destination="Qjg-St-rCc" appends="YES" id="egt-sX-aBC"/>
466 <outletCollection property="gestureRecognizers" destination="VSZ-i0-Jhb" appends="YES" id="UKr-c3-9pp"/> 466 <outletCollection property="gestureRecognizers" destination="VSZ-i0-Jhb" appends="YES" id="UKr-c3-9pp"/>
467 </connections> 467 </connections>
468 </view> 468 </view>
469 </subviews> 469 </subviews>
470 <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> 470 <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
471 <gestureRecognizers/> 471 <gestureRecognizers/>
472 <constraints> 472 <constraints>
473 <constraint firstAttribute="trailing" secondItem="Cf1-lP-zbB" secondAttribute="trailing" constant="10" id="20C-UL-MCu"/> 473 <constraint firstAttribute="trailing" secondItem="Cf1-lP-zbB" secondAttribute="trailing" constant="10" id="20C-UL-MCu"/>
474 <constraint firstItem="clL-JG-rbd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="3tf-ab-v41"/> 474 <constraint firstItem="clL-JG-rbd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="3tf-ab-v41"/>
475 <constraint firstItem="Cf1-lP-zbB" firstAttribute="top" secondItem="clL-JG-rbd" secondAttribute="bottom" id="5vy-x5-G38"/> 475 <constraint firstItem="Cf1-lP-zbB" firstAttribute="top" secondItem="clL-JG-rbd" secondAttribute="bottom" id="5vy-x5-G38"/>
476 <constraint firstItem="Cf1-lP-zbB" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="10" id="974-wJ-aRb"/> 476 <constraint firstItem="Cf1-lP-zbB" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="10" id="974-wJ-aRb"/>
477 <constraint firstItem="yxY-4d-tB6" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="2" id="Jqg-nE-6dv"/> 477 <constraint firstItem="yxY-4d-tB6" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="2" id="Jqg-nE-6dv"/>
478 <constraint firstAttribute="trailing" secondItem="BVv-qD-EHM" secondAttribute="trailing" id="MCi-Tl-hSp"/> 478 <constraint firstAttribute="trailing" secondItem="BVv-qD-EHM" secondAttribute="trailing" id="MCi-Tl-hSp"/>
479 <constraint firstAttribute="trailing" secondItem="yxY-4d-tB6" secondAttribute="trailing" constant="2" id="Qs5-ky-nmB"/> 479 <constraint firstAttribute="trailing" secondItem="yxY-4d-tB6" secondAttribute="trailing" constant="2" id="Qs5-ky-nmB"/>
480 <constraint firstAttribute="bottom" secondItem="BVv-qD-EHM" secondAttribute="bottom" constant="50" id="SbT-PG-8MJ"/> 480 <constraint firstAttribute="bottom" secondItem="BVv-qD-EHM" secondAttribute="bottom" constant="50" id="SbT-PG-8MJ"/>
481 <constraint firstItem="BVv-qD-EHM" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="SqH-AA-Z2K"/> 481 <constraint firstItem="BVv-qD-EHM" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="SqH-AA-Z2K"/>
482 <constraint firstItem="FLa-rV-Aas" firstAttribute="top" secondItem="yxY-4d-tB6" secondAttribute="bottom" constant="15" id="cWw-RX-1Kp"/> 482 <constraint firstItem="FLa-rV-Aas" firstAttribute="top" secondItem="yxY-4d-tB6" secondAttribute="bottom" constant="15" id="cWw-RX-1Kp"/>
483 <constraint firstItem="yxY-4d-tB6" firstAttribute="top" secondItem="Cf1-lP-zbB" secondAttribute="bottom" constant="15" id="dSN-ey-gQ7"/> 483 <constraint firstItem="yxY-4d-tB6" firstAttribute="top" secondItem="Cf1-lP-zbB" secondAttribute="bottom" constant="15" id="dSN-ey-gQ7"/>
484 <constraint firstItem="clL-JG-rbd" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="i5Z-XR-Msb"/> 484 <constraint firstItem="clL-JG-rbd" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="i5Z-XR-Msb"/>
485 <constraint firstItem="FLa-rV-Aas" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="iiN-Zj-1uu"/> 485 <constraint firstItem="FLa-rV-Aas" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="iiN-Zj-1uu"/>
486 <constraint firstAttribute="trailing" secondItem="FLa-rV-Aas" secondAttribute="trailing" id="jme-cz-cFt"/> 486 <constraint firstAttribute="trailing" secondItem="FLa-rV-Aas" secondAttribute="trailing" id="jme-cz-cFt"/>
487 <constraint firstItem="BVv-qD-EHM" firstAttribute="top" secondItem="FLa-rV-Aas" secondAttribute="bottom" constant="5" id="qbT-yT-phN"/> 487 <constraint firstItem="BVv-qD-EHM" firstAttribute="top" secondItem="FLa-rV-Aas" secondAttribute="bottom" constant="5" id="qbT-yT-phN"/>
488 <constraint firstAttribute="trailing" secondItem="clL-JG-rbd" secondAttribute="trailing" id="ri5-LG-xJH"/> 488 <constraint firstAttribute="trailing" secondItem="clL-JG-rbd" secondAttribute="trailing" id="ri5-LG-xJH"/>
489 </constraints> 489 </constraints>
490 <point key="canvasLocation" x="26.5" y="52.5"/> 490 <point key="canvasLocation" x="26.5" y="52.5"/>
491 </view> 491 </view>
492 <swipeGestureRecognizer cancelsTouchesInView="NO" direction="left" id="Qjg-St-rCc"> 492 <swipeGestureRecognizer cancelsTouchesInView="NO" direction="left" id="Qjg-St-rCc">
493 <connections> 493 <connections>
494 <action selector="swipeAction:" destination="-1" id="2Vl-bM-Ta7"/> 494 <action selector="swipeAction:" destination="-1" id="2Vl-bM-Ta7"/>
495 </connections> 495 </connections>
496 </swipeGestureRecognizer> 496 </swipeGestureRecognizer>
497 <swipeGestureRecognizer cancelsTouchesInView="NO" direction="right" id="VSZ-i0-Jhb"> 497 <swipeGestureRecognizer cancelsTouchesInView="NO" direction="right" id="VSZ-i0-Jhb">
498 <connections> 498 <connections>
499 <action selector="swipeAction:" destination="-1" id="hoY-6M-DoS"/> 499 <action selector="swipeAction:" destination="-1" id="hoY-6M-DoS"/>
500 </connections> 500 </connections>
501 </swipeGestureRecognizer> 501 </swipeGestureRecognizer>
502 </objects> 502 </objects>
503 <resources> 503 <resources>
504 <image name="arrow_back" width="22" height="22"/> 504 <image name="arrow_back" width="22" height="22"/>
505 <image name="arrow_next" width="22" height="22"/> 505 <image name="arrow_next" width="22" height="22"/>
506 <image name="icon_menu" width="30" height="30"/> 506 <image name="icon_menu" width="30" height="30"/>
507 <image name="today_back_button" width="73" height="37"/> 507 <image name="today_back_button" width="73" height="37"/>
508 </resources> 508 </resources>
509 </document> 509 </document>
510 510
LifeLog/LifeLog/MyGroupViewController.m
1 // 1 //
2 // MyGroupViewController.m 2 // MyGroupViewController.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/20/17. 5 // Created by nvtu on 8/20/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "MyGroupViewController.h" 9 #import "MyGroupViewController.h"
10
11 #import "Utilities.h" 10
12 #import "ServerAPI.h" 11 #import "Utilities.h"
13 #import "SNSRecentTopicTableViewCell.h" 12 #import "ServerAPI.h"
14 13 #import "SNSRecentTopicTableViewCell.h"
15 @interface MyGroupViewController () 14
16 15 @interface MyGroupViewController ()
17 @end 16
18 17 @end
19 @implementation MyGroupViewController 18
20 19 @implementation MyGroupViewController
21 - (void)viewDidLoad { 20
22 [super viewDidLoad]; 21 - (void)viewDidLoad {
23 isMemberList = false; 22 [super viewDidLoad];
24 _curListGrp = [[NSMutableArray alloc] init]; 23 isMemberList = false;
25 [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; 24 _curListGrp = [[NSMutableArray alloc] init];
26 25 [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"];
27 [self requestGroupList]; 26
28 // Do any additional setup after loading the view from its nib. 27 [self requestGroupList];
29 } 28 // Do any additional setup after loading the view from its nib.
30 29 }
31 - (void)didReceiveMemoryWarning { 30
32 [super didReceiveMemoryWarning]; 31 - (void)didReceiveMemoryWarning {
33 // Dispose of any resources that can be recreated. 32 [super didReceiveMemoryWarning];
34 } 33 // Dispose of any resources that can be recreated.
35 34 }
36 #pragma mark IBAction 35
37 36 #pragma mark IBAction
38 - (IBAction)clickBack:(id)sender { 37
39 [self.navigationController popViewControllerAnimated:true]; 38 - (IBAction)clickBack:(id)sender {
40 } 39 [self.navigationController popViewControllerAnimated:true];
41 40 }
42 - (IBAction)clickShowGrp:(id)sender { 41
43 self.tableGrp.hidden = !self.tableGrp.isHidden; 42 - (IBAction)clickShowGrp:(id)sender {
44 } 43 self.tableGrp.hidden = !self.tableGrp.isHidden;
45 44 }
46 - (IBAction)clickSwitch:(id)sender { 45
47 isMemberList = !isMemberList; 46 - (IBAction)clickSwitch:(id)sender {
48 if(isMemberList) { 47 isMemberList = !isMemberList;
49 [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; 48 if(isMemberList) {
50 } 49 [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal];
51 else { 50 }
52 [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; 51 else {
53 } 52 [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal];
54 [sender setUserInteractionEnabled:false]; 53 }
55 [self resetData]; 54 [sender setUserInteractionEnabled:false];
56 } 55 [self resetData];
57 56 }
58 #pragma mark UITableView Delegate 57
59 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { 58 #pragma mark UITableView Delegate
60 if(tableView == self.tableGrp) 59 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
61 return 1; 60 if(tableView == self.tableGrp)
62 else 61 return 1;
63 return [super numberOfSectionsInTableView:tableView]; 62 else
64 } 63 return [super numberOfSectionsInTableView:tableView];
65 64 }
66 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 65
67 if(tableView == self.tableGrp) 66 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
68 return _curListGrp.count; 67 if(tableView == self.tableGrp)
69 else 68 return _curListGrp.count;
70 return [super tableView:tableView numberOfRowsInSection:section]; 69 else
71 } 70 return [super tableView:tableView numberOfRowsInSection:section];
72 71 }
73 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 72
74 if(tableView == self.tableGrp) { 73 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
75 UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GroupCell"]; 74 if(tableView == self.tableGrp) {
76 if(cell == nil) { 75 UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GroupCell"];
77 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GroupCell"]; 76 if(cell == nil) {
78 } 77 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GroupCell"];
79 GroupObject *object = [_curListGrp objectAtIndex:indexPath.row]; 78 }
80 cell.textLabel.text = object.name; 79 GroupObject *object = [_curListGrp objectAtIndex:indexPath.row];
81 return cell; 80 cell.textLabel.text = object.name;
82 } 81 return cell;
83 else { 82 }
84 SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; 83 else {
85 if(isMemberList) { 84 SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"];
86 MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; 85 if(isMemberList) {
87 [cell setMemberData:object]; 86 MemberObject *object = [_curDataList objectAtIndex:indexPath.row];
88 } 87 [cell setMemberData:object];
89 else {
90 TweetObject *object = [_curDataList objectAtIndex:indexPath.row];
91 [cell setTweetsData:object];
92 }
93 return cell;
94 }
95 }
96
97 - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
98 if(tableView == self.tableGrp) {
99 return;
100 } 88 }
101 [super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath]; 89 else {
102 } 90 TweetObject *object = [_curDataList objectAtIndex:indexPath.row];
103 91 [cell setTweetsData:object];
104 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
105 if(tableView == self.tableGrp) {
106 [tableView setHidden:true];
107 [self resetGroupData:indexPath.row];
108 }
109 }
110
111 #pragma mark Private Function
112
113 - (void) resetGroupData : (int) index {
114 _curGroup = [_curListGrp objectAtIndex:index];
115 self.lblGrpName.text = _curGroup.name; 92 }
116 [_curDataList removeAllObjects]; 93 return cell;
117 [self.tableBase reloadData]; 94 }
118 [self requestGroupDetail]; 95 }
119 } 96
120 97 - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
121 - (void) requestGroupList { 98 if(tableView == self.tableGrp) {
122 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; 99 return;
123 MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; 100 }
124 [[ServerAPI server] requestGroupList:token CompletionHandler:^(NSArray *array, NSError *error) { 101 [super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath];
125 dispatch_async(dispatch_get_main_queue(), ^{ 102 }
126 [hudView hideAnimated:true]; 103
127 }); 104 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
128 if(error == nil) { 105 if(tableView == self.tableGrp) {
129 [_curListGrp removeAllObjects]; 106 [tableView setHidden:true];
130 [_curListGrp addObjectsFromArray:array]; 107 [self resetGroupData:indexPath.row];
131 MyGroupViewController __weak *weakSelf = self; 108 }
132 dispatch_async(dispatch_get_main_queue(), ^{ 109 }
133 [hudView hideAnimated:true]; 110
134 [self.tableGrp reloadData]; 111 #pragma mark Private Function
135 if(_curListGrp.count > 0) { 112
136 [weakSelf resetGroupData:0]; 113 - (void) resetGroupData : (int) index {
137 } 114 _curGroup = [_curListGrp objectAtIndex:index];
138 else { 115 self.lblGrpName.text = _curGroup.name;
139 weakSelf.lblGrpName.text = @"No Group"; 116 [_curDataList removeAllObjects];
140 } 117 [self.tableBase reloadData];
141 [weakSelf.btShowGrp setEnabled:(_curListGrp.count > 0)]; 118 [self requestGroupDetail];
142 }); 119 }
143 } 120
144 }]; 121 - (void) requestGroupList {
145 } 122 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
146 123 MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
147 @end 124 [[ServerAPI server] requestGroupList:token CompletionHandler:^(NSArray *array, NSError *error) {
148 125 dispatch_async(dispatch_get_main_queue(), ^{
LifeLog/LifeLog/SNSRecentTopicTableViewCell.h
1 // 1 //
2 // SNSRecentTopicTableViewCell.h 2 // SNSRecentTopicTableViewCell.h
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/10/17. 5 // Created by nvtu on 8/10/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
10 #import "Entities.h"
10 #import "Entities.h" 11
11 12 @interface SNSRecentTopicTableViewCell : UITableViewCell
12 @interface SNSRecentTopicTableViewCell : UITableViewCell 13
13 14 @property (weak, nonatomic) IBOutlet UIImageView *imgAvatar;
14 @property (weak, nonatomic) IBOutlet UIImageView *imgAvatar; 15 @property (weak, nonatomic) IBOutlet UILabel *lblDateTime;
15 @property (weak, nonatomic) IBOutlet UILabel *lblDateTime; 16 @property (weak, nonatomic) IBOutlet UILabel *lblUsername;
16 @property (weak, nonatomic) IBOutlet UILabel *lblUsername; 17 @property (weak, nonatomic) IBOutlet UILabel *lblDes;
17 @property (weak, nonatomic) IBOutlet UILabel *lblDes; 18 @property (weak, nonatomic) IBOutlet UILabel *lblMode;
18 @property (weak, nonatomic) IBOutlet UILabel *lblMode; 19 @property (weak, nonatomic) IBOutlet UILabel *lblDistance;
19 @property (weak, nonatomic) IBOutlet UILabel *lblDistance; 20 @property (weak, nonatomic) IBOutlet UILabel *lblDuration;
20 @property (weak, nonatomic) IBOutlet UILabel *lblDuration; 21
22 -(void) setMemberData : (MemberObject *) object;
23 -(void) setTweetsData : (TweetObject *) object;
21 24 @end
22 -(void) setMemberData : (MemberObject *) object; 25
LifeLog/LifeLog/SNSRecentTopicTableViewCell.m
1 // 1 //
2 // SNSRecentTopicTableViewCell.m 2 // SNSRecentTopicTableViewCell.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by nvtu on 8/10/17. 5 // Created by nvtu on 8/10/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "SNSRecentTopicTableViewCell.h" 9 #import "SNSRecentTopicTableViewCell.h"
10 #import <SDWebImage/UIImageView+WebCache.h>
11
12 #import "Utilities.h"
10 #import <SDWebImage/UIImageView+WebCache.h> 13
11 14 @implementation SNSRecentTopicTableViewCell
12 #import "Utilities.h" 15
13 16 - (void)awakeFromNib {
14 @implementation SNSRecentTopicTableViewCell 17 [super awakeFromNib];
15 18 // Initialization code
16 - (void)awakeFromNib { 19 }
17 [super awakeFromNib]; 20
18 // Initialization code 21 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
19 } 22 [super setSelected:selected animated:animated];
20 23
21 - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 24 // Configure the view for the selected state
22 [super setSelected:selected animated:animated]; 25 }
23 26
27 -(void) setMemberData : (MemberObject *) object {
28 if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) {
29 [self.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]];
30 }
31 else {
32 [self.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]];
33 }
34 self.lblUsername.text = @"";
35 self.lblDateTime.text = @"";
36 self.lblDes.text = object.userName;
37 self.lblMode.text = @"";
38 self.lblDistance.text = @"";
39 self.lblDuration.text = @"";
40 }
41
42 -(void) setTweetsData : (TweetObject *) object {
43 if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) {
44 [self.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]];
45 }
46 else {
47 [self.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]];
48 }
49 self.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""];
50 self.lblUsername.text = object.userName;
51 self.lblDes.text = object.content;
52 self.lblMode.text = object.mode;
53 self.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance];
54 self.lblDuration.text = object.time;
55 }
56
24 // Configure the view for the selected state 57 @end
25 } 58
LifeLog/LifeLog/SNSViewController.m
1 // 1 //
2 // SNSViewController.m 2 // SNSViewController.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by Nguyen Van Phong on 7/25/17. 5 // Created by Nguyen Van Phong on 7/25/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "SNSViewController.h" 9 #import "SNSViewController.h"
10 10
11 #import "ServerAPI.h"
12 #import "Utilities.h"
13 11 #import "ServerAPI.h"
14 #import "SNSRecentTopicTableViewCell.h" 12 #import "Utilities.h"
15 #import "MyGroupViewController.h" 13
16 #import "SearchGroupViewController.h" 14 #import "SNSRecentTopicTableViewCell.h"
17 #import "GroupDetailViewController.h" 15 #import "MyGroupViewController.h"
18 16 #import "SearchGroupViewController.h"
19 @interface SNSViewController () 17 #import "GroupDetailViewController.h"
20 18
21 @end 19 @interface SNSViewController ()
22 20
23 @implementation SNSViewController 21 @end
24 22
25 - (void)viewDidLoad { 23 @implementation SNSViewController
26 [super viewDidLoad]; 24
27 // Do any additional setup after loading the view from its nib. 25 - (void)viewDidLoad {
28 self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil); 26 [super viewDidLoad];
29 27 // Do any additional setup after loading the view from its nib.
30 [self callRequestToUpdateData]; 28 self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil);
31 29
32 //register nib for table view 30 [self callRequestToUpdateData];
33 [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; 31
34 } 32 //register nib for table view
35 33 [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"];
36 - (void)didReceiveMemoryWarning { 34 }
37 [super didReceiveMemoryWarning]; 35
38 // Dispose of any resources that can be recreated. 36 - (void)didReceiveMemoryWarning {
39 } 37 [super didReceiveMemoryWarning];
40 38 // Dispose of any resources that can be recreated.
41 #pragma mark IBAction 39 }
42 - (IBAction)clickRecommendGroup:(id)sender { 40
43 SearchGroupViewController * search = [[SearchGroupViewController alloc] init]; 41 #pragma mark IBAction
44 [self.navigationController pushViewController:search animated:true]; 42 - (IBAction)clickRecommendGroup:(id)sender {
45 } 43 SearchGroupViewController * search = [[SearchGroupViewController alloc] init];
46 44 [self.navigationController pushViewController:search animated:true];
47 - (IBAction)clickMyGroup:(id)sender { 45 }
48 MyGroupViewController * myGrp = [[MyGroupViewController alloc] init]; 46
49 [self.navigationController pushViewController:myGrp animated:true]; 47 - (IBAction)clickMyGroup:(id)sender {
50 } 48 MyGroupViewController * myGrp = [[MyGroupViewController alloc] init];
51 49 [self.navigationController pushViewController:myGrp animated:true];
52 #pragma mark UITableView Delegate 50 }
53 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 51
54 SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; 52 #pragma mark UITableView Delegate
55 TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; 53 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
56 [cell setTweetsData:object]; 54 SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"];
57 return cell; 55 TweetObject *object = [_curDataList objectAtIndex:indexPath.row];
58 } 56 [cell setTweetsData:object];
59
60 #pragma mark Private Function
61
62 -(void) callRequestToUpdateData {
63 [super callRequestToUpdateData];
64
65 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
66 MBProgressHUD *hudView = nil;
67 if(_curPage == 1 && !self.refreshControl.isRefreshing) {
68 hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
69 }
70 [[ServerAPI server] requestTweetsList:token groupID:-1 withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ 57 return cell;
71 dispatch_async(dispatch_get_main_queue(), ^{ 58 }
72 if(hudView != nil) { 59
73 [hudView hideAnimated:true]; 60 #pragma mark Private Function
74 } 61
75 }); 62 -(void) callRequestToUpdateData {
76 SNSViewController __weak *weakSelf = self; 63 [super callRequestToUpdateData];
77 [weakSelf updateTableData:array error:error]; 64
78 }]; 65 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
79 } 66 MBProgressHUD *hudView = nil;
80 67 if(_curPage == 1 && !self.refreshControl.isRefreshing) {
81 @end 68 hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
82 69 }
LifeLog/LifeLog/ServerAPI.h
1 // 1 //
2 // ServerAPI.h 2 // ServerAPI.h
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by Nguyen Van Phong on 7/30/17. 5 // Created by Nguyen Van Phong on 7/30/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 #import "Entities.h" 10 #import "Entities.h"
11 11
12 extern NSString *const kServerAddress; 12 extern NSString *const kServerAddress;
13 extern NSString *const kUser; 13 extern NSString *const kUser;
14 extern NSString *const kToken; 14 extern NSString *const kToken;
15 extern NSString *const kNotificationToken; 15 extern NSString *const kNotificationToken;
16 16
17 @interface ServerAPI : NSObject 17 @interface ServerAPI : NSObject
18 + (instancetype) server; 18 + (instancetype) server;
19 @property (nonatomic, assign) NSTimeInterval timeOutInterval; 19 @property (nonatomic, assign) NSTimeInterval timeOutInterval;
20 20
21 #pragma mark - Login and Register 21 #pragma mark - Login and Register
22 - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; 22 - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion;
23 - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; 23 - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion;
24 - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion; 24 - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion;
25 - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion; 25 - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion;
26 - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion; 26 - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion;
27 27
28 #pragma mark - Home Screen Function 28 #pragma mark - Home Screen Function
29 - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion; 29 - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion;
30 - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion; 30 - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion;
31 31
32 #pragma mark - History Screen Function 32 #pragma mark - History Screen Function
33 - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion; 33 - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion;
34 - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion; 34 - (void) requestHistoryList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion;
35 - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion;
36 - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion; 35 - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion;
37 -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; 36 -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion;
38 - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion; 37 - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion;
39 38
40 #pragma mark - SNS Screen Function 39 #pragma mark - SNS Screen Function
41 /* 40 /*
42 Get tweet of group and get recent tweet is same API 41 Get tweet of group and get recent tweet is same API
43 If groupID equal -1, it will request recent tweet. Otherwise will request tweet of group 42 If groupID equal -1, it will request recent tweet. Otherwise will request tweet of group
44 */ 43 */
45 - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; 44 - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion;
46 - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; 45 - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion;
47 46
48 #pragma mark - Group Function 47 #pragma mark - Group Function
49 - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; 48 - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion;
50 - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; 49 - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion;
51 50
52 #pragma mark - Common API 51 #pragma mark - Common API
53 - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; 52 - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion;
54 @end 53 @end
55 54
LifeLog/LifeLog/ServerAPI.m
1 // 1 //
2 // ServerAPI.m 2 // ServerAPI.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by Nguyen Van Phong on 7/30/17. 5 // Created by Nguyen Van Phong on 7/30/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "ServerAPI.h" 9 #import "ServerAPI.h"
10 #import "Utilities.h" 10 #import "Utilities.h"
11 11
12 NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/"; 12 NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/";
13 NSString *const kUser = @"KEY_USER"; 13 NSString *const kUser = @"KEY_USER";
14 NSString *const kToken = @"KEY_TOKEN"; 14 NSString *const kToken = @"KEY_TOKEN";
15 NSString *const kNotificationToken = @"TOKEN_INVALID"; 15 NSString *const kNotificationToken = @"TOKEN_INVALID";
16 16
17 @implementation NSString (NSString_Extended) 17 @implementation NSString (NSString_Extended)
18 - (NSString *)urlencode { 18 - (NSString *)urlencode {
19 NSMutableString *output = [NSMutableString string]; 19 NSMutableString *output = [NSMutableString string];
20 const unsigned char *source = (const unsigned char *)[self UTF8String]; 20 const unsigned char *source = (const unsigned char *)[self UTF8String];
21 int sourceLen = (int)strlen((const char *)source); 21 int sourceLen = (int)strlen((const char *)source);
22 for (int i = 0; i < sourceLen; ++i) { 22 for (int i = 0; i < sourceLen; ++i) {
23 const unsigned char thisChar = source[i]; 23 const unsigned char thisChar = source[i];
24 if (thisChar == ' '){ 24 if (thisChar == ' '){
25 [output appendString:@"+"]; 25 [output appendString:@"+"];
26 } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' || 26 } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
27 (thisChar >= 'a' && thisChar <= 'z') || 27 (thisChar >= 'a' && thisChar <= 'z') ||
28 (thisChar >= 'A' && thisChar <= 'Z') || 28 (thisChar >= 'A' && thisChar <= 'Z') ||
29 (thisChar >= '0' && thisChar <= '9')) { 29 (thisChar >= '0' && thisChar <= '9')) {
30 [output appendFormat:@"%c", thisChar]; 30 [output appendFormat:@"%c", thisChar];
31 } else { 31 } else {
32 [output appendFormat:@"%%%02X", thisChar]; 32 [output appendFormat:@"%%%02X", thisChar];
33 } 33 }
34 } 34 }
35 return output; 35 return output;
36 } 36 }
37 @end 37 @end
38 38
39 @implementation ServerAPI 39 @implementation ServerAPI
40 static ServerAPI *_server = nil; 40 static ServerAPI *_server = nil;
41 41
42 NSURLSessionDataTask * searchTask; 42 NSURLSessionDataTask * searchTask;
43 43
44 @synthesize timeOutInterval = _timeOutInterval; 44 @synthesize timeOutInterval = _timeOutInterval;
45 45
46 + (instancetype)server 46 + (instancetype)server
47 { 47 {
48 @synchronized(self) { 48 @synchronized(self) {
49 if (_server == nil) { 49 if (_server == nil) {
50 _server = [[ServerAPI alloc] init]; 50 _server = [[ServerAPI alloc] init];
51 } 51 }
52 } 52 }
53 return _server; 53 return _server;
54 } 54 }
55 55
56 - (instancetype)init 56 - (instancetype)init
57 { 57 {
58 self = [super init]; 58 self = [super init];
59 if (self != nil) { 59 if (self != nil) {
60 self.timeOutInterval = 150; 60 self.timeOutInterval = 150;
61 } 61 }
62 return self; 62 return self;
63 } 63 }
64 64
65 #pragma mark - Login and Register 65 #pragma mark - Login and Register
66 // Login 66 // Login
67 - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion 67 - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion
68 { 68 {
69 [self _request:[kServerAddress stringByAppendingFormat: @"login"] method:@"POST" token:@"" paras:@{@"email":email, @"password": password} completion:^(NSData *data, NSError *error) { 69 [self _request:[kServerAddress stringByAppendingFormat: @"login"] method:@"POST" token:@"" paras:@{@"email":email, @"password": password} completion:^(NSData *data, NSError *error) {
70 70
71 if (completion == NULL) { 71 if (completion == NULL) {
72 return ; 72 return ;
73 } 73 }
74 74
75 if (error == nil) 75 if (error == nil)
76 { 76 {
77 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 77 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
78 78
79 int status = [dataResult[@"status"] intValue]; 79 int status = [dataResult[@"status"] intValue];
80 if (status == 1) { // status = 1 success 80 if (status == 1) { // status = 1 success
81 NSString *token = dataResult[@"result"][@"token"]; 81 NSString *token = dataResult[@"result"][@"token"];
82 NSDictionary *dictUser = dataResult[@"result"][@"user"]; 82 NSDictionary *dictUser = dataResult[@"result"][@"user"];
83 User *user = [[User alloc] init]; 83 User *user = [[User alloc] init];
84 user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; 84 user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]];
85 user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; 85 user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]];
86 user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; 86 user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]];
87 user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; 87 user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]];
88 user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; 88 user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]];
89 user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; 89 user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]];
90 user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; 90 user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]];
91 user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; 91 user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]];
92 user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; 92 user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue];
93 user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; 93 user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue];
94 user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; 94 user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue];
95 user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; 95 user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]];
96 user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; 96 user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]];
97 user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; 97 user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]];
98 user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; 98 user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]];
99 user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; 99 user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]];
100 user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; 100 user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue];
101 user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; 101 user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue];
102 user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; 102 user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue];
103 user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; 103 user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue];
104 user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; 104 user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue];
105 user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; 105 user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue];
106 user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; 106 user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue];
107 completion(user, token, nil); 107 completion(user, token, nil);
108 } 108 }
109 else { // status = 0 error 109 else { // status = 0 error
110 NSString *message = dataResult[@"message"]; 110 NSString *message = dataResult[@"message"];
111 if (message == nil) { 111 if (message == nil) {
112 message = @"Unknown error"; 112 message = @"Unknown error";
113 } 113 }
114 NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 114 NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
115 completion(nil, nil, loginFaild); 115 completion(nil, nil, loginFaild);
116 } 116 }
117 } 117 }
118 else 118 else
119 { 119 {
120 completion(nil, nil, error); 120 completion(nil, nil, error);
121 } 121 }
122 }]; 122 }];
123 } 123 }
124 124
125 // Register 125 // Register
126 - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion { 126 - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion {
127 [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" token:@"" paras:params completion:^(NSData *data, NSError *error) { 127 [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" token:@"" paras:params completion:^(NSData *data, NSError *error) {
128 128
129 if (completion == NULL) { 129 if (completion == NULL) {
130 return ; 130 return ;
131 } 131 }
132 132
133 if (error == nil) 133 if (error == nil)
134 { 134 {
135 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 135 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
136 136
137 int status = [dataResult[@"status"] intValue]; 137 int status = [dataResult[@"status"] intValue];
138 if (status == 1) { // status = 1 success 138 if (status == 1) { // status = 1 success
139 NSString *token = dataResult[@"result"][@"token"]; 139 NSString *token = dataResult[@"result"][@"token"];
140 NSDictionary *dictUser = dataResult[@"result"][@"user"]; 140 NSDictionary *dictUser = dataResult[@"result"][@"user"];
141 User *user = [[User alloc] init]; 141 User *user = [[User alloc] init];
142 user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; 142 user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]];
143 user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; 143 user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]];
144 user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; 144 user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]];
145 user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; 145 user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]];
146 user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; 146 user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]];
147 user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; 147 user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]];
148 user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; 148 user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]];
149 user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; 149 user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]];
150 user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; 150 user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue];
151 user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; 151 user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue];
152 user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; 152 user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue];
153 user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; 153 user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]];
154 user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; 154 user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]];
155 user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; 155 user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]];
156 user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; 156 user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]];
157 user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; 157 user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]];
158 user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; 158 user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue];
159 user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; 159 user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue];
160 user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; 160 user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue];
161 user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; 161 user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue];
162 user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; 162 user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue];
163 user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; 163 user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue];
164 user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; 164 user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue];
165 completion(user, token, nil); 165 completion(user, token, nil);
166 } 166 }
167 else { // status = 0 error 167 else { // status = 0 error
168 NSString *message = dataResult[@"message"]; 168 NSString *message = dataResult[@"message"];
169 if (message == nil) { 169 if (message == nil) {
170 message = @"Unknown error"; 170 message = @"Unknown error";
171 } 171 }
172 NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 172 NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
173 completion(nil, nil, loginFaild); 173 completion(nil, nil, loginFaild);
174 } 174 }
175 } 175 }
176 else 176 else
177 { 177 {
178 completion(nil, nil, error); 178 completion(nil, nil, error);
179 } 179 }
180 }]; 180 }];
181 } 181 }
182 182
183 - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion { 183 - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion {
184 [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" token:@"" paras:@{@"email":email} completion:^(NSData *data, NSError *error) { 184 [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" token:@"" paras:@{@"email":email} completion:^(NSData *data, NSError *error) {
185 185
186 if (completion == NULL) { 186 if (completion == NULL) {
187 return ; 187 return ;
188 } 188 }
189 189
190 if (error == nil) 190 if (error == nil)
191 { 191 {
192 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 192 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
193 193
194 int status = [dataResult[@"status"] intValue]; 194 int status = [dataResult[@"status"] intValue];
195 if (status == 1) { // status = 1 success 195 if (status == 1) { // status = 1 success
196 completion(nil); 196 completion(nil);
197 } 197 }
198 else { // status = 0 error 198 else { // status = 0 error
199 NSString *message = dataResult[@"message"]; 199 NSString *message = dataResult[@"message"];
200 if (message == nil) { 200 if (message == nil) {
201 message = @"Unknown error"; 201 message = @"Unknown error";
202 } 202 }
203 NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 203 NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
204 completion(forgetPass); 204 completion(forgetPass);
205 } 205 }
206 } 206 }
207 else 207 else
208 { 208 {
209 completion(error); 209 completion(error);
210 } 210 }
211 }]; 211 }];
212 } 212 }
213 - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion { 213 - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion {
214 [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" token:@"" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) { 214 [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" token:@"" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) {
215 215
216 if (completion == NULL) { 216 if (completion == NULL) {
217 return ; 217 return ;
218 } 218 }
219 219
220 if (error == nil) 220 if (error == nil)
221 { 221 {
222 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 222 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
223 223
224 int status = [dataResult[@"status"] intValue]; 224 int status = [dataResult[@"status"] intValue];
225 if (status == 1) { // status = 1 success 225 if (status == 1) { // status = 1 success
226 completion(nil); 226 completion(nil);
227 } 227 }
228 else { // status = 0 error 228 else { // status = 0 error
229 NSString *message = dataResult[@"message"]; 229 NSString *message = dataResult[@"message"];
230 NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 230 NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
231 completion(confirmForgetPass); 231 completion(confirmForgetPass);
232 } 232 }
233 } 233 }
234 else 234 else
235 { 235 {
236 completion(error); 236 completion(error);
237 } 237 }
238 }]; 238 }];
239 } 239 }
240 240
241 - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion { 241 - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion {
242 NSDictionary *dict = nil; 242 NSDictionary *dict = nil;
243 NSString *base64Encoded = [data base64EncodedStringWithOptions:0]; 243 NSString *base64Encoded = [data base64EncodedStringWithOptions:0];
244 if (token != nil) { 244 if (token != nil) {
245 dict = @{@"token":token, @"img": base64Encoded}; 245 dict = @{@"token":token, @"img": base64Encoded};
246 } 246 }
247 else { 247 else {
248 dict = @{@"img": base64Encoded}; 248 dict = @{@"img": base64Encoded};
249 } 249 }
250 [self _request:[kServerAddress stringByAppendingFormat: @"upload-image"] method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { 250 [self _request:[kServerAddress stringByAppendingFormat: @"upload-image"] method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) {
251 251
252 if (completion == NULL) { 252 if (completion == NULL) {
253 return ; 253 return ;
254 } 254 }
255 255
256 if (error == nil) 256 if (error == nil)
257 { 257 {
258 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 258 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
259 NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]]; 259 NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]];
260 completion(image_profile, nil); 260 completion(image_profile, nil);
261 } 261 }
262 else 262 else
263 { 263 {
264 completion(nil, error); 264 completion(nil, error);
265 } 265 }
266 }]; 266 }];
267 } 267 }
268 268
269 -(NSString *) convertIntToString : (int) type { 269 -(NSString *) convertIntToString : (int) type {
270 switch (type) { 270 switch (type) {
271 case 1: 271 case 1:
272 return @"week"; 272 return @"week";
273 break; 273 break;
274 case 2: 274 case 2:
275 return @"oneMonth"; 275 return @"oneMonth";
276 break; 276 break;
277 case 3: 277 case 3:
278 return @"threeMonth"; 278 return @"threeMonth";
279 break; 279 break;
280 case 4: 280 case 4:
281 return @"sixMonth"; 281 return @"sixMonth";
282 break; 282 break;
283 default: 283 default:
284 return @"today"; 284 return @"today";
285 break; 285 break;
286 } 286 }
287 } 287 }
288 288
289 #pragma mark - Home Screen Function 289 #pragma mark - Home Screen Function
290 - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion 290 - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion
291 { 291 {
292 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; 292 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
293 NSString *url = [kServerAddress stringByAppendingFormat:@"api/top/%d/%@", mode, date]; 293 NSString *url = [kServerAddress stringByAppendingFormat:@"api/top/%d/%@", mode, date];
294 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { 294 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) {
295 295
296 if (completion == NULL) { 296 if (completion == NULL) {
297 return ; 297 return ;
298 } 298 }
299 299
300 if (error == nil) 300 if (error == nil)
301 { 301 {
302 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 302 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
303 int status = [dataResult[@"status"] intValue]; 303 int status = [dataResult[@"status"] intValue];
304 if (status == 1) { // status = 1 success 304 if (status == 1) { // status = 1 success
305 if(dataResult[@"result"] != nil) { 305 if(dataResult[@"result"] != nil) {
306 NSDictionary * dictResult = dataResult[@"result"]; 306 NSDictionary * dictResult = dataResult[@"result"];
307 TopObject *topObject = [[TopObject alloc] init]; 307 TopObject *topObject = [[TopObject alloc] init];
308 TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; 308 TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]];
309 topObject.targetInfor = targetInfor; 309 topObject.targetInfor = targetInfor;
310 topObject.kcal = [[NSString stringWithFormat:@"%@", dictResult[@"kcal"]] intValue]; 310 topObject.kcal = [[NSString stringWithFormat:@"%@", dictResult[@"kcal"]] intValue];
311 topObject.distance = [[NSString stringWithFormat:@"%@", dictResult[@"distance"]] floatValue]; 311 topObject.distance = [[NSString stringWithFormat:@"%@", dictResult[@"distance"]] floatValue];
312 topObject.time = [NSString stringWithFormat:@"%@", dictResult[@"time"]]; 312 topObject.time = [NSString stringWithFormat:@"%@", dictResult[@"time"]];
313 NSMutableArray *arrayStep = [[NSMutableArray alloc] init]; 313 NSMutableArray *arrayStep = [[NSMutableArray alloc] init];
314 NSArray *array = dictResult[@"dataChart"]; 314 NSArray *array = dictResult[@"dataChart"];
315 for(NSDictionary *dict in array) { 315 for(NSDictionary *dict in array) {
316 StepObject *object = [[StepObject alloc] init]; 316 StepObject *object = [[StepObject alloc] init];
317 if([dict objectForKey:@"numStep"] != nil) { 317 if([dict objectForKey:@"numStep"] != nil) {
318 object.step = [dict[@"numStep"] intValue]; 318 object.step = [dict[@"numStep"] intValue];
319 } 319 }
320 if([dict objectForKey:@"hour"] != nil) { 320 if([dict objectForKey:@"hour"] != nil) {
321 object.hour = [dict[@"hour"] intValue]; 321 object.hour = [dict[@"hour"] intValue];
322 } 322 }
323 switch (mode) { 323 switch (mode) {
324 case 1: 324 case 1:
325 object.typeStep = @"walking"; 325 object.typeStep = @"walking";
326 break; 326 break;
327 case 2: 327 case 2:
328 object.typeStep = @"running"; 328 object.typeStep = @"running";
329 break; 329 break;
330 case 3: 330 case 3:
331 object.typeStep = @"bike"; 331 object.typeStep = @"bike";
332 break; 332 break;
333 default: 333 default:
334 break; 334 break;
335 } 335 }
336 [arrayStep addObject:object]; 336 [arrayStep addObject:object];
337 } 337 }
338 topObject.dataChart = [[NSMutableArray alloc] initWithArray:arrayStep]; 338 topObject.dataChart = [[NSMutableArray alloc] initWithArray:arrayStep];
339 completion(topObject, nil); 339 completion(topObject, nil);
340 } 340 }
341 else { 341 else {
342 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 342 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
343 completion(nil, errorObject); 343 completion(nil, errorObject);
344 } 344 }
345 } 345 }
346 else { 346 else {
347 NSString *message = dataResult[@"message"]; 347 NSString *message = dataResult[@"message"];
348 if (message == nil) { 348 if (message == nil) {
349 message = @"Unknown error"; 349 message = @"Unknown error";
350 } 350 }
351 351
352 if ([message isEqualToString:@"Token is invalid"]) { 352 if ([message isEqualToString:@"Token is invalid"]) {
353 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 353 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
354 [self requestTopWithMode:mode andDate:date CompletionHandler:completion]; 354 [self requestTopWithMode:mode andDate:date CompletionHandler:completion];
355 } 355 }
356 else { 356 else {
357 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 357 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
358 completion(nil, errorObject); 358 completion(nil, errorObject);
359 } 359 }
360 } 360 }
361 } 361 }
362 else 362 else
363 { 363 {
364 completion(nil, error); 364 completion(nil, error);
365 } 365 }
366 }]; 366 }];
367 } 367 }
368 368
369 - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion { 369 - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion {
370 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; 370 NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
371 NSString *url = [kServerAddress stringByAppendingFormat:@"api/createLog"]; 371 NSString *url = [kServerAddress stringByAppendingFormat:@"api/createLog"];
372 NSDictionary *dict = @{@"mode": [NSNumber numberWithInt:mode], @"numStep": [NSNumber numberWithInt:numStep], @"startTime": startDate, @"endTime": endDate}; 372 NSDictionary *dict = @{@"mode": [NSNumber numberWithInt:mode], @"numStep": [NSNumber numberWithInt:numStep], @"startTime": startDate, @"endTime": endDate};
373 [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { 373 [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) {
374 374
375 if (completion == NULL) { 375 if (completion == NULL) {
376 return ; 376 return ;
377 } 377 }
378 378
379 if (error == nil) 379 if (error == nil)
380 { 380 {
381 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 381 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
382 int status = [dataResult[@"status"] intValue]; 382 int status = [dataResult[@"status"] intValue];
383 if (status == 1) { // status = 1 success 383 if (status == 1) { // status = 1 success
384 completion(nil); 384 completion(nil);
385 } 385 }
386 else { 386 else {
387 NSString *message = dataResult[@"message"]; 387 NSString *message = dataResult[@"message"];
388 if (message == nil) { 388 if (message == nil) {
389 message = @"Unknown error"; 389 message = @"Unknown error";
390 } 390 }
391 391
392 if ([message isEqualToString:@"Token is invalid"]) { 392 if ([message isEqualToString:@"Token is invalid"]) {
393 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 393 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
394 [self requestCreateLog:mode withStep:numStep startDate:startDate endDate:endDate CompletionHandler:completion]; 394 [self requestCreateLog:mode withStep:numStep startDate:startDate endDate:endDate CompletionHandler:completion];
395 } 395 }
396 else { 396 else {
397 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 397 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
398 completion(errorObject); 398 completion(errorObject);
399 } 399 }
400 } 400 }
401 } 401 }
402 else 402 else
403 { 403 {
404 completion(error); 404 completion(error);
405 } 405 }
406 }]; 406 }];
407 } 407 }
408 408
409 #pragma mark - History Screen Function 409 #pragma mark - History Screen Function
410 - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion { 410 - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion {
411 NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]]; 411 NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]];
412 NSLog(@"requestHistory link %@", url); 412 NSLog(@"requestHistory link %@", url);
413 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { 413 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) {
414 414
415 if (completion == NULL) { 415 if (completion == NULL) {
416 return ; 416 return ;
417 } 417 }
418 418
419 if (error == nil) 419 if (error == nil)
420 { 420 {
421 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 421 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
422 NSLog(@"%@", dataResult); 422 NSLog(@"%@", dataResult);
423 int status = [dataResult[@"status"] intValue]; 423 int status = [dataResult[@"status"] intValue];
424 if (status == 1) { // status = 1 success 424 if (status == 1) { // status = 1 success
425 NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; 425 NSMutableArray * arrayHistory = [[NSMutableArray alloc] init];
426 NSDictionary * arrResult = dataResult[@"result"]; 426 NSDictionary * arrResult = dataResult[@"result"];
427 if(arrResult != nil) { 427 if(arrResult != nil) {
428 NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_1", @"mode_2", @"mode_3", nil]; 428 NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_1", @"mode_2", @"mode_3", nil];
429 for(NSString * key in arrayKey) { 429 for(NSString * key in arrayKey) {
430 NSDictionary *mode = [arrResult objectForKey:key]; 430 NSDictionary *mode = [arrResult objectForKey:key];
431 if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { 431 if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) {
432 HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode]; 432 HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode];
433 [arrayHistory addObject:objectMode]; 433 [arrayHistory addObject:objectMode];
434 } 434 }
435 else { 435 else {
436 [arrayHistory addObject:[[HistoryObject alloc] init]]; 436 [arrayHistory addObject:[[HistoryObject alloc] init]];
437 } 437 }
438 } 438 }
439 } 439 }
440 completion(arrayHistory, nil); 440 completion(arrayHistory, nil);
441 } 441 }
442 else { 442 else {
443 NSString *message = dataResult[@"message"]; 443 NSString *message = dataResult[@"message"];
444 if (message == nil) { 444 if (message == nil) {
445 message = @"Unknown error"; 445 message = @"Unknown error";
446 } 446 }
447 447
448 if ([message isEqualToString:@"Token is invalid"]) { 448 if ([message isEqualToString:@"Token is invalid"]) {
449 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 449 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
450 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; 450 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
451 [self requestHistory:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion]; 451 [self requestHistory:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion];
452 } 452 }
453 else { 453 else {
454 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 454 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
455 completion(nil, errorObject); 455 completion(nil, errorObject);
456 } 456 }
457 } 457 }
458 } 458 }
459 else 459 else
460 { 460 {
461 completion(nil, error); 461 completion(nil, error);
462 } 462 }
463 }]; 463 }];
464 } 464 }
465 465
466 - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion { 466 - (void) requestHistoryList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion {
467 NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/graph/%@/%d", [self convertIntToString:type], mode]; 467 NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/detail/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]];
468 NSLog(@"requestHistoryGraph link %@", url);
469 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) {
470
471 if (completion == NULL) {
472 return ;
473 }
474
475 if (error == nil)
476 {
477 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
478 NSLog(@"%@", dataResult);
479 int status = [dataResult[@"status"] intValue];
480 if (status == 1) { // status = 1 success
481 HistoryGraphObject * object = [[HistoryGraphObject alloc] initWithData:dataResult[@"result"]];
482 completion(object, nil);
483 }
484 else {
485 NSString *message = dataResult[@"message"];
486 if (message == nil) {
487 message = @"Unknown error";
488 }
489
490 if ([message isEqualToString:@"Token is invalid"]) {
491 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
492 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
493 [self requestHistoryGraph:tokenNew withType:type andMode:mode CompletionHandler:completion];
494 }
495 else {
496 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
497 completion(nil, errorObject);
498 }
499 }
500 }
501 else
502 {
503 completion(nil, error);
504 }
505 }];
506 }
507
508 - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion {
509 NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/list/%@/%d?page=%d&record=50", [self convertIntToString:type], mode, page];
510 NSLog(@"requestHistoryList link %@", url); 468 NSLog(@"requestHistoryList link %@", url);
511 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { 469 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) {
512 470
513 if (completion == NULL) { 471 if (completion == NULL) {
514 return ; 472 return ;
515 } 473 }
516 474
517 if (error == nil) 475 if (error == nil)
518 { 476 {
519 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 477 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
520 NSLog(@"%@", dataResult); 478 NSLog(@"%@", dataResult);
521 int status = [dataResult[@"status"] intValue]; 479 int status = [dataResult[@"status"] intValue];
522 if (status == 1) { // status = 1 success 480 if (status == 1) { // status = 1 success
523 if(dataResult[@"result"] != nil) { 481 if(dataResult[@"result"] != nil) {
524 NSArray * array = dataResult[@"result"][@"data"];
525 NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; 482 NSMutableArray * arrayHistory = [[NSMutableArray alloc] init];
526 for(NSDictionary * dict in array) { 483 NSDictionary * arrResult = dataResult[@"result"];
527 HistoryObject * object = [[HistoryObject alloc] initWithData:dict]; 484 if(arrResult != nil) {
528 [arrayHistory addObject:object]; 485 NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_1", @"mode_2", @"mode_3", nil];
486 for(NSString * key in arrayKey) {
487 NSDictionary *mode = [arrResult objectForKey:key];
488 if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) {
489 NSMutableArray *array = [[NSMutableArray alloc] init];
490 for(NSString *key in mode.allKeys) {
491 HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode[key]];
492 objectMode.date = [Utilities dateFromString:key withFormat:@"yyyy-MM-dd"];
493 [array addObject:objectMode];
494 }
495 [arrayHistory addObject:array];
496 }
497 else {
498 [arrayHistory addObject:[[NSArray alloc] init]];
499 }
500 }
529 } 501 }
530 completion(arrayHistory, nil); 502 completion(arrayHistory, nil);
531 } 503 }
532 else { 504 else {
533 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 505 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
534 completion(nil, errorObject); 506 completion(nil, errorObject);
535 } 507 }
536 } 508 }
537 else { 509 else {
538 NSString *message = dataResult[@"message"]; 510 NSString *message = dataResult[@"message"];
539 if (message == nil) { 511 if (message == nil) {
540 message = @"Unknown error"; 512 message = @"Unknown error";
541 } 513 }
542 514
543 if ([message isEqualToString:@"Token is invalid"]) { 515 if ([message isEqualToString:@"Token is invalid"]) {
544 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 516 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
545 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; 517 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
546 [self requestHistoryList:tokenNew withType:type andMode:mode AtPage:page CompletionHandler:completion]; 518 [self requestHistoryList:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion];
547 } 519 }
548 else { 520 else {
549 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 521 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
550 completion(nil, errorObject); 522 completion(nil, errorObject);
551 } 523 }
552 } 524 }
553 } 525 }
554 else 526 else
555 { 527 {
556 completion(nil, error); 528 completion(nil, error);
557 } 529 }
558 }]; 530 }];
559 } 531 }
560 532
561 #pragma mark - SNS Screen Function 533 #pragma mark - SNS Screen Function
562 - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { 534 - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion {
563 NSString *url = [kServerAddress stringByAppendingFormat:@"/api/sns/%d", page]; 535 NSString *url = [kServerAddress stringByAppendingFormat:@"/api/sns/%d", page];
564 if(groupID > -1) { 536 if(groupID > -1) {
565 url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; 537 url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page];
566 } 538 }
567 NSLog(@"requestTweetsList link %@", url); 539 NSLog(@"requestTweetsList link %@", url);
568 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { 540 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) {
569 541
570 if (completion == NULL) { 542 if (completion == NULL) {
571 return ; 543 return ;
572 } 544 }
573 545
574 if (error == nil) 546 if (error == nil)
575 { 547 {
576 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 548 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
577 NSLog(@"%@", dataResult); 549 NSLog(@"%@", dataResult);
578 int status = [dataResult[@"status"] intValue]; 550 int status = [dataResult[@"status"] intValue];
579 if (status == 1) { // status = 1 success 551 if (status == 1) { // status = 1 success
580 if(dataResult[@"result"] != nil) { 552 if(dataResult[@"result"] != nil) {
581 NSArray * array = dataResult[@"result"]; 553 NSArray * array = dataResult[@"result"];
582 NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; 554 NSMutableArray * arrayTweets = [[NSMutableArray alloc] init];
583 for(NSDictionary * dict in array) { 555 for(NSDictionary * dict in array) {
584 TweetObject * object = [[TweetObject alloc] initWithData:dict]; 556 TweetObject * object = [[TweetObject alloc] initWithData:dict];
585 [arrayTweets addObject:object]; 557 [arrayTweets addObject:object];
586 } 558 }
587 completion(arrayTweets, nil); 559 completion(arrayTweets, nil);
588 } 560 }
589 else { 561 else {
590 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 562 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
591 completion(nil, errorObject); 563 completion(nil, errorObject);
592 } 564 }
593 } 565 }
594 else { 566 else {
595 NSString *message = dataResult[@"message"]; 567 NSString *message = dataResult[@"message"];
596 if (message == nil) { 568 if (message == nil) {
597 message = @"Unknown error"; 569 message = @"Unknown error";
598 } 570 }
599 571
600 if ([message isEqualToString:@"Token is invalid"]) { 572 if ([message isEqualToString:@"Token is invalid"]) {
601 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 573 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
602 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; 574 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
603 [self requestTweetsList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; 575 [self requestTweetsList:tokenNew groupID:groupID withPage:page CompletionHandler:completion];
604 } 576 }
605 else { 577 else {
606 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 578 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
607 completion(nil, errorObject); 579 completion(nil, errorObject);
608 } 580 }
609 } 581 }
610 } 582 }
611 else 583 else
612 { 584 {
613 completion(nil, error); 585 completion(nil, error);
614 } 586 }
615 }]; 587 }];
616 } 588 }
617 589
618 - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { 590 - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion {
619 NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"]; 591 NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"];
620 NSLog(@"searchGroup link %@ page %d", url, page); 592 NSLog(@"searchGroup link %@ page %d", url, page);
621 if(searchTask != nil) { 593 if(searchTask != nil) {
622 [searchTask cancel]; 594 [searchTask cancel];
623 } 595 }
624 596
625 searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) { 597 searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) {
626 searchTask = nil; 598 searchTask = nil;
627 if (completion == NULL) { 599 if (completion == NULL) {
628 return ; 600 return ;
629 } 601 }
630 602
631 if (error == nil) 603 if (error == nil)
632 { 604 {
633 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 605 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
634 NSLog(@"%@", dataResult); 606 NSLog(@"%@", dataResult);
635 int status = [dataResult[@"status"] intValue]; 607 int status = [dataResult[@"status"] intValue];
636 if (status == 1) { // status = 1 success 608 if (status == 1) { // status = 1 success
637 if(dataResult[@"result"] != nil) { 609 if(dataResult[@"result"] != nil) {
638 NSArray * array = dataResult[@"result"]; 610 NSArray * array = dataResult[@"result"];
639 NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; 611 NSMutableArray * arrayTweets = [[NSMutableArray alloc] init];
640 for(NSDictionary * dict in array) { 612 for(NSDictionary * dict in array) {
641 GroupObject * object = [[GroupObject alloc] initWithData:dict]; 613 GroupObject * object = [[GroupObject alloc] initWithData:dict];
642 [arrayTweets addObject:object]; 614 [arrayTweets addObject:object];
643 } 615 }
644 completion(arrayTweets, nil); 616 completion(arrayTweets, nil);
645 } 617 }
646 else { 618 else {
647 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 619 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
648 completion(nil, errorObject); 620 completion(nil, errorObject);
649 } 621 }
650 } 622 }
651 else { 623 else {
652 NSString *message = dataResult[@"message"]; 624 NSString *message = dataResult[@"message"];
653 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 625 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
654 completion(nil, errorObject); 626 completion(nil, errorObject);
655 } 627 }
656 } 628 }
657 else 629 else
658 { 630 {
659 completion(nil, error); 631 completion(nil, error);
660 } 632 }
661 }]; 633 }];
662 } 634 }
663 635
664 #pragma mark - Group Function 636 #pragma mark - Group Function
665 -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { 637 -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion {
666 NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/newGroup"]; 638 NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/newGroup"];
667 NSLog(@"requestCreateGroup link %@", url); 639 NSLog(@"requestCreateGroup link %@", url);
668 NSDictionary * dict = @{@"group_name":group.name, 640 NSDictionary * dict = @{@"group_name":group.name,
669 @"goal":group.goal, 641 @"goal":group.goal,
670 @"walk_mode_active":[NSNumber numberWithBool:group.walkMode], 642 @"walk_mode_active":[NSNumber numberWithBool:group.walkMode],
671 @"run_mode_active":[NSNumber numberWithBool:group.runMode], 643 @"run_mode_active":[NSNumber numberWithBool:group.runMode],
672 @"bike_mode_active":[NSNumber numberWithBool:group.bikeMode], 644 @"bike_mode_active":[NSNumber numberWithBool:group.bikeMode],
673 @"step_mode_active":[NSNumber numberWithBool:group.stepMode], 645 @"step_mode_active":[NSNumber numberWithBool:group.stepMode],
674 @"gym_mode_active":[NSNumber numberWithBool:group.gymMode], 646 @"gym_mode_active":[NSNumber numberWithBool:group.gymMode],
675 @"beginer_mode_active":[NSNumber numberWithBool:group.beginMode], 647 @"beginer_mode_active":[NSNumber numberWithBool:group.beginMode],
676 @"walk_mode_goal":[NSNumber numberWithBool:group.walkGoal], 648 @"walk_mode_goal":[NSNumber numberWithBool:group.walkGoal],
677 @"run_mode_goal":[NSNumber numberWithBool:group.runGoal], 649 @"run_mode_goal":[NSNumber numberWithBool:group.runGoal],
678 @"bike_mode_goal":[NSNumber numberWithBool:group.bikeGoal]}; 650 @"bike_mode_goal":[NSNumber numberWithBool:group.bikeGoal]};
679 651
680 [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { 652 [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) {
681 653
682 if (completion == NULL) { 654 if (completion == NULL) {
683 return ; 655 return ;
684 } 656 }
685 657
686 if (error == nil) 658 if (error == nil)
687 { 659 {
688 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 660 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
689 NSLog(@"%@", dataResult); 661 NSLog(@"%@", dataResult);
690 int status = [dataResult[@"status"] intValue]; 662 int status = [dataResult[@"status"] intValue];
691 if (status == 1) { // status = 1 success 663 if (status == 1) { // status = 1 success
692 if(dataResult[@"result"] != nil) { 664 if(dataResult[@"result"] != nil) {
693 NSDictionary * dict = dataResult[@"result"]; 665 NSDictionary * dict = dataResult[@"result"];
694 group.groupID = [dict[@"group_id"] intValue]; 666 group.groupID = [dict[@"group_id"] intValue];
695 completion(group, nil); 667 completion(group, nil);
696 } 668 }
697 else { 669 else {
698 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 670 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
699 completion(nil, errorObject); 671 completion(nil, errorObject);
700 } 672 }
701 } 673 }
702 else { 674 else {
703 NSString *message = dataResult[@"message"]; 675 NSString *message = dataResult[@"message"];
704 if (message == nil) { 676 if (message == nil) {
705 message = @"Unknown error"; 677 message = @"Unknown error";
706 } 678 }
707 679
708 if ([message isEqualToString:@"Token is invalid"]) { 680 if ([message isEqualToString:@"Token is invalid"]) {
709 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 681 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
710 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; 682 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
711 [self requestCreateGroup:tokenNew withGroup:group CompletionHandler:completion]; 683 [self requestCreateGroup:tokenNew withGroup:group CompletionHandler:completion];
712 } 684 }
713 else { 685 else {
714 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 686 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
715 completion(nil, errorObject); 687 completion(nil, errorObject);
716 } 688 }
717 } 689 }
718 } 690 }
719 else 691 else
720 { 692 {
721 completion(nil, error); 693 completion(nil, error);
722 } 694 }
723 }]; 695 }];
724 } 696 }
725 697
726 - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { 698 - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion {
727 NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID]; 699 NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID];
728 NSLog(@"getGroupDetail link %@", url); 700 NSLog(@"getGroupDetail link %@", url);
729 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { 701 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) {
730 702
731 if (completion == NULL) { 703 if (completion == NULL) {
732 return ; 704 return ;
733 } 705 }
734 706
735 if (error == nil) 707 if (error == nil)
736 { 708 {
737 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 709 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
738 NSLog(@"%@", dataResult); 710 NSLog(@"%@", dataResult);
739 int status = [dataResult[@"status"] intValue]; 711 int status = [dataResult[@"status"] intValue];
740 if (status == 1) { // status = 1 success 712 if (status == 1) { // status = 1 success
741 if(dataResult[@"result"] != nil) { 713 if(dataResult[@"result"] != nil) {
742 NSArray * array = dataResult[@"result"]; 714 NSArray * array = dataResult[@"result"];
743 GroupObject * object = [[GroupObject alloc] initWithData:array[0] andGroupID:groupID]; 715 GroupObject * object = [[GroupObject alloc] initWithData:array[0] andGroupID:groupID];
744 completion(object, nil); 716 completion(object, nil);
745 } 717 }
746 else { 718 else {
747 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 719 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
748 completion(nil, errorObject); 720 completion(nil, errorObject);
749 } 721 }
750 } 722 }
751 else { 723 else {
752 NSString *message = dataResult[@"message"]; 724 NSString *message = dataResult[@"message"];
753 if (message == nil) { 725 if (message == nil) {
754 message = @"Unknown error"; 726 message = @"Unknown error";
755 } 727 }
756 728
757 if ([message isEqualToString:@"Token is invalid"]) { 729 if ([message isEqualToString:@"Token is invalid"]) {
758 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 730 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
759 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; 731 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
760 [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion]; 732 [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion];
761 } 733 }
762 else { 734 else {
763 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 735 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
764 completion(nil, errorObject); 736 completion(nil, errorObject);
765 } 737 }
766 } 738 }
767 } 739 }
768 else 740 else
769 { 741 {
770 completion(nil, error); 742 completion(nil, error);
771 } 743 }
772 }]; 744 }];
773 } 745 }
774 746
775 - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { 747 - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion {
776 NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/member/%d/%d", groupID, page]; 748 NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/member/%d/%d", groupID, page];
777 NSLog(@"requestMemberList link %@ page %d", url, page); 749 NSLog(@"requestMemberList link %@ page %d", url, page);
778 750
779 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { 751 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) {
780 if (completion == NULL) { 752 if (completion == NULL) {
781 return ; 753 return ;
782 } 754 }
783 755
784 if (error == nil) 756 if (error == nil)
785 { 757 {
786 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 758 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
787 NSLog(@"%@", dataResult); 759 NSLog(@"%@", dataResult);
788 int status = [dataResult[@"status"] intValue]; 760 int status = [dataResult[@"status"] intValue];
789 if (status == 1) { // status = 1 success 761 if (status == 1) { // status = 1 success
790 if(dataResult[@"result"] != nil) { 762 if(dataResult[@"result"] != nil) {
791 NSArray * array = dataResult[@"result"]; 763 NSArray * array = dataResult[@"result"];
792 NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; 764 NSMutableArray * arrayTweets = [[NSMutableArray alloc] init];
793 for(NSDictionary * dict in array) { 765 for(NSDictionary * dict in array) {
794 MemberObject * object = [[MemberObject alloc] initWithData:dict]; 766 MemberObject * object = [[MemberObject alloc] initWithData:dict];
795 [arrayTweets addObject:object]; 767 [arrayTweets addObject:object];
796 } 768 }
797 completion(arrayTweets, nil); 769 completion(arrayTweets, nil);
798 } 770 }
799 else { 771 else {
800 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 772 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
801 completion(nil, errorObject); 773 completion(nil, errorObject);
802 } 774 }
803 } 775 }
804 else { 776 else {
805 NSString *message = dataResult[@"message"]; 777 NSString *message = dataResult[@"message"];
806 if (message == nil) { 778 if (message == nil) {
807 message = @"Unknown error"; 779 message = @"Unknown error";
808 } 780 }
809 781
810 if ([message isEqualToString:@"Token is invalid"]) { 782 if ([message isEqualToString:@"Token is invalid"]) {
811 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 783 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
812 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; 784 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
813 [self requestMemberList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; 785 [self requestMemberList:tokenNew groupID:groupID withPage:page CompletionHandler:completion];
814 } 786 }
815 else { 787 else {
816 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 788 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
817 completion(nil, errorObject); 789 completion(nil, errorObject);
818 } 790 }
819 } 791 }
820 } 792 }
821 else 793 else
822 { 794 {
823 completion(nil, error); 795 completion(nil, error);
824 } 796 }
825 }]; 797 }];
826 } 798 }
827 799
828 - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion { 800 - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion {
829 NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/join"]; 801 NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/join"];
830 NSLog(@"requestJoinGroup link %@", url); 802 NSLog(@"requestJoinGroup link %@", url);
831 803
832 [self _request:url method:@"POST" token:token paras:@{@"group_id": [NSNumber numberWithInt:groupID]} completion:^(NSData *data, NSError *error) { 804 [self _request:url method:@"POST" token:token paras:@{@"group_id": [NSNumber numberWithInt:groupID]} completion:^(NSData *data, NSError *error) {
833 if (completion == NULL) { 805 if (completion == NULL) {
834 return ; 806 return ;
835 } 807 }
836 808
837 if (error == nil) 809 if (error == nil)
838 { 810 {
839 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 811 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
840 NSLog(@"%@", dataResult); 812 NSLog(@"%@", dataResult);
841 int status = [dataResult[@"status"] intValue]; 813 int status = [dataResult[@"status"] intValue];
842 if (status == 1) { // status = 1 success 814 if (status == 1) { // status = 1 success
843 if(dataResult[@"result"] != nil) { 815 if(dataResult[@"result"] != nil) {
844 completion(nil); 816 completion(nil);
845 } 817 }
846 else { 818 else {
847 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 819 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
848 completion(errorObject); 820 completion(errorObject);
849 } 821 }
850 } 822 }
851 else { 823 else {
852 NSString *message = dataResult[@"message"]; 824 NSString *message = dataResult[@"message"];
853 if ([message isEqualToString:@"Token is invalid"]) { 825 if ([message isEqualToString:@"Token is invalid"]) {
854 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 826 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
855 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; 827 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
856 [self requestJoinGroup:tokenNew groupID:groupID CompletionHandler:completion]; 828 [self requestJoinGroup:tokenNew groupID:groupID CompletionHandler:completion];
857 } 829 }
858 else { 830 else {
859 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 831 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
860 completion(errorObject); 832 completion(errorObject);
861 } 833 }
862 } 834 }
863 } 835 }
864 else 836 else
865 { 837 {
866 completion(error); 838 completion(error);
867 } 839 }
868 }]; 840 }];
869 } 841 }
870 842
871 - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion { 843 - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion {
872 NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/list"]; 844 NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/list"];
873 NSLog(@"requestGroupList link %@", url); 845 NSLog(@"requestGroupList link %@", url);
874 846
875 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { 847 [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) {
876 if (completion == NULL) { 848 if (completion == NULL) {
877 return ; 849 return ;
878 } 850 }
879 851
880 if (error == nil) 852 if (error == nil)
881 { 853 {
882 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 854 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
883 NSLog(@"%@", dataResult); 855 NSLog(@"%@", dataResult);
884 int status = [dataResult[@"status"] intValue]; 856 int status = [dataResult[@"status"] intValue];
885 if (status == 1) { // status = 1 success 857 if (status == 1) { // status = 1 success
886 if(dataResult[@"result"] != nil) { 858 if(dataResult[@"result"] != nil) {
887 NSArray * array = dataResult[@"result"]; 859 NSArray * array = dataResult[@"result"];
888 NSMutableArray * arrayGroup = [[NSMutableArray alloc] init]; 860 NSMutableArray * arrayGroup = [[NSMutableArray alloc] init];
889 for(NSDictionary * dict in array) { 861 for(NSDictionary * dict in array) {
890 GroupObject * object = [[GroupObject alloc] initWithShortData:dict]; 862 GroupObject * object = [[GroupObject alloc] initWithShortData:dict];
891 [arrayGroup addObject:object]; 863 [arrayGroup addObject:object];
892 } 864 }
893 completion(arrayGroup, nil); 865 completion(arrayGroup, nil);
894 } 866 }
895 else { 867 else {
896 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 868 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
897 completion(nil, errorObject); 869 completion(nil, errorObject);
898 } 870 }
899 } 871 }
900 else { 872 else {
901 NSString *message = dataResult[@"message"]; 873 NSString *message = dataResult[@"message"];
902 if (message == nil) { 874 if (message == nil) {
903 message = @"Unknown error"; 875 message = @"Unknown error";
904 } 876 }
905 877
906 if ([message isEqualToString:@"Token is invalid"]) { 878 if ([message isEqualToString:@"Token is invalid"]) {
907 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; 879 [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES];
908 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; 880 NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken];
909 [self requestGroupList:tokenNew CompletionHandler:completion]; 881 [self requestGroupList:tokenNew CompletionHandler:completion];
910 } 882 }
911 else { 883 else {
912 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 884 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
913 completion(nil, errorObject); 885 completion(nil, errorObject);
914 } 886 }
915 } 887 }
916 } 888 }
917 else 889 else
918 { 890 {
919 completion(nil, error); 891 completion(nil, error);
920 } 892 }
921 }]; 893 }];
922 } 894 }
923 #pragma mark - Common API 895 #pragma mark - Common API
924 - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { 896 - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion {
925 [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { 897 [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) {
926 898
927 if (completion == NULL) { 899 if (completion == NULL) {
928 return ; 900 return ;
929 } 901 }
930 902
931 if (error == nil) 903 if (error == nil)
932 { 904 {
933 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; 905 NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error];
934 906
935 int status = [dataResult[@"status"] intValue]; 907 int status = [dataResult[@"status"] intValue];
936 if (status == 1) { // status = 1 success 908 if (status == 1) { // status = 1 success
937 NSArray *arrayResult = dataResult[@"result"]; 909 NSArray *arrayResult = dataResult[@"result"];
938 if (arrayResult.count > 0) { 910 if (arrayResult.count > 0) {
939 NSString *token = arrayResult[0]; 911 NSString *token = arrayResult[0];
940 completion(token, nil); 912 completion(token, nil);
941 } 913 }
942 else { 914 else {
943 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; 915 NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}];
944 completion(nil, errorObject); 916 completion(nil, errorObject);
945 } 917 }
946 918
947 } 919 }
948 else { // status = 0 error 920 else { // status = 0 error
949 NSString *message = dataResult[@"message"]; 921 NSString *message = dataResult[@"message"];
950 if (message == nil) { 922 if (message == nil) {
951 message = @"Unknown error"; 923 message = @"Unknown error";
952 } 924 }
953 NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; 925 NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}];
954 completion(nil, loginFaild); 926 completion(nil, loginFaild);
955 } 927 }
956 } 928 }
957 else 929 else
958 { 930 {
959 completion(nil, error); 931 completion(nil, error);
960 } 932 }
961 }]; 933 }];
962 } 934 }
963 935
964 #pragma mark - Private Function 936 #pragma mark - Private Function
965 - (void) checkToken { 937 - (void) checkToken {
966 // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; 938 // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil];
967 NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; 939 NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser];
968 User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; 940 User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data];
969 if (user != nil) { 941 if (user != nil) {
970 [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { 942 [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) {
971 if (error == nil) { 943 if (error == nil) {
972 [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; 944 [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken];
973 [[NSUserDefaults standardUserDefaults] synchronize]; 945 [[NSUserDefaults standardUserDefaults] synchronize];
974 } 946 }
975 }]; 947 }];
976 } 948 }
977 } 949 }
978 - (NSData *) _encodeDictionary: (NSDictionary *) dictionary 950 - (NSData *) _encodeDictionary: (NSDictionary *) dictionary
979 { 951 {
980 NSMutableArray *parts = [[NSMutableArray alloc] init]; 952 NSMutableArray *parts = [[NSMutableArray alloc] init];
981 for (id key in dictionary) 953 for (id key in dictionary)
982 { 954 {
983 NSString *encodedValue = [[dictionary[key] description] urlencode]; 955 NSString *encodedValue = [[dictionary[key] description] urlencode];
984 NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; 956 NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
985 NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; 957 NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue];
986 [parts addObject:part]; 958 [parts addObject:part];
987 } 959 }
988 NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; 960 NSString *encodedDictionary = [parts componentsJoinedByString:@"&"];
989 return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; 961 return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding];
990 } 962 }
991 963
992 - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion 964 - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion
993 { 965 {
994 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; 966 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]];
995 request.HTTPMethod = method; 967 request.HTTPMethod = method;
996 [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; 968 [request setValue: @"application/json" forHTTPHeaderField: @"Accept"];
997 [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; 969 [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"];
998 if(token != nil && ![token isEqual: @""]) { 970 if(token != nil && ![token isEqual: @""]) {
999 [request setValue: token forHTTPHeaderField: @"token"]; 971 [request setValue: token forHTTPHeaderField: @"token"];
1000 } 972 }
1001 [request setTimeoutInterval:self.timeOutInterval]; 973 [request setTimeoutInterval:self.timeOutInterval];
1002 974
1003 if (paras != nil) 975 if (paras != nil)
1004 { 976 {
1005 NSData *encodedData = [self _encodeDictionary: paras]; 977 NSData *encodedData = [self _encodeDictionary: paras];
1006 [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; 978 [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"];
1007 [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; 979 [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"];
1008 [request setHTTPBody: encodedData]; 980 [request setHTTPBody: encodedData];
1009 } 981 }
1010 982
1011 NSURLSession *session = [NSURLSession sharedSession]; 983 NSURLSession *session = [NSURLSession sharedSession];
1012 NSURLSessionDataTask *task = [session dataTaskWithRequest:request 984 NSURLSessionDataTask *task = [session dataTaskWithRequest:request
1013 completionHandler: 985 completionHandler:
1014 ^(NSData *data, NSURLResponse *response, NSError *error) { 986 ^(NSData *data, NSURLResponse *response, NSError *error) {
1015 if (completion == NULL) { 987 if (completion == NULL) {
1016 return ; 988 return ;
1017 } 989 }
1018 if (error == nil) 990 if (error == nil)
1019 { 991 {
1020 completion(data, nil); 992 completion(data, nil);
1021 } 993 }
1022 else 994 else
1023 { 995 {
1024 completion(nil, error); 996 completion(nil, error);
LifeLog/LifeLog/Utilities.h
1 // 1 //
2 // Utilities.h 2 // Utilities.h
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by Nguyen Van Phong on 7/29/17. 5 // Created by Nguyen Van Phong on 7/29/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 #import <UIKit/UIKit.h> 10 #import <UIKit/UIKit.h>
11 11
12 @interface Utilities : NSObject 12 @interface Utilities : NSObject
13 + (NSString *)addCommaFromNumber:(NSInteger)number; 13 + (NSString *)addCommaFromNumber:(NSInteger)number;
14 + (UIColor *)convertHecToColor:(int) hex; 14 + (UIColor *)convertHecToColor:(int) hex;
15 + (void)showMessage:(NSString *)message withViewController:(UIViewController *)vc; 15 + (void)showMessage:(NSString *)message withViewController:(UIViewController *)vc;
16 + (void)showErrorMessage:(NSString *)message withViewController:(UIViewController *)vc; 16 + (void)showErrorMessage:(NSString *)message withViewController:(UIViewController *)vc;
17 + (NSString *) getImageLink : (NSString *) path; 17 + (NSString *) getImageLink : (NSString *) path;
18 18
19 //share function 19 //share function
20 + (void) shareFacebook : (NSString *) content withViewController:(UIViewController *)vc; 20 + (void) shareFacebook : (NSString *) content withViewController:(UIViewController *)vc;
21 + (void) shareTwitter : (NSString *) content withViewController:(UIViewController *)vc; 21 + (void) shareTwitter : (NSString *) content withViewController:(UIViewController *)vc;
22 + (void) shareLine : (NSString *) content withViewController:(UIViewController *)vc; 22 + (void) shareLine : (NSString *) content withViewController:(UIViewController *)vc;
23 + (void) shareEmail : (NSString *) content withViewController:(UIViewController *)vc; 23 + (void) shareEmail : (NSString *) content withViewController:(UIViewController *)vc;
24 + (void) shareOther : (NSString *) content withViewController:(UIViewController *)vc;
24 + (void) shareOther : (NSString *) content withViewController:(UIViewController *)vc; 25
25 26 //convert date time
26 //convert date time 27 + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format;
27 + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format; 28 + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format locale:(NSString *) locale;
29 + (NSString *) convertSecondToShortTime : (int) seconds;
30 + (NSString *) convertSecondToLongTime : (int) seconds;
28 + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format locale:(NSString *) locale; 31 @end
29 + (NSString *) convertSecondToShortTime : (int) seconds; 32
LifeLog/LifeLog/Utilities.m
1 // 1 //
2 // Utilities.m 2 // Utilities.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by Nguyen Van Phong on 7/29/17. 5 // Created by Nguyen Van Phong on 7/29/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import <Social/Social.h> 9 #import <Social/Social.h>
10 #import <LineKit/Line.h> 10 #import <LineKit/Line.h>
11 11
12 #import "Utilities.h" 12 #import "Utilities.h"
13 #import "ServerAPI.h" 13 #import "ServerAPI.h"
14 14
15 @implementation Utilities 15 @implementation Utilities
16 + (NSString *)addCommaFromNumber:(NSInteger)number 16 + (NSString *)addCommaFromNumber:(NSInteger)number
17 { 17 {
18 NSNumberFormatter *fmt = [[NSNumberFormatter alloc] init]; 18 NSNumberFormatter *fmt = [[NSNumberFormatter alloc] init];
19 [fmt setNumberStyle:NSNumberFormatterDecimalStyle]; 19 [fmt setNumberStyle:NSNumberFormatterDecimalStyle];
20 [fmt setMaximumFractionDigits:0]; 20 [fmt setMaximumFractionDigits:0];
21 NSString *result = [fmt stringFromNumber:@(number)]; 21 NSString *result = [fmt stringFromNumber:@(number)];
22 return result; 22 return result;
23 } 23 }
24 24
25 + (UIColor *)convertHecToColor:(int) hex 25 + (UIColor *)convertHecToColor:(int) hex
26 { 26 {
27 return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 \ 27 return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 \
28 green:((float)((hex & 0xFF00) >> 8))/255.0 \ 28 green:((float)((hex & 0xFF00) >> 8))/255.0 \
29 blue:((float)(hex & 0xFF))/255.0 alpha:1.0]; 29 blue:((float)(hex & 0xFF))/255.0 alpha:1.0];
30 } 30 }
31 31
32 + (void)showMessage:(NSString *)message withViewController:(UIViewController *)vc 32 + (void)showMessage:(NSString *)message withViewController:(UIViewController *)vc
33 { 33 {
34 if (message.length > 0) { 34 if (message.length > 0) {
35 UIAlertController * alert= [UIAlertController 35 UIAlertController * alert= [UIAlertController
36 alertControllerWithTitle:@"Message" 36 alertControllerWithTitle:@"Message"
37 message:message 37 message:message
38 preferredStyle:UIAlertControllerStyleAlert]; 38 preferredStyle:UIAlertControllerStyleAlert];
39 39
40 UIAlertAction* ok = [UIAlertAction 40 UIAlertAction* ok = [UIAlertAction
41 actionWithTitle:@"OK" 41 actionWithTitle:@"OK"
42 style:UIAlertActionStyleDefault 42 style:UIAlertActionStyleDefault
43 handler:^(UIAlertAction * action) 43 handler:^(UIAlertAction * action)
44 { 44 {
45 [alert dismissViewControllerAnimated:YES completion:nil]; 45 [alert dismissViewControllerAnimated:YES completion:nil];
46 }]; 46 }];
47 47
48 [alert addAction:ok]; 48 [alert addAction:ok];
49 49
50 [vc presentViewController:alert animated:YES completion:nil]; 50 [vc presentViewController:alert animated:YES completion:nil];
51 } 51 }
52 } 52 }
53 53
54 + (void)showErrorMessage:(NSString *)message withViewController:(UIViewController *)vc 54 + (void)showErrorMessage:(NSString *)message withViewController:(UIViewController *)vc
55 { 55 {
56 if (message.length > 0) { 56 if (message.length > 0) {
57 UIAlertController * alert= [UIAlertController 57 UIAlertController * alert= [UIAlertController
58 alertControllerWithTitle:@"Error" 58 alertControllerWithTitle:@"Error"
59 message:message 59 message:message
60 preferredStyle:UIAlertControllerStyleAlert]; 60 preferredStyle:UIAlertControllerStyleAlert];
61 61
62 UIAlertAction* ok = [UIAlertAction 62 UIAlertAction* ok = [UIAlertAction
63 actionWithTitle:@"OK" 63 actionWithTitle:@"OK"
64 style:UIAlertActionStyleDefault 64 style:UIAlertActionStyleDefault
65 handler:^(UIAlertAction * action) 65 handler:^(UIAlertAction * action)
66 { 66 {
67 [alert dismissViewControllerAnimated:YES completion:nil]; 67 [alert dismissViewControllerAnimated:YES completion:nil];
68 }]; 68 }];
69 69
70 [alert addAction:ok]; 70 [alert addAction:ok];
71 71
72 [vc presentViewController:alert animated:YES completion:nil]; 72 [vc presentViewController:alert animated:YES completion:nil];
73 } 73 }
74 } 74 }
75 75
76 + (NSString *) getImageLink : (NSString *) path { 76 + (NSString *) getImageLink : (NSString *) path {
77 NSString * link = kServerAddress; 77 NSString * link = kServerAddress;
78 return [link stringByAppendingString:path]; 78 return [link stringByAppendingString:path];
79 } 79 }
80 80
81 + (void) shareFacebook : (NSString *) content withViewController:(UIViewController *)vc { 81 + (void) shareFacebook : (NSString *) content withViewController:(UIViewController *)vc {
82 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 82 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
83 { 83 {
84 SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 84 SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
85 85
86 [composeViewController setInitialText:content]; 86 [composeViewController setInitialText:content];
87 [composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) { 87 [composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
88 88
89 switch (result) { 89 switch (result) {
90 case SLComposeViewControllerResultCancelled: 90 case SLComposeViewControllerResultCancelled:
91 NSLog(@"canceled"); 91 NSLog(@"canceled");
92 break; 92 break;
93 case SLComposeViewControllerResultDone: 93 case SLComposeViewControllerResultDone:
94 NSLog(@"done"); 94 NSLog(@"done");
95 break; 95 break;
96 default: 96 default:
97 break; 97 break;
98 } 98 }
99 }]; 99 }];
100 [vc presentViewController:composeViewController animated:YES completion:nil]; 100 [vc presentViewController:composeViewController animated:YES completion:nil];
101 } 101 }
102 else { 102 else {
103 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=FACEBOOK"]]; 103 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=FACEBOOK"]];
104 } 104 }
105 } 105 }
106 106
107 + (void) shareTwitter : (NSString *) content withViewController:(UIViewController *)vc { 107 + (void) shareTwitter : (NSString *) content withViewController:(UIViewController *)vc {
108 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 108 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
109 { 109 {
110 SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; 110 SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
111 111
112 [composeViewController setInitialText:content]; 112 [composeViewController setInitialText:content];
113 [composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) { 113 [composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
114 114
115 switch (result) { 115 switch (result) {
116 case SLComposeViewControllerResultCancelled: 116 case SLComposeViewControllerResultCancelled:
117 NSLog(@"canceled"); 117 NSLog(@"canceled");
118 break; 118 break;
119 case SLComposeViewControllerResultDone: 119 case SLComposeViewControllerResultDone:
120 NSLog(@"done"); 120 NSLog(@"done");
121 break; 121 break;
122 default: 122 default:
123 break; 123 break;
124 } 124 }
125 }]; 125 }];
126 [vc presentViewController:composeViewController animated:YES completion:nil]; 126 [vc presentViewController:composeViewController animated:YES completion:nil];
127 } 127 }
128 else { 128 else {
129 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=TWITTER"]]; 129 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=TWITTER"]];
130 } 130 }
131 } 131 }
132 132
133 + (void) shareLine : (NSString *) content withViewController:(UIViewController *)vc { 133 + (void) shareLine : (NSString *) content withViewController:(UIViewController *)vc {
134 if (![Line isLineInstalled]) { 134 if (![Line isLineInstalled]) {
135 [self showErrorMessage:@"Install Line app first" withViewController:vc]; 135 [self showErrorMessage:@"Install Line app first" withViewController:vc];
136 } 136 }
137 else { 137 else {
138 [Line shareText:content]; 138 [Line shareText:content];
139 } 139 }
140 } 140 }
141 141
142 + (void) shareEmail : (NSString *) content withViewController:(UIViewController *)vc { 142 + (void) shareEmail : (NSString *) content withViewController:(UIViewController *)vc {
143 NSString *urlEmail = @"mailto:?subject=Share from LifeLog&body="; 143 NSString *urlEmail = @"mailto:?subject=Share from LifeLog&body=";
144 urlEmail = [urlEmail stringByAppendingString:content]; 144 urlEmail = [urlEmail stringByAppendingString:content];
145 urlEmail = [urlEmail stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]; 145 urlEmail = [urlEmail stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
146 [[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlEmail]]; 146 [[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlEmail]];
147 } 147 }
148 148
149 + (void) shareOther : (NSString *) content withViewController:(UIViewController *)vc {
150 NSArray *items = @[content];
151 UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
152 [vc presentViewController:controller animated:true completion:nil];
153 }
154
149 + (void) shareOther : (NSString *) content withViewController:(UIViewController *)vc { 155 #pragma mark convert date time
150 NSArray *items = @[content]; 156 + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format {
151 UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil]; 157 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
152 [vc presentViewController:controller animated:true completion:nil]; 158 [dateFormat setDateFormat:format];
153 } 159 NSDate *date = [dateFormat dateFromString:dateString];
154 160 if(date == NULL) {
155 #pragma mark convert date time 161 return [NSDate date];
156 + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format { 162 }
157 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 163 return date;
158 [dateFormat setDateFormat:format]; 164 }
159 NSDate *date = [dateFormat dateFromString:dateString]; 165
160 if(date == NULL) { 166 + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format locale:(NSString *) locale {
161 return [NSDate date]; 167 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
162 } 168 [dateFormat setDateFormat:format];
163 return date; 169 if(![locale isEqual: @""]) {
164 } 170 [dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:locale]];
165 171 }
166 + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format locale:(NSString *) locale { 172 NSString *dateString = [dateFormat stringFromDate:date];
167 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 173 return dateString;
168 [dateFormat setDateFormat:format]; 174 }
169 if(![locale isEqual: @""]) { 175
176 + (NSString *) convertSecondToShortTime : (int) seconds {
177 int hour = seconds / 3600;
178 int minutes = (seconds - hour * 3600) / 60;
179 return [NSString stringWithFormat:@"%02d:%02d", hour, minutes];
180 }
181
182 + (NSString *) convertSecondToLongTime : (int) seconds {
183 int hour = seconds / 3600;
184 int minutes = (seconds - hour * 3600) / 60;
185 int sec = seconds - hour * 3600 - minutes * 60;
186 return [NSString stringWithFormat:@"%02d:%02d:%02d", hour, minutes, sec];
187 }
188
170 [dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:locale]]; 189 @end
171 } 190