From 73a5aaa681b81bf66f6f739e66489b4a02007bca Mon Sep 17 00:00:00 2001 From: nvtu Date: Mon, 21 Aug 2017 11:42:43 +0700 Subject: [PATCH] Fix check null of result from History API, add some function to convert seconds to string, add other share --- LifeLog/LifeLog/HistoryObject.h | 2 +- LifeLog/LifeLog/HistoryObject.m | 9 ++------- LifeLog/LifeLog/HistoryViewController.m | 19 +++++++++++-------- LifeLog/LifeLog/HistoryViewController.xib | 20 ++++++++++---------- LifeLog/LifeLog/ServerAPI.m | 2 +- LifeLog/LifeLog/Utilities.h | 3 +++ LifeLog/LifeLog/Utilities.m | 19 +++++++++++++++++++ 7 files changed, 47 insertions(+), 27 deletions(-) diff --git a/LifeLog/LifeLog/HistoryObject.h b/LifeLog/LifeLog/HistoryObject.h index b483f3f..7fbb964 100644 --- a/LifeLog/LifeLog/HistoryObject.h +++ b/LifeLog/LifeLog/HistoryObject.h @@ -13,10 +13,10 @@ @property (nonatomic) int step; @property (nonatomic) int missing; @property (nonatomic) int target; +@property (nonatomic) int time; @property (nonatomic) float percent; @property (nonatomic) float distance; @property (nonatomic) float calories; -@property (nonatomic, strong) NSString * time; @property (nonatomic, strong) NSDate *date; @property (nonatomic, strong) NSMutableArray *dataGraph; diff --git a/LifeLog/LifeLog/HistoryObject.m b/LifeLog/LifeLog/HistoryObject.m index 1e498af..a4975a8 100644 --- a/LifeLog/LifeLog/HistoryObject.m +++ b/LifeLog/LifeLog/HistoryObject.m @@ -12,7 +12,7 @@ -(id) initWithData : (NSDictionary *) dict { if([dict objectForKey:@"steps"] != nil) { - self.step = [dict[@"step"] intValue]; + self.step = [dict[@"steps"] intValue]; } if([dict objectForKey:@"target"] != nil) { self.target = [dict[@"target"] intValue]; @@ -36,12 +36,7 @@ self.calories = [dict[@"kcal"] floatValue]; } if([dict objectForKey:@"time"] != nil) { - if([dict[@"time"] isKindOfClass:[NSString class]]) { - self.time = dict[@"time"]; - } - else { - self.time = @"0:0"; - } + self.time = [dict[@"time"] intValue]; } if([dict objectForKey:@"date"] != nil) { NSString *dateString = dict[@"date"]; diff --git a/LifeLog/LifeLog/HistoryViewController.m b/LifeLog/LifeLog/HistoryViewController.m index ed96bf0..76908e2 100644 --- a/LifeLog/LifeLog/HistoryViewController.m +++ b/LifeLog/LifeLog/HistoryViewController.m @@ -106,12 +106,14 @@ -(void) updateView { HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; - self.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; - self.lblRemaining.text = [NSString stringWithFormat:@"%d", obj.missing]; - self.lblPercent.text = [NSString stringWithFormat:@"%0.2f", obj.percent * 100]; - self.lblCalories.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; - self.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; - self.lblTime.text = obj.time; + self.lblStep.text = [NSString stringWithFormat:@"%d step", obj.step]; + self.lblCircleStep.text = self.lblStep.text; + self.lblRemaining.text = [NSString stringWithFormat:@"%d step", obj.missing]; + self.lblCircleRemain.text = [NSString stringWithFormat:@"目標まであと\n%d stepです", obj.missing]; + self.lblPercent.text = [NSString stringWithFormat:@"%0.2f%%", obj.percent]; + self.lblCalories.text = [NSString stringWithFormat:@"%0.2f kcal", obj.calories]; + self.lblDistance.text = [NSString stringWithFormat:@"%0.1f KM", obj.distance]; + self.lblTime.text = [Utilities convertSecondToShortTime:obj.time]; [self updateGraphView]; } @@ -262,7 +264,8 @@ case 3: // share email [Utilities shareEmail:content withViewController:weakSelf]; break; - default: + default: //share other + [Utilities shareOther:content withViewController:weakSelf]; break; } } @@ -275,7 +278,7 @@ cell.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; cell.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; - cell.lblDuration.text = obj.time; + cell.lblDuration.text = [Utilities convertSecondToShortTime:obj.time]; return cell; } diff --git a/LifeLog/LifeLog/HistoryViewController.xib b/LifeLog/LifeLog/HistoryViewController.xib index 70589f6..e5208af 100644 --- a/LifeLog/LifeLog/HistoryViewController.xib +++ b/LifeLog/LifeLog/HistoryViewController.xib @@ -1,10 +1,10 @@ - + - + @@ -154,7 +154,7 @@ -