Commit 73a5aaa681b81bf66f6f739e66489b4a02007bca
1 parent
168c4f0402
Exists in
master
and in
1 other branch
Fix check null of result from History API, add some function to convert seconds …
…to string, add other share
Showing 7 changed files with 47 additions and 27 deletions Side-by-side Diff
LifeLog/LifeLog/HistoryObject.h
... | ... | @@ -13,10 +13,10 @@ |
13 | 13 | @property (nonatomic) int step; |
14 | 14 | @property (nonatomic) int missing; |
15 | 15 | @property (nonatomic) int target; |
16 | +@property (nonatomic) int time; | |
16 | 17 | @property (nonatomic) float percent; |
17 | 18 | @property (nonatomic) float distance; |
18 | 19 | @property (nonatomic) float calories; |
19 | -@property (nonatomic, strong) NSString * time; | |
20 | 20 | @property (nonatomic, strong) NSDate *date; |
21 | 21 | @property (nonatomic, strong) NSMutableArray *dataGraph; |
22 | 22 |
LifeLog/LifeLog/HistoryObject.m
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | |
13 | 13 | -(id) initWithData : (NSDictionary *) dict { |
14 | 14 | if([dict objectForKey:@"steps"] != nil) { |
15 | - self.step = [dict[@"step"] intValue]; | |
15 | + self.step = [dict[@"steps"] intValue]; | |
16 | 16 | } |
17 | 17 | if([dict objectForKey:@"target"] != nil) { |
18 | 18 | self.target = [dict[@"target"] intValue]; |
... | ... | @@ -36,12 +36,7 @@ |
36 | 36 | self.calories = [dict[@"kcal"] floatValue]; |
37 | 37 | } |
38 | 38 | if([dict objectForKey:@"time"] != nil) { |
39 | - if([dict[@"time"] isKindOfClass:[NSString class]]) { | |
40 | - self.time = dict[@"time"]; | |
41 | - } | |
42 | - else { | |
43 | - self.time = @"0:0"; | |
44 | - } | |
39 | + self.time = [dict[@"time"] intValue]; | |
45 | 40 | } |
46 | 41 | if([dict objectForKey:@"date"] != nil) { |
47 | 42 | NSString *dateString = dict[@"date"]; |
LifeLog/LifeLog/HistoryViewController.m
... | ... | @@ -106,12 +106,14 @@ |
106 | 106 | |
107 | 107 | -(void) updateView { |
108 | 108 | HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; |
109 | - self.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; | |
110 | - self.lblRemaining.text = [NSString stringWithFormat:@"%d", obj.missing]; | |
111 | - self.lblPercent.text = [NSString stringWithFormat:@"%0.2f", obj.percent * 100]; | |
112 | - self.lblCalories.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; | |
113 | - self.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; | |
114 | - self.lblTime.text = obj.time; | |
109 | + self.lblStep.text = [NSString stringWithFormat:@"%d step", obj.step]; | |
110 | + self.lblCircleStep.text = self.lblStep.text; | |
111 | + self.lblRemaining.text = [NSString stringWithFormat:@"%d step", obj.missing]; | |
112 | + self.lblCircleRemain.text = [NSString stringWithFormat:@"目標まであと\n%d stepです", obj.missing]; | |
113 | + self.lblPercent.text = [NSString stringWithFormat:@"%0.2f%%", obj.percent]; | |
114 | + self.lblCalories.text = [NSString stringWithFormat:@"%0.2f kcal", obj.calories]; | |
115 | + self.lblDistance.text = [NSString stringWithFormat:@"%0.1f KM", obj.distance]; | |
116 | + self.lblTime.text = [Utilities convertSecondToShortTime:obj.time]; | |
115 | 117 | [self updateGraphView]; |
116 | 118 | } |
117 | 119 | |
... | ... | @@ -262,7 +264,8 @@ |
262 | 264 | case 3: // share email |
263 | 265 | [Utilities shareEmail:content withViewController:weakSelf]; |
264 | 266 | break; |
265 | - default: | |
267 | + default: //share other | |
268 | + [Utilities shareOther:content withViewController:weakSelf]; | |
266 | 269 | break; |
267 | 270 | } |
268 | 271 | } |
... | ... | @@ -275,7 +278,7 @@ |
275 | 278 | cell.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; |
276 | 279 | cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; |
277 | 280 | cell.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; |
278 | - cell.lblDuration.text = obj.time; | |
281 | + cell.lblDuration.text = [Utilities convertSecondToShortTime:obj.time]; | |
279 | 282 | return cell; |
280 | 283 | } |
281 | 284 |
LifeLog/LifeLog/HistoryViewController.xib
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
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"> | |
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"> | |
3 | 3 | <device id="retina4_7" orientation="portrait"> |
4 | 4 | <adaptation id="fullscreen"/> |
5 | 5 | </device> |
6 | 6 | <dependencies> |
7 | - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/> | |
7 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/> | |
8 | 8 | <capability name="Aspect ratio constraints" minToolsVersion="5.1"/> |
9 | 9 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
10 | 10 | </dependencies> |
... | ... | @@ -154,7 +154,7 @@ |
154 | 154 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Kzk-mN-AOf"> |
155 | 155 | <rect key="frame" x="20" y="30" width="120" height="120"/> |
156 | 156 | <subviews> |
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"> | |
157 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oWg-A8-aCr"> | |
158 | 158 | <rect key="frame" x="18" y="35" width="82" height="21"/> |
159 | 159 | <constraints> |
160 | 160 | <constraint firstAttribute="height" constant="21" id="zOX-0d-IVv"/> |
... | ... | @@ -170,7 +170,7 @@ |
170 | 170 | <constraint firstAttribute="height" constant="42" id="zRP-Fu-qZ9"/> |
171 | 171 | </constraints> |
172 | 172 | <string key="text">目標まであと |
173 | -500 stepです</string> | |
173 | +0 stepです</string> | |
174 | 174 | <fontDescription key="fontDescription" type="system" pointSize="11"/> |
175 | 175 | <nil key="textColor"/> |
176 | 176 | <nil key="highlightedColor"/> |
... | ... | @@ -226,7 +226,7 @@ |
226 | 226 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.percent"/> |
227 | 227 | </userDefinedRuntimeAttributes> |
228 | 228 | </label> |
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"> | |
229 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0pf-fX-QXT"> | |
230 | 230 | <rect key="frame" x="63" y="38" width="118" height="15"/> |
231 | 231 | <constraints> |
232 | 232 | <constraint firstAttribute="height" constant="15" id="Z6o-LI-Eu9"/> |
233 | 233 | |
... | ... | @@ -235,13 +235,13 @@ |
235 | 235 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
236 | 236 | <nil key="highlightedColor"/> |
237 | 237 | </label> |
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"> | |
238 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1NH-b3-ST8"> | |
239 | 239 | <rect key="frame" x="63" y="53" width="118" height="15"/> |
240 | 240 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
241 | 241 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
242 | 242 | <nil key="highlightedColor"/> |
243 | 243 | </label> |
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"> | |
244 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 %" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8Ru-Jc-Ouv"> | |
245 | 245 | <rect key="frame" x="63" y="68" width="118" height="15"/> |
246 | 246 | <fontDescription key="fontDescription" type="system" pointSize="12"/> |
247 | 247 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
... | ... | @@ -293,7 +293,7 @@ |
293 | 293 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.calories"/> |
294 | 294 | </userDefinedRuntimeAttributes> |
295 | 295 | </label> |
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"> | |
296 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0 kcal" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dAE-C8-QLr"> | |
297 | 297 | <rect key="frame" x="0.0" y="17" width="111.5" height="18"/> |
298 | 298 | <constraints> |
299 | 299 | <constraint firstAttribute="height" constant="18" id="r0d-xi-3u7"/> |
... | ... | @@ -328,7 +328,7 @@ |
328 | 328 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.distance"/> |
329 | 329 | </userDefinedRuntimeAttributes> |
330 | 330 | </label> |
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"> | |
331 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0.0 KM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1tR-JC-pyw"> | |
332 | 332 | <rect key="frame" x="0.0" y="17" width="112" height="18"/> |
333 | 333 | <constraints> |
334 | 334 | <constraint firstAttribute="height" constant="18" id="sNT-xl-BKH"/> |
... | ... | @@ -363,7 +363,7 @@ |
363 | 363 | <userDefinedRuntimeAttribute type="string" keyPath="localizeKey" value="lifelog.history.title.time"/> |
364 | 364 | </userDefinedRuntimeAttributes> |
365 | 365 | </label> |
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"> | |
366 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PfZ-7x-LAR"> | |
367 | 367 | <rect key="frame" x="0.0" y="17" width="111.5" height="18"/> |
368 | 368 | <constraints> |
369 | 369 | <constraint firstAttribute="height" constant="18" id="lno-Dx-ZNm"/> |
LifeLog/LifeLog/ServerAPI.m
... | ... | @@ -428,7 +428,7 @@ |
428 | 428 | NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_1", @"mode_2", @"mode_3", nil]; |
429 | 429 | for(NSString * key in arrayKey) { |
430 | 430 | NSDictionary *mode = [arrResult objectForKey:key]; |
431 | - if(mode.count > 0) { | |
431 | + if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { | |
432 | 432 | HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode]; |
433 | 433 | [arrayHistory addObject:objectMode]; |
434 | 434 | } |
LifeLog/LifeLog/Utilities.h
... | ... | @@ -21,9 +21,12 @@ |
21 | 21 | + (void) shareTwitter : (NSString *) content withViewController:(UIViewController *)vc; |
22 | 22 | + (void) shareLine : (NSString *) content withViewController:(UIViewController *)vc; |
23 | 23 | + (void) shareEmail : (NSString *) content withViewController:(UIViewController *)vc; |
24 | ++ (void) shareOther : (NSString *) content withViewController:(UIViewController *)vc; | |
24 | 25 | |
25 | 26 | //convert date time |
26 | 27 | + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format; |
27 | 28 | + (NSString *) stringFromDate : (NSDate *) date withFormat: (NSString *) format locale:(NSString *) locale; |
29 | ++ (NSString *) convertSecondToShortTime : (int) seconds; | |
30 | ++ (NSString *) convertSecondToLongTime : (int) seconds; | |
28 | 31 | @end |
LifeLog/LifeLog/Utilities.m
... | ... | @@ -146,6 +146,12 @@ |
146 | 146 | [[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlEmail]]; |
147 | 147 | } |
148 | 148 | |
149 | ++ (void) shareOther : (NSString *) content withViewController:(UIViewController *)vc { | |
150 | + NSArray *items = @[content]; | |
151 | + UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil]; | |
152 | + [vc presentViewController:controller animated:true completion:nil]; | |
153 | +} | |
154 | + | |
149 | 155 | #pragma mark convert date time |
150 | 156 | + (NSDate *) dateFromString : (NSString *) dateString withFormat: (NSString *) format { |
151 | 157 | NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; |
... | ... | @@ -165,6 +171,19 @@ |
165 | 171 | } |
166 | 172 | NSString *dateString = [dateFormat stringFromDate:date]; |
167 | 173 | return dateString; |
174 | +} | |
175 | + | |
176 | ++ (NSString *) convertSecondToShortTime : (int) seconds { | |
177 | + int hour = seconds / 3600; | |
178 | + int minutes = (seconds - hour * 3600) / 60; | |
179 | + return [NSString stringWithFormat:@"%02d:%02d", hour, minutes]; | |
180 | +} | |
181 | + | |
182 | ++ (NSString *) convertSecondToLongTime : (int) seconds { | |
183 | + int hour = seconds / 3600; | |
184 | + int minutes = (seconds - hour * 3600) / 60; | |
185 | + int sec = seconds - hour * 3600 - minutes * 60; | |
186 | + return [NSString stringWithFormat:@"%02d:%02d:%02d", hour, minutes, sec]; | |
168 | 187 | } |
169 | 188 | |
170 | 189 | @end |