diff --git a/LifeLog/LifeLog/HomeViewController.m b/LifeLog/LifeLog/HomeViewController.m index 63dc656..d84d680 100644 --- a/LifeLog/LifeLog/HomeViewController.m +++ b/LifeLog/LifeLog/HomeViewController.m @@ -16,10 +16,12 @@ #import "ServerAPI.h" static NSInteger maxRequest = 20; +static NSInteger numberTotal = 10000; @interface HomeViewController () { MBProgressHUD *progressHud; + NSInteger targetStep; } @property (nonatomic, weak) IBOutlet UILabel *lblTitle; @property (nonatomic, weak) IBOutlet UIImageView *avatar; @@ -113,6 +115,7 @@ static NSInteger maxRequest = 20; progressHud.mode = MBProgressHUDModeIndeterminate; progressHud.detailsLabel.text = NSLocalizedString(@"lifelog.home.progressHud.title", nil); // [self saveDataStep7LastDay]; + targetStep = numberTotal; } - (void)viewWillAppear:(BOOL)animated { @@ -185,6 +188,7 @@ static NSInteger maxRequest = 20; - (IBAction)todayButtonTouchUpInside:(id)sender { TodayViewController *todayVC = [[TodayViewController alloc] initWithNibName:@"TodayViewController" bundle:nil]; + todayVC.targetStep = targetStep; [self.navigationController pushViewController:todayVC animated:YES]; } @@ -254,48 +258,6 @@ static NSInteger maxRequest = 20; // PhongNV weakSelf.currentIndex = 0; [weakSelf save20objectOfActivityExtras:arrayActivities]; - //[weakSelf saveStepFromActivityExtras:arrayActivities]; - /* - for (CMMotionActivityExtra *activityExtra in arrayActivities) { - [weakSelf.pedometer queryPedometerDataFromDate:activityExtra.activity.startDate toDate:activityExtra.endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) { - NSInteger numberStep = [pedometerData.numberOfSteps integerValue]; - int mode = 1; - if (activityExtra.activity.cycling) { - // self.bike - weakSelf.bike += numberStep; - mode = 3; - } - else if (activityExtra.activity.walking) { - // self.walking - weakSelf.walking += numberStep; - mode = 1; - } - else if (activityExtra.activity.running) { - weakSelf.running += numberStep; - mode = 2; - } - else { - // unknown - } - - // save step to server - if (numberStep > 0) { - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; - NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate]; - NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate]; - [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) { - if (error) { - NSLog(@"Error: %@", error); - } - }]; - } - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf updateStepUI]; - }); - }]; - } - */ }]; }); } @@ -373,56 +335,6 @@ static NSInteger maxRequest = 20; } } -- (void)saveStepFromActivityExtras:(NSArray *)activities -{ - if (self.currentIndex >= activities.count) { - self.currentIndex = 0; - dispatch_async(dispatch_get_main_queue(), ^{ - [self updateStepUI]; - }); - return; - } - HomeViewController __weak *weakSelf = self; - CMMotionActivityExtra *activityExtra = [activities objectAtIndex:self.currentIndex]; - [self.pedometer queryPedometerDataFromDate:activityExtra.activity.startDate toDate:activityExtra.endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) { - if (weakSelf == nil) { - return ; - } - NSInteger numberStep = [pedometerData.numberOfSteps integerValue]; - int mode = 1; - if (activityExtra.activity.cycling) { - mode = 3; - } - else if (activityExtra.activity.walking) { - mode = 1; - } - else if (activityExtra.activity.running) { - mode = 2; - } - else { - // unknown - } - // save step to server - if (numberStep > 0) { - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; - NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate]; - NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate]; - [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) { - if (error) { - NSLog(@"Error: %@", error); - } - weakSelf.currentIndex += 1; - [weakSelf saveStepFromActivityExtras:activities]; - }]; - } - else { - weakSelf.currentIndex += 1; - [weakSelf saveStepFromActivityExtras:activities]; - } - }]; -} - - (void)updateStepUI { [self requestTopByDate:self.dateCurrent]; @@ -508,6 +420,8 @@ static NSInteger maxRequest = 20; - (void)updateStepUI:(TargetInfor *)targetInfor { + NSString *stringTargetStep = [targetInfor.target_step stringByReplacingOccurrencesOfString:@"," withString:@""]; + targetStep = [stringTargetStep integerValue]; self.lblValueStep.text = targetInfor.num_step; self.lblValueStepOther.text = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"lifelog.today.remaining.other", nil), targetInfor.remaining_step]; self.lblPercent.text = [NSString stringWithFormat:@"%@ %i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), [targetInfor.complete_percent intValue], NSLocalizedString(@"lifelog.today.percent", nil)]; diff --git a/LifeLog/LifeLog/TodayViewController.h b/LifeLog/LifeLog/TodayViewController.h index 8a32c3a..04f649e 100644 --- a/LifeLog/LifeLog/TodayViewController.h +++ b/LifeLog/LifeLog/TodayViewController.h @@ -9,5 +9,5 @@ #import @interface TodayViewController : UIViewController - +@property (nonatomic, assign) NSInteger targetStep; @end diff --git a/LifeLog/LifeLog/TodayViewController.m b/LifeLog/LifeLog/TodayViewController.m index 43bb1a7..514b562 100644 --- a/LifeLog/LifeLog/TodayViewController.m +++ b/LifeLog/LifeLog/TodayViewController.m @@ -48,6 +48,9 @@ static NSInteger numberTotal = 10000; _motionActivityManager = [[CMMotionActivityManager alloc] init]; } self.isRequesting = NO; + if (_targetStep <= 0) { + _targetStep = numberTotal; + } } - (void)viewWillAppear:(BOOL)animated { @@ -123,14 +126,14 @@ static NSInteger numberTotal = 10000; { // NSLog(@"Number of step: %ld", numberStep); self.isRequesting = NO; - float valueProgress = numberStep*1.f/numberTotal; + float valueProgress = numberStep*1.f/_targetStep; [self.circleProgressToday setProgress:valueProgress animated:YES]; self.lblValueStep.text = [Utilities addCommaFromNumber:numberStep]; - self.lblTotalStep.text = [NSString stringWithFormat:@"/ %@", [Utilities addCommaFromNumber:numberTotal]]; - self.lblRemainingStep.text = [NSString stringWithFormat:@"%@%ld%@", NSLocalizedString(@"lifelog.today.remaining.step.1", nil), (numberTotal - numberStep), NSLocalizedString(@"lifelog.today.remaining.step.2", nil)]; - self.lblTotalStepOther.text = [NSString stringWithFormat:@"%@%@%@", NSLocalizedString(@"lifelog.today.total.other", nil), [Utilities addCommaFromNumber:numberTotal], NSLocalizedString(@"lifelog.today.unit.step", nil)]; - self.lblRemainingStepOther.text = [NSString stringWithFormat:@"%@%ld%@", NSLocalizedString(@"lifelog.today.remaining.other", nil), (numberTotal - numberStep), NSLocalizedString(@"lifelog.today.unit.step", nil)]; - self.lblPercent.text = [NSString stringWithFormat:@"%@%i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), (int)(numberStep*100/numberTotal), NSLocalizedString(@"lifelog.today.percent", nil)]; + self.lblTotalStep.text = [NSString stringWithFormat:@"/ %@", [Utilities addCommaFromNumber:_targetStep]]; + self.lblRemainingStep.text = [NSString stringWithFormat:@"%@%ld%@", NSLocalizedString(@"lifelog.today.remaining.step.1", nil), (_targetStep - numberStep), NSLocalizedString(@"lifelog.today.remaining.step.2", nil)]; + self.lblTotalStepOther.text = [NSString stringWithFormat:@"%@%@%@", NSLocalizedString(@"lifelog.today.total.other", nil), [Utilities addCommaFromNumber:_targetStep], NSLocalizedString(@"lifelog.today.unit.step", nil)]; + self.lblRemainingStepOther.text = [NSString stringWithFormat:@"%@%ld%@", NSLocalizedString(@"lifelog.today.remaining.other", nil), (_targetStep - numberStep), NSLocalizedString(@"lifelog.today.unit.step", nil)]; + self.lblPercent.text = [NSString stringWithFormat:@"%@%i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), (int)(numberStep*100/_targetStep), NSLocalizedString(@"lifelog.today.percent", nil)]; } @end