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