Commit 168c4f04021e6d3b17dc227ad079bd80117b41b8
1 parent
e759cbb03c
Exists in
master
and in
1 other branch
Update API history and change some object
Showing 12 changed files with 112 additions and 52 deletions Inline Diff
- LifeLog/LifeLog/GroupDetailViewController.m
- LifeLog/LifeLog/HistoryObject.h
- LifeLog/LifeLog/HistoryObject.m
- LifeLog/LifeLog/HistoryViewController.h
- LifeLog/LifeLog/HistoryViewController.m
- LifeLog/LifeLog/HistoryViewController.xib
- LifeLog/LifeLog/MyGroupViewController.m
- LifeLog/LifeLog/SNSViewController.m
- LifeLog/LifeLog/ServerAPI.h
- LifeLog/LifeLog/ServerAPI.m
- LifeLog/LifeLog/Utilities.h
- LifeLog/LifeLog/Utilities.m
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 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 154 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
155 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 155 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
156 | } | 156 | } |
157 | else { | 157 | else { |
158 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | 158 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; |
159 | } | 159 | } |
160 | cell.lblUsername.text = @""; | 160 | cell.lblUsername.text = @""; |
161 | cell.lblDateTime.text = @""; | 161 | cell.lblDateTime.text = @""; |
162 | cell.lblDes.text = object.userName; | 162 | cell.lblDes.text = object.userName; |
163 | cell.lblMode.text = @""; | 163 | cell.lblMode.text = @""; |
164 | cell.lblDistance.text = @""; | 164 | cell.lblDistance.text = @""; |
165 | cell.lblDuration.text = @""; | 165 | cell.lblDuration.text = @""; |
166 | } | 166 | } |
167 | else { | 167 | else { |
168 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 168 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
169 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 169 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
170 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 170 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
171 | } | 171 | } |
172 | else { | 172 | else { |
173 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | 173 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; |
174 | } | 174 | } |
175 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; | 175 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; |
176 | cell.lblUsername.text = object.userName; | 176 | cell.lblUsername.text = object.userName; |
177 | cell.lblDes.text = object.content; | 177 | cell.lblDes.text = object.content; |
178 | cell.lblMode.text = object.mode; | 178 | cell.lblMode.text = object.mode; |
179 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | 179 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; |
180 | cell.lblDuration.text = object.time; | 180 | cell.lblDuration.text = object.time; |
181 | } | 181 | } |
182 | 182 | ||
183 | return cell; | 183 | return cell; |
184 | } | 184 | } |
185 | 185 | ||
186 | #pragma mark Private Function | 186 | #pragma mark Private Function |
187 | 187 | ||
188 | -(void) callRequestToUpdateData { | 188 | -(void) callRequestToUpdateData { |
189 | [super callRequestToUpdateData]; | 189 | [super callRequestToUpdateData]; |
190 | 190 | ||
191 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 191 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
192 | MBProgressHUD *hudView = nil; | 192 | MBProgressHUD *hudView = nil; |
193 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 193 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
194 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 194 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
195 | } | 195 | } |
196 | if(isMemberList) { | 196 | if(isMemberList) { |
197 | [[ServerAPI server] requestMemberList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 197 | [[ServerAPI server] requestMemberList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
198 | dispatch_async(dispatch_get_main_queue(), ^{ | 198 | dispatch_async(dispatch_get_main_queue(), ^{ |
199 | if(hudView != nil) { | 199 | if(hudView != nil) { |
200 | [hudView hideAnimated:true]; | 200 | [hudView hideAnimated:true]; |
201 | } | 201 | } |
202 | }); | 202 | }); |
203 | GroupDetailViewController __weak *weakSelf = self; | 203 | GroupDetailViewController __weak *weakSelf = self; |
204 | [weakSelf updateTableData:array error:error]; | 204 | [weakSelf updateTableData:array error:error]; |
205 | [weakSelf.btSwitch setUserInteractionEnabled:true]; | 205 | [weakSelf.btSwitch setUserInteractionEnabled:true]; |
206 | }]; | 206 | }]; |
207 | } | 207 | } |
208 | else { | 208 | else { |
209 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 209 | [[ServerAPI server] requestTweetsList:token groupID:_curGroup.groupID withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
210 | dispatch_async(dispatch_get_main_queue(), ^{ | 210 | dispatch_async(dispatch_get_main_queue(), ^{ |
211 | if(hudView != nil) { | 211 | if(hudView != nil) { |
212 | [hudView hideAnimated:true]; | 212 | [hudView hideAnimated:true]; |
213 | } | 213 | } |
214 | }); | 214 | }); |
215 | GroupDetailViewController __weak *weakSelf = self; | 215 | GroupDetailViewController __weak *weakSelf = self; |
216 | [weakSelf updateTableData:array error:error]; | 216 | [weakSelf updateTableData:array error:error]; |
217 | [weakSelf.btSwitch setUserInteractionEnabled:true]; | 217 | [weakSelf.btSwitch setUserInteractionEnabled:true]; |
218 | }]; | 218 | }]; |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | @end | 222 | @end |
223 | 223 |
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 missing; | 14 | @property (nonatomic) int missing; |
15 | @property (nonatomic) int target; | 15 | @property (nonatomic) int target; |
16 | @property (nonatomic) float percent; | 16 | @property (nonatomic) float percent; |
17 | @property (nonatomic) float distance; | 17 | @property (nonatomic) float distance; |
18 | @property (nonatomic) float calories; | 18 | @property (nonatomic) float calories; |
19 | @property (nonatomic, strong) NSString * time; | 19 | @property (nonatomic, strong) NSString * time; |
20 | @property (nonatomic, strong) NSDate *date; | 20 | @property (nonatomic, strong) NSDate *date; |
21 | @property (nonatomic, strong) NSMutableArray *dataGraph; | ||
21 | 22 | ||
22 | -(id) initWithData : (NSDictionary *) dict; | 23 | -(id) initWithData : (NSDictionary *) dict; |
23 | 24 | ||
24 | @end | 25 | @end |
25 | 26 |
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 | 10 | ||
11 | @implementation HistoryObject | 11 | @implementation HistoryObject |
12 | 12 | ||
13 | -(id) initWithData : (NSDictionary *) dict { | 13 | -(id) initWithData : (NSDictionary *) dict { |
14 | if([dict objectForKey:@"step"] != nil) { | 14 | if([dict objectForKey:@"steps"] != nil) { |
15 | self.step = [dict[@"step"] intValue]; | 15 | self.step = [dict[@"step"] intValue]; |
16 | } | 16 | } |
17 | if([dict objectForKey:@"target"] != nil) { | 17 | if([dict objectForKey:@"target"] != nil) { |
18 | self.target = [dict[@"target"] intValue]; | 18 | self.target = [dict[@"target"] intValue]; |
19 | } | 19 | } |
20 | if([dict objectForKey:@"missing"] != nil) { | 20 | if([dict objectForKey:@"step_remain"] != nil) { |
21 | self.missing = [dict[@"missing"] intValue]; | 21 | self.missing = [dict[@"step_remain"] intValue]; |
22 | } | 22 | } |
23 | if([dict objectForKey:@"percent"] != nil) { | 23 | if([dict objectForKey:@"complete_percent"] != nil) { |
24 | self.percent = [dict[@"percent"] floatValue]; | 24 | self.percent = [dict[@"complete_percent"] floatValue]; |
25 | } | 25 | } |
26 | if([dict objectForKey:@"distance"] != nil) { | 26 | if([dict objectForKey:@"distance"] != nil) { |
27 | if([dict[@"distance"] isKindOfClass:[NSString class]]) { | 27 | if([dict[@"distance"] isKindOfClass:[NSString class]]) { |
28 | NSString *distance = dict[@"distance"]; | 28 | NSString *distance = dict[@"distance"]; |
29 | self.distance = [distance floatValue]; | 29 | self.distance = [distance floatValue]; |
30 | } | 30 | } |
31 | else { | 31 | else { |
32 | self.distance = [dict[@"distance"] floatValue]; | 32 | self.distance = [dict[@"distance"] floatValue]; |
33 | } | 33 | } |
34 | } | 34 | } |
35 | if([dict objectForKey:@"kcal"] != nil) { | 35 | if([dict objectForKey:@"kcal"] != nil) { |
36 | self.calories = [dict[@"kcal"] floatValue]; | 36 | self.calories = [dict[@"kcal"] floatValue]; |
37 | } | 37 | } |
38 | if([dict objectForKey:@"time"] != nil) { | 38 | if([dict objectForKey:@"time"] != nil) { |
39 | if([dict[@"time"] isKindOfClass:[NSString class]]) { | 39 | if([dict[@"time"] isKindOfClass:[NSString class]]) { |
40 | self.time = dict[@"time"]; | 40 | self.time = dict[@"time"]; |
41 | } | 41 | } |
42 | else { | 42 | else { |
43 | self.time = @"0:0"; | 43 | self.time = @"0:0"; |
44 | } | 44 | } |
45 | } | 45 | } |
46 | if([dict objectForKey:@"date"] != nil) { | 46 | if([dict objectForKey:@"date"] != nil) { |
47 | NSString *dateString = dict[@"date"]; | 47 | NSString *dateString = dict[@"date"]; |
48 | NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; | 48 | NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; |
49 | [dateFormat setDateFormat:@"yyyy-MM-dd"]; | 49 | [dateFormat setDateFormat:@"yyyy-MM-dd"]; |
50 | self.date = [dateFormat dateFromString:dateString]; | 50 | self.date = [dateFormat dateFromString:dateString]; |
51 | } | 51 | } |
52 | else { | 52 | else { |
53 | self.date = [NSDate date]; | 53 | self.date = [NSDate date]; |
54 | } | ||
55 | if([dict objectForKey:@"data_chart"] != nil) { | ||
56 | self.dataGraph = [[NSMutableArray alloc] init]; | ||
57 | NSDictionary * graph = [dict objectForKey:@"data_chart"]; | ||
58 | if([graph count] == 24) { | ||
59 | for(int i = 0; i < 24; i++) { | ||
60 | [self.dataGraph addObject:[graph objectForKey:[NSString stringWithFormat:@"%d", i]]]; | ||
61 | } | ||
62 | } | ||
54 | } | 63 | } |
55 | return self; | 64 | return self; |
56 | } | 65 | } |
57 | @end | 66 | @end |
58 | 67 |
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 * _curDate; | 18 | NSDate * _startDate; |
19 | HistoryObject * _curHisObj; | 19 | NSDate * _endDate; |
20 | HistoryGraphObject * _curHisGraphObj; | 20 | NSArray * _curHisArray; |
21 | } | 21 | } |
22 | @property (weak, nonatomic) IBOutlet UILabel *lblDatetime; | ||
22 | 23 | ||
23 | @property (weak, nonatomic) IBOutlet UILabel *lblCircleStep; | 24 | @property (weak, nonatomic) IBOutlet UILabel *lblCircleStep; |
24 | @property (weak, nonatomic) IBOutlet UILabel *lblCircleRemain; | 25 | @property (weak, nonatomic) IBOutlet UILabel *lblCircleRemain; |
25 | 26 | ||
26 | @property (weak, nonatomic) IBOutlet UILabel *lblStep; | 27 | @property (weak, nonatomic) IBOutlet UILabel *lblStep; |
27 | @property (weak, nonatomic) IBOutlet UILabel *lblRemaining; | 28 | @property (weak, nonatomic) IBOutlet UILabel *lblRemaining; |
28 | @property (weak, nonatomic) IBOutlet UILabel *lblPercent; | 29 | @property (weak, nonatomic) IBOutlet UILabel *lblPercent; |
29 | @property (weak, nonatomic) IBOutlet UILabel *lblCalories; | 30 | @property (weak, nonatomic) IBOutlet UILabel *lblCalories; |
30 | @property (weak, nonatomic) IBOutlet UILabel *lblDistance; | 31 | @property (weak, nonatomic) IBOutlet UILabel *lblDistance; |
31 | @property (weak, nonatomic) IBOutlet UILabel *lblTime; | 32 | @property (weak, nonatomic) IBOutlet UILabel *lblTime; |
32 | 33 | ||
33 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionType; | 34 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionType; |
34 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionMode; | 35 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionMode; |
35 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionShare; | 36 | @property (weak, nonatomic) IBOutlet CollectionView *viewCollectionShare; |
36 | 37 | ||
37 | @property (weak, nonatomic) IBOutlet BarChartView *viewBarChart; | 38 | @property (weak, nonatomic) IBOutlet BarChartView *viewBarChart; |
38 | 39 | ||
39 | @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; | 40 | @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; |
40 | 41 | ||
41 | - (IBAction)swipeAction:(UISwipeGestureRecognizer *)sender; | 42 | - (IBAction)swipeAction:(UISwipeGestureRecognizer *)sender; |
43 | - (IBAction)clickBackward:(UIButton *)sender; | ||
44 | - (IBAction)clickForward:(UIButton *)sender; | ||
42 | 45 | ||
43 | @end | 46 | @end |
44 | 47 |
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 | [self setupView]; | 26 | [self setupView]; |
27 | [self setupChartView]; | 27 | [self setupChartView]; |
28 | 28 | ||
29 | _curDate = [NSDate date]; | 29 | _startDate = [NSDate date]; |
30 | _endDate = _startDate; | ||
30 | 31 | ||
32 | self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; | ||
33 | |||
31 | [self checkRequestData]; | 34 | [self checkRequestData]; |
32 | 35 | ||
33 | //register nib for table view | 36 | //register nib for table view |
34 | [self.tableBase registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; | 37 | [self.tableBase registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; |
35 | } | 38 | } |
36 | 39 | ||
37 | - (void)viewDidAppear:(BOOL) animated | 40 | - (void)viewDidAppear:(BOOL) animated |
38 | { | 41 | { |
39 | [super viewDidAppear:animated]; | 42 | [super viewDidAppear:animated]; |
40 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 400); | 43 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 400); |
41 | [self.scrollView setNeedsLayout]; | 44 | [self.scrollView setNeedsLayout]; |
42 | [self.scrollView setNeedsUpdateConstraints]; | 45 | [self.scrollView setNeedsUpdateConstraints]; |
43 | 46 | ||
44 | } | 47 | } |
45 | 48 | ||
46 | - (void)didReceiveMemoryWarning { | 49 | - (void)didReceiveMemoryWarning { |
47 | [super didReceiveMemoryWarning]; | 50 | [super didReceiveMemoryWarning]; |
48 | // Dispose of any resources that can be recreated. | 51 | // Dispose of any resources that can be recreated. |
49 | } | 52 | } |
50 | 53 | ||
51 | - (void)setupView { | 54 | - (void)setupView { |
52 | 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]; | 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]; |
53 | [self.viewCollectionType setButtonNumber:typeTitle.count]; | 56 | [self.viewCollectionType setButtonNumber:typeTitle.count]; |
54 | [self.viewCollectionType setSpacing:2]; | 57 | [self.viewCollectionType setSpacing:2]; |
55 | [self.viewCollectionType setArrayTitle:typeTitle]; | 58 | [self.viewCollectionType setArrayTitle:typeTitle]; |
56 | self.viewCollectionType.changeCurrentIndex = ^(int index){ | 59 | self.viewCollectionType.changeCurrentIndex = ^(int index){ |
57 | [self checkRequestData]; | 60 | [self changeDate]; |
58 | }; | 61 | }; |
59 | 62 | ||
60 | NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.mode.1", nil), NSLocalizedString(@"lifelog.history.mode.2", nil), NSLocalizedString(@"lifelog.history.mode.3", nil), nil]; | 63 | NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.mode.1", nil), NSLocalizedString(@"lifelog.history.mode.2", nil), NSLocalizedString(@"lifelog.history.mode.3", nil), nil]; |
61 | [self.viewCollectionMode setButtonNumber:modeTitle.count]; | 64 | [self.viewCollectionMode setButtonNumber:modeTitle.count]; |
62 | [self.viewCollectionMode setSpacing:0]; | 65 | [self.viewCollectionMode setSpacing:0]; |
63 | [self.viewCollectionMode setCornerRadius:0]; | 66 | [self.viewCollectionMode setCornerRadius:0]; |
64 | [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; | 67 | [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; |
65 | [self.viewCollectionMode setArrayTitle:modeTitle]; | 68 | [self.viewCollectionMode setArrayTitle:modeTitle]; |
66 | self.viewCollectionMode.changeCurrentIndex = ^(int index){ | 69 | self.viewCollectionMode.changeCurrentIndex = ^(int index){ |
67 | [self checkRequestData]; | 70 | [self updateView]; |
68 | }; | 71 | }; |
69 | 72 | ||
70 | 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]; | 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]; |
71 | [self.viewCollectionShare setButtonNumber:typeTitle.count]; | 74 | [self.viewCollectionShare setButtonNumber:typeTitle.count]; |
72 | [self.viewCollectionShare setSpacing:3]; | 75 | [self.viewCollectionShare setSpacing:3]; |
73 | [self.viewCollectionShare setArrayTitle:shareTitle]; | 76 | [self.viewCollectionShare setArrayTitle:shareTitle]; |
74 | [self.viewCollectionShare disableSelection]; | 77 | [self.viewCollectionShare disableSelection]; |
75 | 78 | ||
76 | //add tap gesture for enable tap on gesture on CollectionView in ScrollView | 79 | //add tap gesture for enable tap on gesture on CollectionView in ScrollView |
77 | UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; | 80 | UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; |
78 | [recognizer setNumberOfTapsRequired:1]; | 81 | [recognizer setNumberOfTapsRequired:1]; |
79 | self.scrollView.userInteractionEnabled = YES; | 82 | self.scrollView.userInteractionEnabled = YES; |
80 | [self.scrollView addGestureRecognizer:recognizer]; | 83 | [self.scrollView addGestureRecognizer:recognizer]; |
81 | } | 84 | } |
82 | 85 | ||
83 | - (void)setupChartView { | 86 | - (void)setupChartView { |
84 | self.viewBarChart.chartDescription.enabled = NO; | 87 | self.viewBarChart.chartDescription.enabled = NO; |
85 | self.viewBarChart.leftAxis.drawGridLinesEnabled = NO; | 88 | self.viewBarChart.leftAxis.drawGridLinesEnabled = NO; |
86 | self.viewBarChart.rightAxis.drawGridLinesEnabled = NO; | 89 | self.viewBarChart.rightAxis.drawGridLinesEnabled = NO; |
87 | self.viewBarChart.legend.enabled = NO; | 90 | self.viewBarChart.legend.enabled = NO; |
88 | 91 | ||
89 | ChartXAxis *xAxis = self.viewBarChart.xAxis; | 92 | ChartXAxis *xAxis = self.viewBarChart.xAxis; |
90 | xAxis.labelPosition = XAxisLabelPositionBottom; | 93 | xAxis.labelPosition = XAxisLabelPositionBottom; |
91 | xAxis.drawGridLinesEnabled = NO; | 94 | xAxis.drawGridLinesEnabled = NO; |
92 | xAxis.drawAxisLineEnabled = NO; | 95 | xAxis.drawAxisLineEnabled = NO; |
93 | xAxis.drawLabelsEnabled = YES; | 96 | xAxis.drawLabelsEnabled = YES; |
94 | xAxis.labelPosition = XAxisLabelPositionBottom; | 97 | xAxis.labelPosition = XAxisLabelPositionBottom; |
95 | xAxis.labelFont = [UIFont systemFontOfSize:10.f]; | 98 | xAxis.labelFont = [UIFont systemFontOfSize:10.f]; |
96 | xAxis.labelTextColor = [UIColor whiteColor]; | 99 | xAxis.labelTextColor = [UIColor whiteColor]; |
97 | xAxis.granularity = 1.0; // only intervals of 1 day | 100 | xAxis.granularity = 1.0; // only intervals of 1 day |
98 | xAxis.labelCount = 8; | 101 | xAxis.labelCount = 8; |
99 | 102 | ||
100 | self.viewBarChart.leftAxis.drawAxisLineEnabled = NO; | 103 | self.viewBarChart.leftAxis.drawAxisLineEnabled = NO; |
101 | self.viewBarChart.rightAxis.drawAxisLineEnabled = NO; | 104 | self.viewBarChart.rightAxis.drawAxisLineEnabled = NO; |
102 | } | 105 | } |
103 | 106 | ||
104 | -(void) updateView { | 107 | -(void) updateView { |
105 | self.lblStep.text = [NSString stringWithFormat:@"%d", _curHisObj.step]; | 108 | HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; |
106 | self.lblRemaining.text = [NSString stringWithFormat:@"%d", _curHisObj.missing]; | 109 | self.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; |
107 | self.lblPercent.text = [NSString stringWithFormat:@"%0.2f", _curHisObj.percent * 100]; | 110 | self.lblRemaining.text = [NSString stringWithFormat:@"%d", obj.missing]; |
108 | self.lblCalories.text = [NSString stringWithFormat:@"%0.2f", _curHisObj.calories]; | 111 | self.lblPercent.text = [NSString stringWithFormat:@"%0.2f", obj.percent * 100]; |
109 | self.lblDistance.text = [NSString stringWithFormat:@"%0.1f", _curHisObj.distance]; | 112 | self.lblCalories.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; |
110 | self.lblTime.text = _curHisObj.time; | 113 | self.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; |
114 | self.lblTime.text = obj.time; | ||
115 | [self updateGraphView]; | ||
111 | } | 116 | } |
112 | 117 | ||
113 | -(void) updateGraphView { | 118 | -(void) updateGraphView { |
119 | HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; | ||
120 | |||
114 | NSMutableArray *yVals = [[NSMutableArray alloc] init]; | 121 | NSMutableArray *yVals = [[NSMutableArray alloc] init]; |
115 | for (int i = 0; i < _curHisGraphObj.arrayStep.count; i++) | 122 | for (int i = 0; i < obj.dataGraph.count; i++) |
116 | { | 123 | { |
117 | [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:[[_curHisGraphObj.arrayStep objectAtIndex:i] doubleValue]]]; | 124 | [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:[[obj.dataGraph objectAtIndex:i] doubleValue]]]; |
118 | } | 125 | } |
119 | 126 | ||
120 | BarChartDataSet *set1 = nil; | 127 | BarChartDataSet *set1 = nil; |
121 | if (self.viewBarChart.data.dataSetCount > 0) | 128 | if (self.viewBarChart.data.dataSetCount > 0) |
122 | { | 129 | { |
123 | set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0]; | 130 | set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0]; |
124 | set1.values = yVals; | 131 | set1.values = yVals; |
125 | [self.viewBarChart.data notifyDataChanged]; | 132 | [self.viewBarChart.data notifyDataChanged]; |
126 | [self.viewBarChart notifyDataSetChanged]; | 133 | [self.viewBarChart notifyDataSetChanged]; |
127 | } | 134 | } |
128 | else | 135 | else |
129 | { | 136 | { |
130 | set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""]; | 137 | set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""]; |
131 | [set1 setColor:[UIColor whiteColor]]; | 138 | [set1 setColor:[UIColor whiteColor]]; |
132 | 139 | ||
133 | NSMutableArray *dataSets = [[NSMutableArray alloc] init]; | 140 | NSMutableArray *dataSets = [[NSMutableArray alloc] init]; |
134 | [dataSets addObject:set1]; | 141 | [dataSets addObject:set1]; |
135 | 142 | ||
136 | BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets]; | 143 | BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets]; |
137 | data.barWidth = 0.5f; | 144 | data.barWidth = 0.5f; |
138 | 145 | ||
139 | self.viewBarChart.data = data; | 146 | self.viewBarChart.data = data; |
140 | } | 147 | } |
141 | } | 148 | } |
142 | 149 | ||
143 | -(void) checkRequestData { | 150 | -(void) checkRequestData { |
144 | if(self.tableBase.alpha == 0.0) { | 151 | if(self.tableBase.alpha == 0.0) { |
145 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 152 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
146 | int type = self.viewCollectionType.getCurrentIndex; | ||
147 | int mode = self.viewCollectionMode.getCurrentIndex + 1; | ||
148 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 153 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
149 | [[ServerAPI server] requestHistory:token atDate:_curDate withType:type andMode:mode CompletionHandler:^(HistoryObject *object, NSError *error) { | 154 | [[ServerAPI server] requestHistory:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) { |
150 | HistoryViewController __weak *weakSelf = self; | 155 | HistoryViewController __weak *weakSelf = self; |
151 | dispatch_async(dispatch_get_main_queue(), ^{ | 156 | dispatch_async(dispatch_get_main_queue(), ^{ |
152 | if(hudView != nil) { | 157 | if(hudView != nil) { |
153 | [hudView hideAnimated:true]; | 158 | [hudView hideAnimated:true]; |
154 | } | 159 | } |
155 | }); | 160 | }); |
156 | if(error == nil) { | 161 | if(error == nil) { |
157 | _curHisObj = object; | 162 | _curHisArray = array; |
158 | dispatch_async(dispatch_get_main_queue(), ^{ | 163 | dispatch_async(dispatch_get_main_queue(), ^{ |
159 | [weakSelf updateView]; | 164 | [weakSelf updateView]; |
160 | }); | 165 | }); |
161 | } | 166 | } |
162 | else { | 167 | else { |
163 | dispatch_async(dispatch_get_main_queue(), ^{ | 168 | dispatch_async(dispatch_get_main_queue(), ^{ |
164 | NSString *message = [error.userInfo objectForKey:@"message"]; | 169 | NSString *message = [error.userInfo objectForKey:@"message"]; |
165 | [Utilities showErrorMessage:message withViewController:weakSelf]; | 170 | [Utilities showErrorMessage:message withViewController:weakSelf]; |
166 | }); | 171 | }); |
167 | } | 172 | } |
168 | }]; | 173 | }]; |
169 | |||
170 | [[ServerAPI server] requestHistoryGraph:token withType:type andMode:mode CompletionHandler:^(HistoryGraphObject *object, NSError *error) { | ||
171 | HistoryViewController __weak *weakSelf = self; | ||
172 | if(error == nil) { | ||
173 | _curHisGraphObj = object; | ||
174 | dispatch_async(dispatch_get_main_queue(), ^{ | ||
175 | [self updateGraphView]; | ||
176 | }); | ||
177 | } | ||
178 | else { | ||
179 | dispatch_async(dispatch_get_main_queue(), ^{ | ||
180 | NSString *message = [error.userInfo objectForKey:@"message"]; | ||
181 | [Utilities showErrorMessage:message withViewController:weakSelf]; | ||
182 | }); | ||
183 | } | ||
184 | }]; | ||
185 | } | 174 | } |
186 | else { | 175 | else { |
187 | [self resetData]; | 176 | [self resetData]; |
188 | } | 177 | } |
189 | } | 178 | } |
190 | 179 | ||
191 | -(void) callRequestToUpdateData { | 180 | -(void) callRequestToUpdateData { |
192 | [super callRequestToUpdateData]; | 181 | [super callRequestToUpdateData]; |
193 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 182 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
194 | int type = self.viewCollectionType.getCurrentIndex; | 183 | int type = self.viewCollectionType.getCurrentIndex; |
195 | int mode = self.viewCollectionMode.getCurrentIndex + 1; | 184 | int mode = self.viewCollectionMode.getCurrentIndex + 1; |
196 | 185 | ||
197 | MBProgressHUD *hudView = nil; | 186 | MBProgressHUD *hudView = nil; |
198 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 187 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
199 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 188 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
200 | } | 189 | } |
201 | [[ServerAPI server] requestHistoryList:token withType:type andMode:mode AtPage:_curPage CompletionHandler:^(NSArray *array, NSError *error) { | 190 | [[ServerAPI server] requestHistoryList:token withType:type andMode:mode AtPage:_curPage CompletionHandler:^(NSArray *array, NSError *error) { |
202 | dispatch_async(dispatch_get_main_queue(), ^{ | 191 | dispatch_async(dispatch_get_main_queue(), ^{ |
203 | if(hudView != nil) { | 192 | if(hudView != nil) { |
204 | [hudView hideAnimated:true]; | 193 | [hudView hideAnimated:true]; |
205 | } | 194 | } |
206 | }); | 195 | }); |
207 | HistoryViewController __weak *weakSelf = self; | 196 | HistoryViewController __weak *weakSelf = self; |
208 | [weakSelf updateTableData:array error:error]; | 197 | [weakSelf updateTableData:array error:error]; |
209 | }]; | 198 | }]; |
210 | } | 199 | } |
211 | 200 | ||
201 | - (void) changeDate { | ||
202 | switch (self.viewCollectionType.getCurrentIndex) { | ||
203 | case 1: | ||
204 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 7]; | ||
205 | break; | ||
206 | case 2: | ||
207 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30]; | ||
208 | break; | ||
209 | case 3: | ||
210 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 3]; | ||
211 | break; | ||
212 | case 4: | ||
213 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 6]; | ||
214 | break; | ||
215 | default: | ||
216 | _startDate = _endDate; | ||
217 | break; | ||
218 | } | ||
219 | [self checkRequestData]; | ||
220 | } | ||
221 | |||
212 | #pragma mark IBAction | 222 | #pragma mark IBAction |
213 | -(void) swipeAction:(UISwipeGestureRecognizer *)sender { | 223 | -(void) swipeAction:(UISwipeGestureRecognizer *)sender { |
214 | bool alphaValue = self.scrollView.alpha == 1.0 ? 1.0 : 0.0; | 224 | bool alphaValue = self.scrollView.alpha == 1.0 ? 1.0 : 0.0; |
215 | [UIView animateWithDuration:0.5 animations:^{ | 225 | [UIView animateWithDuration:0.5 animations:^{ |
216 | self.tableBase.alpha = alphaValue; | 226 | self.tableBase.alpha = alphaValue; |
217 | self.scrollView.alpha = 1.0 - alphaValue; | 227 | self.scrollView.alpha = 1.0 - alphaValue; |
218 | } completion:^(BOOL completed) { | 228 | } completion:^(BOOL completed) { |
219 | [self checkRequestData]; | 229 | [self checkRequestData]; |
220 | }]; | 230 | }]; |
231 | } | ||
232 | |||
233 | - (IBAction)clickBackward:(UIButton *)sender { | ||
234 | _endDate = [_endDate dateByAddingTimeInterval:-86400]; | ||
235 | self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; | ||
236 | [self changeDate]; | ||
237 | } | ||
238 | |||
239 | - (IBAction)clickForward:(UIButton *)sender { | ||
240 | _endDate = [_endDate dateByAddingTimeInterval:86400]; | ||
241 | self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; | ||
242 | [self changeDate]; | ||
221 | } | 243 | } |
222 | 244 | ||
223 | -(void)gestureAction:(UITapGestureRecognizer *) sender | 245 | -(void)gestureAction:(UITapGestureRecognizer *) sender |
224 | { | 246 | { |
225 | CGPoint touchLocation = [sender locationOfTouch:0 inView:self.viewCollectionShare]; | 247 | CGPoint touchLocation = [sender locationOfTouch:0 inView:self.viewCollectionShare]; |
226 | NSIndexPath *indexPath = [self.viewCollectionShare.collectionView indexPathForItemAtPoint:touchLocation]; | 248 | NSIndexPath *indexPath = [self.viewCollectionShare.collectionView indexPathForItemAtPoint:touchLocation]; |
227 | NSString * content = @"Finish 500 steps"; | 249 | NSString * content = @"Finish 500 steps"; |
228 | HistoryViewController __weak *weakSelf = self; | 250 | HistoryViewController __weak *weakSelf = self; |
229 | if(indexPath != NULL) { | 251 | if(indexPath != NULL) { |
230 | switch (indexPath.row) { | 252 | switch (indexPath.row) { |
231 | case 0: //share facebook | 253 | case 0: //share facebook |
232 | [Utilities shareFacebook:content withViewController:weakSelf]; | 254 | [Utilities shareFacebook:content withViewController:weakSelf]; |
233 | break; | 255 | break; |
234 | case 1: //share twitter | 256 | case 1: //share twitter |
235 | [Utilities shareTwitter:content withViewController:weakSelf]; | 257 | [Utilities shareTwitter:content withViewController:weakSelf]; |
236 | break; | 258 | break; |
237 | case 2 : //share line | 259 | case 2 : //share line |
238 | [Utilities shareLine:content withViewController:weakSelf]; | 260 | [Utilities shareLine:content withViewController:weakSelf]; |
239 | break; | 261 | break; |
240 | case 3: // share email | 262 | case 3: // share email |
241 | [Utilities shareEmail:content withViewController:weakSelf]; | 263 | [Utilities shareEmail:content withViewController:weakSelf]; |
242 | break; | 264 | break; |
243 | default: | 265 | default: |
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="12118" systemVersion="16D32" 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="12086"/> |
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="lblDistance" destination="1tR-JC-pyw" id="q4s-Ru-vLO"/> | 18 | <outlet property="lblDistance" destination="1tR-JC-pyw" id="q4s-Ru-vLO"/> |
18 | <outlet property="lblPercent" destination="8Ru-Jc-Ouv" id="ZHn-Kt-0Qk"/> | 19 | <outlet property="lblPercent" destination="8Ru-Jc-Ouv" id="ZHn-Kt-0Qk"/> |
19 | <outlet property="lblRemaining" destination="1NH-b3-ST8" id="hFc-q9-b0h"/> | 20 | <outlet property="lblRemaining" destination="1NH-b3-ST8" id="hFc-q9-b0h"/> |
20 | <outlet property="lblStep" destination="0pf-fX-QXT" id="jK4-9Y-89Q"/> | 21 | <outlet property="lblStep" destination="0pf-fX-QXT" id="jK4-9Y-89Q"/> |
21 | <outlet property="lblTime" destination="PfZ-7x-LAR" id="NQv-fs-rl7"/> | 22 | <outlet property="lblTime" destination="PfZ-7x-LAR" id="NQv-fs-rl7"/> |
22 | <outlet property="scrollView" destination="rey-N3-l8b" id="s3w-fi-n5l"/> | 23 | <outlet property="scrollView" destination="rey-N3-l8b" id="s3w-fi-n5l"/> |
23 | <outlet property="tableBase" destination="FXQ-4O-sRc" id="UHy-Nk-f7u"/> | 24 | <outlet property="tableBase" destination="FXQ-4O-sRc" id="UHy-Nk-f7u"/> |
24 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | 25 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> |
25 | <outlet property="viewBarChart" destination="VqD-Y3-cYQ" id="RdJ-G5-pPy"/> | 26 | <outlet property="viewBarChart" destination="VqD-Y3-cYQ" id="RdJ-G5-pPy"/> |
26 | <outlet property="viewCollectionMode" destination="BVv-qD-EHM" id="A6n-32-oxg"/> | 27 | <outlet property="viewCollectionMode" destination="BVv-qD-EHM" id="A6n-32-oxg"/> |
27 | <outlet property="viewCollectionShare" destination="Iw2-nW-e7g" id="LW3-j0-yEY"/> | 28 | <outlet property="viewCollectionShare" destination="Iw2-nW-e7g" id="LW3-j0-yEY"/> |
28 | <outlet property="viewCollectionType" destination="yxY-4d-tB6" id="K1D-Gc-kWV"/> | 29 | <outlet property="viewCollectionType" destination="yxY-4d-tB6" id="K1D-Gc-kWV"/> |
29 | </connections> | 30 | </connections> |
30 | </placeholder> | 31 | </placeholder> |
31 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | 32 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> |
32 | <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> | 33 | <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> |
33 | <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"/> |
34 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | 35 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
35 | <subviews> | 36 | <subviews> |
36 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="clL-JG-rbd" userLabel="ViewHeader"> | 37 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="clL-JG-rbd" userLabel="ViewHeader"> |
37 | <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"/> |
38 | <subviews> | 39 | <subviews> |
39 | <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"> |
40 | <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"/> |
41 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 42 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
42 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 43 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
43 | <nil key="highlightedColor"/> | 44 | <nil key="highlightedColor"/> |
44 | <userDefinedRuntimeAttributes> | 45 | <userDefinedRuntimeAttributes> |
45 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title"/> | 46 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title"/> |
46 | </userDefinedRuntimeAttributes> | 47 | </userDefinedRuntimeAttributes> |
47 | </label> | 48 | </label> |
48 | <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"> |
49 | <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"/> |
50 | <constraints> | 51 | <constraints> |
51 | <constraint firstAttribute="width" constant="70" id="xAE-oP-WEf"/> | 52 | <constraint firstAttribute="width" constant="70" id="xAE-oP-WEf"/> |
52 | </constraints> | 53 | </constraints> |
53 | <state key="normal" image="today_back_button"/> | 54 | <state key="normal" image="today_back_button"/> |
54 | </button> | 55 | </button> |
55 | <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"> |
56 | <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"/> |
57 | <constraints> | 58 | <constraints> |
58 | <constraint firstAttribute="width" constant="45" id="V0g-Ii-pNQ"/> | 59 | <constraint firstAttribute="width" constant="45" id="V0g-Ii-pNQ"/> |
59 | </constraints> | 60 | </constraints> |
60 | <state key="normal" image="icon_menu"/> | 61 | <state key="normal" image="icon_menu"/> |
61 | </button> | 62 | </button> |
62 | </subviews> | 63 | </subviews> |
63 | <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"/> |
64 | <constraints> | 65 | <constraints> |
65 | <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"/> |
66 | <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"/> |
67 | <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"/> |
68 | <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"/> |
69 | <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"/> |
70 | <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"/> |
71 | <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"/> |
72 | <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"/> |
73 | <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"/> |
74 | <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"/> |
75 | <constraint firstAttribute="height" constant="46" id="xGd-BD-bgs"/> | 76 | <constraint firstAttribute="height" constant="46" id="xGd-BD-bgs"/> |
76 | </constraints> | 77 | </constraints> |
77 | </view> | 78 | </view> |
78 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cf1-lP-zbB" userLabel="ViewTime"> | 79 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cf1-lP-zbB" userLabel="ViewTime"> |
79 | <rect key="frame" x="10" y="46" width="355" height="35"/> | 80 | <rect key="frame" x="10" y="46" width="355" height="35"/> |
80 | <subviews> | 81 | <subviews> |
81 | <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"> |
82 | <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"/> |
83 | <constraints> | 84 | <constraints> |
84 | <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"/> |
85 | </constraints> | 86 | </constraints> |
86 | <state key="normal" backgroundImage="arrow_back"/> | 87 | <state key="normal" backgroundImage="arrow_back"/> |
88 | <connections> | ||
89 | <action selector="clickBackward:" destination="-1" eventType="touchUpInside" id="pwN-yT-qyp"/> | ||
90 | </connections> | ||
87 | </button> | 91 | </button> |
88 | <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"> |
89 | <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"/> |
90 | <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 94 | <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
91 | <state key="normal" backgroundImage="arrow_next"/> | 95 | <state key="normal" backgroundImage="arrow_next"/> |
96 | <connections> | ||
97 | <action selector="clickForward:" destination="-1" eventType="touchUpInside" id="1NC-km-Lfe"/> | ||
98 | </connections> | ||
92 | </button> | 99 | </button> |
93 | <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"> |
94 | <rect key="frame" x="40" y="2" width="275" height="31"/> | 101 | <rect key="frame" x="40" y="2" width="275" height="31"/> |
95 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 102 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
96 | <nil key="textColor"/> | 103 | <nil key="textColor"/> |
97 | <nil key="highlightedColor"/> | 104 | <nil key="highlightedColor"/> |
98 | </label> | 105 | </label> |
99 | </subviews> | 106 | </subviews> |
100 | <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 107 | <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
101 | <constraints> | 108 | <constraints> |
102 | <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"/> |
103 | <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"/> |
104 | <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"/> |
105 | <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"/> |
106 | <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"/> |
107 | <constraint firstAttribute="height" constant="35" id="Pdg-IR-g8y"/> | 114 | <constraint firstAttribute="height" constant="35" id="Pdg-IR-g8y"/> |
108 | <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"/> |
109 | <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"/> |
110 | <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"/> |
111 | <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"/> |
112 | <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"/> |
113 | <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"/> |
114 | </constraints> | 121 | </constraints> |
115 | </view> | 122 | </view> |
116 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yxY-4d-tB6" customClass="CollectionView"> | 123 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yxY-4d-tB6" customClass="CollectionView"> |
117 | <rect key="frame" x="2" y="96" width="371" height="40"/> | 124 | <rect key="frame" x="2" y="96" width="371" height="40"/> |
118 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 125 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
119 | <constraints> | 126 | <constraints> |
120 | <constraint firstAttribute="height" constant="40" id="U7Q-wa-CDi"/> | 127 | <constraint firstAttribute="height" constant="40" id="U7Q-wa-CDi"/> |
121 | </constraints> | 128 | </constraints> |
122 | </view> | 129 | </view> |
123 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVv-qD-EHM" customClass="CollectionView"> | 130 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVv-qD-EHM" customClass="CollectionView"> |
124 | <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"/> |
125 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 132 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
126 | <constraints> | 133 | <constraints> |
127 | <constraint firstAttribute="height" constant="40" id="6wc-NQ-UAH"/> | 134 | <constraint firstAttribute="height" constant="40" id="6wc-NQ-UAH"/> |
128 | </constraints> | 135 | </constraints> |
129 | </view> | 136 | </view> |
130 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FLa-rV-Aas" userLabel="ViewContent"> | 137 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FLa-rV-Aas" userLabel="ViewContent"> |
131 | <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"/> |
132 | <subviews> | 139 | <subviews> |
133 | <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"> |
134 | <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"/> |
135 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 142 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
136 | <connections> | 143 | <connections> |
137 | <outlet property="dataSource" destination="-1" id="GQy-lg-1Af"/> | 144 | <outlet property="dataSource" destination="-1" id="GQy-lg-1Af"/> |
138 | <outlet property="delegate" destination="-1" id="Jka-Ij-zNq"/> | 145 | <outlet property="delegate" destination="-1" id="Jka-Ij-zNq"/> |
139 | </connections> | 146 | </connections> |
140 | </tableView> | 147 | </tableView> |
141 | <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"> |
142 | <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"/> |
143 | <subviews> | 150 | <subviews> |
144 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cam-ML-IEO"> | 151 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cam-ML-IEO"> |
145 | <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"/> |
146 | <subviews> | 153 | <subviews> |
147 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Kzk-mN-AOf"> | 154 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Kzk-mN-AOf"> |
148 | <rect key="frame" x="20" y="30" width="120" height="120"/> | 155 | <rect key="frame" x="20" y="30" width="120" height="120"/> |
149 | <subviews> | 156 | <subviews> |
150 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="500 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="500 step" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oWg-A8-aCr"> |
151 | <rect key="frame" x="18" y="35" width="82" height="21"/> | 158 | <rect key="frame" x="18" y="35" width="82" height="21"/> |
152 | <constraints> | 159 | <constraints> |
153 | <constraint firstAttribute="height" constant="21" id="zOX-0d-IVv"/> | 160 | <constraint firstAttribute="height" constant="21" id="zOX-0d-IVv"/> |
154 | </constraints> | 161 | </constraints> |
155 | <fontDescription key="fontDescription" type="system" pointSize="17"/> | 162 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
156 | <nil key="textColor"/> | 163 | <nil key="textColor"/> |
157 | <nil key="highlightedColor"/> | 164 | <nil key="highlightedColor"/> |
158 | </label> | 165 | </label> |
159 | <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"> |
160 | <rect key="frame" x="20" y="61" width="80" height="42"/> | 167 | <rect key="frame" x="20" y="61" width="80" height="42"/> |
161 | <constraints> | 168 | <constraints> |
162 | <constraint firstAttribute="width" constant="80" id="IOc-sB-dA2"/> | 169 | <constraint firstAttribute="width" constant="80" id="IOc-sB-dA2"/> |
163 | <constraint firstAttribute="height" constant="42" id="zRP-Fu-qZ9"/> | 170 | <constraint firstAttribute="height" constant="42" id="zRP-Fu-qZ9"/> |
164 | </constraints> | 171 | </constraints> |
165 | <string key="text">目標まであと | 172 | <string key="text">目標まであと |
166 | 500 stepです</string> | 173 | 500 stepです</string> |
167 | <fontDescription key="fontDescription" type="system" pointSize="11"/> | 174 | <fontDescription key="fontDescription" type="system" pointSize="11"/> |
168 | <nil key="textColor"/> | 175 | <nil key="textColor"/> |
169 | <nil key="highlightedColor"/> | 176 | <nil key="highlightedColor"/> |
170 | </label> | 177 | </label> |
171 | </subviews> | 178 | </subviews> |
172 | <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 179 | <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
173 | <constraints> | 180 | <constraints> |
174 | <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"/> |
175 | <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"/> |
176 | <constraint firstAttribute="width" constant="120" id="E48-cC-dsc"/> | 183 | <constraint firstAttribute="width" constant="120" id="E48-cC-dsc"/> |
177 | <constraint firstAttribute="height" constant="120" id="SlY-sr-tR9"/> | 184 | <constraint firstAttribute="height" constant="120" id="SlY-sr-tR9"/> |
178 | <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"/> |
179 | <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"/> |
180 | <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"/> |
181 | </constraints> | 188 | </constraints> |
182 | <userDefinedRuntimeAttributes> | 189 | <userDefinedRuntimeAttributes> |
183 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> | 190 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> |
184 | <integer key="value" value="60"/> | 191 | <integer key="value" value="60"/> |
185 | </userDefinedRuntimeAttribute> | 192 | </userDefinedRuntimeAttribute> |
186 | </userDefinedRuntimeAttributes> | 193 | </userDefinedRuntimeAttributes> |
187 | </view> | 194 | </view> |
188 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4ix-HE-d9T"> | 195 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4ix-HE-d9T"> |
189 | <rect key="frame" x="148" y="30" width="219" height="120"/> | 196 | <rect key="frame" x="148" y="30" width="219" height="120"/> |
190 | <subviews> | 197 | <subviews> |
191 | <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"> |
192 | <rect key="frame" x="10" y="38" width="45" height="15"/> | 199 | <rect key="frame" x="10" y="38" width="45" height="15"/> |
193 | <constraints> | 200 | <constraints> |
194 | <constraint firstAttribute="width" constant="45" id="6Ce-YE-wbx"/> | 201 | <constraint firstAttribute="width" constant="45" id="6Ce-YE-wbx"/> |
195 | <constraint firstAttribute="height" constant="15" id="eFR-Ao-75U"/> | 202 | <constraint firstAttribute="height" constant="15" id="eFR-Ao-75U"/> |
196 | </constraints> | 203 | </constraints> |
197 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 204 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
198 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 205 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
199 | <nil key="highlightedColor"/> | 206 | <nil key="highlightedColor"/> |
200 | <userDefinedRuntimeAttributes> | 207 | <userDefinedRuntimeAttributes> |
201 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.total"/> | 208 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.total"/> |
202 | </userDefinedRuntimeAttributes> | 209 | </userDefinedRuntimeAttributes> |
203 | </label> | 210 | </label> |
204 | <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"> |
205 | <rect key="frame" x="10" y="53" width="45" height="15"/> | 212 | <rect key="frame" x="10" y="53" width="45" height="15"/> |
206 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 213 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
207 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 214 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
208 | <nil key="highlightedColor"/> | 215 | <nil key="highlightedColor"/> |
209 | <userDefinedRuntimeAttributes> | 216 | <userDefinedRuntimeAttributes> |
210 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.remaining"/> | 217 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.remaining"/> |
211 | </userDefinedRuntimeAttributes> | 218 | </userDefinedRuntimeAttributes> |
212 | </label> | 219 | </label> |
213 | <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"> |
214 | <rect key="frame" x="10" y="68" width="45" height="15"/> | 221 | <rect key="frame" x="10" y="68" width="45" height="15"/> |
215 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 222 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
216 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 223 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
217 | <nil key="highlightedColor"/> | 224 | <nil key="highlightedColor"/> |
218 | <userDefinedRuntimeAttributes> | 225 | <userDefinedRuntimeAttributes> |
219 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.percent"/> | 226 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.percent"/> |
220 | </userDefinedRuntimeAttributes> | 227 | </userDefinedRuntimeAttributes> |
221 | </label> | 228 | </label> |
222 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0pf-fX-QXT"> | 229 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0pf-fX-QXT"> |
223 | <rect key="frame" x="63" y="38" width="118" height="15"/> | 230 | <rect key="frame" x="63" y="38" width="118" height="15"/> |
224 | <constraints> | 231 | <constraints> |
225 | <constraint firstAttribute="height" constant="15" id="Z6o-LI-Eu9"/> | 232 | <constraint firstAttribute="height" constant="15" id="Z6o-LI-Eu9"/> |
226 | </constraints> | 233 | </constraints> |
227 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 234 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
228 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 235 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
229 | <nil key="highlightedColor"/> | 236 | <nil key="highlightedColor"/> |
230 | </label> | 237 | </label> |
231 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="500 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="500 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1NH-b3-ST8"> |
232 | <rect key="frame" x="63" y="53" width="118" height="15"/> | 239 | <rect key="frame" x="63" y="53" width="118" height="15"/> |
233 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 240 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
234 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 241 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
235 | <nil key="highlightedColor"/> | 242 | <nil key="highlightedColor"/> |
236 | </label> | 243 | </label> |
237 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="50 %" 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="50 %" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8Ru-Jc-Ouv"> |
238 | <rect key="frame" x="63" y="68" width="118" height="15"/> | 245 | <rect key="frame" x="63" y="68" width="118" height="15"/> |
239 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 246 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
240 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 247 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
241 | <nil key="highlightedColor"/> | 248 | <nil key="highlightedColor"/> |
242 | </label> | 249 | </label> |
243 | </subviews> | 250 | </subviews> |
244 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 251 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
245 | <constraints> | 252 | <constraints> |
246 | <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"/> |
247 | <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"/> |
248 | <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"/> |
249 | <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"/> |
250 | <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"/> |
251 | <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"/> |
252 | <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"/> |
253 | <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"/> |
254 | <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"/> |
255 | <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"/> |
256 | <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"/> |
257 | <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"/> |
258 | <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"/> |
259 | <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"/> |
260 | <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"/> |
261 | <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"/> |
262 | <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"/> |
263 | <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"/> |
264 | <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"/> |
265 | <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"/> |
266 | <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"/> |
267 | <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"/> |
268 | <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"/> |
269 | </constraints> | 276 | </constraints> |
270 | </view> | 277 | </view> |
271 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iEh-Ze-suq"> | 278 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iEh-Ze-suq"> |
272 | <rect key="frame" x="20" y="158" width="335" height="35"/> | 279 | <rect key="frame" x="20" y="158" width="335" height="35"/> |
273 | <subviews> | 280 | <subviews> |
274 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UwA-5Q-gdv"> | 281 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UwA-5Q-gdv"> |
275 | <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"/> |
276 | <subviews> | 283 | <subviews> |
277 | <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"> |
278 | <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"/> |
279 | <constraints> | 286 | <constraints> |
280 | <constraint firstAttribute="height" constant="18" id="Ywp-RA-6am"/> | 287 | <constraint firstAttribute="height" constant="18" id="Ywp-RA-6am"/> |
281 | </constraints> | 288 | </constraints> |
282 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 289 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
283 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 290 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
284 | <nil key="highlightedColor"/> | 291 | <nil key="highlightedColor"/> |
285 | <userDefinedRuntimeAttributes> | 292 | <userDefinedRuntimeAttributes> |
286 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.calories"/> | 293 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.calories"/> |
287 | </userDefinedRuntimeAttributes> | 294 | </userDefinedRuntimeAttributes> |
288 | </label> | 295 | </label> |
289 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 kcal" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dAE-C8-QLr"> | 296 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1000 kcal" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dAE-C8-QLr"> |
290 | <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"/> |
291 | <constraints> | 298 | <constraints> |
292 | <constraint firstAttribute="height" constant="18" id="r0d-xi-3u7"/> | 299 | <constraint firstAttribute="height" constant="18" id="r0d-xi-3u7"/> |
293 | </constraints> | 300 | </constraints> |
294 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 301 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
295 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 302 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
296 | <nil key="highlightedColor"/> | 303 | <nil key="highlightedColor"/> |
297 | </label> | 304 | </label> |
298 | </subviews> | 305 | </subviews> |
299 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 306 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
300 | <constraints> | 307 | <constraints> |
301 | <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"/> |
302 | <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"/> |
303 | <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"/> |
304 | <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"/> |
305 | <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"/> |
306 | <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"/> |
307 | </constraints> | 314 | </constraints> |
308 | </view> | 315 | </view> |
309 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVs-KG-fDF"> | 316 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BVs-KG-fDF"> |
310 | <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"/> |
311 | <subviews> | 318 | <subviews> |
312 | <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"> |
313 | <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"/> |
314 | <constraints> | 321 | <constraints> |
315 | <constraint firstAttribute="height" constant="18" id="tct-pY-7wo"/> | 322 | <constraint firstAttribute="height" constant="18" id="tct-pY-7wo"/> |
316 | </constraints> | 323 | </constraints> |
317 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 324 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
318 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 325 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
319 | <nil key="highlightedColor"/> | 326 | <nil key="highlightedColor"/> |
320 | <userDefinedRuntimeAttributes> | 327 | <userDefinedRuntimeAttributes> |
321 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.distance"/> | 328 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.distance"/> |
322 | </userDefinedRuntimeAttributes> | 329 | </userDefinedRuntimeAttributes> |
323 | </label> | 330 | </label> |
324 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="4.0 KM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1tR-JC-pyw"> | 331 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="4.0 KM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1tR-JC-pyw"> |
325 | <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"/> |
326 | <constraints> | 333 | <constraints> |
327 | <constraint firstAttribute="height" constant="18" id="sNT-xl-BKH"/> | 334 | <constraint firstAttribute="height" constant="18" id="sNT-xl-BKH"/> |
328 | </constraints> | 335 | </constraints> |
329 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 336 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
330 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 337 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
331 | <nil key="highlightedColor"/> | 338 | <nil key="highlightedColor"/> |
332 | </label> | 339 | </label> |
333 | </subviews> | 340 | </subviews> |
334 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 341 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
335 | <constraints> | 342 | <constraints> |
336 | <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"/> |
337 | <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"/> |
338 | <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"/> |
339 | <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"/> |
340 | <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"/> |
341 | <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"/> |
342 | </constraints> | 349 | </constraints> |
343 | </view> | 350 | </view> |
344 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="j5h-QD-Igf"> | 351 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="j5h-QD-Igf"> |
345 | <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"/> |
346 | <subviews> | 353 | <subviews> |
347 | <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"> |
348 | <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"/> |
349 | <constraints> | 356 | <constraints> |
350 | <constraint firstAttribute="height" constant="18" id="EVe-qW-qqp"/> | 357 | <constraint firstAttribute="height" constant="18" id="EVe-qW-qqp"/> |
351 | </constraints> | 358 | </constraints> |
352 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 359 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
353 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 360 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
354 | <nil key="highlightedColor"/> | 361 | <nil key="highlightedColor"/> |
355 | <userDefinedRuntimeAttributes> | 362 | <userDefinedRuntimeAttributes> |
356 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.time"/> | 363 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.time"/> |
357 | </userDefinedRuntimeAttributes> | 364 | </userDefinedRuntimeAttributes> |
358 | </label> | 365 | </label> |
359 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1:00 時間" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PfZ-7x-LAR"> | 366 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1:00 時間" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PfZ-7x-LAR"> |
360 | <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"/> |
361 | <constraints> | 368 | <constraints> |
362 | <constraint firstAttribute="height" constant="18" id="lno-Dx-ZNm"/> | 369 | <constraint firstAttribute="height" constant="18" id="lno-Dx-ZNm"/> |
363 | </constraints> | 370 | </constraints> |
364 | <fontDescription key="fontDescription" type="system" pointSize="12"/> | 371 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
365 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 372 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
366 | <nil key="highlightedColor"/> | 373 | <nil key="highlightedColor"/> |
367 | </label> | 374 | </label> |
368 | </subviews> | 375 | </subviews> |
369 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 376 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
370 | <constraints> | 377 | <constraints> |
371 | <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"/> |
372 | <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"/> |
373 | <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"/> |
374 | <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"/> |
375 | <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"/> |
376 | <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"/> |
377 | </constraints> | 384 | </constraints> |
378 | </view> | 385 | </view> |
379 | </subviews> | 386 | </subviews> |
380 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 387 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
381 | <constraints> | 388 | <constraints> |
382 | <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"/> |
383 | <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"/> |
384 | <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"/> |
385 | <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"/> |
386 | <constraint firstAttribute="height" constant="35" id="WDe-uC-4Qb"/> | 393 | <constraint firstAttribute="height" constant="35" id="WDe-uC-4Qb"/> |
387 | <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"/> |
388 | <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"/> |
389 | <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"/> |
390 | <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"/> |
391 | <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"/> |
392 | <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"/> |
393 | <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"/> |
394 | <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"/> |
395 | </constraints> | 402 | </constraints> |
396 | </view> | 403 | </view> |
397 | <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"> |
398 | <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"/> |
399 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 406 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
400 | <constraints> | 407 | <constraints> |
401 | <constraint firstAttribute="height" constant="100" id="aQR-hf-MhR"/> | 408 | <constraint firstAttribute="height" constant="100" id="aQR-hf-MhR"/> |
402 | </constraints> | 409 | </constraints> |
403 | </view> | 410 | </view> |
404 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Iw2-nW-e7g" customClass="CollectionView"> | 411 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Iw2-nW-e7g" customClass="CollectionView"> |
405 | <rect key="frame" x="20" y="316" width="335" height="50"/> | 412 | <rect key="frame" x="20" y="316" width="335" height="50"/> |
406 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 413 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
407 | <constraints> | 414 | <constraints> |
408 | <constraint firstAttribute="height" constant="50" id="Yzh-hD-r0n"/> | 415 | <constraint firstAttribute="height" constant="50" id="Yzh-hD-r0n"/> |
409 | </constraints> | 416 | </constraints> |
410 | </view> | 417 | </view> |
411 | </subviews> | 418 | </subviews> |
412 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 419 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
413 | <constraints> | 420 | <constraints> |
414 | <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"/> |
415 | <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"/> |
416 | <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"/> |
417 | <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"/> |
418 | <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"/> |
419 | <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"/> |
420 | <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"/> |
421 | <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"/> |
422 | <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"/> |
423 | <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"/> |
424 | <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"/> |
425 | <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"/> |
426 | <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"/> |
427 | <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"/> |
428 | <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"/> |
429 | </constraints> | 436 | </constraints> |
430 | </view> | 437 | </view> |
431 | </subviews> | 438 | </subviews> |
432 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 439 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
433 | <constraints> | 440 | <constraints> |
434 | <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"/> |
435 | <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"/> |
436 | <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"/> |
437 | <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"/> |
438 | <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"/> |
439 | <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"/> |
440 | </constraints> | 447 | </constraints> |
441 | <connections> | 448 | <connections> |
442 | <outlet property="delegate" destination="-1" id="3Fl-Qy-gjm"/> | 449 | <outlet property="delegate" destination="-1" id="3Fl-Qy-gjm"/> |
443 | </connections> | 450 | </connections> |
444 | </scrollView> | 451 | </scrollView> |
445 | </subviews> | 452 | </subviews> |
446 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 453 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
447 | <constraints> | 454 | <constraints> |
448 | <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"/> |
449 | <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"/> |
450 | <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"/> |
451 | <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"/> |
452 | <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"/> |
453 | <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"/> |
454 | <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"/> |
455 | <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"/> |
456 | </constraints> | 463 | </constraints> |
457 | <connections> | 464 | <connections> |
458 | <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"/> |
459 | <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"/> |
460 | </connections> | 467 | </connections> |
461 | </view> | 468 | </view> |
462 | </subviews> | 469 | </subviews> |
463 | <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> | 470 | <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> |
464 | <gestureRecognizers/> | 471 | <gestureRecognizers/> |
465 | <constraints> | 472 | <constraints> |
466 | <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"/> |
467 | <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"/> |
468 | <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"/> |
469 | <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"/> |
470 | <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"/> |
471 | <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"/> |
472 | <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"/> |
473 | <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"/> |
474 | <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"/> |
475 | <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"/> |
476 | <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"/> |
477 | <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"/> |
478 | <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"/> |
479 | <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"/> |
480 | <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"/> |
481 | <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"/> |
482 | </constraints> | 489 | </constraints> |
483 | <point key="canvasLocation" x="26.5" y="52.5"/> | 490 | <point key="canvasLocation" x="26.5" y="52.5"/> |
484 | </view> | 491 | </view> |
485 | <swipeGestureRecognizer cancelsTouchesInView="NO" direction="left" id="Qjg-St-rCc"> | 492 | <swipeGestureRecognizer cancelsTouchesInView="NO" direction="left" id="Qjg-St-rCc"> |
486 | <connections> | 493 | <connections> |
487 | <action selector="swipeAction:" destination="-1" id="2Vl-bM-Ta7"/> | 494 | <action selector="swipeAction:" destination="-1" id="2Vl-bM-Ta7"/> |
488 | </connections> | 495 | </connections> |
489 | </swipeGestureRecognizer> | 496 | </swipeGestureRecognizer> |
490 | <swipeGestureRecognizer cancelsTouchesInView="NO" direction="right" id="VSZ-i0-Jhb"> | 497 | <swipeGestureRecognizer cancelsTouchesInView="NO" direction="right" id="VSZ-i0-Jhb"> |
491 | <connections> | 498 | <connections> |
492 | <action selector="swipeAction:" destination="-1" id="hoY-6M-DoS"/> | 499 | <action selector="swipeAction:" destination="-1" id="hoY-6M-DoS"/> |
493 | </connections> | 500 | </connections> |
494 | </swipeGestureRecognizer> | 501 | </swipeGestureRecognizer> |
495 | </objects> | 502 | </objects> |
496 | <resources> | 503 | <resources> |
497 | <image name="arrow_back" width="22" height="22"/> | 504 | <image name="arrow_back" width="22" height="22"/> |
498 | <image name="arrow_next" width="22" height="22"/> | 505 | <image name="arrow_next" width="22" height="22"/> |
499 | <image name="icon_menu" width="30" height="30"/> | 506 | <image name="icon_menu" width="30" height="30"/> |
500 | <image name="today_back_button" width="73" height="37"/> | 507 | <image name="today_back_button" width="73" height="37"/> |
501 | </resources> | 508 | </resources> |
502 | </document> | 509 | </document> |
503 | 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 | #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 MyGroupViewController () | 16 | @interface MyGroupViewController () |
17 | 17 | ||
18 | @end | 18 | @end |
19 | 19 | ||
20 | @implementation MyGroupViewController | 20 | @implementation MyGroupViewController |
21 | 21 | ||
22 | - (void)viewDidLoad { | 22 | - (void)viewDidLoad { |
23 | [super viewDidLoad]; | 23 | [super viewDidLoad]; |
24 | isMemberList = false; | 24 | isMemberList = false; |
25 | _curListGrp = [[NSMutableArray alloc] init]; | 25 | _curListGrp = [[NSMutableArray alloc] init]; |
26 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; | 26 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
27 | 27 | ||
28 | [self requestGroupList]; | 28 | [self requestGroupList]; |
29 | // Do any additional setup after loading the view from its nib. | 29 | // Do any additional setup after loading the view from its nib. |
30 | } | 30 | } |
31 | 31 | ||
32 | - (void)didReceiveMemoryWarning { | 32 | - (void)didReceiveMemoryWarning { |
33 | [super didReceiveMemoryWarning]; | 33 | [super didReceiveMemoryWarning]; |
34 | // Dispose of any resources that can be recreated. | 34 | // Dispose of any resources that can be recreated. |
35 | } | 35 | } |
36 | 36 | ||
37 | #pragma mark IBAction | 37 | #pragma mark IBAction |
38 | 38 | ||
39 | - (IBAction)clickBack:(id)sender { | 39 | - (IBAction)clickBack:(id)sender { |
40 | [self.navigationController popViewControllerAnimated:true]; | 40 | [self.navigationController popViewControllerAnimated:true]; |
41 | } | 41 | } |
42 | 42 | ||
43 | - (IBAction)clickShowGrp:(id)sender { | 43 | - (IBAction)clickShowGrp:(id)sender { |
44 | self.tableGrp.hidden = !self.tableGrp.isHidden; | 44 | self.tableGrp.hidden = !self.tableGrp.isHidden; |
45 | } | 45 | } |
46 | 46 | ||
47 | - (IBAction)clickSwitch:(id)sender { | 47 | - (IBAction)clickSwitch:(id)sender { |
48 | isMemberList = !isMemberList; | 48 | isMemberList = !isMemberList; |
49 | if(isMemberList) { | 49 | if(isMemberList) { |
50 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; | 50 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewTweet", nil) forState:UIControlStateNormal]; |
51 | } | 51 | } |
52 | else { | 52 | else { |
53 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; | 53 | [sender setTitle:NSLocalizedString(@"lifelog.grDetail.bt.viewMem", nil) forState:UIControlStateNormal]; |
54 | } | 54 | } |
55 | [sender setUserInteractionEnabled:false]; | 55 | [sender setUserInteractionEnabled:false]; |
56 | [self resetData]; | 56 | [self resetData]; |
57 | } | 57 | } |
58 | 58 | ||
59 | #pragma mark UITableView Delegate | 59 | #pragma mark UITableView Delegate |
60 | -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { | 60 | -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
61 | if(tableView == self.tableGrp) | 61 | if(tableView == self.tableGrp) |
62 | return 1; | 62 | return 1; |
63 | else | 63 | else |
64 | return [super numberOfSectionsInTableView:tableView]; | 64 | return [super numberOfSectionsInTableView:tableView]; |
65 | } | 65 | } |
66 | 66 | ||
67 | - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | 67 | - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
68 | if(tableView == self.tableGrp) | 68 | if(tableView == self.tableGrp) |
69 | return _curListGrp.count; | 69 | return _curListGrp.count; |
70 | else | 70 | else |
71 | return [super tableView:tableView numberOfRowsInSection:section]; | 71 | return [super tableView:tableView numberOfRowsInSection:section]; |
72 | } | 72 | } |
73 | 73 | ||
74 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 74 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
75 | if(tableView == self.tableGrp) { | 75 | if(tableView == self.tableGrp) { |
76 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GroupCell"]; | 76 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GroupCell"]; |
77 | if(cell == nil) { | 77 | if(cell == nil) { |
78 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GroupCell"]; | 78 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GroupCell"]; |
79 | } | 79 | } |
80 | GroupObject *object = [_curListGrp objectAtIndex:indexPath.row]; | 80 | GroupObject *object = [_curListGrp objectAtIndex:indexPath.row]; |
81 | cell.textLabel.text = object.name; | 81 | cell.textLabel.text = object.name; |
82 | return cell; | 82 | return cell; |
83 | } | 83 | } |
84 | else { | 84 | else { |
85 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; | 85 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
86 | if(isMemberList) { | 86 | if(isMemberList) { |
87 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; | 87 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; |
88 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 88 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
89 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 89 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
90 | } | 90 | } |
91 | else { | 91 | else { |
92 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | 92 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; |
93 | } | 93 | } |
94 | cell.lblUsername.text = @""; | 94 | cell.lblUsername.text = @""; |
95 | cell.lblDateTime.text = @""; | 95 | cell.lblDateTime.text = @""; |
96 | cell.lblDes.text = object.userName; | 96 | cell.lblDes.text = object.userName; |
97 | cell.lblMode.text = @""; | 97 | cell.lblMode.text = @""; |
98 | cell.lblDistance.text = @""; | 98 | cell.lblDistance.text = @""; |
99 | cell.lblDuration.text = @""; | 99 | cell.lblDuration.text = @""; |
100 | } | 100 | } |
101 | else { | 101 | else { |
102 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 102 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
103 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 103 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
104 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 104 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
105 | } | 105 | } |
106 | else { | 106 | else { |
107 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | 107 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; |
108 | } | 108 | } |
109 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; | 109 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; |
110 | cell.lblUsername.text = object.userName; | 110 | cell.lblUsername.text = object.userName; |
111 | cell.lblDes.text = object.content; | 111 | cell.lblDes.text = object.content; |
112 | cell.lblMode.text = object.mode; | 112 | cell.lblMode.text = object.mode; |
113 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | 113 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; |
114 | cell.lblDuration.text = object.time; | 114 | cell.lblDuration.text = object.time; |
115 | } | 115 | } |
116 | return cell; | 116 | return cell; |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { | 120 | - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { |
121 | if(tableView == self.tableGrp) { | 121 | if(tableView == self.tableGrp) { |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | [super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath]; | 124 | [super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath]; |
125 | } | 125 | } |
126 | 126 | ||
127 | -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | 127 | -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
128 | if(tableView == self.tableGrp) { | 128 | if(tableView == self.tableGrp) { |
129 | [tableView setHidden:true]; | 129 | [tableView setHidden:true]; |
130 | [self resetGroupData:indexPath.row]; | 130 | [self resetGroupData:indexPath.row]; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | #pragma mark Private Function | 134 | #pragma mark Private Function |
135 | 135 | ||
136 | - (void) resetGroupData : (int) index { | 136 | - (void) resetGroupData : (int) index { |
137 | _curGroup = [_curListGrp objectAtIndex:index]; | 137 | _curGroup = [_curListGrp objectAtIndex:index]; |
138 | self.lblGrpName.text = _curGroup.name; | 138 | self.lblGrpName.text = _curGroup.name; |
139 | [_curDataList removeAllObjects]; | 139 | [_curDataList removeAllObjects]; |
140 | [self.tableBase reloadData]; | 140 | [self.tableBase reloadData]; |
141 | [self requestGroupDetail]; | 141 | [self requestGroupDetail]; |
142 | } | 142 | } |
143 | 143 | ||
144 | - (void) requestGroupList { | 144 | - (void) requestGroupList { |
145 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 145 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
146 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 146 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
147 | [[ServerAPI server] requestGroupList:token CompletionHandler:^(NSArray *array, NSError *error) { | 147 | [[ServerAPI server] requestGroupList:token CompletionHandler:^(NSArray *array, NSError *error) { |
148 | dispatch_async(dispatch_get_main_queue(), ^{ | 148 | dispatch_async(dispatch_get_main_queue(), ^{ |
149 | [hudView hideAnimated:true]; | 149 | [hudView hideAnimated:true]; |
150 | }); | 150 | }); |
151 | if(error == nil) { | 151 | if(error == nil) { |
152 | [_curListGrp removeAllObjects]; | 152 | [_curListGrp removeAllObjects]; |
153 | [_curListGrp addObjectsFromArray:array]; | 153 | [_curListGrp addObjectsFromArray:array]; |
154 | MyGroupViewController __weak *weakSelf = self; | 154 | MyGroupViewController __weak *weakSelf = self; |
155 | dispatch_async(dispatch_get_main_queue(), ^{ | 155 | dispatch_async(dispatch_get_main_queue(), ^{ |
156 | [hudView hideAnimated:true]; | 156 | [hudView hideAnimated:true]; |
157 | [self.tableGrp reloadData]; | 157 | [self.tableGrp reloadData]; |
158 | if(_curListGrp.count > 0) { | 158 | if(_curListGrp.count > 0) { |
159 | [weakSelf resetGroupData:0]; | 159 | [weakSelf resetGroupData:0]; |
160 | } | 160 | } |
161 | else { | 161 | else { |
162 | weakSelf.lblGrpName.text = @"No Group"; | 162 | weakSelf.lblGrpName.text = @"No Group"; |
163 | } | 163 | } |
164 | [weakSelf.btShowGrp setEnabled:(_curListGrp.count > 0)]; | 164 | [weakSelf.btShowGrp setEnabled:(_curListGrp.count > 0)]; |
165 | }); | 165 | }); |
166 | } | 166 | } |
167 | }]; | 167 | }]; |
168 | } | 168 | } |
169 | 169 | ||
170 | @end | 170 | @end |
171 | 171 |
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 <SDWebImage/UIImageView+WebCache.h> | 11 | #import <SDWebImage/UIImageView+WebCache.h> |
12 | 12 | ||
13 | #import "ServerAPI.h" | 13 | #import "ServerAPI.h" |
14 | #import "Utilities.h" | 14 | #import "Utilities.h" |
15 | 15 | ||
16 | #import "SNSRecentTopicTableViewCell.h" | 16 | #import "SNSRecentTopicTableViewCell.h" |
17 | #import "MyGroupViewController.h" | 17 | #import "MyGroupViewController.h" |
18 | #import "SearchGroupViewController.h" | 18 | #import "SearchGroupViewController.h" |
19 | #import "GroupDetailViewController.h" | 19 | #import "GroupDetailViewController.h" |
20 | 20 | ||
21 | @interface SNSViewController () | 21 | @interface SNSViewController () |
22 | 22 | ||
23 | @end | 23 | @end |
24 | 24 | ||
25 | @implementation SNSViewController | 25 | @implementation SNSViewController |
26 | 26 | ||
27 | - (void)viewDidLoad { | 27 | - (void)viewDidLoad { |
28 | [super viewDidLoad]; | 28 | [super viewDidLoad]; |
29 | // Do any additional setup after loading the view from its nib. | 29 | // Do any additional setup after loading the view from its nib. |
30 | self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil); | 30 | self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil); |
31 | 31 | ||
32 | [self callRequestToUpdateData]; | 32 | [self callRequestToUpdateData]; |
33 | 33 | ||
34 | //register nib for table view | 34 | //register nib for table view |
35 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; | 35 | [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; |
36 | } | 36 | } |
37 | 37 | ||
38 | - (void)didReceiveMemoryWarning { | 38 | - (void)didReceiveMemoryWarning { |
39 | [super didReceiveMemoryWarning]; | 39 | [super didReceiveMemoryWarning]; |
40 | // Dispose of any resources that can be recreated. | 40 | // Dispose of any resources that can be recreated. |
41 | } | 41 | } |
42 | 42 | ||
43 | #pragma mark IBAction | 43 | #pragma mark IBAction |
44 | - (IBAction)clickRecommendGroup:(id)sender { | 44 | - (IBAction)clickRecommendGroup:(id)sender { |
45 | SearchGroupViewController * search = [[SearchGroupViewController alloc] init]; | 45 | SearchGroupViewController * search = [[SearchGroupViewController alloc] init]; |
46 | [self.navigationController pushViewController:search animated:true]; | 46 | [self.navigationController pushViewController:search animated:true]; |
47 | } | 47 | } |
48 | 48 | ||
49 | - (IBAction)clickMyGroup:(id)sender { | 49 | - (IBAction)clickMyGroup:(id)sender { |
50 | MyGroupViewController * myGrp = [[MyGroupViewController alloc] init]; | 50 | MyGroupViewController * myGrp = [[MyGroupViewController alloc] init]; |
51 | [self.navigationController pushViewController:myGrp animated:true]; | 51 | [self.navigationController pushViewController:myGrp animated:true]; |
52 | } | 52 | } |
53 | 53 | ||
54 | #pragma mark UITableView Delegate | 54 | #pragma mark UITableView Delegate |
55 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 55 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
56 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; | 56 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
57 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; | 57 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
58 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | 58 | if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { |
59 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | 59 | [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; |
60 | } | 60 | } |
61 | else { | 61 | else { |
62 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | 62 | [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; |
63 | } | 63 | } |
64 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm"]; | 64 | cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; |
65 | cell.lblUsername.text = object.userName; | 65 | cell.lblUsername.text = object.userName; |
66 | cell.lblDes.text = object.content; | 66 | cell.lblDes.text = object.content; |
67 | cell.lblMode.text = object.mode; | 67 | cell.lblMode.text = object.mode; |
68 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | 68 | cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; |
69 | cell.lblDuration.text = object.time; | 69 | cell.lblDuration.text = object.time; |
70 | return cell; | 70 | return cell; |
71 | } | 71 | } |
72 | 72 | ||
73 | #pragma mark Private Function | 73 | #pragma mark Private Function |
74 | 74 | ||
75 | -(void) callRequestToUpdateData { | 75 | -(void) callRequestToUpdateData { |
76 | [super callRequestToUpdateData]; | 76 | [super callRequestToUpdateData]; |
77 | 77 | ||
78 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 78 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
79 | MBProgressHUD *hudView = nil; | 79 | MBProgressHUD *hudView = nil; |
80 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 80 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
81 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 81 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
82 | } | 82 | } |
83 | [[ServerAPI server] requestTweetsList:token groupID:-1 withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ | 83 | [[ServerAPI server] requestTweetsList:token groupID:-1 withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ |
84 | dispatch_async(dispatch_get_main_queue(), ^{ | 84 | dispatch_async(dispatch_get_main_queue(), ^{ |
85 | if(hudView != nil) { | 85 | if(hudView != nil) { |
86 | [hudView hideAnimated:true]; | 86 | [hudView hideAnimated:true]; |
87 | } | 87 | } |
88 | }); | 88 | }); |
89 | SNSViewController __weak *weakSelf = self; | 89 | SNSViewController __weak *weakSelf = self; |
90 | [weakSelf updateTableData:array error:error]; | 90 | [weakSelf updateTableData:array error:error]; |
91 | }]; | 91 | }]; |
92 | } | 92 | } |
93 | 93 | ||
94 | @end | 94 | @end |
95 | 95 |
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 atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, 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) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion; |
35 | - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page 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; | 36 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion; |
37 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; | 37 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; |
38 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 38 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
39 | 39 | ||
40 | #pragma mark - SNS Screen Function | 40 | #pragma mark - SNS Screen Function |
41 | /* | 41 | /* |
42 | Get tweet of group and get recent tweet is same API | 42 | 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 | 43 | If groupID equal -1, it will request recent tweet. Otherwise will request tweet of group |
44 | */ | 44 | */ |
45 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 45 | - (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; | 46 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
47 | 47 | ||
48 | #pragma mark - Group Function | 48 | #pragma mark - Group Function |
49 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; | 49 | - (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; | 50 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
51 | 51 | ||
52 | #pragma mark - Common API | 52 | #pragma mark - Common API |
53 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; | 53 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; |
54 | @end | 54 | @end |
55 | 55 |
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 | 11 | ||
11 | NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/"; | 12 | NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/"; |
12 | NSString *const kUser = @"KEY_USER"; | 13 | NSString *const kUser = @"KEY_USER"; |
13 | NSString *const kToken = @"KEY_TOKEN"; | 14 | NSString *const kToken = @"KEY_TOKEN"; |
14 | NSString *const kNotificationToken = @"TOKEN_INVALID"; | 15 | NSString *const kNotificationToken = @"TOKEN_INVALID"; |
15 | 16 | ||
16 | @implementation NSString (NSString_Extended) | 17 | @implementation NSString (NSString_Extended) |
17 | - (NSString *)urlencode { | 18 | - (NSString *)urlencode { |
18 | NSMutableString *output = [NSMutableString string]; | 19 | NSMutableString *output = [NSMutableString string]; |
19 | const unsigned char *source = (const unsigned char *)[self UTF8String]; | 20 | const unsigned char *source = (const unsigned char *)[self UTF8String]; |
20 | int sourceLen = (int)strlen((const char *)source); | 21 | int sourceLen = (int)strlen((const char *)source); |
21 | for (int i = 0; i < sourceLen; ++i) { | 22 | for (int i = 0; i < sourceLen; ++i) { |
22 | const unsigned char thisChar = source[i]; | 23 | const unsigned char thisChar = source[i]; |
23 | if (thisChar == ' '){ | 24 | if (thisChar == ' '){ |
24 | [output appendString:@"+"]; | 25 | [output appendString:@"+"]; |
25 | } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' || | 26 | } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' || |
26 | (thisChar >= 'a' && thisChar <= 'z') || | 27 | (thisChar >= 'a' && thisChar <= 'z') || |
27 | (thisChar >= 'A' && thisChar <= 'Z') || | 28 | (thisChar >= 'A' && thisChar <= 'Z') || |
28 | (thisChar >= '0' && thisChar <= '9')) { | 29 | (thisChar >= '0' && thisChar <= '9')) { |
29 | [output appendFormat:@"%c", thisChar]; | 30 | [output appendFormat:@"%c", thisChar]; |
30 | } else { | 31 | } else { |
31 | [output appendFormat:@"%%%02X", thisChar]; | 32 | [output appendFormat:@"%%%02X", thisChar]; |
32 | } | 33 | } |
33 | } | 34 | } |
34 | return output; | 35 | return output; |
35 | } | 36 | } |
36 | @end | 37 | @end |
37 | 38 | ||
38 | @implementation ServerAPI | 39 | @implementation ServerAPI |
39 | static ServerAPI *_server = nil; | 40 | static ServerAPI *_server = nil; |
40 | 41 | ||
41 | NSURLSessionDataTask * searchTask; | 42 | NSURLSessionDataTask * searchTask; |
42 | 43 | ||
43 | @synthesize timeOutInterval = _timeOutInterval; | 44 | @synthesize timeOutInterval = _timeOutInterval; |
44 | 45 | ||
45 | + (instancetype)server | 46 | + (instancetype)server |
46 | { | 47 | { |
47 | @synchronized(self) { | 48 | @synchronized(self) { |
48 | if (_server == nil) { | 49 | if (_server == nil) { |
49 | _server = [[ServerAPI alloc] init]; | 50 | _server = [[ServerAPI alloc] init]; |
50 | } | 51 | } |
51 | } | 52 | } |
52 | return _server; | 53 | return _server; |
53 | } | 54 | } |
54 | 55 | ||
55 | - (instancetype)init | 56 | - (instancetype)init |
56 | { | 57 | { |
57 | self = [super init]; | 58 | self = [super init]; |
58 | if (self != nil) { | 59 | if (self != nil) { |
59 | self.timeOutInterval = 150; | 60 | self.timeOutInterval = 150; |
60 | } | 61 | } |
61 | return self; | 62 | return self; |
62 | } | 63 | } |
63 | 64 | ||
64 | #pragma mark - Login and Register | 65 | #pragma mark - Login and Register |
65 | // Login | 66 | // Login |
66 | - (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 |
67 | { | 68 | { |
68 | [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) { |
69 | 70 | ||
70 | if (completion == NULL) { | 71 | if (completion == NULL) { |
71 | return ; | 72 | return ; |
72 | } | 73 | } |
73 | 74 | ||
74 | if (error == nil) | 75 | if (error == nil) |
75 | { | 76 | { |
76 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 77 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
77 | 78 | ||
78 | int status = [dataResult[@"status"] intValue]; | 79 | int status = [dataResult[@"status"] intValue]; |
79 | if (status == 1) { // status = 1 success | 80 | if (status == 1) { // status = 1 success |
80 | NSString *token = dataResult[@"result"][@"token"]; | 81 | NSString *token = dataResult[@"result"][@"token"]; |
81 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; | 82 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; |
82 | User *user = [[User alloc] init]; | 83 | User *user = [[User alloc] init]; |
83 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; | 84 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; |
84 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; | 85 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; |
85 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; | 86 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; |
86 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; | 87 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; |
87 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; | 88 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; |
88 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; | 89 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; |
89 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; | 90 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; |
90 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; | 91 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; |
91 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; | 92 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; |
92 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; | 93 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; |
93 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; | 94 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; |
94 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; | 95 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; |
95 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; | 96 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; |
96 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; | 97 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; |
97 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; | 98 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; |
98 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; | 99 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; |
99 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; | 100 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; |
100 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; | 101 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; |
101 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; | 102 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; |
102 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; | 103 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; |
103 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; | 104 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; |
104 | 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]; |
105 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; | 106 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; |
106 | completion(user, token, nil); | 107 | completion(user, token, nil); |
107 | } | 108 | } |
108 | else { // status = 0 error | 109 | else { // status = 0 error |
109 | NSString *message = dataResult[@"message"]; | 110 | NSString *message = dataResult[@"message"]; |
110 | if (message == nil) { | 111 | if (message == nil) { |
111 | message = @"Unknown error"; | 112 | message = @"Unknown error"; |
112 | } | 113 | } |
113 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 114 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
114 | completion(nil, nil, loginFaild); | 115 | completion(nil, nil, loginFaild); |
115 | } | 116 | } |
116 | } | 117 | } |
117 | else | 118 | else |
118 | { | 119 | { |
119 | completion(nil, nil, error); | 120 | completion(nil, nil, error); |
120 | } | 121 | } |
121 | }]; | 122 | }]; |
122 | } | 123 | } |
123 | 124 | ||
124 | // Register | 125 | // Register |
125 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion { | 126 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion { |
126 | [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) { |
127 | 128 | ||
128 | if (completion == NULL) { | 129 | if (completion == NULL) { |
129 | return ; | 130 | return ; |
130 | } | 131 | } |
131 | 132 | ||
132 | if (error == nil) | 133 | if (error == nil) |
133 | { | 134 | { |
134 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 135 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
135 | 136 | ||
136 | int status = [dataResult[@"status"] intValue]; | 137 | int status = [dataResult[@"status"] intValue]; |
137 | if (status == 1) { // status = 1 success | 138 | if (status == 1) { // status = 1 success |
138 | NSString *token = dataResult[@"result"][@"token"]; | 139 | NSString *token = dataResult[@"result"][@"token"]; |
139 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; | 140 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; |
140 | User *user = [[User alloc] init]; | 141 | User *user = [[User alloc] init]; |
141 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; | 142 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; |
142 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; | 143 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; |
143 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; | 144 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; |
144 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; | 145 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; |
145 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; | 146 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; |
146 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; | 147 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; |
147 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; | 148 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; |
148 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; | 149 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; |
149 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; | 150 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; |
150 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; | 151 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; |
151 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; | 152 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; |
152 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; | 153 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; |
153 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; | 154 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; |
154 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; | 155 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; |
155 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; | 156 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; |
156 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; | 157 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; |
157 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; | 158 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; |
158 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; | 159 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; |
159 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; | 160 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; |
160 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; | 161 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; |
161 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; | 162 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; |
162 | 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]; |
163 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; | 164 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; |
164 | completion(user, token, nil); | 165 | completion(user, token, nil); |
165 | } | 166 | } |
166 | else { // status = 0 error | 167 | else { // status = 0 error |
167 | NSString *message = dataResult[@"message"]; | 168 | NSString *message = dataResult[@"message"]; |
168 | if (message == nil) { | 169 | if (message == nil) { |
169 | message = @"Unknown error"; | 170 | message = @"Unknown error"; |
170 | } | 171 | } |
171 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 172 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
172 | completion(nil, nil, loginFaild); | 173 | completion(nil, nil, loginFaild); |
173 | } | 174 | } |
174 | } | 175 | } |
175 | else | 176 | else |
176 | { | 177 | { |
177 | completion(nil, nil, error); | 178 | completion(nil, nil, error); |
178 | } | 179 | } |
179 | }]; | 180 | }]; |
180 | } | 181 | } |
181 | 182 | ||
182 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion { | 183 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion { |
183 | [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) { |
184 | 185 | ||
185 | if (completion == NULL) { | 186 | if (completion == NULL) { |
186 | return ; | 187 | return ; |
187 | } | 188 | } |
188 | 189 | ||
189 | if (error == nil) | 190 | if (error == nil) |
190 | { | 191 | { |
191 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 192 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
192 | 193 | ||
193 | int status = [dataResult[@"status"] intValue]; | 194 | int status = [dataResult[@"status"] intValue]; |
194 | if (status == 1) { // status = 1 success | 195 | if (status == 1) { // status = 1 success |
195 | completion(nil); | 196 | completion(nil); |
196 | } | 197 | } |
197 | else { // status = 0 error | 198 | else { // status = 0 error |
198 | NSString *message = dataResult[@"message"]; | 199 | NSString *message = dataResult[@"message"]; |
199 | if (message == nil) { | 200 | if (message == nil) { |
200 | message = @"Unknown error"; | 201 | message = @"Unknown error"; |
201 | } | 202 | } |
202 | NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 203 | NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
203 | completion(forgetPass); | 204 | completion(forgetPass); |
204 | } | 205 | } |
205 | } | 206 | } |
206 | else | 207 | else |
207 | { | 208 | { |
208 | completion(error); | 209 | completion(error); |
209 | } | 210 | } |
210 | }]; | 211 | }]; |
211 | } | 212 | } |
212 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion { | 213 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion { |
213 | [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) { |
214 | 215 | ||
215 | if (completion == NULL) { | 216 | if (completion == NULL) { |
216 | return ; | 217 | return ; |
217 | } | 218 | } |
218 | 219 | ||
219 | if (error == nil) | 220 | if (error == nil) |
220 | { | 221 | { |
221 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 222 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
222 | 223 | ||
223 | int status = [dataResult[@"status"] intValue]; | 224 | int status = [dataResult[@"status"] intValue]; |
224 | if (status == 1) { // status = 1 success | 225 | if (status == 1) { // status = 1 success |
225 | completion(nil); | 226 | completion(nil); |
226 | } | 227 | } |
227 | else { // status = 0 error | 228 | else { // status = 0 error |
228 | NSString *message = dataResult[@"message"]; | 229 | NSString *message = dataResult[@"message"]; |
229 | NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 230 | NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
230 | completion(confirmForgetPass); | 231 | completion(confirmForgetPass); |
231 | } | 232 | } |
232 | } | 233 | } |
233 | else | 234 | else |
234 | { | 235 | { |
235 | completion(error); | 236 | completion(error); |
236 | } | 237 | } |
237 | }]; | 238 | }]; |
238 | } | 239 | } |
239 | 240 | ||
240 | - (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 { |
241 | NSDictionary *dict = nil; | 242 | NSDictionary *dict = nil; |
242 | NSString *base64Encoded = [data base64EncodedStringWithOptions:0]; | 243 | NSString *base64Encoded = [data base64EncodedStringWithOptions:0]; |
243 | if (token != nil) { | 244 | if (token != nil) { |
244 | dict = @{@"token":token, @"img": base64Encoded}; | 245 | dict = @{@"token":token, @"img": base64Encoded}; |
245 | } | 246 | } |
246 | else { | 247 | else { |
247 | dict = @{@"img": base64Encoded}; | 248 | dict = @{@"img": base64Encoded}; |
248 | } | 249 | } |
249 | [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) { |
250 | 251 | ||
251 | if (completion == NULL) { | 252 | if (completion == NULL) { |
252 | return ; | 253 | return ; |
253 | } | 254 | } |
254 | 255 | ||
255 | if (error == nil) | 256 | if (error == nil) |
256 | { | 257 | { |
257 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 258 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
258 | NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]]; | 259 | NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]]; |
259 | completion(image_profile, nil); | 260 | completion(image_profile, nil); |
260 | } | 261 | } |
261 | else | 262 | else |
262 | { | 263 | { |
263 | completion(nil, error); | 264 | completion(nil, error); |
264 | } | 265 | } |
265 | }]; | 266 | }]; |
266 | } | 267 | } |
267 | 268 | ||
268 | -(NSString *) convertIntToString : (int) type { | 269 | -(NSString *) convertIntToString : (int) type { |
269 | switch (type) { | 270 | switch (type) { |
270 | case 1: | 271 | case 1: |
271 | return @"week"; | 272 | return @"week"; |
272 | break; | 273 | break; |
273 | case 2: | 274 | case 2: |
274 | return @"oneMonth"; | 275 | return @"oneMonth"; |
275 | break; | 276 | break; |
276 | case 3: | 277 | case 3: |
277 | return @"threeMonth"; | 278 | return @"threeMonth"; |
278 | break; | 279 | break; |
279 | case 4: | 280 | case 4: |
280 | return @"sixMonth"; | 281 | return @"sixMonth"; |
281 | break; | 282 | break; |
282 | default: | 283 | default: |
283 | return @"today"; | 284 | return @"today"; |
284 | break; | 285 | break; |
285 | } | 286 | } |
286 | } | 287 | } |
287 | 288 | ||
288 | #pragma mark - Home Screen Function | 289 | #pragma mark - Home Screen Function |
289 | - (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 |
290 | { | 291 | { |
291 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 292 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
292 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/top/%d/%@", mode, date]; | 293 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/top/%d/%@", mode, date]; |
293 | [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) { |
294 | 295 | ||
295 | if (completion == NULL) { | 296 | if (completion == NULL) { |
296 | return ; | 297 | return ; |
297 | } | 298 | } |
298 | 299 | ||
299 | if (error == nil) | 300 | if (error == nil) |
300 | { | 301 | { |
301 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 302 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
302 | int status = [dataResult[@"status"] intValue]; | 303 | int status = [dataResult[@"status"] intValue]; |
303 | if (status == 1) { // status = 1 success | 304 | if (status == 1) { // status = 1 success |
304 | if(dataResult[@"result"] != nil) { | 305 | if(dataResult[@"result"] != nil) { |
305 | NSDictionary * dictResult = dataResult[@"result"]; | 306 | NSDictionary * dictResult = dataResult[@"result"]; |
306 | TopObject *topObject = [[TopObject alloc] init]; | 307 | TopObject *topObject = [[TopObject alloc] init]; |
307 | TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; | 308 | TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; |
308 | topObject.targetInfor = targetInfor; | 309 | topObject.targetInfor = targetInfor; |
309 | topObject.kcal = [[NSString stringWithFormat:@"%@", dictResult[@"kcal"]] intValue]; | 310 | topObject.kcal = [[NSString stringWithFormat:@"%@", dictResult[@"kcal"]] intValue]; |
310 | topObject.distance = [[NSString stringWithFormat:@"%@", dictResult[@"distance"]] floatValue]; | 311 | topObject.distance = [[NSString stringWithFormat:@"%@", dictResult[@"distance"]] floatValue]; |
311 | topObject.time = [NSString stringWithFormat:@"%@", dictResult[@"time"]]; | 312 | topObject.time = [NSString stringWithFormat:@"%@", dictResult[@"time"]]; |
312 | NSMutableArray *arrayStep = [[NSMutableArray alloc] init]; | 313 | NSMutableArray *arrayStep = [[NSMutableArray alloc] init]; |
313 | NSArray *array = dictResult[@"dataChart"]; | 314 | NSArray *array = dictResult[@"dataChart"]; |
314 | for(NSDictionary *dict in array) { | 315 | for(NSDictionary *dict in array) { |
315 | StepObject *object = [[StepObject alloc] init]; | 316 | StepObject *object = [[StepObject alloc] init]; |
316 | if([dict objectForKey:@"numStep"] != nil) { | 317 | if([dict objectForKey:@"numStep"] != nil) { |
317 | object.step = [dict[@"numStep"] intValue]; | 318 | object.step = [dict[@"numStep"] intValue]; |
318 | } | 319 | } |
319 | if([dict objectForKey:@"hour"] != nil) { | 320 | if([dict objectForKey:@"hour"] != nil) { |
320 | object.hour = [dict[@"hour"] intValue]; | 321 | object.hour = [dict[@"hour"] intValue]; |
321 | } | 322 | } |
322 | switch (mode) { | 323 | switch (mode) { |
323 | case 1: | 324 | case 1: |
324 | object.typeStep = @"walking"; | 325 | object.typeStep = @"walking"; |
325 | break; | 326 | break; |
326 | case 2: | 327 | case 2: |
327 | object.typeStep = @"running"; | 328 | object.typeStep = @"running"; |
328 | break; | 329 | break; |
329 | case 3: | 330 | case 3: |
330 | object.typeStep = @"bike"; | 331 | object.typeStep = @"bike"; |
331 | break; | 332 | break; |
332 | default: | 333 | default: |
333 | break; | 334 | break; |
334 | } | 335 | } |
335 | [arrayStep addObject:object]; | 336 | [arrayStep addObject:object]; |
336 | } | 337 | } |
337 | topObject.dataChart = [[NSMutableArray alloc] initWithArray:arrayStep]; | 338 | topObject.dataChart = [[NSMutableArray alloc] initWithArray:arrayStep]; |
338 | completion(topObject, nil); | 339 | completion(topObject, nil); |
339 | } | 340 | } |
340 | else { | 341 | else { |
341 | 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"}]; |
342 | completion(nil, errorObject); | 343 | completion(nil, errorObject); |
343 | } | 344 | } |
344 | } | 345 | } |
345 | else { | 346 | else { |
346 | NSString *message = dataResult[@"message"]; | 347 | NSString *message = dataResult[@"message"]; |
347 | if (message == nil) { | 348 | if (message == nil) { |
348 | message = @"Unknown error"; | 349 | message = @"Unknown error"; |
349 | } | 350 | } |
350 | 351 | ||
351 | if ([message isEqualToString:@"Token is invalid"]) { | 352 | if ([message isEqualToString:@"Token is invalid"]) { |
352 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 353 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
353 | [self requestTopWithMode:mode andDate:date CompletionHandler:completion]; | 354 | [self requestTopWithMode:mode andDate:date CompletionHandler:completion]; |
354 | } | 355 | } |
355 | else { | 356 | else { |
356 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 357 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
357 | completion(nil, errorObject); | 358 | completion(nil, errorObject); |
358 | } | 359 | } |
359 | } | 360 | } |
360 | } | 361 | } |
361 | else | 362 | else |
362 | { | 363 | { |
363 | completion(nil, error); | 364 | completion(nil, error); |
364 | } | 365 | } |
365 | }]; | 366 | }]; |
366 | } | 367 | } |
367 | 368 | ||
368 | - (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 { |
369 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 370 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
370 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/createLog"]; | 371 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/createLog"]; |
371 | 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}; |
372 | [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) { |
373 | 374 | ||
374 | if (completion == NULL) { | 375 | if (completion == NULL) { |
375 | return ; | 376 | return ; |
376 | } | 377 | } |
377 | 378 | ||
378 | if (error == nil) | 379 | if (error == nil) |
379 | { | 380 | { |
380 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 381 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
381 | int status = [dataResult[@"status"] intValue]; | 382 | int status = [dataResult[@"status"] intValue]; |
382 | if (status == 1) { // status = 1 success | 383 | if (status == 1) { // status = 1 success |
383 | completion(nil); | 384 | completion(nil); |
384 | } | 385 | } |
385 | else { | 386 | else { |
386 | NSString *message = dataResult[@"message"]; | 387 | NSString *message = dataResult[@"message"]; |
387 | if (message == nil) { | 388 | if (message == nil) { |
388 | message = @"Unknown error"; | 389 | message = @"Unknown error"; |
389 | } | 390 | } |
390 | 391 | ||
391 | if ([message isEqualToString:@"Token is invalid"]) { | 392 | if ([message isEqualToString:@"Token is invalid"]) { |
392 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 393 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
393 | [self requestCreateLog:mode withStep:numStep startDate:startDate endDate:endDate CompletionHandler:completion]; | 394 | [self requestCreateLog:mode withStep:numStep startDate:startDate endDate:endDate CompletionHandler:completion]; |
394 | } | 395 | } |
395 | else { | 396 | else { |
396 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 397 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
397 | completion(errorObject); | 398 | completion(errorObject); |
398 | } | 399 | } |
399 | } | 400 | } |
400 | } | 401 | } |
401 | else | 402 | else |
402 | { | 403 | { |
403 | completion(error); | 404 | completion(error); |
404 | } | 405 | } |
405 | }]; | 406 | }]; |
406 | } | 407 | } |
407 | 408 | ||
408 | #pragma mark - History Screen Function | 409 | #pragma mark - History Screen Function |
409 | - (void) requestHistory:(NSString *)token atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, NSError *)) completion { | 410 | - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
410 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/%@/%d", [self convertIntToString:type], mode]; | 411 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]]; |
411 | NSLog(@"requestHistory link %@", url); | 412 | NSLog(@"requestHistory link %@", url); |
412 | [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) { |
413 | 414 | ||
414 | if (completion == NULL) { | 415 | if (completion == NULL) { |
415 | return ; | 416 | return ; |
416 | } | 417 | } |
417 | 418 | ||
418 | if (error == nil) | 419 | if (error == nil) |
419 | { | 420 | { |
420 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 421 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
421 | NSLog(@"%@", dataResult); | 422 | NSLog(@"%@", dataResult); |
422 | int status = [dataResult[@"status"] intValue]; | 423 | int status = [dataResult[@"status"] intValue]; |
423 | if (status == 1) { // status = 1 success | 424 | if (status == 1) { // status = 1 success |
424 | HistoryObject * object = [[HistoryObject alloc] initWithData:dataResult[@"result"]]; | 425 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; |
425 | completion(object, nil); | 426 | NSDictionary * arrResult = dataResult[@"result"]; |
427 | if(arrResult != nil) { | ||
428 | NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_1", @"mode_2", @"mode_3", nil]; | ||
429 | for(NSString * key in arrayKey) { | ||
430 | NSDictionary *mode = [arrResult objectForKey:key]; | ||
431 | if(mode.count > 0) { | ||
432 | HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode]; | ||
433 | [arrayHistory addObject:objectMode]; | ||
434 | } | ||
435 | else { | ||
436 | [arrayHistory addObject:[[HistoryObject alloc] init]]; | ||
437 | } | ||
438 | } | ||
439 | } | ||
440 | completion(arrayHistory, nil); | ||
426 | } | 441 | } |
427 | else { | 442 | else { |
428 | NSString *message = dataResult[@"message"]; | 443 | NSString *message = dataResult[@"message"]; |
429 | if (message == nil) { | 444 | if (message == nil) { |
430 | message = @"Unknown error"; | 445 | message = @"Unknown error"; |
431 | } | 446 | } |
432 | 447 | ||
433 | if ([message isEqualToString:@"Token is invalid"]) { | 448 | if ([message isEqualToString:@"Token is invalid"]) { |
434 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 449 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
435 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 450 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
436 | [self requestHistory:tokenNew atDate:date withType:type andMode:mode CompletionHandler:completion]; | 451 | [self requestHistory:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion]; |
437 | } | 452 | } |
438 | else { | 453 | else { |
439 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 454 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
440 | completion(nil, errorObject); | 455 | completion(nil, errorObject); |
441 | } | 456 | } |
442 | } | 457 | } |
443 | } | 458 | } |
444 | else | 459 | else |
445 | { | 460 | { |
446 | completion(nil, error); | 461 | completion(nil, error); |
447 | } | 462 | } |
448 | }]; | 463 | }]; |
449 | } | 464 | } |
450 | 465 | ||
451 | - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion { | 466 | - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion { |
452 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/graph/%@/%d", [self convertIntToString:type], mode]; | 467 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/graph/%@/%d", [self convertIntToString:type], mode]; |
453 | NSLog(@"requestHistoryGraph link %@", url); | 468 | NSLog(@"requestHistoryGraph link %@", url); |
454 | [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) { |
455 | 470 | ||
456 | if (completion == NULL) { | 471 | if (completion == NULL) { |
457 | return ; | 472 | return ; |
458 | } | 473 | } |
459 | 474 | ||
460 | if (error == nil) | 475 | if (error == nil) |
461 | { | 476 | { |
462 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 477 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
463 | NSLog(@"%@", dataResult); | 478 | NSLog(@"%@", dataResult); |
464 | int status = [dataResult[@"status"] intValue]; | 479 | int status = [dataResult[@"status"] intValue]; |
465 | if (status == 1) { // status = 1 success | 480 | if (status == 1) { // status = 1 success |
466 | HistoryGraphObject * object = [[HistoryGraphObject alloc] initWithData:dataResult[@"result"]]; | 481 | HistoryGraphObject * object = [[HistoryGraphObject alloc] initWithData:dataResult[@"result"]]; |
467 | completion(object, nil); | 482 | completion(object, nil); |
468 | } | 483 | } |
469 | else { | 484 | else { |
470 | NSString *message = dataResult[@"message"]; | 485 | NSString *message = dataResult[@"message"]; |
471 | if (message == nil) { | 486 | if (message == nil) { |
472 | message = @"Unknown error"; | 487 | message = @"Unknown error"; |
473 | } | 488 | } |
474 | 489 | ||
475 | if ([message isEqualToString:@"Token is invalid"]) { | 490 | if ([message isEqualToString:@"Token is invalid"]) { |
476 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 491 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
477 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 492 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
478 | [self requestHistoryGraph:tokenNew withType:type andMode:mode CompletionHandler:completion]; | 493 | [self requestHistoryGraph:tokenNew withType:type andMode:mode CompletionHandler:completion]; |
479 | } | 494 | } |
480 | else { | 495 | else { |
481 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 496 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
482 | completion(nil, errorObject); | 497 | completion(nil, errorObject); |
483 | } | 498 | } |
484 | } | 499 | } |
485 | } | 500 | } |
486 | else | 501 | else |
487 | { | 502 | { |
488 | completion(nil, error); | 503 | completion(nil, error); |
489 | } | 504 | } |
490 | }]; | 505 | }]; |
491 | } | 506 | } |
492 | 507 | ||
493 | - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 508 | - (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
494 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/list/%@/%d?page=%d&record=50", [self convertIntToString:type], mode, page]; | 509 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/list/%@/%d?page=%d&record=50", [self convertIntToString:type], mode, page]; |
495 | NSLog(@"requestHistoryList link %@", url); | 510 | NSLog(@"requestHistoryList link %@", url); |
496 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 511 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
497 | 512 | ||
498 | if (completion == NULL) { | 513 | if (completion == NULL) { |
499 | return ; | 514 | return ; |
500 | } | 515 | } |
501 | 516 | ||
502 | if (error == nil) | 517 | if (error == nil) |
503 | { | 518 | { |
504 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 519 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
505 | NSLog(@"%@", dataResult); | 520 | NSLog(@"%@", dataResult); |
506 | int status = [dataResult[@"status"] intValue]; | 521 | int status = [dataResult[@"status"] intValue]; |
507 | if (status == 1) { // status = 1 success | 522 | if (status == 1) { // status = 1 success |
508 | if(dataResult[@"result"] != nil) { | 523 | if(dataResult[@"result"] != nil) { |
509 | NSArray * array = dataResult[@"result"][@"data"]; | 524 | NSArray * array = dataResult[@"result"][@"data"]; |
510 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; | 525 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; |
511 | for(NSDictionary * dict in array) { | 526 | for(NSDictionary * dict in array) { |
512 | HistoryObject * object = [[HistoryObject alloc] initWithData:dict]; | 527 | HistoryObject * object = [[HistoryObject alloc] initWithData:dict]; |
513 | [arrayHistory addObject:object]; | 528 | [arrayHistory addObject:object]; |
514 | } | 529 | } |
515 | completion(arrayHistory, nil); | 530 | completion(arrayHistory, nil); |
516 | } | 531 | } |
517 | else { | 532 | else { |
518 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 533 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
519 | completion(nil, errorObject); | 534 | completion(nil, errorObject); |
520 | } | 535 | } |
521 | } | 536 | } |
522 | else { | 537 | else { |
523 | NSString *message = dataResult[@"message"]; | 538 | NSString *message = dataResult[@"message"]; |
524 | if (message == nil) { | 539 | if (message == nil) { |
525 | message = @"Unknown error"; | 540 | message = @"Unknown error"; |
526 | } | 541 | } |
527 | 542 | ||
528 | if ([message isEqualToString:@"Token is invalid"]) { | 543 | if ([message isEqualToString:@"Token is invalid"]) { |
529 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 544 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
530 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 545 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
531 | [self requestHistoryList:tokenNew withType:type andMode:mode AtPage:page CompletionHandler:completion]; | 546 | [self requestHistoryList:tokenNew withType:type andMode:mode AtPage:page CompletionHandler:completion]; |
532 | } | 547 | } |
533 | else { | 548 | else { |
534 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 549 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
535 | completion(nil, errorObject); | 550 | completion(nil, errorObject); |
536 | } | 551 | } |
537 | } | 552 | } |
538 | } | 553 | } |
539 | else | 554 | else |
540 | { | 555 | { |
541 | completion(nil, error); | 556 | completion(nil, error); |
542 | } | 557 | } |
543 | }]; | 558 | }]; |
544 | } | 559 | } |
545 | 560 | ||
546 | #pragma mark - SNS Screen Function | 561 | #pragma mark - SNS Screen Function |
547 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 562 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
548 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/sns/%d", page]; | 563 | NSString *url = [kServerAddress stringByAppendingFormat:@"/api/sns/%d", page]; |
549 | if(groupID > -1) { | 564 | if(groupID > -1) { |
550 | url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; | 565 | url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; |
551 | } | 566 | } |
552 | NSLog(@"requestTweetsList link %@", url); | 567 | NSLog(@"requestTweetsList link %@", url); |
553 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 568 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
554 | 569 | ||
555 | if (completion == NULL) { | 570 | if (completion == NULL) { |
556 | return ; | 571 | return ; |
557 | } | 572 | } |
558 | 573 | ||
559 | if (error == nil) | 574 | if (error == nil) |
560 | { | 575 | { |
561 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 576 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
562 | NSLog(@"%@", dataResult); | 577 | NSLog(@"%@", dataResult); |
563 | int status = [dataResult[@"status"] intValue]; | 578 | int status = [dataResult[@"status"] intValue]; |
564 | if (status == 1) { // status = 1 success | 579 | if (status == 1) { // status = 1 success |
565 | if(dataResult[@"result"] != nil) { | 580 | if(dataResult[@"result"] != nil) { |
566 | NSArray * array = dataResult[@"result"]; | 581 | NSArray * array = dataResult[@"result"]; |
567 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 582 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
568 | for(NSDictionary * dict in array) { | 583 | for(NSDictionary * dict in array) { |
569 | TweetObject * object = [[TweetObject alloc] initWithData:dict]; | 584 | TweetObject * object = [[TweetObject alloc] initWithData:dict]; |
570 | [arrayTweets addObject:object]; | 585 | [arrayTweets addObject:object]; |
571 | } | 586 | } |
572 | completion(arrayTweets, nil); | 587 | completion(arrayTweets, nil); |
573 | } | 588 | } |
574 | else { | 589 | else { |
575 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 590 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
576 | completion(nil, errorObject); | 591 | completion(nil, errorObject); |
577 | } | 592 | } |
578 | } | 593 | } |
579 | else { | 594 | else { |
580 | NSString *message = dataResult[@"message"]; | 595 | NSString *message = dataResult[@"message"]; |
581 | if (message == nil) { | 596 | if (message == nil) { |
582 | message = @"Unknown error"; | 597 | message = @"Unknown error"; |
583 | } | 598 | } |
584 | 599 | ||
585 | if ([message isEqualToString:@"Token is invalid"]) { | 600 | if ([message isEqualToString:@"Token is invalid"]) { |
586 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 601 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
587 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 602 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
588 | [self requestTweetsList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; | 603 | [self requestTweetsList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; |
589 | } | 604 | } |
590 | else { | 605 | else { |
591 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 606 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
592 | completion(nil, errorObject); | 607 | completion(nil, errorObject); |
593 | } | 608 | } |
594 | } | 609 | } |
595 | } | 610 | } |
596 | else | 611 | else |
597 | { | 612 | { |
598 | completion(nil, error); | 613 | completion(nil, error); |
599 | } | 614 | } |
600 | }]; | 615 | }]; |
601 | } | 616 | } |
602 | 617 | ||
603 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 618 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
604 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"]; | 619 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"]; |
605 | NSLog(@"searchGroup link %@ page %d", url, page); | 620 | NSLog(@"searchGroup link %@ page %d", url, page); |
606 | if(searchTask != nil) { | 621 | if(searchTask != nil) { |
607 | [searchTask cancel]; | 622 | [searchTask cancel]; |
608 | } | 623 | } |
609 | 624 | ||
610 | searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) { | 625 | searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) { |
611 | searchTask = nil; | 626 | searchTask = nil; |
612 | if (completion == NULL) { | 627 | if (completion == NULL) { |
613 | return ; | 628 | return ; |
614 | } | 629 | } |
615 | 630 | ||
616 | if (error == nil) | 631 | if (error == nil) |
617 | { | 632 | { |
618 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 633 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
619 | NSLog(@"%@", dataResult); | 634 | NSLog(@"%@", dataResult); |
620 | int status = [dataResult[@"status"] intValue]; | 635 | int status = [dataResult[@"status"] intValue]; |
621 | if (status == 1) { // status = 1 success | 636 | if (status == 1) { // status = 1 success |
622 | if(dataResult[@"result"] != nil) { | 637 | if(dataResult[@"result"] != nil) { |
623 | NSArray * array = dataResult[@"result"]; | 638 | NSArray * array = dataResult[@"result"]; |
624 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 639 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
625 | for(NSDictionary * dict in array) { | 640 | for(NSDictionary * dict in array) { |
626 | GroupObject * object = [[GroupObject alloc] initWithData:dict]; | 641 | GroupObject * object = [[GroupObject alloc] initWithData:dict]; |
627 | [arrayTweets addObject:object]; | 642 | [arrayTweets addObject:object]; |
628 | } | 643 | } |
629 | completion(arrayTweets, nil); | 644 | completion(arrayTweets, nil); |
630 | } | 645 | } |
631 | else { | 646 | else { |
632 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 647 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
633 | completion(nil, errorObject); | 648 | completion(nil, errorObject); |
634 | } | 649 | } |
635 | } | 650 | } |
636 | else { | 651 | else { |
637 | NSString *message = dataResult[@"message"]; | 652 | NSString *message = dataResult[@"message"]; |
638 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 653 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
639 | completion(nil, errorObject); | 654 | completion(nil, errorObject); |
640 | } | 655 | } |
641 | } | 656 | } |
642 | else | 657 | else |
643 | { | 658 | { |
644 | completion(nil, error); | 659 | completion(nil, error); |
645 | } | 660 | } |
646 | }]; | 661 | }]; |
647 | } | 662 | } |
648 | 663 | ||
649 | #pragma mark - Group Function | 664 | #pragma mark - Group Function |
650 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { | 665 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { |
651 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/newGroup"]; | 666 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/newGroup"]; |
652 | NSLog(@"requestCreateGroup link %@", url); | 667 | NSLog(@"requestCreateGroup link %@", url); |
653 | NSDictionary * dict = @{@"group_name":group.name, | 668 | NSDictionary * dict = @{@"group_name":group.name, |
654 | @"goal":group.goal, | 669 | @"goal":group.goal, |
655 | @"walk_mode_active":[NSNumber numberWithBool:group.walkMode], | 670 | @"walk_mode_active":[NSNumber numberWithBool:group.walkMode], |
656 | @"run_mode_active":[NSNumber numberWithBool:group.runMode], | 671 | @"run_mode_active":[NSNumber numberWithBool:group.runMode], |
657 | @"bike_mode_active":[NSNumber numberWithBool:group.bikeMode], | 672 | @"bike_mode_active":[NSNumber numberWithBool:group.bikeMode], |
658 | @"step_mode_active":[NSNumber numberWithBool:group.stepMode], | 673 | @"step_mode_active":[NSNumber numberWithBool:group.stepMode], |
659 | @"gym_mode_active":[NSNumber numberWithBool:group.gymMode], | 674 | @"gym_mode_active":[NSNumber numberWithBool:group.gymMode], |
660 | @"beginer_mode_active":[NSNumber numberWithBool:group.beginMode], | 675 | @"beginer_mode_active":[NSNumber numberWithBool:group.beginMode], |
661 | @"walk_mode_goal":[NSNumber numberWithBool:group.walkGoal], | 676 | @"walk_mode_goal":[NSNumber numberWithBool:group.walkGoal], |
662 | @"run_mode_goal":[NSNumber numberWithBool:group.runGoal], | 677 | @"run_mode_goal":[NSNumber numberWithBool:group.runGoal], |
663 | @"bike_mode_goal":[NSNumber numberWithBool:group.bikeGoal]}; | 678 | @"bike_mode_goal":[NSNumber numberWithBool:group.bikeGoal]}; |
664 | 679 | ||
665 | [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { | 680 | [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { |
666 | 681 | ||
667 | if (completion == NULL) { | 682 | if (completion == NULL) { |
668 | return ; | 683 | return ; |
669 | } | 684 | } |
670 | 685 | ||
671 | if (error == nil) | 686 | if (error == nil) |
672 | { | 687 | { |
673 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 688 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
674 | NSLog(@"%@", dataResult); | 689 | NSLog(@"%@", dataResult); |
675 | int status = [dataResult[@"status"] intValue]; | 690 | int status = [dataResult[@"status"] intValue]; |
676 | if (status == 1) { // status = 1 success | 691 | if (status == 1) { // status = 1 success |
677 | if(dataResult[@"result"] != nil) { | 692 | if(dataResult[@"result"] != nil) { |
678 | NSDictionary * dict = dataResult[@"result"]; | 693 | NSDictionary * dict = dataResult[@"result"]; |
679 | group.groupID = [dict[@"group_id"] intValue]; | 694 | group.groupID = [dict[@"group_id"] intValue]; |
680 | completion(group, nil); | 695 | completion(group, nil); |
681 | } | 696 | } |
682 | else { | 697 | else { |
683 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 698 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
684 | completion(nil, errorObject); | 699 | completion(nil, errorObject); |
685 | } | 700 | } |
686 | } | 701 | } |
687 | else { | 702 | else { |
688 | NSString *message = dataResult[@"message"]; | 703 | NSString *message = dataResult[@"message"]; |
689 | if (message == nil) { | 704 | if (message == nil) { |
690 | message = @"Unknown error"; | 705 | message = @"Unknown error"; |
691 | } | 706 | } |
692 | 707 | ||
693 | if ([message isEqualToString:@"Token is invalid"]) { | 708 | if ([message isEqualToString:@"Token is invalid"]) { |
694 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 709 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
695 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 710 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
696 | [self requestCreateGroup:tokenNew withGroup:group CompletionHandler:completion]; | 711 | [self requestCreateGroup:tokenNew withGroup:group CompletionHandler:completion]; |
697 | } | 712 | } |
698 | else { | 713 | else { |
699 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 714 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
700 | completion(nil, errorObject); | 715 | completion(nil, errorObject); |
701 | } | 716 | } |
702 | } | 717 | } |
703 | } | 718 | } |
704 | else | 719 | else |
705 | { | 720 | { |
706 | completion(nil, error); | 721 | completion(nil, error); |
707 | } | 722 | } |
708 | }]; | 723 | }]; |
709 | } | 724 | } |
710 | 725 | ||
711 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { | 726 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { |
712 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID]; | 727 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID]; |
713 | NSLog(@"getGroupDetail link %@", url); | 728 | NSLog(@"getGroupDetail link %@", url); |
714 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 729 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
715 | 730 | ||
716 | if (completion == NULL) { | 731 | if (completion == NULL) { |
717 | return ; | 732 | return ; |
718 | } | 733 | } |
719 | 734 | ||
720 | if (error == nil) | 735 | if (error == nil) |
721 | { | 736 | { |
722 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 737 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
723 | NSLog(@"%@", dataResult); | 738 | NSLog(@"%@", dataResult); |
724 | int status = [dataResult[@"status"] intValue]; | 739 | int status = [dataResult[@"status"] intValue]; |
725 | if (status == 1) { // status = 1 success | 740 | if (status == 1) { // status = 1 success |
726 | if(dataResult[@"result"] != nil) { | 741 | if(dataResult[@"result"] != nil) { |
727 | NSArray * array = dataResult[@"result"]; | 742 | NSArray * array = dataResult[@"result"]; |
728 | GroupObject * object = [[GroupObject alloc] initWithData:array[0] andGroupID:groupID]; | 743 | GroupObject * object = [[GroupObject alloc] initWithData:array[0] andGroupID:groupID]; |
729 | completion(object, nil); | 744 | completion(object, nil); |
730 | } | 745 | } |
731 | else { | 746 | else { |
732 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 747 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
733 | completion(nil, errorObject); | 748 | completion(nil, errorObject); |
734 | } | 749 | } |
735 | } | 750 | } |
736 | else { | 751 | else { |
737 | NSString *message = dataResult[@"message"]; | 752 | NSString *message = dataResult[@"message"]; |
738 | if (message == nil) { | 753 | if (message == nil) { |
739 | message = @"Unknown error"; | 754 | message = @"Unknown error"; |
740 | } | 755 | } |
741 | 756 | ||
742 | if ([message isEqualToString:@"Token is invalid"]) { | 757 | if ([message isEqualToString:@"Token is invalid"]) { |
743 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 758 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
744 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 759 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
745 | [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion]; | 760 | [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion]; |
746 | } | 761 | } |
747 | else { | 762 | else { |
748 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 763 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
749 | completion(nil, errorObject); | 764 | completion(nil, errorObject); |
750 | } | 765 | } |
751 | } | 766 | } |
752 | } | 767 | } |
753 | else | 768 | else |
754 | { | 769 | { |
755 | completion(nil, error); | 770 | completion(nil, error); |
756 | } | 771 | } |
757 | }]; | 772 | }]; |
758 | } | 773 | } |
759 | 774 | ||
760 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 775 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
761 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/member/%d/%d", groupID, page]; | 776 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/member/%d/%d", groupID, page]; |
762 | NSLog(@"requestMemberList link %@ page %d", url, page); | 777 | NSLog(@"requestMemberList link %@ page %d", url, page); |
763 | 778 | ||
764 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 779 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
765 | if (completion == NULL) { | 780 | if (completion == NULL) { |
766 | return ; | 781 | return ; |
767 | } | 782 | } |
768 | 783 | ||
769 | if (error == nil) | 784 | if (error == nil) |
770 | { | 785 | { |
771 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 786 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
772 | NSLog(@"%@", dataResult); | 787 | NSLog(@"%@", dataResult); |
773 | int status = [dataResult[@"status"] intValue]; | 788 | int status = [dataResult[@"status"] intValue]; |
774 | if (status == 1) { // status = 1 success | 789 | if (status == 1) { // status = 1 success |
775 | if(dataResult[@"result"] != nil) { | 790 | if(dataResult[@"result"] != nil) { |
776 | NSArray * array = dataResult[@"result"]; | 791 | NSArray * array = dataResult[@"result"]; |
777 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 792 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
778 | for(NSDictionary * dict in array) { | 793 | for(NSDictionary * dict in array) { |
779 | MemberObject * object = [[MemberObject alloc] initWithData:dict]; | 794 | MemberObject * object = [[MemberObject alloc] initWithData:dict]; |
780 | [arrayTweets addObject:object]; | 795 | [arrayTweets addObject:object]; |
781 | } | 796 | } |
782 | completion(arrayTweets, nil); | 797 | completion(arrayTweets, nil); |
783 | } | 798 | } |
784 | else { | 799 | else { |
785 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 800 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
786 | completion(nil, errorObject); | 801 | completion(nil, errorObject); |
787 | } | 802 | } |
788 | } | 803 | } |
789 | else { | 804 | else { |
790 | NSString *message = dataResult[@"message"]; | 805 | NSString *message = dataResult[@"message"]; |
791 | if (message == nil) { | 806 | if (message == nil) { |
792 | message = @"Unknown error"; | 807 | message = @"Unknown error"; |
793 | } | 808 | } |
794 | 809 | ||
795 | if ([message isEqualToString:@"Token is invalid"]) { | 810 | if ([message isEqualToString:@"Token is invalid"]) { |
796 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 811 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
797 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 812 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
798 | [self requestMemberList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; | 813 | [self requestMemberList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; |
799 | } | 814 | } |
800 | else { | 815 | else { |
801 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 816 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
802 | completion(nil, errorObject); | 817 | completion(nil, errorObject); |
803 | } | 818 | } |
804 | } | 819 | } |
805 | } | 820 | } |
806 | else | 821 | else |
807 | { | 822 | { |
808 | completion(nil, error); | 823 | completion(nil, error); |
809 | } | 824 | } |
810 | }]; | 825 | }]; |
811 | } | 826 | } |
812 | 827 | ||
813 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion { | 828 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion { |
814 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/join"]; | 829 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/join"]; |
815 | NSLog(@"requestJoinGroup link %@", url); | 830 | NSLog(@"requestJoinGroup link %@", url); |
816 | 831 | ||
817 | [self _request:url method:@"POST" token:token paras:@{@"group_id": [NSNumber numberWithInt:groupID]} completion:^(NSData *data, NSError *error) { | 832 | [self _request:url method:@"POST" token:token paras:@{@"group_id": [NSNumber numberWithInt:groupID]} completion:^(NSData *data, NSError *error) { |
818 | if (completion == NULL) { | 833 | if (completion == NULL) { |
819 | return ; | 834 | return ; |
820 | } | 835 | } |
821 | 836 | ||
822 | if (error == nil) | 837 | if (error == nil) |
823 | { | 838 | { |
824 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 839 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
825 | NSLog(@"%@", dataResult); | 840 | NSLog(@"%@", dataResult); |
826 | int status = [dataResult[@"status"] intValue]; | 841 | int status = [dataResult[@"status"] intValue]; |
827 | if (status == 1) { // status = 1 success | 842 | if (status == 1) { // status = 1 success |
828 | if(dataResult[@"result"] != nil) { | 843 | if(dataResult[@"result"] != nil) { |
829 | completion(nil); | 844 | completion(nil); |
830 | } | 845 | } |
831 | else { | 846 | else { |
832 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 847 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
833 | completion(errorObject); | 848 | completion(errorObject); |
834 | } | 849 | } |
835 | } | 850 | } |
836 | else { | 851 | else { |
837 | NSString *message = dataResult[@"message"]; | 852 | NSString *message = dataResult[@"message"]; |
838 | if ([message isEqualToString:@"Token is invalid"]) { | 853 | if ([message isEqualToString:@"Token is invalid"]) { |
839 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 854 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
840 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 855 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
841 | [self requestJoinGroup:tokenNew groupID:groupID CompletionHandler:completion]; | 856 | [self requestJoinGroup:tokenNew groupID:groupID CompletionHandler:completion]; |
842 | } | 857 | } |
843 | else { | 858 | else { |
844 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 859 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
845 | completion(errorObject); | 860 | completion(errorObject); |
846 | } | 861 | } |
847 | } | 862 | } |
848 | } | 863 | } |
849 | else | 864 | else |
850 | { | 865 | { |
851 | completion(error); | 866 | completion(error); |
852 | } | 867 | } |
853 | }]; | 868 | }]; |
854 | } | 869 | } |
855 | 870 | ||
856 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 871 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
857 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/list"]; | 872 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/list"]; |
858 | NSLog(@"requestGroupList link %@", url); | 873 | NSLog(@"requestGroupList link %@", url); |
859 | 874 | ||
860 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 875 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
861 | if (completion == NULL) { | 876 | if (completion == NULL) { |
862 | return ; | 877 | return ; |
863 | } | 878 | } |
864 | 879 | ||
865 | if (error == nil) | 880 | if (error == nil) |
866 | { | 881 | { |
867 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 882 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
868 | NSLog(@"%@", dataResult); | 883 | NSLog(@"%@", dataResult); |
869 | int status = [dataResult[@"status"] intValue]; | 884 | int status = [dataResult[@"status"] intValue]; |
870 | if (status == 1) { // status = 1 success | 885 | if (status == 1) { // status = 1 success |
871 | if(dataResult[@"result"] != nil) { | 886 | if(dataResult[@"result"] != nil) { |
872 | NSArray * array = dataResult[@"result"]; | 887 | NSArray * array = dataResult[@"result"]; |
873 | NSMutableArray * arrayGroup = [[NSMutableArray alloc] init]; | 888 | NSMutableArray * arrayGroup = [[NSMutableArray alloc] init]; |
874 | for(NSDictionary * dict in array) { | 889 | for(NSDictionary * dict in array) { |
875 | GroupObject * object = [[GroupObject alloc] initWithShortData:dict]; | 890 | GroupObject * object = [[GroupObject alloc] initWithShortData:dict]; |
876 | [arrayGroup addObject:object]; | 891 | [arrayGroup addObject:object]; |
877 | } | 892 | } |
878 | completion(arrayGroup, nil); | 893 | completion(arrayGroup, nil); |
879 | } | 894 | } |
880 | else { | 895 | else { |
881 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 896 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
882 | completion(nil, errorObject); | 897 | completion(nil, errorObject); |
883 | } | 898 | } |
884 | } | 899 | } |
885 | else { | 900 | else { |
886 | NSString *message = dataResult[@"message"]; | 901 | NSString *message = dataResult[@"message"]; |
887 | if (message == nil) { | 902 | if (message == nil) { |
888 | message = @"Unknown error"; | 903 | message = @"Unknown error"; |
889 | } | 904 | } |
890 | 905 | ||
891 | if ([message isEqualToString:@"Token is invalid"]) { | 906 | if ([message isEqualToString:@"Token is invalid"]) { |
892 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 907 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
893 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 908 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
894 | [self requestGroupList:tokenNew CompletionHandler:completion]; | 909 | [self requestGroupList:tokenNew CompletionHandler:completion]; |
895 | } | 910 | } |
896 | else { | 911 | else { |
897 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 912 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
898 | completion(nil, errorObject); | 913 | completion(nil, errorObject); |
899 | } | 914 | } |
900 | } | 915 | } |
901 | } | 916 | } |
902 | else | 917 | else |
903 | { | 918 | { |
904 | completion(nil, error); | 919 | completion(nil, error); |
905 | } | 920 | } |
906 | }]; | 921 | }]; |
907 | } | 922 | } |
908 | #pragma mark - Common API | 923 | #pragma mark - Common API |
909 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { | 924 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { |
910 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { | 925 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { |
911 | 926 | ||
912 | if (completion == NULL) { | 927 | if (completion == NULL) { |
913 | return ; | 928 | return ; |
914 | } | 929 | } |
915 | 930 | ||
916 | if (error == nil) | 931 | if (error == nil) |
917 | { | 932 | { |
918 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 933 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
919 | 934 | ||
920 | int status = [dataResult[@"status"] intValue]; | 935 | int status = [dataResult[@"status"] intValue]; |
921 | if (status == 1) { // status = 1 success | 936 | if (status == 1) { // status = 1 success |
922 | NSArray *arrayResult = dataResult[@"result"]; | 937 | NSArray *arrayResult = dataResult[@"result"]; |
923 | if (arrayResult.count > 0) { | 938 | if (arrayResult.count > 0) { |
924 | NSString *token = arrayResult[0]; | 939 | NSString *token = arrayResult[0]; |
925 | completion(token, nil); | 940 | completion(token, nil); |
926 | } | 941 | } |
927 | else { | 942 | else { |
928 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 943 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
929 | completion(nil, errorObject); | 944 | completion(nil, errorObject); |
930 | } | 945 | } |
931 | 946 | ||
932 | } | 947 | } |
933 | else { // status = 0 error | 948 | else { // status = 0 error |
934 | NSString *message = dataResult[@"message"]; | 949 | NSString *message = dataResult[@"message"]; |
935 | if (message == nil) { | 950 | if (message == nil) { |
936 | message = @"Unknown error"; | 951 | message = @"Unknown error"; |
937 | } | 952 | } |
938 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 953 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
939 | completion(nil, loginFaild); | 954 | completion(nil, loginFaild); |
940 | } | 955 | } |
941 | } | 956 | } |
942 | else | 957 | else |
943 | { | 958 | { |
944 | completion(nil, error); | 959 | completion(nil, error); |
945 | } | 960 | } |
946 | }]; | 961 | }]; |
947 | } | 962 | } |
948 | 963 | ||
949 | #pragma mark - Private Function | 964 | #pragma mark - Private Function |
950 | - (void) checkToken { | 965 | - (void) checkToken { |
951 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; | 966 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; |
952 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; | 967 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; |
953 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; | 968 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; |
954 | if (user != nil) { | 969 | if (user != nil) { |
955 | [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { | 970 | [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { |
956 | if (error == nil) { | 971 | if (error == nil) { |
957 | [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; | 972 | [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; |
958 | [[NSUserDefaults standardUserDefaults] synchronize]; | 973 | [[NSUserDefaults standardUserDefaults] synchronize]; |
959 | } | 974 | } |
960 | }]; | 975 | }]; |
961 | } | 976 | } |
962 | } | 977 | } |
963 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary | 978 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary |
964 | { | 979 | { |
965 | NSMutableArray *parts = [[NSMutableArray alloc] init]; | 980 | NSMutableArray *parts = [[NSMutableArray alloc] init]; |
966 | for (id key in dictionary) | 981 | for (id key in dictionary) |
967 | { | 982 | { |
968 | NSString *encodedValue = [[dictionary[key] description] urlencode]; | 983 | NSString *encodedValue = [[dictionary[key] description] urlencode]; |
969 | NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; | 984 | NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; |
970 | NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; | 985 | NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; |
971 | [parts addObject:part]; | 986 | [parts addObject:part]; |
972 | } | 987 | } |
973 | NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; | 988 | NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; |
974 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; | 989 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; |
975 | } | 990 | } |
976 | 991 | ||
977 | - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion | 992 | - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion |
978 | { | 993 | { |
979 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; | 994 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; |
980 | request.HTTPMethod = method; | 995 | request.HTTPMethod = method; |
981 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; | 996 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; |
982 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; | 997 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; |
983 | if(token != nil && ![token isEqual: @""]) { | 998 | if(token != nil && ![token isEqual: @""]) { |
984 | [request setValue: token forHTTPHeaderField: @"token"]; | 999 | [request setValue: token forHTTPHeaderField: @"token"]; |
985 | } | 1000 | } |
986 | [request setTimeoutInterval:self.timeOutInterval]; | 1001 | [request setTimeoutInterval:self.timeOutInterval]; |
987 | 1002 | ||
988 | if (paras != nil) | 1003 | if (paras != nil) |
989 | { | 1004 | { |
990 | NSData *encodedData = [self _encodeDictionary: paras]; | 1005 | NSData *encodedData = [self _encodeDictionary: paras]; |
991 | [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; | 1006 | [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; |
992 | [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; | 1007 | [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; |
993 | [request setHTTPBody: encodedData]; | 1008 | [request setHTTPBody: encodedData]; |
994 | } | 1009 | } |
995 | 1010 | ||
996 | NSURLSession *session = [NSURLSession sharedSession]; | 1011 | NSURLSession *session = [NSURLSession sharedSession]; |
997 | NSURLSessionDataTask *task = [session dataTaskWithRequest:request | 1012 | NSURLSessionDataTask *task = [session dataTaskWithRequest:request |
998 | completionHandler: | 1013 | completionHandler: |
999 | ^(NSData *data, NSURLResponse *response, NSError *error) { | 1014 | ^(NSData *data, NSURLResponse *response, NSError *error) { |
1000 | if (completion == NULL) { | 1015 | if (completion == NULL) { |
1001 | return ; | 1016 | return ; |
1002 | } | 1017 | } |
1003 | if (error == nil) | 1018 | if (error == nil) |
1004 | { | 1019 | { |
1005 | completion(data, nil); | 1020 | completion(data, nil); |
1006 | } | 1021 | } |
1007 | else | 1022 | else |
1008 | { | 1023 | { |
1009 | completion(nil, error); | 1024 | completion(nil, error); |
1010 | } | 1025 | } |
1011 | }]; | 1026 | }]; |
1012 | [task resume]; | 1027 | [task resume]; |
1013 | return task; | 1028 | return task; |
1014 | } | 1029 | } |
1015 | 1030 | ||
1016 | -(void)waitUntilDone:(void(^)(void))waitBlock { | 1031 | -(void)waitUntilDone:(void(^)(void))waitBlock { |
1017 | //use your statement or call method here | 1032 | //use your statement or call method here |
1018 | if(waitBlock){ | 1033 | if(waitBlock){ |
1019 | waitBlock(); | 1034 | waitBlock(); |
1020 | } | 1035 | } |
1021 | } | 1036 | } |
1022 | 1037 | ||
1023 | @end | 1038 | @end |
1024 | 1039 |
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 | 24 | ||
25 | //convert date time | 25 | //convert date time |
26 | + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format; | 26 | + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format; |
27 | + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format; | 27 | + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format locale:(NSString *) locale; |
28 | @end | 28 | @end |
29 | 29 |
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 | #pragma mark convert date time | 149 | #pragma mark convert date time |
150 | + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format { | 150 | + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format { |
151 | NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; | 151 | NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; |
152 | [dateFormat setDateFormat:format]; | 152 | [dateFormat setDateFormat:format]; |
153 | NSDate *date = [dateFormat dateFromString:dateString]; | 153 | NSDate *date = [dateFormat dateFromString:dateString]; |
154 | if(date == NULL) { | 154 | if(date == NULL) { |
155 | return [NSDate date]; | 155 | return [NSDate date]; |
156 | } | 156 | } |
157 | return date; | 157 | return date; |
158 | } | 158 | } |
159 | 159 | ||
160 | + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format { | 160 | + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format locale:(NSString *) locale { |
161 | NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; | 161 | NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; |
162 | [dateFormat setDateFormat:format]; | 162 | [dateFormat setDateFormat:format]; |
163 | if(![locale isEqual: @""]) { | ||
164 | [dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:locale]]; | ||
165 | } | ||
163 | NSString *dateString = [dateFormat stringFromDate:date]; | 166 | NSString *dateString = [dateFormat stringFromDate:date]; |
164 | return dateString; | 167 | return dateString; |
165 | } | 168 | } |
166 | 169 | ||
167 | @end | 170 | @end |
168 | 171 |