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