1010#import " ProjectInfoCell.h"
1111#import " ProjectItemsCell.h"
1212#import " ProjectDescriptionCell.h"
13+ #import " ProjectReadMeCell.h"
1314#import " ProjectViewController.h"
1415#import " Coding_NetAPIManager.h"
1516#import " ODRefreshControl.h"
17+ #import " WebViewController.h"
1618
1719@interface NProjectViewController ()<UITableViewDataSource, UITableViewDelegate>
1820@property (nonatomic , strong ) UITableView *myTableView;
@@ -36,6 +38,7 @@ - (void)viewDidLoad{
3638 [tableView registerClass: [ProjectItemsCell class ] forCellReuseIdentifier: kCellIdentifier_ProjectItemsCell_Private ];
3739 [tableView registerClass: [ProjectItemsCell class ] forCellReuseIdentifier: kCellIdentifier_ProjectItemsCell_Public ];
3840 [tableView registerClass: [ProjectDescriptionCell class ] forCellReuseIdentifier: kCellIdentifier_ProjectDescriptionCell ];
41+ [tableView registerClass: [ProjectReadMeCell class ] forCellReuseIdentifier: kCellIdentifier_ProjectReadMeCell ];
3942 [self .view addSubview: tableView];
4043 [tableView mas_makeConstraints: ^(MASConstraintMaker *make) {
4144 make.edges .equalTo (self.view );
@@ -54,23 +57,39 @@ - (void)refresh{
5457 if (_myProject.isLoadingDetail ) {
5558 return ;
5659 }
57-
5860 __weak typeof (self) weakSelf = self;
5961 [[Coding_NetAPIManager sharedManager ] request_ProjectDetail_WithObj: _myProject andBlock: ^(id data, NSError *error) {
6062 [weakSelf.refreshControl endRefreshing ];
6163 if (data) {
64+ CGFloat readMeHeight = weakSelf.myProject .readMeHeight ;
6265 weakSelf.myProject = data;
63- [weakSelf.myTableView reloadSections: [NSIndexSet indexSetWithIndex: 0 ] withRowAnimation: UITableViewRowAnimationNone];
66+ weakSelf.myProject .readMeHeight = readMeHeight;
67+ if (weakSelf.myProject .is_public .boolValue ) {
68+ [weakSelf refreshReadMe ];
69+ }else {
70+ [weakSelf.myTableView reloadData ];
71+ }
6472 }
6573 }];
6674}
6775
76+ - (void )refreshReadMe {
77+ if (_myProject.is_public .boolValue ) {
78+ __weak typeof (self) weakSelf = self;
79+ [[Coding_NetAPIManager sharedManager ] request_ReadMeOFProject: _myProject andBlock: ^(id data, NSError *error) {
80+ weakSelf.myProject .readMeHtml = data;
81+ [weakSelf.myTableView reloadData ];
82+ }];
83+ NSLog (@" ee" );
84+ }
85+ }
86+
6887#pragma mark Table M
6988
7089- (NSInteger )numberOfSectionsInTableView : (UITableView *)tableView {
7190 NSInteger section = 0 ;
7291 if (_myProject.is_public ) {
73- section = _myProject.is_public .boolValue ? 2 : 1 ;
92+ section = _myProject.is_public .boolValue ? 3 : 1 ;
7493 }
7594 return section;
7695}
@@ -83,7 +102,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger
83102}
84103
85104- (CGFloat)tableView : (UITableView *)tableView heightForFooterInSection : (NSInteger )section {
86- if (section == _myProject.is_public .boolValue ? 1 : 0 ) {
105+ if (section == ( _myProject.is_public .boolValue ? 2 : 0 ) ) {
87106 return 0 ;
88107 }
89108 return 20 ;
@@ -92,20 +111,13 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege
92111- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section {
93112 NSInteger row = 0 ;
94113 if (_myProject.is_public ) {
95- switch (section) {
96- case 0 :
97- row = 2 ;
98- break ;
99- case 1 :
100- default :
101- row = _myProject.is_public .boolValue ? 1 : 0 ;
102- break ;
103- }
114+ row = section == 0 ? 2 : 1 ;
104115 }
105116 return row;
106117}
107118
108119- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
120+ __weak typeof (self) weakSelf = self;
109121 if (_myProject.is_public .boolValue ) {
110122 if (indexPath.section == 0 ) {
111123 if (indexPath.row == 0 ) {
@@ -116,15 +128,26 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
116128 ProjectDescriptionCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_ProjectDescriptionCell forIndexPath: indexPath];
117129 cell.curProject = _myProject;
118130 cell.gitButtonClickedBlock = ^(NSInteger index){
119- [self gitButtonClicked: index];
131+ [weakSelf gitButtonClicked: index];
120132 };
121133 return cell;
122134 }
123- }else {
135+ }else if (indexPath. section == 1 ) {
124136 ProjectItemsCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_ProjectItemsCell_Public forIndexPath: indexPath];
125137 cell.curProject = _myProject;
126138 cell.itemClickedBlock = ^(NSInteger index){
127- [self goToIndex: index];
139+ [weakSelf goToIndex: index];
140+ };
141+ return cell;
142+ }else {
143+ ProjectReadMeCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_ProjectReadMeCell forIndexPath: indexPath];
144+ cell.curProject = _myProject;
145+ cell.cellHeightChangedBlock = ^(){
146+ [weakSelf.myTableView reloadSections: [NSIndexSet indexSetWithIndex: 2 ] withRowAnimation: UITableViewRowAnimationNone];
147+ // [weakSelf.myTableView reloadData];
148+ };
149+ cell.loadRequestBlock = ^(NSURLRequest *curRequest){
150+ [weakSelf loadRequest: curRequest];
128151 };
129152 return cell;
130153 }
@@ -149,8 +172,10 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
149172 if (_myProject.is_public .boolValue ) {
150173 if (indexPath.section == 0 ) {
151174 cellHeight = indexPath.row == 0 ? [ProjectInfoCell cellHeight ]: [ProjectDescriptionCell cellHeightWithObj: _myProject];
152- }else {
175+ }else if (indexPath. section == 1 ) {
153176 cellHeight = [ProjectItemsCell cellHeightWithObj: _myProject];
177+ }else {
178+ cellHeight = [ProjectReadMeCell cellHeightWithObj: _myProject];
154179 }
155180 }else {
156181 cellHeight = indexPath.row == 0 ? [ProjectInfoCell cellHeight ]: [ProjectItemsCell cellHeightWithObj: _myProject];
@@ -170,6 +195,24 @@ - (void)goToIndex:(NSInteger)index{
170195 [self .navigationController pushViewController: vc animated: YES ];
171196}
172197
198+ #pragma mark loadCellRequest
199+ - (void )loadRequest : (NSURLRequest *)curRequest {
200+ NSString *linkStr = curRequest.URL .absoluteString ;
201+ NSLog (@" \n linkStr : %@ " , linkStr);
202+ [self analyseLinkStr: linkStr];
203+ }
204+
205+ - (void )analyseLinkStr : (NSString *)linkStr {
206+ UIViewController *vc = [BaseViewController analyseVCFromLinkStr: linkStr];
207+ if (vc) {
208+ [self .navigationController pushViewController: vc animated: YES ];
209+ }else {
210+ // 跳转去网页
211+ WebViewController *webVc = [WebViewController webVCWithUrlStr: linkStr];
212+ [self .navigationController pushViewController: webVc animated: YES ];
213+ }
214+ }
215+
173216#pragma mark Git_Btn
174217- (void )gitButtonClicked : (NSInteger )index {
175218 __weak typeof (self) weakSelf = self;
@@ -194,20 +237,14 @@ - (void)gitButtonClicked:(NSInteger)index{
194237 break ;
195238 default :// Fork
196239 {
197- if (_myProject.forked .boolValue
198- || [_myProject.owner_user_name isEqualToString: [Login curLoginUser ].global_key]) {
199- return ;
200- }else {
201-
202- [[Coding_NetAPIManager sharedManager ] request_ForkProject: _myProject andBlock: ^(id data, NSError *error) {
203- [weakSelf.myTableView reloadSections: [NSIndexSet indexSetWithIndex: 0 ] withRowAnimation: UITableViewRowAnimationNone];
204- if (data) {
205- NProjectViewController *vc = [[NProjectViewController alloc ] init ];
206- vc.myProject = data;
207- [weakSelf.navigationController pushViewController: vc animated: YES ];
208- }
209- }];
210- }
240+ [[Coding_NetAPIManager sharedManager ] request_ForkProject: _myProject andBlock: ^(id data, NSError *error) {
241+ [weakSelf.myTableView reloadSections: [NSIndexSet indexSetWithIndex: 0 ] withRowAnimation: UITableViewRowAnimationNone];
242+ if (data) {
243+ NProjectViewController *vc = [[NProjectViewController alloc ] init ];
244+ vc.myProject = data;
245+ [weakSelf.navigationController pushViewController: vc animated: YES ];
246+ }
247+ }];
211248 }
212249 break ;
213250 }
0 commit comments