Commit 39b57938e7152a39e55db776201105a82928504a
1 parent
02fd57747b
Exists in
master
update api Top
Showing 3 changed files with 36 additions and 17 deletions Side-by-side Diff
LifeLog/LifeLog/HomeViewController.m
| ... | ... | @@ -117,14 +117,15 @@ |
| 117 | 117 | - (void)viewWillAppear:(BOOL)animated { |
| 118 | 118 | [super viewWillAppear:animated]; |
| 119 | 119 | [self saveStepForDay:self.dateCurrent]; |
| 120 | - [self requestTopByDate:_dateCurrent]; | |
| 120 | + [self requestTopByDate:self.dateCurrent]; | |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | - (void)requestTopByDate:(NSDate *)date { |
| 124 | 124 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
| 125 | 125 | [dateFormatter setDateFormat:@"yyyy-MM-dd"]; |
| 126 | 126 | NSString *dateString = [dateFormatter stringFromDate:date]; |
| 127 | - | |
| 127 | + [progressHud showAnimated:YES]; | |
| 128 | + [progressHud setHidden:NO]; | |
| 128 | 129 | HomeViewController __weak *weakSelf = self; |
| 129 | 130 | int mode = 1; |
| 130 | 131 | switch (_segmentHome.selectedSegmentIndex) { |
| ... | ... | @@ -149,6 +150,9 @@ |
| 149 | 150 | } |
| 150 | 151 | if (error == nil) { |
| 151 | 152 | NSLog(@"TopObject: %@", topObject); |
| 153 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 154 | + [weakSelf updateStepUI:topObject.targetInfor]; | |
| 155 | + }); | |
| 152 | 156 | } |
| 153 | 157 | else { |
| 154 | 158 | dispatch_async(dispatch_get_main_queue(), ^{ |
| ... | ... | @@ -156,6 +160,9 @@ |
| 156 | 160 | [Utilities showErrorMessage:message withViewController:weakSelf]; |
| 157 | 161 | }); |
| 158 | 162 | } |
| 163 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 164 | + [progressHud setHidden:YES]; | |
| 165 | + }); | |
| 159 | 166 | }]; |
| 160 | 167 | } |
| 161 | 168 | |
| ... | ... | @@ -185,6 +192,7 @@ |
| 185 | 192 | self.dateCurrent = [self.dateCurrent dateByAddingTimeInterval:-(24*60*60)]; |
| 186 | 193 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; |
| 187 | 194 | [self saveStepForDay:self.dateCurrent]; |
| 195 | + [self requestTopByDate:self.dateCurrent]; | |
| 188 | 196 | } |
| 189 | 197 | |
| 190 | 198 | - (IBAction)rightButtonTouchUpInside:(id)sender |
| 191 | 199 | |
| 192 | 200 | |
| ... | ... | @@ -192,18 +200,20 @@ |
| 192 | 200 | self.dateCurrent = [self.dateCurrent dateByAddingTimeInterval:24*60*60]; |
| 193 | 201 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; |
| 194 | 202 | [self saveStepForDay:self.dateCurrent]; |
| 203 | + [self requestTopByDate:self.dateCurrent]; | |
| 195 | 204 | } |
| 196 | 205 | |
| 197 | 206 | - (IBAction)segmentValueChange:(id)sender { |
| 198 | - [self updateStepUI]; | |
| 207 | + // [self updateStepUI]; | |
| 208 | + [self requestTopByDate:self.dateCurrent]; | |
| 199 | 209 | } |
| 200 | 210 | |
| 201 | 211 | #pragma mark - Functions Private |
| 202 | 212 | - (void)saveStepForDay:(NSDate *)date |
| 203 | 213 | { |
| 204 | 214 | if ([CMMotionActivityManager isActivityAvailable]) { |
| 205 | - [progressHud showAnimated:YES]; | |
| 206 | - [progressHud setHidden:NO]; | |
| 215 | +// [progressHud showAnimated:YES]; | |
| 216 | +// [progressHud setHidden:NO]; | |
| 207 | 217 | self.bike = 0; |
| 208 | 218 | self.walking = 0; |
| 209 | 219 | self.running = 0; |
| 210 | 220 | |
| ... | ... | @@ -286,14 +296,15 @@ |
| 286 | 296 | }]; |
| 287 | 297 | }); |
| 288 | 298 | } |
| 289 | - else { | |
| 290 | - [progressHud setHidden:YES]; | |
| 291 | - } | |
| 299 | +// else { | |
| 300 | +// [progressHud setHidden:YES]; | |
| 301 | +// } | |
| 292 | 302 | } |
| 293 | 303 | |
| 294 | 304 | - (void)updateStepUI |
| 295 | 305 | { |
| 296 | 306 | if (self.totalRequest == self.countComplete) { |
| 307 | + /* | |
| 297 | 308 | switch (self.segmentHome.selectedSegmentIndex) { |
| 298 | 309 | case 0: |
| 299 | 310 | self.lblValueStep.text = [Utilities addCommaFromNumber:self.bike]; |
| 300 | 311 | |
| ... | ... | @@ -316,9 +327,10 @@ |
| 316 | 327 | default: |
| 317 | 328 | break; |
| 318 | 329 | } |
| 330 | + */ | |
| 319 | 331 | self.countComplete = 0; |
| 320 | 332 | self.totalRequest = 0; |
| 321 | - [progressHud setHidden:YES]; | |
| 333 | + //[progressHud setHidden:YES]; | |
| 322 | 334 | } |
| 323 | 335 | } |
| 324 | 336 | |
| ... | ... | @@ -398,6 +410,13 @@ |
| 398 | 410 | }]; |
| 399 | 411 | }); |
| 400 | 412 | } |
| 413 | +} | |
| 414 | + | |
| 415 | +- (void)updateStepUI:(TargetInfor *)targetInfor | |
| 416 | +{ | |
| 417 | + self.lblValueStep.text = targetInfor.num_step; | |
| 418 | + self.lblValueStepOther.text = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"lifelog.today.remaining.other", nil), targetInfor.remaining_step]; | |
| 419 | + self.lblPercent.text = [NSString stringWithFormat:@"%@ %i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), [targetInfor.complete_percent intValue], NSLocalizedString(@"lifelog.today.percent", nil)]; | |
| 401 | 420 | } |
| 402 | 421 | |
| 403 | 422 | @end |
LifeLog/LifeLog/TargetInfor.h
| ... | ... | @@ -9,10 +9,10 @@ |
| 9 | 9 | #import <Foundation/Foundation.h> |
| 10 | 10 | |
| 11 | 11 | @interface TargetInfor : NSObject |
| 12 | -@property (nonatomic) int target_step; | |
| 13 | -@property (nonatomic) int num_step; | |
| 14 | -@property (nonatomic) int remaining_step; | |
| 15 | -@property (nonatomic) float complete_percent; | |
| 12 | +@property (nonatomic, strong) NSString *target_step; | |
| 13 | +@property (nonatomic, strong) NSString *num_step; | |
| 14 | +@property (nonatomic, strong) NSString *remaining_step; | |
| 15 | +@property (nonatomic, strong) NSString *complete_percent; | |
| 16 | 16 | -(id) initWithData : (NSDictionary *) dict; |
| 17 | 17 | @end |
LifeLog/LifeLog/TargetInfor.m
| ... | ... | @@ -11,16 +11,16 @@ |
| 11 | 11 | @implementation TargetInfor |
| 12 | 12 | -(id) initWithData : (NSDictionary *) dict { |
| 13 | 13 | if([dict objectForKey:@"target_step"] != nil) { |
| 14 | - self.target_step = [dict[@"target_step"] intValue]; | |
| 14 | + self.target_step = dict[@"target_step"]; | |
| 15 | 15 | } |
| 16 | 16 | if([dict objectForKey:@"num_step"] != nil) { |
| 17 | - self.num_step = [dict[@"num_step"] intValue]; | |
| 17 | + self.num_step = dict[@"num_step"]; | |
| 18 | 18 | } |
| 19 | 19 | if([dict objectForKey:@"remaining_step"] != nil) { |
| 20 | - self.remaining_step = [dict[@"remaining_step"] intValue]; | |
| 20 | + self.remaining_step = dict[@"remaining_step"]; | |
| 21 | 21 | } |
| 22 | 22 | if([dict objectForKey:@"complete_percent"] != nil) { |
| 23 | - self.complete_percent = [dict[@"complete_percent"] floatValue]; | |
| 23 | + self.complete_percent = dict[@"complete_percent"]; | |
| 24 | 24 | } |
| 25 | 25 | return self; |
| 26 | 26 | } |