Commit 22aac67aa3422be4ee60c88970c9c423fbbe7977

Authored by nvtu11790@gmail.com
1 parent 881d547d57
Exists in master

Always request again when history view appear

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