Skip to content

Commit b621af8

Browse files
committed
共有项目-README
1 parent 7ee79f6 commit b621af8

File tree

12 files changed

+250
-42
lines changed

12 files changed

+250
-42
lines changed

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
4E6D718D1A762879005AD988 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E6D718B1A762879005AD988 /* [email protected] */; };
9090
4E6D718E1A762879005AD988 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E6D718C1A762879005AD988 /* [email protected] */; };
9191
4E6FFAF61AB2BF4100F27B3F /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E6FFAF51AB2BF4100F27B3F /* [email protected] */; };
92+
4E6FFB311AB3176900F27B3F /* ProjectReadMeCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6FFB301AB3176900F27B3F /* ProjectReadMeCell.m */; };
9293
4E743E691A8866E300DADDE5 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E743E671A8866E300DADDE5 /* [email protected] */; };
9394
4E743E6A1A8866E300DADDE5 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E743E681A8866E300DADDE5 /* [email protected] */; };
9495
4E743E6D1A88A3CC00DADDE5 /* EaseMarkdownTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E743E6C1A88A3CC00DADDE5 /* EaseMarkdownTextView.m */; };
@@ -685,6 +686,8 @@
685686
4E6D718B1A762879005AD988 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
686687
4E6D718C1A762879005AD988 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
687688
4E6FFAF51AB2BF4100F27B3F /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
689+
4E6FFB2F1AB3176900F27B3F /* ProjectReadMeCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectReadMeCell.h; sourceTree = "<group>"; };
690+
4E6FFB301AB3176900F27B3F /* ProjectReadMeCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProjectReadMeCell.m; sourceTree = "<group>"; };
688691
4E743E671A8866E300DADDE5 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
689692
4E743E681A8866E300DADDE5 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
690693
4E743E6B1A88A3CC00DADDE5 /* EaseMarkdownTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EaseMarkdownTextView.h; sourceTree = "<group>"; };
@@ -2852,6 +2855,8 @@
28522855
4E1A22841AB172C400CFC14F /* ProjectItemsCell.m */,
28532856
4E1A22861AB1731600CFC14F /* ProjectDescriptionCell.h */,
28542857
4E1A22871AB1731600CFC14F /* ProjectDescriptionCell.m */,
2858+
4E6FFB2F1AB3176900F27B3F /* ProjectReadMeCell.h */,
2859+
4E6FFB301AB3176900F27B3F /* ProjectReadMeCell.m */,
28552860
);
28562861
path = Cell;
28572862
sourceTree = "<group>";
@@ -3466,6 +3471,7 @@
34663471
4E59E1D31A5E6B34004DAEEC /* TaskDescriptionViewController.m in Sources */,
34673472
4ECE8AFD1A3946C10021E29C /* AddressManager.m in Sources */,
34683473
8E1C3DED19E7D58A00EF3032 /* ActionSheetDistancePicker.m in Sources */,
3474+
4E6FFB311AB3176900F27B3F /* ProjectReadMeCell.m in Sources */,
34693475
8E59F0F41A00F3B9009A905F /* ProjectCodeListCell.m in Sources */,
34703476
8E59F0F71A00F3E2009A905F /* ProjectFolderListCell.m in Sources */,
34713477
8EA6D1C319E240C40076D59C /* User.m in Sources */,

Coding_iOS/Controllers/NProjectViewController/NProjectViewController.m

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
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
}

Coding_iOS/Models/Projects.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ typedef NS_ENUM(NSInteger, ProjectsType)
5050
@property (readwrite, nonatomic, strong) NSNumber *id, *owner_id, *is_public, *un_read_activities_count, *done, *processing, *star_count, *stared, *watch_count, *watched, *fork_count, *forked;
5151
@property (assign, nonatomic) BOOL isStaring, isWatching, isLoadingMember, isLoadingDetail;
5252

53+
@property (strong, nonatomic) NSString *readMeHtml;
54+
@property (assign, nonatomic) CGFloat readMeHeight;
55+
5356
+(Project *)project_All;
5457

5558
- (NSString *)toMembersPath;

Coding_iOS/Models/Projects.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ - (instancetype)init
8282
self = [super init];
8383
if (self) {
8484
_isStaring = _isWatching = _isLoadingMember = _isLoadingDetail = NO;
85+
_readMeHeight = 20;
8586
}
8687
return self;
8788
}

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
- (void)request_StarProject:(Project *)project andBlock:(void (^)(id data, NSError *error))block;
124124
- (void)request_WatchProject:(Project *)project andBlock:(void (^)(id data, NSError *error))block;
125125
- (void)request_ForkProject:(Project *)project andBlock:(void (^)(id data, NSError *error))block;
126+
- (void)request_ReadMeOFProject:(Project *)project andBlock:(void (^)(id data, NSError *error))block;
126127

127128
//Image
128129
- (void)uploadUserIconImage:(UIImage *)image

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,18 @@ - (void)request_ForkProject:(Project *)project andBlock:(void (^)(id data, NSErr
12731273
}
12741274
}];
12751275
}
1276-
1276+
- (void)request_ReadMeOFProject:(Project *)project andBlock:(void (^)(id data, NSError *error))block{
1277+
[MobClick event:kUmeng_Event_Request label:@"项目_README"];
1278+
NSString *path = [NSString stringWithFormat:@"api/user/%@/project/%@/git/tree/master",project.owner_user_name, project.name];
1279+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) {
1280+
if (data) {
1281+
NSString *readMeHtml = [[[data valueForKey:@"data"] valueForKey:@"readme"] valueForKey:@"preview"];
1282+
block(readMeHtml, nil);
1283+
}else{
1284+
block(nil, error);
1285+
}
1286+
}];
1287+
}
12771288
//Image
12781289
- (void)uploadUserIconImage:(UIImage *)image
12791290
successBlock:(void (^)(NSString *imagePath))success

Coding_iOS/Views/Cell/ProjectDescriptionCell.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (void)setCurProject:(Project *)curProject{
7979
default:
8080
{
8181
obj.userNum = _curProject.fork_count.integerValue;
82-
obj.checked = _curProject.stared.boolValue;
82+
obj.checked = _curProject.forked.boolValue;
8383
}
8484
break;
8585
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// ProjectReadMeCell.h
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/3/13.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#define kCellIdentifier_ProjectReadMeCell @"ProjectReadMeCell"
10+
11+
#import <UIKit/UIKit.h>
12+
#import "Projects.h"
13+
14+
@interface ProjectReadMeCell : UITableViewCell
15+
@property (nonatomic, strong) Project *curProject;
16+
@property (nonatomic, copy) void (^loadRequestBlock)(NSURLRequest *curRequest);
17+
@property (nonatomic, copy) void (^cellHeightChangedBlock)();
18+
+ (CGFloat)cellHeightWithObj:(id)obj;
19+
@end

0 commit comments

Comments
 (0)