Commit 46f6779bfd807cb015c7d59b119690cbf3124b42

Authored by phong
1 parent e835b9fcc8
Exists in master

Today screen: set target step from server

Showing 3 changed files with 16 additions and 99 deletions Side-by-side Diff

LifeLog/LifeLog/HomeViewController.m
... ... @@ -16,10 +16,12 @@
16 16 #import "ServerAPI.h"
17 17  
18 18 static NSInteger maxRequest = 20;
  19 +static NSInteger numberTotal = 10000;
19 20  
20 21 @interface HomeViewController ()
21 22 {
22 23 MBProgressHUD *progressHud;
  24 + NSInteger targetStep;
23 25 }
24 26 @property (nonatomic, weak) IBOutlet UILabel *lblTitle;
25 27 @property (nonatomic, weak) IBOutlet UIImageView *avatar;
... ... @@ -113,6 +115,7 @@
113 115 progressHud.mode = MBProgressHUDModeIndeterminate;
114 116 progressHud.detailsLabel.text = NSLocalizedString(@"lifelog.home.progressHud.title", nil);
115 117 // [self saveDataStep7LastDay];
  118 + targetStep = numberTotal;
116 119 }
117 120  
118 121 - (void)viewWillAppear:(BOOL)animated {
... ... @@ -185,6 +188,7 @@
185 188 - (IBAction)todayButtonTouchUpInside:(id)sender
186 189 {
187 190 TodayViewController *todayVC = [[TodayViewController alloc] initWithNibName:@"TodayViewController" bundle:nil];
  191 + todayVC.targetStep = targetStep;
188 192 [self.navigationController pushViewController:todayVC animated:YES];
189 193 }
190 194  
... ... @@ -254,48 +258,6 @@
254 258 // PhongNV
255 259 weakSelf.currentIndex = 0;
256 260 [weakSelf save20objectOfActivityExtras:arrayActivities];
257   - //[weakSelf saveStepFromActivityExtras:arrayActivities];
258   - /*
259   - for (CMMotionActivityExtra *activityExtra in arrayActivities) {
260   - [weakSelf.pedometer queryPedometerDataFromDate:activityExtra.activity.startDate toDate:activityExtra.endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {
261   - NSInteger numberStep = [pedometerData.numberOfSteps integerValue];
262   - int mode = 1;
263   - if (activityExtra.activity.cycling) {
264   - // self.bike
265   - weakSelf.bike += numberStep;
266   - mode = 3;
267   - }
268   - else if (activityExtra.activity.walking) {
269   - // self.walking
270   - weakSelf.walking += numberStep;
271   - mode = 1;
272   - }
273   - else if (activityExtra.activity.running) {
274   - weakSelf.running += numberStep;
275   - mode = 2;
276   - }
277   - else {
278   - // unknown
279   - }
280   -
281   - // save step to server
282   - if (numberStep > 0) {
283   - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
284   - [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
285   - NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate];
286   - NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate];
287   - [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) {
288   - if (error) {
289   - NSLog(@"Error: %@", error);
290   - }
291   - }];
292   - }
293   - dispatch_async(dispatch_get_main_queue(), ^{
294   - [weakSelf updateStepUI];
295   - });
296   - }];
297   - }
298   - */
299 261 }];
300 262 });
301 263 }
... ... @@ -373,56 +335,6 @@
373 335 }
374 336 }
375 337  
376   -- (void)saveStepFromActivityExtras:(NSArray *)activities
377   -{
378   - if (self.currentIndex >= activities.count) {
379   - self.currentIndex = 0;
380   - dispatch_async(dispatch_get_main_queue(), ^{
381   - [self updateStepUI];
382   - });
383   - return;
384   - }
385   - HomeViewController __weak *weakSelf = self;
386   - CMMotionActivityExtra *activityExtra = [activities objectAtIndex:self.currentIndex];
387   - [self.pedometer queryPedometerDataFromDate:activityExtra.activity.startDate toDate:activityExtra.endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {
388   - if (weakSelf == nil) {
389   - return ;
390   - }
391   - NSInteger numberStep = [pedometerData.numberOfSteps integerValue];
392   - int mode = 1;
393   - if (activityExtra.activity.cycling) {
394   - mode = 3;
395   - }
396   - else if (activityExtra.activity.walking) {
397   - mode = 1;
398   - }
399   - else if (activityExtra.activity.running) {
400   - mode = 2;
401   - }
402   - else {
403   - // unknown
404   - }
405   - // save step to server
406   - if (numberStep > 0) {
407   - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
408   - [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
409   - NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate];
410   - NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate];
411   - [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) {
412   - if (error) {
413   - NSLog(@"Error: %@", error);
414   - }
415   - weakSelf.currentIndex += 1;
416   - [weakSelf saveStepFromActivityExtras:activities];
417   - }];
418   - }
419   - else {
420   - weakSelf.currentIndex += 1;
421   - [weakSelf saveStepFromActivityExtras:activities];
422   - }
423   - }];
424   -}
425   -
426 338 - (void)updateStepUI
427 339 {
428 340 [self requestTopByDate:self.dateCurrent];
... ... @@ -508,6 +420,8 @@
508 420  
509 421 - (void)updateStepUI:(TargetInfor *)targetInfor
510 422 {
  423 + NSString *stringTargetStep = [targetInfor.target_step stringByReplacingOccurrencesOfString:@"," withString:@""];
  424 + targetStep = [stringTargetStep integerValue];
511 425 self.lblValueStep.text = targetInfor.num_step;
512 426 self.lblValueStepOther.text = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"lifelog.today.remaining.other", nil), targetInfor.remaining_step];
513 427 self.lblPercent.text = [NSString stringWithFormat:@"%@ %i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), [targetInfor.complete_percent intValue], NSLocalizedString(@"lifelog.today.percent", nil)];
LifeLog/LifeLog/TodayViewController.h
... ... @@ -9,6 +9,6 @@
9 9 #import <UIKit/UIKit.h>
10 10  
11 11 @interface TodayViewController : UIViewController
12   -
  12 +@property (nonatomic, assign) NSInteger targetStep;
13 13 @end
LifeLog/LifeLog/TodayViewController.m
... ... @@ -48,6 +48,9 @@
48 48 _motionActivityManager = [[CMMotionActivityManager alloc] init];
49 49 }
50 50 self.isRequesting = NO;
  51 + if (_targetStep <= 0) {
  52 + _targetStep = numberTotal;
  53 + }
51 54 }
52 55  
53 56 - (void)viewWillAppear:(BOOL)animated {
54 57  
... ... @@ -123,14 +126,14 @@
123 126 {
124 127 // NSLog(@"Number of step: %ld", numberStep);
125 128 self.isRequesting = NO;
126   - float valueProgress = numberStep*1.f/numberTotal;
  129 + float valueProgress = numberStep*1.f/_targetStep;
127 130 [self.circleProgressToday setProgress:valueProgress animated:YES];
128 131 self.lblValueStep.text = [Utilities addCommaFromNumber:numberStep];
129   - self.lblTotalStep.text = [NSString stringWithFormat:@"/ %@", [Utilities addCommaFromNumber:numberTotal]];
130   - self.lblRemainingStep.text = [NSString stringWithFormat:@"%@%ld%@", NSLocalizedString(@"lifelog.today.remaining.step.1", nil), (numberTotal - numberStep), NSLocalizedString(@"lifelog.today.remaining.step.2", nil)];
131   - self.lblTotalStepOther.text = [NSString stringWithFormat:@"%@%@%@", NSLocalizedString(@"lifelog.today.total.other", nil), [Utilities addCommaFromNumber:numberTotal], NSLocalizedString(@"lifelog.today.unit.step", nil)];
132   - self.lblRemainingStepOther.text = [NSString stringWithFormat:@"%@%ld%@", NSLocalizedString(@"lifelog.today.remaining.other", nil), (numberTotal - numberStep), NSLocalizedString(@"lifelog.today.unit.step", nil)];
133   - self.lblPercent.text = [NSString stringWithFormat:@"%@%i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), (int)(numberStep*100/numberTotal), NSLocalizedString(@"lifelog.today.percent", nil)];
  132 + self.lblTotalStep.text = [NSString stringWithFormat:@"/ %@", [Utilities addCommaFromNumber:_targetStep]];
  133 + self.lblRemainingStep.text = [NSString stringWithFormat:@"%@%ld%@", NSLocalizedString(@"lifelog.today.remaining.step.1", nil), (_targetStep - numberStep), NSLocalizedString(@"lifelog.today.remaining.step.2", nil)];
  134 + self.lblTotalStepOther.text = [NSString stringWithFormat:@"%@%@%@", NSLocalizedString(@"lifelog.today.total.other", nil), [Utilities addCommaFromNumber:_targetStep], NSLocalizedString(@"lifelog.today.unit.step", nil)];
  135 + self.lblRemainingStepOther.text = [NSString stringWithFormat:@"%@%ld%@", NSLocalizedString(@"lifelog.today.remaining.other", nil), (_targetStep - numberStep), NSLocalizedString(@"lifelog.today.unit.step", nil)];
  136 + self.lblPercent.text = [NSString stringWithFormat:@"%@%i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), (int)(numberStep*100/_targetStep), NSLocalizedString(@"lifelog.today.percent", nil)];
134 137 }
135 138  
136 139 @end