Commit 5739e821e548c57099487f8adeddce435f4b1e73
1 parent
5cc9773c6d
Exists in
master
and in
1 other branch
Fix history list API, add disable load more option
Showing 15 changed files with 123 additions and 65 deletions Side-by-side Diff
- LifeLog/LifeLog/Assets.xcassets/History/arrow_decre.imageset/Contents.json
- LifeLog/LifeLog/Assets.xcassets/History/arrow_decre.imageset/arrow_decre.png
- LifeLog/LifeLog/Assets.xcassets/History/arrow_incre.imageset/Contents.json
- LifeLog/LifeLog/Assets.xcassets/History/arrow_incre.imageset/arrow_incre.png
- LifeLog/LifeLog/BaseTableViewController.h
- LifeLog/LifeLog/BaseTableViewController.m
- LifeLog/LifeLog/HistoryListTableViewCell.h
- LifeLog/LifeLog/HistoryListTableViewCell.xib
- LifeLog/LifeLog/HistoryObject.h
- LifeLog/LifeLog/HistoryObject.m
- LifeLog/LifeLog/HistoryViewController.h
- LifeLog/LifeLog/HistoryViewController.m
- LifeLog/LifeLog/HistoryViewController.xib
- LifeLog/LifeLog/ServerAPI.h
- LifeLog/LifeLog/ServerAPI.m
LifeLog/LifeLog/Assets.xcassets/History/arrow_decre.imageset/Contents.json
1 | +{ | |
2 | + "images" : [ | |
3 | + { | |
4 | + "idiom" : "universal", | |
5 | + "scale" : "1x" | |
6 | + }, | |
7 | + { | |
8 | + "idiom" : "universal", | |
9 | + "filename" : "arrow_decre.png", | |
10 | + "scale" : "2x" | |
11 | + }, | |
12 | + { | |
13 | + "idiom" : "universal", | |
14 | + "scale" : "3x" | |
15 | + } | |
16 | + ], | |
17 | + "info" : { | |
18 | + "version" : 1, | |
19 | + "author" : "xcode" | |
20 | + } | |
21 | +} |
LifeLog/LifeLog/Assets.xcassets/History/arrow_decre.imageset/arrow_decre.png
1.33 KB
LifeLog/LifeLog/Assets.xcassets/History/arrow_incre.imageset/Contents.json
1 | +{ | |
2 | + "images" : [ | |
3 | + { | |
4 | + "idiom" : "universal", | |
5 | + "scale" : "1x" | |
6 | + }, | |
7 | + { | |
8 | + "idiom" : "universal", | |
9 | + "filename" : "arrow_incre.png", | |
10 | + "scale" : "2x" | |
11 | + }, | |
12 | + { | |
13 | + "idiom" : "universal", | |
14 | + "scale" : "3x" | |
15 | + } | |
16 | + ], | |
17 | + "info" : { | |
18 | + "version" : 1, | |
19 | + "author" : "xcode" | |
20 | + } | |
21 | +} |
LifeLog/LifeLog/Assets.xcassets/History/arrow_incre.imageset/arrow_incre.png
1.49 KB
LifeLog/LifeLog/BaseTableViewController.h
LifeLog/LifeLog/BaseTableViewController.m
... | ... | @@ -20,6 +20,7 @@ |
20 | 20 | _firstTime = false; |
21 | 21 | _curPage = 1; |
22 | 22 | _isEndOfResult = false; |
23 | + _isDisableLoadMore = false; | |
23 | 24 | _curDataList = [[NSMutableArray alloc] init]; |
24 | 25 | self.refreshControl = [[UIRefreshControl alloc] init]; |
25 | 26 | [self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged]; |
... | ... | @@ -114,7 +115,7 @@ |
114 | 115 | NSInteger lastRowIndex = [tableView numberOfRowsInSection:0] - 1; |
115 | 116 | if (indexPath.row == lastRowIndex) { |
116 | 117 | // This is the last cell |
117 | - if(!_isLoading) { | |
118 | + if(!_isLoading && !_isDisableLoadMore) { | |
118 | 119 | _curPage += 1; |
119 | 120 | [self callRequestToUpdateData]; |
120 | 121 | } |
LifeLog/LifeLog/HistoryListTableViewCell.h
... | ... | @@ -10,8 +10,11 @@ |
10 | 10 | |
11 | 11 | @interface HistoryListTableViewCell : UITableViewCell |
12 | 12 | |
13 | +@property (weak, nonatomic) IBOutlet UIImageView *imgArrow; | |
14 | + | |
13 | 15 | @property (weak, nonatomic) IBOutlet UILabel *lblTitle; |
14 | 16 | @property (weak, nonatomic) IBOutlet UILabel *lblStep; |
17 | +@property (weak, nonatomic) IBOutlet UILabel *lblDiff; | |
15 | 18 | @property (weak, nonatomic) IBOutlet UILabel *lblDistance; |
16 | 19 | @property (weak, nonatomic) IBOutlet UILabel *lblPower; |
17 | 20 | @property (weak, nonatomic) IBOutlet UILabel *lblDuration; |
LifeLog/LifeLog/HistoryListTableViewCell.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="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
9 | 9 | </dependencies> |
10 | 10 | <objects> |
... | ... | @@ -44,6 +44,13 @@ |
44 | 44 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
45 | 45 | <nil key="highlightedColor"/> |
46 | 46 | </label> |
47 | + <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="arrow_incre" translatesAutoresizingMaskIntoConstraints="NO" id="uC9-bK-F7u"> | |
48 | + <rect key="frame" x="229" y="2" width="21" height="25"/> | |
49 | + <constraints> | |
50 | + <constraint firstAttribute="width" constant="21" id="Mml-ka-nwr"/> | |
51 | + <constraint firstAttribute="height" constant="25" id="OUH-L1-Don"/> | |
52 | + </constraints> | |
53 | + </imageView> | |
47 | 54 | </subviews> |
48 | 55 | <color key="backgroundColor" red="0.36078431372549019" green="0.36078431372549019" blue="0.36078431372549019" alpha="1" colorSpace="calibratedRGB"/> |
49 | 56 | <constraints> |
50 | 57 | |
... | ... | @@ -55,9 +62,11 @@ |
55 | 62 | <constraint firstAttribute="bottom" secondItem="Eop-bg-Dy9" secondAttribute="bottom" constant="5" id="Wor-Tc-WPf"/> |
56 | 63 | <constraint firstItem="zW0-JI-PIE" firstAttribute="leading" secondItem="l97-iI-4Nl" secondAttribute="leading" constant="4" id="ZBL-QQ-0jD"/> |
57 | 64 | <constraint firstAttribute="bottom" secondItem="qgK-8d-giH" secondAttribute="bottom" constant="5" id="cyO-Tr-6Md"/> |
65 | + <constraint firstItem="qgK-8d-giH" firstAttribute="leading" secondItem="uC9-bK-F7u" secondAttribute="trailing" constant="-10" id="e8q-Pv-h1j"/> | |
58 | 66 | <constraint firstItem="zW0-JI-PIE" firstAttribute="top" secondItem="l97-iI-4Nl" secondAttribute="top" id="iDg-dJ-y0S"/> |
59 | 67 | <constraint firstItem="qgK-8d-giH" firstAttribute="leading" secondItem="Eop-bg-Dy9" secondAttribute="trailing" id="vhm-kx-gmg"/> |
60 | 68 | <constraint firstItem="Eop-bg-Dy9" firstAttribute="top" secondItem="l97-iI-4Nl" secondAttribute="top" id="xli-4P-Kun"/> |
69 | + <constraint firstItem="uC9-bK-F7u" firstAttribute="centerY" secondItem="l97-iI-4Nl" secondAttribute="centerY" constant="-3" id="zqt-y0-dLW"/> | |
61 | 70 | </constraints> |
62 | 71 | <userDefinedRuntimeAttributes> |
63 | 72 | <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> |
... | ... | @@ -147,6 +156,8 @@ |
147 | 156 | </tableViewCellContentView> |
148 | 157 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
149 | 158 | <connections> |
159 | + <outlet property="imgArrow" destination="uC9-bK-F7u" id="0pM-jI-nwl"/> | |
160 | + <outlet property="lblDiff" destination="qgK-8d-giH" id="8e8-ew-yEX"/> | |
150 | 161 | <outlet property="lblDistance" destination="f2Y-XG-L6g" id="gwM-yJ-wWM"/> |
151 | 162 | <outlet property="lblDuration" destination="lmZ-T8-ABg" id="ioM-85-tg7"/> |
152 | 163 | <outlet property="lblPower" destination="Yy6-cn-agT" id="6KD-eN-oTW"/> |
... | ... | @@ -156,5 +167,8 @@ |
156 | 167 | <point key="canvasLocation" x="26" y="124"/> |
157 | 168 | </tableViewCell> |
158 | 169 | </objects> |
170 | + <resources> | |
171 | + <image name="arrow_incre" width="10" height="12"/> | |
172 | + </resources> | |
159 | 173 | </document> |
LifeLog/LifeLog/HistoryObject.h
LifeLog/LifeLog/HistoryObject.m
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | // |
8 | 8 | |
9 | 9 | #import "HistoryObject.h" |
10 | +#import "Utilities.h" | |
10 | 11 | |
11 | 12 | @implementation HistoryObject |
12 | 13 | |
... | ... | @@ -14,6 +15,9 @@ |
14 | 15 | if([dict objectForKey:@"steps"] != nil) { |
15 | 16 | self.step = [dict[@"steps"] intValue]; |
16 | 17 | } |
18 | + if([dict objectForKey:@"step_diff"] != nil) { | |
19 | + self.step_diff = [dict[@"step_diff"] intValue]; | |
20 | + } | |
17 | 21 | if([dict objectForKey:@"target"] != nil) { |
18 | 22 | self.target = [dict[@"target"] intValue]; |
19 | 23 | } |
... | ... | @@ -40,9 +44,7 @@ |
40 | 44 | } |
41 | 45 | if([dict objectForKey:@"date"] != nil) { |
42 | 46 | NSString *dateString = dict[@"date"]; |
43 | - NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; | |
44 | - [dateFormat setDateFormat:@"yyyy-MM-dd"]; | |
45 | - self.date = [dateFormat dateFromString:dateString]; | |
47 | + self.date = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd"]; | |
46 | 48 | } |
47 | 49 | else { |
48 | 50 | self.date = [NSDate date]; |
LifeLog/LifeLog/HistoryViewController.h
LifeLog/LifeLog/HistoryViewController.m
... | ... | @@ -23,6 +23,8 @@ |
23 | 23 | // Do any additional setup after loading the view from its nib. |
24 | 24 | self.title = NSLocalizedString(@"lifelog.history.title", nil); |
25 | 25 | |
26 | + _isDisableLoadMore = true; | |
27 | + | |
26 | 28 | [self setupView]; |
27 | 29 | [self setupChartView]; |
28 | 30 | |
... | ... | @@ -67,7 +69,13 @@ |
67 | 69 | [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; |
68 | 70 | [self.viewCollectionMode setArrayTitle:modeTitle]; |
69 | 71 | self.viewCollectionMode.changeCurrentIndex = ^(int index){ |
70 | - [self updateView]; | |
72 | + if(self.tableBase.alpha == 0.0) { | |
73 | + [self updateView]; | |
74 | + } | |
75 | + else { | |
76 | + NSArray * list = [_curListArray objectAtIndex:index]; | |
77 | + [self updateTableData:list error:nil]; | |
78 | + } | |
71 | 79 | }; |
72 | 80 | |
73 | 81 | NSArray *shareTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.share.1", nil), NSLocalizedString(@"lifelog.history.share.2", nil), NSLocalizedString(@"lifelog.history.share.3", nil), NSLocalizedString(@"lifelog.history.share.4", nil), NSLocalizedString(@"lifelog.history.share.5", nil), nil]; |
74 | 82 | |
75 | 83 | |
... | ... | @@ -182,21 +190,26 @@ |
182 | 190 | -(void) callRequestToUpdateData { |
183 | 191 | [super callRequestToUpdateData]; |
184 | 192 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
185 | - int type = self.viewCollectionType.getCurrentIndex; | |
186 | - int mode = self.viewCollectionMode.getCurrentIndex + 1; | |
187 | 193 | |
188 | 194 | MBProgressHUD *hudView = nil; |
189 | 195 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
190 | 196 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
191 | 197 | } |
192 | - [[ServerAPI server] requestHistoryList:token withType:type andMode:mode AtPage:_curPage CompletionHandler:^(NSArray *array, NSError *error) { | |
198 | + [[ServerAPI server] requestHistoryList:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) { | |
193 | 199 | dispatch_async(dispatch_get_main_queue(), ^{ |
194 | 200 | if(hudView != nil) { |
195 | 201 | [hudView hideAnimated:true]; |
196 | 202 | } |
197 | 203 | }); |
198 | 204 | HistoryViewController __weak *weakSelf = self; |
199 | - [weakSelf updateTableData:array error:error]; | |
205 | + if(error == nil) { | |
206 | + _curListArray = array; | |
207 | + NSArray * list = [array objectAtIndex:weakSelf.viewCollectionMode.getCurrentIndex]; | |
208 | + [weakSelf updateTableData:list error:error]; | |
209 | + } | |
210 | + else { | |
211 | + [weakSelf updateTableData:array error:error]; | |
212 | + } | |
200 | 213 | }]; |
201 | 214 | } |
202 | 215 | |
... | ... | @@ -218,6 +231,14 @@ |
218 | 231 | _startDate = _endDate; |
219 | 232 | break; |
220 | 233 | } |
234 | + if(_startDate == _endDate) { | |
235 | + self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYYๅนดMMๆddๆฅ EEEE" locale:@"ja_JP"]; | |
236 | + } | |
237 | + else { | |
238 | + NSString * startDateString = [Utilities stringFromDate:_startDate withFormat:@"YYYYๅนดMMๆddๆฅ" locale:@"ja_JP"]; | |
239 | + NSString * endDateString = [Utilities stringFromDate:_endDate withFormat:@"YYYYๅนดMMๆddๆฅ" locale:@"ja_JP"]; | |
240 | + self.lblDatetime.text = [NSString stringWithFormat:@"%@-%@", startDateString, endDateString]; | |
241 | + } | |
221 | 242 | [self checkRequestData]; |
222 | 243 | } |
223 | 244 | |
224 | 245 | |
... | ... | @@ -234,13 +255,11 @@ |
234 | 255 | |
235 | 256 | - (IBAction)clickBackward:(UIButton *)sender { |
236 | 257 | _endDate = [_endDate dateByAddingTimeInterval:-86400]; |
237 | - self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYYๅนดMMๆddๆฅ EEEE" locale:@"ja_JP"]; | |
238 | 258 | [self changeDate]; |
239 | 259 | } |
240 | 260 | |
241 | 261 | - (IBAction)clickForward:(UIButton *)sender { |
242 | 262 | _endDate = [_endDate dateByAddingTimeInterval:86400]; |
243 | - self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYYๅนดMMๆddๆฅ EEEE" locale:@"ja_JP"]; | |
244 | 263 | [self changeDate]; |
245 | 264 | } |
246 | 265 | |
247 | 266 | |
... | ... | @@ -275,7 +294,10 @@ |
275 | 294 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
276 | 295 | HistoryListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryListCell"]; |
277 | 296 | HistoryObject * obj = [_curDataList objectAtIndex:indexPath.row]; |
297 | + cell.lblTitle.text = [Utilities stringFromDate:obj.date withFormat:@"ddๆฅ (EEEE)" locale:@"ja_JP"]; | |
278 | 298 | cell.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; |
299 | + cell.lblDiff.text = [NSString stringWithFormat:@"%d", obj.step_diff]; | |
300 | + cell.imgArrow.image = (obj.step_diff > 0) ? [UIImage imageNamed:@"arrow_incre"] : [UIImage imageNamed:@"arrow_decre"]; | |
279 | 301 | cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; |
280 | 302 | cell.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; |
281 | 303 | cell.lblDuration.text = [Utilities convertSecondToShortTime:obj.time]; |
LifeLog/LifeLog/HistoryViewController.xib
... | ... | @@ -99,7 +99,7 @@ |
99 | 99 | </button> |
100 | 100 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2017ๅนด1ๆ1ๆฅใๆฅๆๆฅ" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EM7-vA-s1e"> |
101 | 101 | <rect key="frame" x="40" y="2" width="275" height="31"/> |
102 | - <fontDescription key="fontDescription" type="system" pointSize="17"/> | |
102 | + <fontDescription key="fontDescription" type="system" pointSize="15"/> | |
103 | 103 | <nil key="textColor"/> |
104 | 104 | <nil key="highlightedColor"/> |
105 | 105 | </label> |
LifeLog/LifeLog/ServerAPI.h
... | ... | @@ -31,8 +31,7 @@ |
31 | 31 | |
32 | 32 | #pragma mark - History Screen Function |
33 | 33 | - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
34 | -- (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion; | |
35 | -- (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | |
34 | +- (void) requestHistoryList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | |
36 | 35 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion; |
37 | 36 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; |
38 | 37 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
LifeLog/LifeLog/ServerAPI.m
... | ... | @@ -463,50 +463,8 @@ |
463 | 463 | }]; |
464 | 464 | } |
465 | 465 | |
466 | -- (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion { | |
467 | - NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/graph/%@/%d", [self convertIntToString:type], mode]; | |
468 | - NSLog(@"requestHistoryGraph link %@", url); | |
469 | - [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | |
470 | - | |
471 | - if (completion == NULL) { | |
472 | - return ; | |
473 | - } | |
474 | - | |
475 | - if (error == nil) | |
476 | - { | |
477 | - NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | |
478 | - NSLog(@"%@", dataResult); | |
479 | - int status = [dataResult[@"status"] intValue]; | |
480 | - if (status == 1) { // status = 1 success | |
481 | - HistoryGraphObject * object = [[HistoryGraphObject alloc] initWithData:dataResult[@"result"]]; | |
482 | - completion(object, nil); | |
483 | - } | |
484 | - else { | |
485 | - NSString *message = dataResult[@"message"]; | |
486 | - if (message == nil) { | |
487 | - message = @"Unknown error"; | |
488 | - } | |
489 | - | |
490 | - if ([message isEqualToString:@"Token is invalid"]) { | |
491 | - [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | |
492 | - NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | |
493 | - [self requestHistoryGraph:tokenNew withType:type andMode:mode CompletionHandler:completion]; | |
494 | - } | |
495 | - else { | |
496 | - NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | |
497 | - completion(nil, errorObject); | |
498 | - } | |
499 | - } | |
500 | - } | |
501 | - else | |
502 | - { | |
503 | - completion(nil, error); | |
504 | - } | |
505 | - }]; | |
506 | -} | |
507 | - | |
508 | -- (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | |
509 | - NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/list/%@/%d?page=%d&record=50", [self convertIntToString:type], mode, page]; | |
466 | +- (void) requestHistoryList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | |
467 | + NSString *url = [kServerAddress stringByAppendingFormat:@"/api/history/detail/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]]; | |
510 | 468 | NSLog(@"requestHistoryList link %@", url); |
511 | 469 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
512 | 470 | |
513 | 471 | |
... | ... | @@ -521,11 +479,25 @@ |
521 | 479 | int status = [dataResult[@"status"] intValue]; |
522 | 480 | if (status == 1) { // status = 1 success |
523 | 481 | if(dataResult[@"result"] != nil) { |
524 | - NSArray * array = dataResult[@"result"][@"data"]; | |
525 | 482 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; |
526 | - for(NSDictionary * dict in array) { | |
527 | - HistoryObject * object = [[HistoryObject alloc] initWithData:dict]; | |
528 | - [arrayHistory addObject:object]; | |
483 | + NSDictionary * arrResult = dataResult[@"result"]; | |
484 | + if(arrResult != nil) { | |
485 | + NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_1", @"mode_2", @"mode_3", nil]; | |
486 | + for(NSString * key in arrayKey) { | |
487 | + NSDictionary *mode = [arrResult objectForKey:key]; | |
488 | + if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { | |
489 | + NSMutableArray *array = [[NSMutableArray alloc] init]; | |
490 | + for(NSString *key in mode.allKeys) { | |
491 | + HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode[key]]; | |
492 | + objectMode.date = [Utilities dateFromString:key withFormat:@"yyyy-MM-dd"]; | |
493 | + [array addObject:objectMode]; | |
494 | + } | |
495 | + [arrayHistory addObject:array]; | |
496 | + } | |
497 | + else { | |
498 | + [arrayHistory addObject:[[NSArray alloc] init]]; | |
499 | + } | |
500 | + } | |
529 | 501 | } |
530 | 502 | completion(arrayHistory, nil); |
531 | 503 | } |
... | ... | @@ -543,7 +515,7 @@ |
543 | 515 | if ([message isEqualToString:@"Token is invalid"]) { |
544 | 516 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
545 | 517 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
546 | - [self requestHistoryList:tokenNew withType:type andMode:mode AtPage:page CompletionHandler:completion]; | |
518 | + [self requestHistoryList:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion]; | |
547 | 519 | } |
548 | 520 | else { |
549 | 521 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |