|
12 | 12 | #import "NProjectItemCell.h" |
13 | 13 |
|
14 | 14 | //#import "ProjectItemsCell.h" |
15 | | -//#import "ProjectReadMeCell.h" |
16 | 15 | //#import "ProjectActivityListCell.h" |
17 | 16 | #import "ProjectViewController.h" |
18 | 17 | #import "Coding_NetAPIManager.h" |
|
26 | 25 | //#import "FileViewController.h" |
27 | 26 |
|
28 | 27 | #import "CodeViewController.h" |
| 28 | +#import "EaseGitButtonsView.h" |
29 | 29 |
|
30 | 30 | @interface NProjectViewController ()<UITableViewDataSource, UITableViewDelegate> |
31 | 31 | @property (nonatomic, strong) UITableView *myTableView; |
32 | 32 | @property (nonatomic, strong) ODRefreshControl *refreshControl; |
33 | 33 |
|
| 34 | +@property (strong, nonatomic) EaseGitButtonsView *gitButtonsView; |
| 35 | + |
34 | 36 | @end |
35 | 37 |
|
36 | 38 | @implementation NProjectViewController |
37 | 39 |
|
38 | 40 | -(void)viewWillAppear:(BOOL)animated{ |
39 | 41 | [super viewWillAppear:animated]; |
40 | 42 | [self.myTableView reloadData]; |
| 43 | + [self refreshGitButtonsView]; |
41 | 44 | } |
42 | 45 |
|
43 | 46 | - (void)viewDidLoad{ |
@@ -47,7 +50,7 @@ - (void)viewDidLoad{ |
47 | 50 |
|
48 | 51 | // 添加myTableView |
49 | 52 | _myTableView = ({ |
50 | | - UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; |
| 53 | + UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; |
51 | 54 | tableView.backgroundColor = [UIColor clearColor]; |
52 | 55 | tableView.dataSource = self; |
53 | 56 | tableView.delegate = self; |
@@ -61,6 +64,17 @@ - (void)viewDidLoad{ |
61 | 64 | }]; |
62 | 65 | tableView; |
63 | 66 | }); |
| 67 | + |
| 68 | + __weak typeof(self) weakSelf = self; |
| 69 | + _gitButtonsView = [EaseGitButtonsView new]; |
| 70 | + _gitButtonsView.gitButtonClickedBlock = ^(NSInteger index){ |
| 71 | + [weakSelf gitButtonClicked:index]; |
| 72 | + }; |
| 73 | + [self.view addSubview:_gitButtonsView]; |
| 74 | + [_gitButtonsView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 75 | + make.left.right.bottom.equalTo(self.view); |
| 76 | + make.height.mas_equalTo(EaseGitButtonsView_Height); |
| 77 | + }]; |
64 | 78 |
|
65 | 79 | _refreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView]; |
66 | 80 | [_refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged]; |
@@ -77,6 +91,7 @@ - (void)refresh{ |
77 | 91 | [[Coding_NetAPIManager sharedManager] request_ProjectDetail_WithObj:_myProject andBlock:^(id data, NSError *error) { |
78 | 92 | if (data) { |
79 | 93 | weakSelf.myProject = data; |
| 94 | + [self refreshGitButtonsView]; |
80 | 95 | [weakSelf.myTableView reloadData]; |
81 | 96 | } |
82 | 97 | [weakSelf.refreshControl endRefreshing]; |
@@ -91,20 +106,33 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ |
91 | 106 | //footer |
92 | 107 | - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ |
93 | 108 | if (section < 2) { |
94 | | - UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 20)]; |
| 109 | + UIView *footerView = [UIView new]; |
95 | 110 | footerView.backgroundColor = [UIColor colorWithHexString:@"0xe5e5e5"]; |
96 | | - [footerView addLineUp:YES andDown:NO andColor:tableView.separatorColor]; |
97 | 111 | return footerView; |
98 | 112 | }else{ |
99 | 113 | return nil; |
100 | 114 | } |
101 | 115 | } |
102 | 116 |
|
103 | 117 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ |
104 | | - CGFloat footerHeight = section < 2? 20: 0; |
| 118 | + CGFloat footerHeight = section < 2? 20: 0.5; |
105 | 119 | return footerHeight; |
106 | 120 | } |
107 | 121 |
|
| 122 | +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ |
| 123 | + return 0.5; |
| 124 | +} |
| 125 | + |
| 126 | +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ |
| 127 | + if (section > 0) { |
| 128 | + UIView *headerView = [UIView new]; |
| 129 | + headerView.backgroundColor = [UIColor colorWithHexString:@"0xe5e5e5"]; |
| 130 | + return headerView; |
| 131 | + }else{ |
| 132 | + return nil; |
| 133 | + } |
| 134 | +} |
| 135 | + |
108 | 136 | //data |
109 | 137 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
110 | 138 | NSInteger row = 0; |
@@ -179,89 +207,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N |
179 | 207 | [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:50]; |
180 | 208 | return cell; |
181 | 209 | } |
182 | | - |
183 | | - |
184 | | - { |
185 | | - |
186 | | -// if (_myProject.is_public.boolValue) { |
187 | | -// if (indexPath.section == 0) { |
188 | | -// if (indexPath.row == 0) { |
189 | | -// ProjectInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectInfoCell forIndexPath:indexPath]; |
190 | | -// cell.curProject = _myProject; |
191 | | -// cell.projectBlock = ^(Project *clickedPro){ |
192 | | -// [weakSelf gotoPro:clickedPro]; |
193 | | -// }; |
194 | | -// return cell; |
195 | | -// }else{ |
196 | | -// ProjectDescriptionCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectDescriptionCell forIndexPath:indexPath]; |
197 | | -// cell.curProject = _myProject; |
198 | | -// cell.gitButtonClickedBlock = ^(NSInteger index){ |
199 | | -// [weakSelf gitButtonClicked:index]; |
200 | | -// }; |
201 | | -// return cell; |
202 | | -// } |
203 | | -// }else if (indexPath.section == 1){ |
204 | | -// ProjectItemsCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectItemsCell_Public forIndexPath:indexPath]; |
205 | | -// cell.curProject = _myProject; |
206 | | -// cell.itemClickedBlock = ^(NSInteger index){ |
207 | | -// [weakSelf goToIndex:index]; |
208 | | -// }; |
209 | | -// return cell; |
210 | | -// }else{ |
211 | | -// ProjectReadMeCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectReadMeCell forIndexPath:indexPath]; |
212 | | -// cell.curProject = _myProject; |
213 | | -// cell.cellHeightChangedBlock = ^(){ |
214 | | -// [weakSelf.myTableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationNone]; |
215 | | -// }; |
216 | | -// cell.loadRequestBlock = ^(NSURLRequest *curRequest){ |
217 | | -// [weakSelf loadRequest:curRequest]; |
218 | | -// }; |
219 | | -// return cell; |
220 | | -// } |
221 | | -// }else{ |
222 | | -// if (indexPath.section == 0) { |
223 | | -// if (indexPath.row == 0) { |
224 | | -// ProjectInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectInfoCell forIndexPath:indexPath]; |
225 | | -// cell.curProject = _myProject; |
226 | | -// return cell; |
227 | | -// }else{ |
228 | | -// ProjectItemsCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectItemsCell_Private forIndexPath:indexPath]; |
229 | | -// cell.curProject = _myProject; |
230 | | -// cell.itemClickedBlock = ^(NSInteger index){ |
231 | | -// [self goToIndex:index]; |
232 | | -// }; |
233 | | -// return cell; |
234 | | -// } |
235 | | -// }else{ |
236 | | -// ListGroupItem *item = [_myProActs.listGroups objectAtIndex:indexPath.section - 1]; |
237 | | -// NSUInteger row = indexPath.row +item.location; |
238 | | -// ProjectActivity *curProAct = [_myProActs.list objectAtIndex:row]; |
239 | | -// ProjectActivityListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectActivityList forIndexPath:indexPath]; |
240 | | -// BOOL haveRead, isTop, isBottom; |
241 | | -// |
242 | | -// if (_myProActs.isOfUser || ![_myProActs.type isEqualToString:@"all"]) { |
243 | | -// haveRead = YES; |
244 | | -// isTop = (row == item.location); |
245 | | -// isBottom = (row == item.location +item.length -1); |
246 | | -// }else{ |
247 | | -// haveRead = row >= _un_read_activities_count; |
248 | | -// isTop = (row == item.location) || (row == _un_read_activities_count); |
249 | | -// isBottom = (row == item.location +item.length -1) || (row == _un_read_activities_count-1); |
250 | | -// } |
251 | | -// |
252 | | -// [cell configWithProAct:curProAct haveRead:haveRead isTop:isTop isBottom:isBottom]; |
253 | | -// [cell.userIconView addTapBlock:^(id obj) { |
254 | | -// [weakSelf goToUserInfo:curProAct.user]; |
255 | | -// }]; |
256 | | -// cell.htmlItemClickedBlock = ^(HtmlMediaItem *clickedItem, ProjectActivity *proAct, BOOL isContent){ |
257 | | -// [weakSelf goToVCWithItem:clickedItem activity:proAct isContent:isContent inProject:weakSelf.myProject]; |
258 | | -// }; |
259 | | -// [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace: |
260 | | -// (row == item.location +item.length -1)? 0: 85 hasSectionLine:NO]; |
261 | | -// return cell; |
262 | | -// } |
263 | | -// } |
264 | | - } |
265 | 210 | } |
266 | 211 |
|
267 | 212 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ |
@@ -328,7 +273,7 @@ - (void)gitButtonClicked:(NSInteger)index{ |
328 | 273 | { |
329 | 274 | if (!_myProject.isStaring) { |
330 | 275 | [[Coding_NetAPIManager sharedManager] request_StarProject:_myProject andBlock:^(id data, NSError *error) { |
331 | | - [weakSelf.myTableView reloadData]; |
| 276 | + [weakSelf refreshGitButtonsView]; |
332 | 277 | }]; |
333 | 278 | } |
334 | 279 | } |
@@ -337,7 +282,7 @@ - (void)gitButtonClicked:(NSInteger)index{ |
337 | 282 | { |
338 | 283 | if (!_myProject.isWatching) { |
339 | 284 | [[Coding_NetAPIManager sharedManager] request_WatchProject:_myProject andBlock:^(id data, NSError *error) { |
340 | | - [weakSelf.myTableView reloadData]; |
| 285 | + [weakSelf refreshGitButtonsView]; |
341 | 286 | }]; |
342 | 287 | } |
343 | 288 | } |
@@ -347,7 +292,7 @@ - (void)gitButtonClicked:(NSInteger)index{ |
347 | 292 | [[UIActionSheet bk_actionSheetCustomWithTitle:@"fork将会将此项目复制到您的个人空间,确定要fork吗?" buttonTitles:@[@"确定"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { |
348 | 293 | if (index == 0) { |
349 | 294 | [[Coding_NetAPIManager sharedManager] request_ForkProject:_myProject andBlock:^(id data, NSError *error) { |
350 | | - [weakSelf.myTableView reloadData]; |
| 295 | + [weakSelf refreshGitButtonsView]; |
351 | 296 | if (data) { |
352 | 297 | NProjectViewController *vc = [[NProjectViewController alloc] init]; |
353 | 298 | vc.myProject = data; |
@@ -361,5 +306,15 @@ - (void)gitButtonClicked:(NSInteger)index{ |
361 | 306 | } |
362 | 307 | } |
363 | 308 |
|
| 309 | +- (void)refreshGitButtonsView{ |
| 310 | + self.gitButtonsView.curProject = self.myProject; |
| 311 | + CGFloat gitButtonsViewHeight = 0; |
| 312 | + if (self.myProject.is_public.boolValue) { |
| 313 | + gitButtonsViewHeight = CGRectGetHeight(self.gitButtonsView.frame) - 1; |
| 314 | + } |
| 315 | + UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, gitButtonsViewHeight, 0); |
| 316 | + self.myTableView.contentInset = insets; |
| 317 | + self.myTableView.scrollIndicatorInsets = insets; |
| 318 | +} |
364 | 319 |
|
365 | 320 | @end |