Compare View
Commits (3)
-
…to string, add other share
Changes
Showing 22 changed files 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/GroupDetailViewController.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/MyGroupViewController.m
- LifeLog/LifeLog/SNSRecentTopicTableViewCell.h
- LifeLog/LifeLog/SNSRecentTopicTableViewCell.m
- LifeLog/LifeLog/SNSViewController.m
- LifeLog/LifeLog/ServerAPI.h
- LifeLog/LifeLog/ServerAPI.m
- LifeLog/LifeLog/Utilities.h
- LifeLog/LifeLog/Utilities.m
LifeLog/LifeLog/Assets.xcassets/History/arrow_decre.imageset/Contents.json
... | ... | @@ -0,0 +1,21 @@ |
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 | +} | |
0 | 22 | \ No newline at end of file |
LifeLog/LifeLog/Assets.xcassets/History/arrow_decre.imageset/arrow_decre.png
1.33 KB
LifeLog/LifeLog/Assets.xcassets/History/arrow_incre.imageset/Contents.json
... | ... | @@ -0,0 +1,21 @@ |
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 | +} | |
0 | 22 | \ No newline at end of file |
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/GroupDetailViewController.m
... | ... | @@ -151,33 +151,11 @@ |
151 | 151 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
152 | 152 | if(isMemberList) { |
153 | 153 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; |
154 | - if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | |
155 | - [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | |
156 | - } | |
157 | - else { | |
158 | - [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | |
159 | - } | |
160 | - cell.lblUsername.text = @""; | |
161 | - cell.lblDateTime.text = @""; | |
162 | - cell.lblDes.text = object.userName; | |
163 | - cell.lblMode.text = @""; | |
164 | - cell.lblDistance.text = @""; | |
165 | - cell.lblDuration.text = @""; | |
154 | + [cell setMemberData:object]; | |
166 | 155 | } |
167 | 156 | else { |
168 | 157 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
169 | - if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | |
170 | - [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | |
171 | - } | |
172 | - else { | |
173 | - [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | |
174 | - } | |
175 | - cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; | |
176 | - cell.lblUsername.text = object.userName; | |
177 | - cell.lblDes.text = object.content; | |
178 | - cell.lblMode.text = object.mode; | |
179 | - cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | |
180 | - cell.lblDuration.text = object.time; | |
158 | + [cell setTweetsData:object]; | |
181 | 159 | } |
182 | 160 | |
183 | 161 | return cell; |
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> |
... | ... | @@ -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,4 +167,7 @@ |
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
... | ... | @@ -11,12 +11,13 @@ |
11 | 11 | @interface HistoryObject : NSObject |
12 | 12 | |
13 | 13 | @property (nonatomic) int step; |
14 | +@property (nonatomic) int step_diff; | |
14 | 15 | @property (nonatomic) int missing; |
15 | 16 | @property (nonatomic) int target; |
17 | +@property (nonatomic) int time; | |
16 | 18 | @property (nonatomic) float percent; |
17 | 19 | @property (nonatomic) float distance; |
18 | 20 | @property (nonatomic) float calories; |
19 | -@property (nonatomic, strong) NSString * time; | |
20 | 21 | @property (nonatomic, strong) NSDate *date; |
21 | 22 | @property (nonatomic, strong) NSMutableArray *dataGraph; |
22 | 23 |
LifeLog/LifeLog/HistoryObject.m
... | ... | @@ -7,12 +7,16 @@ |
7 | 7 | // |
8 | 8 | |
9 | 9 | #import "HistoryObject.h" |
10 | +#import "Utilities.h" | |
10 | 11 | |
11 | 12 | @implementation HistoryObject |
12 | 13 | |
13 | 14 | -(id) initWithData : (NSDictionary *) dict { |
14 | 15 | if([dict objectForKey:@"steps"] != nil) { |
15 | - self.step = [dict[@"step"] intValue]; | |
16 | + self.step = [dict[@"steps"] intValue]; | |
17 | + } | |
18 | + if([dict objectForKey:@"step_diff"] != nil) { | |
19 | + self.step_diff = [dict[@"step_diff"] intValue]; | |
16 | 20 | } |
17 | 21 | if([dict objectForKey:@"target"] != nil) { |
18 | 22 | self.target = [dict[@"target"] intValue]; |
... | ... | @@ -36,18 +40,11 @@ |
36 | 40 | self.calories = [dict[@"kcal"] floatValue]; |
37 | 41 | } |
38 | 42 | 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 | - } | |
43 | + self.time = [dict[@"time"] intValue]; | |
45 | 44 | } |
46 | 45 | if([dict objectForKey:@"date"] != nil) { |
47 | 46 | NSString *dateString = dict[@"date"]; |
48 | - NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; | |
49 | - [dateFormat setDateFormat:@"yyyy-MM-dd"]; | |
50 | - self.date = [dateFormat dateFromString:dateString]; | |
47 | + self.date = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd"]; | |
51 | 48 | } |
52 | 49 | else { |
53 | 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]; |
... | ... | @@ -106,12 +114,14 @@ |
106 | 114 | |
107 | 115 | -(void) updateView { |
108 | 116 | 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; | |
117 | + self.lblStep.text = [NSString stringWithFormat:@"%d step", obj.step]; | |
118 | + self.lblCircleStep.text = self.lblStep.text; | |
119 | + self.lblRemaining.text = [NSString stringWithFormat:@"%d step", obj.missing]; | |
120 | + self.lblCircleRemain.text = [NSString stringWithFormat:@"目標まであと\n%d stepです", obj.missing]; | |
121 | + self.lblPercent.text = [NSString stringWithFormat:@"%0.2f%%", obj.percent]; | |
122 | + self.lblCalories.text = [NSString stringWithFormat:@"%0.2f kcal", obj.calories]; | |
123 | + self.lblDistance.text = [NSString stringWithFormat:@"%0.1f KM", obj.distance]; | |
124 | + self.lblTime.text = [Utilities convertSecondToShortTime:obj.time]; | |
115 | 125 | [self updateGraphView]; |
116 | 126 | } |
117 | 127 | |
... | ... | @@ -180,21 +190,26 @@ |
180 | 190 | -(void) callRequestToUpdateData { |
181 | 191 | [super callRequestToUpdateData]; |
182 | 192 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
183 | - int type = self.viewCollectionType.getCurrentIndex; | |
184 | - int mode = self.viewCollectionMode.getCurrentIndex + 1; | |
185 | 193 | |
186 | 194 | MBProgressHUD *hudView = nil; |
187 | 195 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
188 | 196 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
189 | 197 | } |
190 | - [[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) { | |
191 | 199 | dispatch_async(dispatch_get_main_queue(), ^{ |
192 | 200 | if(hudView != nil) { |
193 | 201 | [hudView hideAnimated:true]; |
194 | 202 | } |
195 | 203 | }); |
196 | 204 | HistoryViewController __weak *weakSelf = self; |
197 | - [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 | + } | |
198 | 213 | }]; |
199 | 214 | } |
200 | 215 | |
... | ... | @@ -216,6 +231,14 @@ |
216 | 231 | _startDate = _endDate; |
217 | 232 | break; |
218 | 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 | + } | |
219 | 242 | [self checkRequestData]; |
220 | 243 | } |
221 | 244 | |
... | ... | @@ -232,13 +255,11 @@ |
232 | 255 | |
233 | 256 | - (IBAction)clickBackward:(UIButton *)sender { |
234 | 257 | _endDate = [_endDate dateByAddingTimeInterval:-86400]; |
235 | - self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; | |
236 | 258 | [self changeDate]; |
237 | 259 | } |
238 | 260 | |
239 | 261 | - (IBAction)clickForward:(UIButton *)sender { |
240 | 262 | _endDate = [_endDate dateByAddingTimeInterval:86400]; |
241 | - self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; | |
242 | 263 | [self changeDate]; |
243 | 264 | } |
244 | 265 | |
... | ... | @@ -262,7 +283,8 @@ |
262 | 283 | case 3: // share email |
263 | 284 | [Utilities shareEmail:content withViewController:weakSelf]; |
264 | 285 | break; |
265 | - default: | |
286 | + default: //share other | |
287 | + [Utilities shareOther:content withViewController:weakSelf]; | |
266 | 288 | break; |
267 | 289 | } |
268 | 290 | } |
... | ... | @@ -272,10 +294,13 @@ |
272 | 294 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
273 | 295 | HistoryListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryListCell"]; |
274 | 296 | HistoryObject * obj = [_curDataList objectAtIndex:indexPath.row]; |
297 | + cell.lblTitle.text = [Utilities stringFromDate:obj.date withFormat:@"dd日 (EEEE)" locale:@"ja_JP"]; | |
275 | 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"]; | |
276 | 301 | cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; |
277 | 302 | cell.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; |
278 | - cell.lblDuration.text = obj.time; | |
303 | + cell.lblDuration.text = [Utilities convertSecondToShortTime:obj.time]; | |
279 | 304 | return cell; |
280 | 305 | } |
281 | 306 |
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> |
... | ... | @@ -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> |
... | ... | @@ -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"/> |
... | ... | @@ -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/MyGroupViewController.m
... | ... | @@ -7,7 +7,6 @@ |
7 | 7 | // |
8 | 8 | |
9 | 9 | #import "MyGroupViewController.h" |
10 | -#import <SDWebImage/UIImageView+WebCache.h> | |
11 | 10 | |
12 | 11 | #import "Utilities.h" |
13 | 12 | #import "ServerAPI.h" |
... | ... | @@ -85,33 +84,11 @@ |
85 | 84 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
86 | 85 | if(isMemberList) { |
87 | 86 | MemberObject *object = [_curDataList objectAtIndex:indexPath.row]; |
88 | - if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | |
89 | - [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | |
90 | - } | |
91 | - else { | |
92 | - [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | |
93 | - } | |
94 | - cell.lblUsername.text = @""; | |
95 | - cell.lblDateTime.text = @""; | |
96 | - cell.lblDes.text = object.userName; | |
97 | - cell.lblMode.text = @""; | |
98 | - cell.lblDistance.text = @""; | |
99 | - cell.lblDuration.text = @""; | |
87 | + [cell setMemberData:object]; | |
100 | 88 | } |
101 | 89 | else { |
102 | 90 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
103 | - if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | |
104 | - [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | |
105 | - } | |
106 | - else { | |
107 | - [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | |
108 | - } | |
109 | - cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; | |
110 | - cell.lblUsername.text = object.userName; | |
111 | - cell.lblDes.text = object.content; | |
112 | - cell.lblMode.text = object.mode; | |
113 | - cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | |
114 | - cell.lblDuration.text = object.time; | |
91 | + [cell setTweetsData:object]; | |
115 | 92 | } |
116 | 93 | return cell; |
117 | 94 | } |
LifeLog/LifeLog/SNSRecentTopicTableViewCell.h
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | // |
8 | 8 | |
9 | 9 | #import <UIKit/UIKit.h> |
10 | +#import "Entities.h" | |
10 | 11 | |
11 | 12 | @interface SNSRecentTopicTableViewCell : UITableViewCell |
12 | 13 | |
... | ... | @@ -18,4 +19,6 @@ |
18 | 19 | @property (weak, nonatomic) IBOutlet UILabel *lblDistance; |
19 | 20 | @property (weak, nonatomic) IBOutlet UILabel *lblDuration; |
20 | 21 | |
22 | +-(void) setMemberData : (MemberObject *) object; | |
23 | +-(void) setTweetsData : (TweetObject *) object; | |
21 | 24 | @end |
LifeLog/LifeLog/SNSRecentTopicTableViewCell.m
... | ... | @@ -7,6 +7,9 @@ |
7 | 7 | // |
8 | 8 | |
9 | 9 | #import "SNSRecentTopicTableViewCell.h" |
10 | +#import <SDWebImage/UIImageView+WebCache.h> | |
11 | + | |
12 | +#import "Utilities.h" | |
10 | 13 | |
11 | 14 | @implementation SNSRecentTopicTableViewCell |
12 | 15 | |
... | ... | @@ -21,4 +24,34 @@ |
21 | 24 | // Configure the view for the selected state |
22 | 25 | } |
23 | 26 | |
27 | +-(void) setMemberData : (MemberObject *) object { | |
28 | + if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | |
29 | + [self.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | |
30 | + } | |
31 | + else { | |
32 | + [self.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | |
33 | + } | |
34 | + self.lblUsername.text = @""; | |
35 | + self.lblDateTime.text = @""; | |
36 | + self.lblDes.text = object.userName; | |
37 | + self.lblMode.text = @""; | |
38 | + self.lblDistance.text = @""; | |
39 | + self.lblDuration.text = @""; | |
40 | +} | |
41 | + | |
42 | +-(void) setTweetsData : (TweetObject *) object { | |
43 | + if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | |
44 | + [self.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | |
45 | + } | |
46 | + else { | |
47 | + [self.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | |
48 | + } | |
49 | + self.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; | |
50 | + self.lblUsername.text = object.userName; | |
51 | + self.lblDes.text = object.content; | |
52 | + self.lblMode.text = object.mode; | |
53 | + self.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | |
54 | + self.lblDuration.text = object.time; | |
55 | +} | |
56 | + | |
24 | 57 | @end |
LifeLog/LifeLog/SNSViewController.m
... | ... | @@ -8,8 +8,6 @@ |
8 | 8 | |
9 | 9 | #import "SNSViewController.h" |
10 | 10 | |
11 | -#import <SDWebImage/UIImageView+WebCache.h> | |
12 | - | |
13 | 11 | #import "ServerAPI.h" |
14 | 12 | #import "Utilities.h" |
15 | 13 | |
... | ... | @@ -55,18 +53,7 @@ |
55 | 53 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
56 | 54 | SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; |
57 | 55 | TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; |
58 | - if(object.avatar && ![object.avatar isKindOfClass:[NSNull class]]) { | |
59 | - [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatar]]]; | |
60 | - } | |
61 | - else { | |
62 | - [cell.imgAvatar setImage:[UIImage imageNamed:@"avatar_default"]]; | |
63 | - } | |
64 | - cell.lblDateTime.text = [Utilities stringFromDate:object.createDate withFormat:@"YYYY/MM/dd hh:mm" locale:@""]; | |
65 | - cell.lblUsername.text = object.userName; | |
66 | - cell.lblDes.text = object.content; | |
67 | - cell.lblMode.text = object.mode; | |
68 | - cell.lblDistance.text = [NSString stringWithFormat:@"%.0f m", object.distance]; | |
69 | - cell.lblDuration.text = object.time; | |
56 | + [cell setTweetsData:object]; | |
70 | 57 | return cell; |
71 | 58 | } |
72 | 59 |
LifeLog/LifeLog/ServerAPI.h
... | ... | @@ -31,8 +31,7 @@ extern NSString *const kNotificationToken; |
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
... | ... | @@ -428,7 +428,7 @@ NSURLSessionDataTask * searchTask; |
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 | } |
... | ... | @@ -463,50 +463,8 @@ NSURLSessionDataTask * searchTask; |
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 | |
... | ... | @@ -521,11 +479,25 @@ NSURLSessionDataTask * searchTask; |
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 @@ NSURLSessionDataTask * searchTask; |
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}]; |
LifeLog/LifeLog/Utilities.h
... | ... | @@ -21,8 +21,11 @@ |
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]; |
... | ... | @@ -167,4 +173,17 @@ |
167 | 173 | return dateString; |
168 | 174 | } |
169 | 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]; | |
187 | +} | |
188 | + | |
170 | 189 | @end |