Commit 29486f50ff55914f3ba67a2fe8d5da65f3dd5036
1 parent
5739e821e5
Exists in
master
and in
1 other branch
Set color for graph depend on percent of steps
Showing 1 changed file with 42 additions and 1 deletions Inline Diff
LifeLog/LifeLog/HistoryViewController.m
1 | // | 1 | // |
2 | // HistoryViewController.m | 2 | // HistoryViewController.m |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by Nguyen Van Phong on 7/25/17. | 5 | // Created by Nguyen Van Phong on 7/25/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import "HistoryViewController.h" | 9 | #import "HistoryViewController.h" |
10 | #import "Utilities.h" | 10 | #import "Utilities.h" |
11 | #import "ServerAPI.h" | 11 | #import "ServerAPI.h" |
12 | 12 | ||
13 | #import "HistoryListTableViewCell.h" | 13 | #import "HistoryListTableViewCell.h" |
14 | 14 | ||
15 | @interface HistoryViewController () | 15 | @interface HistoryViewController () |
16 | 16 | ||
17 | @end | 17 | @end |
18 | 18 | ||
19 | @implementation HistoryViewController | 19 | @implementation HistoryViewController |
20 | 20 | ||
21 | - (void)viewDidLoad { | 21 | - (void)viewDidLoad { |
22 | [super viewDidLoad]; | 22 | [super viewDidLoad]; |
23 | // Do any additional setup after loading the view from its nib. | 23 | // Do any additional setup after loading the view from its nib. |
24 | self.title = NSLocalizedString(@"lifelog.history.title", nil); | 24 | self.title = NSLocalizedString(@"lifelog.history.title", nil); |
25 | 25 | ||
26 | _isDisableLoadMore = true; | 26 | _isDisableLoadMore = true; |
27 | 27 | ||
28 | [self setupView]; | 28 | [self setupView]; |
29 | [self setupChartView]; | 29 | [self setupChartView]; |
30 | 30 | ||
31 | _startDate = [NSDate date]; | 31 | _startDate = [NSDate date]; |
32 | _endDate = _startDate; | 32 | _endDate = _startDate; |
33 | 33 | ||
34 | self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; | 34 | self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; |
35 | 35 | ||
36 | [self checkRequestData]; | 36 | [self checkRequestData]; |
37 | 37 | ||
38 | //register nib for table view | 38 | //register nib for table view |
39 | [self.tableBase registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; | 39 | [self.tableBase registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; |
40 | } | 40 | } |
41 | 41 | ||
42 | - (void)viewDidAppear:(BOOL) animated | 42 | - (void)viewDidAppear:(BOOL) animated |
43 | { | 43 | { |
44 | [super viewDidAppear:animated]; | 44 | [super viewDidAppear:animated]; |
45 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 400); | 45 | self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 400); |
46 | [self.scrollView setNeedsLayout]; | 46 | [self.scrollView setNeedsLayout]; |
47 | [self.scrollView setNeedsUpdateConstraints]; | 47 | [self.scrollView setNeedsUpdateConstraints]; |
48 | 48 | ||
49 | } | 49 | } |
50 | 50 | ||
51 | - (void)didReceiveMemoryWarning { | 51 | - (void)didReceiveMemoryWarning { |
52 | [super didReceiveMemoryWarning]; | 52 | [super didReceiveMemoryWarning]; |
53 | // Dispose of any resources that can be recreated. | 53 | // Dispose of any resources that can be recreated. |
54 | } | 54 | } |
55 | 55 | ||
56 | - (void)setupView { | 56 | - (void)setupView { |
57 | NSArray *typeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.type.1", nil), NSLocalizedString(@"lifelog.history.type.2", nil), NSLocalizedString(@"lifelog.history.type.3", nil), NSLocalizedString(@"lifelog.history.type.4", nil), NSLocalizedString(@"lifelog.history.type.5", nil), nil]; | 57 | NSArray *typeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.type.1", nil), NSLocalizedString(@"lifelog.history.type.2", nil), NSLocalizedString(@"lifelog.history.type.3", nil), NSLocalizedString(@"lifelog.history.type.4", nil), NSLocalizedString(@"lifelog.history.type.5", nil), nil]; |
58 | [self.viewCollectionType setButtonNumber:typeTitle.count]; | 58 | [self.viewCollectionType setButtonNumber:typeTitle.count]; |
59 | [self.viewCollectionType setSpacing:2]; | 59 | [self.viewCollectionType setSpacing:2]; |
60 | [self.viewCollectionType setArrayTitle:typeTitle]; | 60 | [self.viewCollectionType setArrayTitle:typeTitle]; |
61 | self.viewCollectionType.changeCurrentIndex = ^(int index){ | 61 | self.viewCollectionType.changeCurrentIndex = ^(int index){ |
62 | [self changeDate]; | 62 | [self changeDate]; |
63 | }; | 63 | }; |
64 | 64 | ||
65 | NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.mode.1", nil), NSLocalizedString(@"lifelog.history.mode.2", nil), NSLocalizedString(@"lifelog.history.mode.3", nil), nil]; | 65 | NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.mode.1", nil), NSLocalizedString(@"lifelog.history.mode.2", nil), NSLocalizedString(@"lifelog.history.mode.3", nil), nil]; |
66 | [self.viewCollectionMode setButtonNumber:modeTitle.count]; | 66 | [self.viewCollectionMode setButtonNumber:modeTitle.count]; |
67 | [self.viewCollectionMode setSpacing:0]; | 67 | [self.viewCollectionMode setSpacing:0]; |
68 | [self.viewCollectionMode setCornerRadius:0]; | 68 | [self.viewCollectionMode setCornerRadius:0]; |
69 | [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; | 69 | [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; |
70 | [self.viewCollectionMode setArrayTitle:modeTitle]; | 70 | [self.viewCollectionMode setArrayTitle:modeTitle]; |
71 | self.viewCollectionMode.changeCurrentIndex = ^(int index){ | 71 | self.viewCollectionMode.changeCurrentIndex = ^(int index){ |
72 | if(self.tableBase.alpha == 0.0) { | 72 | if(self.tableBase.alpha == 0.0) { |
73 | [self updateView]; | 73 | [self updateView]; |
74 | } | 74 | } |
75 | else { | 75 | else { |
76 | NSArray * list = [_curListArray objectAtIndex:index]; | 76 | NSArray * list = [_curListArray objectAtIndex:index]; |
77 | [self updateTableData:list error:nil]; | 77 | [self updateTableData:list error:nil]; |
78 | } | 78 | } |
79 | }; | 79 | }; |
80 | 80 | ||
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]; | 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]; |
82 | [self.viewCollectionShare setButtonNumber:typeTitle.count]; | 82 | [self.viewCollectionShare setButtonNumber:typeTitle.count]; |
83 | [self.viewCollectionShare setSpacing:3]; | 83 | [self.viewCollectionShare setSpacing:3]; |
84 | [self.viewCollectionShare setArrayTitle:shareTitle]; | 84 | [self.viewCollectionShare setArrayTitle:shareTitle]; |
85 | [self.viewCollectionShare disableSelection]; | 85 | [self.viewCollectionShare disableSelection]; |
86 | 86 | ||
87 | //add tap gesture for enable tap on gesture on CollectionView in ScrollView | 87 | //add tap gesture for enable tap on gesture on CollectionView in ScrollView |
88 | UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; | 88 | UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; |
89 | [recognizer setNumberOfTapsRequired:1]; | 89 | [recognizer setNumberOfTapsRequired:1]; |
90 | self.scrollView.userInteractionEnabled = YES; | 90 | self.scrollView.userInteractionEnabled = YES; |
91 | [self.scrollView addGestureRecognizer:recognizer]; | 91 | [self.scrollView addGestureRecognizer:recognizer]; |
92 | } | 92 | } |
93 | 93 | ||
94 | - (void)setupChartView { | 94 | - (void)setupChartView { |
95 | self.viewBarChart.chartDescription.enabled = NO; | 95 | self.viewBarChart.chartDescription.enabled = NO; |
96 | self.viewBarChart.leftAxis.drawGridLinesEnabled = NO; | 96 | self.viewBarChart.leftAxis.drawGridLinesEnabled = NO; |
97 | self.viewBarChart.rightAxis.drawGridLinesEnabled = NO; | 97 | self.viewBarChart.rightAxis.drawGridLinesEnabled = NO; |
98 | self.viewBarChart.legend.enabled = NO; | 98 | self.viewBarChart.legend.enabled = NO; |
99 | 99 | ||
100 | ChartXAxis *xAxis = self.viewBarChart.xAxis; | 100 | ChartXAxis *xAxis = self.viewBarChart.xAxis; |
101 | xAxis.labelPosition = XAxisLabelPositionBottom; | 101 | xAxis.labelPosition = XAxisLabelPositionBottom; |
102 | xAxis.drawGridLinesEnabled = NO; | 102 | xAxis.drawGridLinesEnabled = NO; |
103 | xAxis.drawAxisLineEnabled = NO; | 103 | xAxis.drawAxisLineEnabled = NO; |
104 | xAxis.drawLabelsEnabled = YES; | 104 | xAxis.drawLabelsEnabled = YES; |
105 | xAxis.labelPosition = XAxisLabelPositionBottom; | 105 | xAxis.labelPosition = XAxisLabelPositionBottom; |
106 | xAxis.labelFont = [UIFont systemFontOfSize:10.f]; | 106 | xAxis.labelFont = [UIFont systemFontOfSize:10.f]; |
107 | xAxis.labelTextColor = [UIColor whiteColor]; | 107 | xAxis.labelTextColor = [UIColor whiteColor]; |
108 | xAxis.granularity = 1.0; // only intervals of 1 day | 108 | xAxis.granularity = 1.0; // only intervals of 1 day |
109 | xAxis.labelCount = 8; | 109 | xAxis.labelCount = 8; |
110 | 110 | ||
111 | self.viewBarChart.leftAxis.drawAxisLineEnabled = NO; | 111 | self.viewBarChart.leftAxis.drawAxisLineEnabled = NO; |
112 | self.viewBarChart.rightAxis.drawAxisLineEnabled = NO; | 112 | self.viewBarChart.rightAxis.drawAxisLineEnabled = NO; |
113 | } | 113 | } |
114 | 114 | ||
115 | -(void) updateView { | 115 | -(void) updateView { |
116 | HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; | 116 | HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; |
117 | self.lblStep.text = [NSString stringWithFormat:@"%d step", obj.step]; | 117 | self.lblStep.text = [NSString stringWithFormat:@"%d step", obj.step]; |
118 | self.lblCircleStep.text = self.lblStep.text; | 118 | self.lblCircleStep.text = self.lblStep.text; |
119 | self.lblRemaining.text = [NSString stringWithFormat:@"%d step", obj.missing]; | 119 | self.lblRemaining.text = [NSString stringWithFormat:@"%d step", obj.missing]; |
120 | self.lblCircleRemain.text = [NSString stringWithFormat:@"目標まであと\n%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]; | 121 | self.lblPercent.text = [NSString stringWithFormat:@"%0.2f%%", obj.percent]; |
122 | self.lblCalories.text = [NSString stringWithFormat:@"%0.2f kcal", obj.calories]; | 122 | self.lblCalories.text = [NSString stringWithFormat:@"%0.2f kcal", obj.calories]; |
123 | self.lblDistance.text = [NSString stringWithFormat:@"%0.1f KM", obj.distance]; | 123 | self.lblDistance.text = [NSString stringWithFormat:@"%0.1f KM", obj.distance]; |
124 | self.lblTime.text = [Utilities convertSecondToShortTime:obj.time]; | 124 | self.lblTime.text = [Utilities convertSecondToShortTime:obj.time]; |
125 | [self updateGraphView]; | 125 | [self updateGraphView]; |
126 | } | 126 | } |
127 | 127 | ||
128 | -(void) updateGraphView { | 128 | -(void) updateGraphView { |
129 | HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; | 129 | HistoryObject * obj = [_curHisArray objectAtIndex:self.viewCollectionMode.getCurrentIndex]; |
130 | 130 | ||
131 | NSMutableArray *yVals = [[NSMutableArray alloc] init]; | 131 | NSMutableArray *yVals = [[NSMutableArray alloc] init]; |
132 | for (int i = 0; i < obj.dataGraph.count; i++) | 132 | for (int i = 0; i < obj.dataGraph.count; i++) |
133 | { | 133 | { |
134 | [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:[[obj.dataGraph objectAtIndex:i] doubleValue]]]; | 134 | [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:[[obj.dataGraph objectAtIndex:i] doubleValue]]]; |
135 | } | 135 | } |
136 | 136 | ||
137 | BarChartDataSet *set1 = nil; | 137 | BarChartDataSet *set1 = nil; |
138 | if (self.viewBarChart.data.dataSetCount > 0) | 138 | if (self.viewBarChart.data.dataSetCount > 0) |
139 | { | 139 | { |
140 | set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0]; | 140 | set1 = (BarChartDataSet *)self.viewBarChart.data.dataSets[0]; |
141 | set1.values = yVals; | 141 | set1.values = yVals; |
142 | |||
143 | NSMutableArray *color = [[NSMutableArray alloc] init]; | ||
144 | for(int i = 0; i < yVals.count; i++) { | ||
145 | BarChartDataEntry *en = yVals[i]; | ||
146 | if(obj.step != 0) { | ||
147 | double percent = en.y / obj.step * 100; | ||
148 | if(percent > 80) { | ||
149 | [color addObject:[UIColor redColor]]; | ||
150 | } | ||
151 | else if(percent > 60) { | ||
152 | [color addObject:[UIColor yellowColor]]; | ||
153 | } | ||
154 | else { | ||
155 | [color addObject:[UIColor whiteColor]]; | ||
156 | } | ||
157 | } | ||
158 | else { | ||
159 | [color addObject:[UIColor whiteColor]]; | ||
160 | } | ||
161 | } | ||
162 | [set1 setColors:color]; | ||
163 | |||
142 | [self.viewBarChart.data notifyDataChanged]; | 164 | [self.viewBarChart.data notifyDataChanged]; |
143 | [self.viewBarChart notifyDataSetChanged]; | 165 | [self.viewBarChart notifyDataSetChanged]; |
144 | } | 166 | } |
145 | else | 167 | else |
146 | { | 168 | { |
147 | set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""]; | 169 | set1 = [[BarChartDataSet alloc] initWithValues:yVals label:@""]; |
148 | [set1 setColor:[UIColor whiteColor]]; | ||
149 | 170 | ||
171 | NSMutableArray *color = [[NSMutableArray alloc] init]; | ||
172 | for(int i = 0; i < yVals.count; i++) { | ||
173 | BarChartDataEntry *en = yVals[i]; | ||
174 | if(obj.step != 0) { | ||
175 | double percent = en.y / obj.step * 100; | ||
176 | if(percent > 80) { | ||
177 | [color addObject:[UIColor redColor]]; | ||
178 | } | ||
179 | else if(percent > 60) { | ||
180 | [color addObject:[UIColor yellowColor]]; | ||
181 | } | ||
182 | else { | ||
183 | [color addObject:[UIColor whiteColor]]; | ||
184 | } | ||
185 | } | ||
186 | else { | ||
187 | [color addObject:[UIColor whiteColor]]; | ||
188 | } | ||
189 | } | ||
190 | [set1 setColors:color]; | ||
150 | NSMutableArray *dataSets = [[NSMutableArray alloc] init]; | 191 | NSMutableArray *dataSets = [[NSMutableArray alloc] init]; |
151 | [dataSets addObject:set1]; | 192 | [dataSets addObject:set1]; |
152 | 193 | ||
153 | BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets]; | 194 | BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets]; |
154 | data.barWidth = 0.5f; | 195 | data.barWidth = 0.5f; |
155 | 196 | ||
156 | self.viewBarChart.data = data; | 197 | self.viewBarChart.data = data; |
157 | } | 198 | } |
158 | } | 199 | } |
159 | 200 | ||
160 | -(void) checkRequestData { | 201 | -(void) checkRequestData { |
161 | if(self.tableBase.alpha == 0.0) { | 202 | if(self.tableBase.alpha == 0.0) { |
162 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 203 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
163 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 204 | MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
164 | [[ServerAPI server] requestHistory:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) { | 205 | [[ServerAPI server] requestHistory:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) { |
165 | HistoryViewController __weak *weakSelf = self; | 206 | HistoryViewController __weak *weakSelf = self; |
166 | dispatch_async(dispatch_get_main_queue(), ^{ | 207 | dispatch_async(dispatch_get_main_queue(), ^{ |
167 | if(hudView != nil) { | 208 | if(hudView != nil) { |
168 | [hudView hideAnimated:true]; | 209 | [hudView hideAnimated:true]; |
169 | } | 210 | } |
170 | }); | 211 | }); |
171 | if(error == nil) { | 212 | if(error == nil) { |
172 | _curHisArray = array; | 213 | _curHisArray = array; |
173 | dispatch_async(dispatch_get_main_queue(), ^{ | 214 | dispatch_async(dispatch_get_main_queue(), ^{ |
174 | [weakSelf updateView]; | 215 | [weakSelf updateView]; |
175 | }); | 216 | }); |
176 | } | 217 | } |
177 | else { | 218 | else { |
178 | dispatch_async(dispatch_get_main_queue(), ^{ | 219 | dispatch_async(dispatch_get_main_queue(), ^{ |
179 | NSString *message = [error.userInfo objectForKey:@"message"]; | 220 | NSString *message = [error.userInfo objectForKey:@"message"]; |
180 | [Utilities showErrorMessage:message withViewController:weakSelf]; | 221 | [Utilities showErrorMessage:message withViewController:weakSelf]; |
181 | }); | 222 | }); |
182 | } | 223 | } |
183 | }]; | 224 | }]; |
184 | } | 225 | } |
185 | else { | 226 | else { |
186 | [self resetData]; | 227 | [self resetData]; |
187 | } | 228 | } |
188 | } | 229 | } |
189 | 230 | ||
190 | -(void) callRequestToUpdateData { | 231 | -(void) callRequestToUpdateData { |
191 | [super callRequestToUpdateData]; | 232 | [super callRequestToUpdateData]; |
192 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 233 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
193 | 234 | ||
194 | MBProgressHUD *hudView = nil; | 235 | MBProgressHUD *hudView = nil; |
195 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { | 236 | if(_curPage == 1 && !self.refreshControl.isRefreshing) { |
196 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; | 237 | hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; |
197 | } | 238 | } |
198 | [[ServerAPI server] requestHistoryList:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) { | 239 | [[ServerAPI server] requestHistoryList:token startDate:_startDate endDate:_endDate CompletionHandler:^(NSArray *array, NSError *error) { |
199 | dispatch_async(dispatch_get_main_queue(), ^{ | 240 | dispatch_async(dispatch_get_main_queue(), ^{ |
200 | if(hudView != nil) { | 241 | if(hudView != nil) { |
201 | [hudView hideAnimated:true]; | 242 | [hudView hideAnimated:true]; |
202 | } | 243 | } |
203 | }); | 244 | }); |
204 | HistoryViewController __weak *weakSelf = self; | 245 | HistoryViewController __weak *weakSelf = self; |
205 | if(error == nil) { | 246 | if(error == nil) { |
206 | _curListArray = array; | 247 | _curListArray = array; |
207 | NSArray * list = [array objectAtIndex:weakSelf.viewCollectionMode.getCurrentIndex]; | 248 | NSArray * list = [array objectAtIndex:weakSelf.viewCollectionMode.getCurrentIndex]; |
208 | [weakSelf updateTableData:list error:error]; | 249 | [weakSelf updateTableData:list error:error]; |
209 | } | 250 | } |
210 | else { | 251 | else { |
211 | [weakSelf updateTableData:array error:error]; | 252 | [weakSelf updateTableData:array error:error]; |
212 | } | 253 | } |
213 | }]; | 254 | }]; |
214 | } | 255 | } |
215 | 256 | ||
216 | - (void) changeDate { | 257 | - (void) changeDate { |
217 | switch (self.viewCollectionType.getCurrentIndex) { | 258 | switch (self.viewCollectionType.getCurrentIndex) { |
218 | case 1: | 259 | case 1: |
219 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 7]; | 260 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 7]; |
220 | break; | 261 | break; |
221 | case 2: | 262 | case 2: |
222 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30]; | 263 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30]; |
223 | break; | 264 | break; |
224 | case 3: | 265 | case 3: |
225 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 3]; | 266 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 3]; |
226 | break; | 267 | break; |
227 | case 4: | 268 | case 4: |
228 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 6]; | 269 | _startDate = [_endDate dateByAddingTimeInterval:-86400 * 30 * 6]; |
229 | break; | 270 | break; |
230 | default: | 271 | default: |
231 | _startDate = _endDate; | 272 | _startDate = _endDate; |
232 | break; | 273 | break; |
233 | } | 274 | } |
234 | if(_startDate == _endDate) { | 275 | if(_startDate == _endDate) { |
235 | self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; | 276 | self.lblDatetime.text = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日 EEEE" locale:@"ja_JP"]; |
236 | } | 277 | } |
237 | else { | 278 | else { |
238 | NSString * startDateString = [Utilities stringFromDate:_startDate withFormat:@"YYYY年MM月dd日" locale:@"ja_JP"]; | 279 | 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"]; | 280 | NSString * endDateString = [Utilities stringFromDate:_endDate withFormat:@"YYYY年MM月dd日" locale:@"ja_JP"]; |
240 | self.lblDatetime.text = [NSString stringWithFormat:@"%@-%@", startDateString, endDateString]; | 281 | self.lblDatetime.text = [NSString stringWithFormat:@"%@-%@", startDateString, endDateString]; |
241 | } | 282 | } |
242 | [self checkRequestData]; | 283 | [self checkRequestData]; |
243 | } | 284 | } |
244 | 285 | ||
245 | #pragma mark IBAction | 286 | #pragma mark IBAction |
246 | -(void) swipeAction:(UISwipeGestureRecognizer *)sender { | 287 | -(void) swipeAction:(UISwipeGestureRecognizer *)sender { |
247 | bool alphaValue = self.scrollView.alpha == 1.0 ? 1.0 : 0.0; | 288 | bool alphaValue = self.scrollView.alpha == 1.0 ? 1.0 : 0.0; |
248 | [UIView animateWithDuration:0.5 animations:^{ | 289 | [UIView animateWithDuration:0.5 animations:^{ |
249 | self.tableBase.alpha = alphaValue; | 290 | self.tableBase.alpha = alphaValue; |
250 | self.scrollView.alpha = 1.0 - alphaValue; | 291 | self.scrollView.alpha = 1.0 - alphaValue; |
251 | } completion:^(BOOL completed) { | 292 | } completion:^(BOOL completed) { |
252 | [self checkRequestData]; | 293 | [self checkRequestData]; |
253 | }]; | 294 | }]; |
254 | } | 295 | } |
255 | 296 | ||
256 | - (IBAction)clickBackward:(UIButton *)sender { | 297 | - (IBAction)clickBackward:(UIButton *)sender { |
257 | _endDate = [_endDate dateByAddingTimeInterval:-86400]; | 298 | _endDate = [_endDate dateByAddingTimeInterval:-86400]; |
258 | [self changeDate]; | 299 | [self changeDate]; |
259 | } | 300 | } |
260 | 301 | ||
261 | - (IBAction)clickForward:(UIButton *)sender { | 302 | - (IBAction)clickForward:(UIButton *)sender { |
262 | _endDate = [_endDate dateByAddingTimeInterval:86400]; | 303 | _endDate = [_endDate dateByAddingTimeInterval:86400]; |
263 | [self changeDate]; | 304 | [self changeDate]; |
264 | } | 305 | } |
265 | 306 | ||
266 | -(void)gestureAction:(UITapGestureRecognizer *) sender | 307 | -(void)gestureAction:(UITapGestureRecognizer *) sender |
267 | { | 308 | { |
268 | CGPoint touchLocation = [sender locationOfTouch:0 inView:self.viewCollectionShare]; | 309 | CGPoint touchLocation = [sender locationOfTouch:0 inView:self.viewCollectionShare]; |
269 | NSIndexPath *indexPath = [self.viewCollectionShare.collectionView indexPathForItemAtPoint:touchLocation]; | 310 | NSIndexPath *indexPath = [self.viewCollectionShare.collectionView indexPathForItemAtPoint:touchLocation]; |
270 | NSString * content = @"Finish 500 steps"; | 311 | NSString * content = @"Finish 500 steps"; |
271 | HistoryViewController __weak *weakSelf = self; | 312 | HistoryViewController __weak *weakSelf = self; |
272 | if(indexPath != NULL) { | 313 | if(indexPath != NULL) { |
273 | switch (indexPath.row) { | 314 | switch (indexPath.row) { |
274 | case 0: //share facebook | 315 | case 0: //share facebook |
275 | [Utilities shareFacebook:content withViewController:weakSelf]; | 316 | [Utilities shareFacebook:content withViewController:weakSelf]; |
276 | break; | 317 | break; |
277 | case 1: //share twitter | 318 | case 1: //share twitter |
278 | [Utilities shareTwitter:content withViewController:weakSelf]; | 319 | [Utilities shareTwitter:content withViewController:weakSelf]; |
279 | break; | 320 | break; |
280 | case 2 : //share line | 321 | case 2 : //share line |
281 | [Utilities shareLine:content withViewController:weakSelf]; | 322 | [Utilities shareLine:content withViewController:weakSelf]; |
282 | break; | 323 | break; |
283 | case 3: // share email | 324 | case 3: // share email |
284 | [Utilities shareEmail:content withViewController:weakSelf]; | 325 | [Utilities shareEmail:content withViewController:weakSelf]; |
285 | break; | 326 | break; |
286 | default: //share other | 327 | default: //share other |
287 | [Utilities shareOther:content withViewController:weakSelf]; | 328 | [Utilities shareOther:content withViewController:weakSelf]; |
288 | break; | 329 | break; |
289 | } | 330 | } |
290 | } | 331 | } |
291 | } | 332 | } |
292 | 333 | ||
293 | #pragma mark UITableView Delegate | 334 | #pragma mark UITableView Delegate |
294 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | 335 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
295 | HistoryListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryListCell"]; | 336 | HistoryListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryListCell"]; |
296 | HistoryObject * obj = [_curDataList objectAtIndex:indexPath.row]; | 337 | HistoryObject * obj = [_curDataList objectAtIndex:indexPath.row]; |
297 | cell.lblTitle.text = [Utilities stringFromDate:obj.date withFormat:@"dd日 (EEEE)" locale:@"ja_JP"]; | 338 | cell.lblTitle.text = [Utilities stringFromDate:obj.date withFormat:@"dd日 (EEEE)" locale:@"ja_JP"]; |
298 | cell.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; | 339 | cell.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; |
299 | cell.lblDiff.text = [NSString stringWithFormat:@"%d", obj.step_diff]; | 340 | 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"]; | 341 | cell.imgArrow.image = (obj.step_diff > 0) ? [UIImage imageNamed:@"arrow_incre"] : [UIImage imageNamed:@"arrow_decre"]; |
301 | cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; | 342 | cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; |
302 | cell.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; | 343 | cell.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; |
303 | cell.lblDuration.text = [Utilities convertSecondToShortTime:obj.time]; | 344 | cell.lblDuration.text = [Utilities convertSecondToShortTime:obj.time]; |
304 | return cell; | 345 | return cell; |
305 | } | 346 | } |
306 | 347 | ||
307 | @end | 348 | @end |