Skip to content

Commit 52aeb6a

Browse files
committed
Fork 列表
1 parent 79d0c2b commit 52aeb6a

File tree

11 files changed

+251
-4
lines changed

11 files changed

+251
-4
lines changed

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
4E095A831B6B24DE008DC439 /* task_description_icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E095A801B6B24DE008DC439 /* task_description_icon@2x.png */; };
7575
4E095A841B6B24DE008DC439 /* time_clock_icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E095A811B6B24DE008DC439 /* time_clock_icon@2x.png */; };
7676
4E095A851B6B24DE008DC439 /* topic_comment_icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E095A821B6B24DE008DC439 /* topic_comment_icon@2x.png */; };
77+
4E0B9A341BAC1CD100D57D54 /* ForkTreeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E0B9A331BAC1CD100D57D54 /* ForkTreeViewController.m */; };
78+
4E0B9A371BAD377600D57D54 /* ForkTreeCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E0B9A361BAD377600D57D54 /* ForkTreeCell.m */; };
7779
4E0BD8561B6C7DFD0061CAA6 /* UIView+Frame.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E0BD8551B6C7DFD0061CAA6 /* UIView+Frame.m */; };
7880
4E0BD86A1B6C7E3D0061CAA6 /* CSHotTopicView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E0BD8591B6C7E3D0061CAA6 /* CSHotTopicView.m */; };
7981
4E0BD86B1B6C7E3D0061CAA6 /* CSLikesVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E0BD85B1B6C7E3D0061CAA6 /* CSLikesVC.m */; };
@@ -1001,6 +1003,10 @@
10011003
4E095A801B6B24DE008DC439 /* task_description_icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "task_description_icon@2x.png"; sourceTree = "<group>"; };
10021004
4E095A811B6B24DE008DC439 /* time_clock_icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "time_clock_icon@2x.png"; sourceTree = "<group>"; };
10031005
4E095A821B6B24DE008DC439 /* topic_comment_icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "topic_comment_icon@2x.png"; sourceTree = "<group>"; };
1006+
4E0B9A321BAC1CD100D57D54 /* ForkTreeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ForkTreeViewController.h; sourceTree = "<group>"; };
1007+
4E0B9A331BAC1CD100D57D54 /* ForkTreeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ForkTreeViewController.m; sourceTree = "<group>"; };
1008+
4E0B9A351BAD377600D57D54 /* ForkTreeCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ForkTreeCell.h; sourceTree = "<group>"; };
1009+
4E0B9A361BAD377600D57D54 /* ForkTreeCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ForkTreeCell.m; sourceTree = "<group>"; };
10041010
4E0BD8541B6C7DFD0061CAA6 /* UIView+Frame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Frame.h"; sourceTree = "<group>"; };
10051011
4E0BD8551B6C7DFD0061CAA6 /* UIView+Frame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Frame.m"; sourceTree = "<group>"; };
10061012
4E0BD8581B6C7E3D0061CAA6 /* CSHotTopicView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSHotTopicView.h; sourceTree = "<group>"; };
@@ -3831,6 +3837,8 @@
38313837
4E93F2431B85C4C300017916 /* FileInfoViewController.xib */,
38323838
4E753D421B8AFDEC003A00B9 /* FileEditViewController.h */,
38333839
4E753D431B8AFDEC003A00B9 /* FileEditViewController.m */,
3840+
4E0B9A321BAC1CD100D57D54 /* ForkTreeViewController.h */,
3841+
4E0B9A331BAC1CD100D57D54 /* ForkTreeViewController.m */,
38343842
);
38353843
path = Controllers;
38363844
sourceTree = "<group>";
@@ -4586,6 +4594,8 @@
45864594
4EAE06B61B7B330900179F4B /* FileActivityCell.m */,
45874595
4EAE06C61B7C9EFF00179F4B /* FileVersionCell.h */,
45884596
4EAE06C71B7C9EFF00179F4B /* FileVersionCell.m */,
4597+
4E0B9A351BAD377600D57D54 /* ForkTreeCell.h */,
4598+
4E0B9A361BAD377600D57D54 /* ForkTreeCell.m */,
45894599
);
45904600
path = Cell;
45914601
sourceTree = "<group>";
@@ -5303,6 +5313,7 @@
53035313
4E72F82D1B144778001B6CE6 /* NSMutableString+Common.m in Sources */,
53045314
4E4D6A791B1C6C7800FD2E49 /* MRPRDetailCell.m in Sources */,
53055315
8EF643CA19FF7E2900F7EEB0 /* TopicContentCell.m in Sources */,
5316+
4E0B9A371BAD377600D57D54 /* ForkTreeCell.m in Sources */,
53065317
4E4D6A6A1B1C688200FD2E49 /* MRPRAcceptViewController.m in Sources */,
53075318
4ECE8AE81A3943E80021E29C /* UIView+Common.m in Sources */,
53085319
4EA7F15E1A6D192B00A046BD /* SDWebImageDownloaderOperation.m in Sources */,
@@ -5375,6 +5386,7 @@
53755386
4EA7F1601A6D192B00A046BD /* SDWebImagePrefetcher.m in Sources */,
53765387
4E4D6A941B1D851E00FD2E49 /* FileChanges.m in Sources */,
53775388
4E6BA2E81A1EE6AF005FD721 /* UIWebView+AFNetworking.m in Sources */,
5389+
4E0B9A341BAC1CD100D57D54 /* ForkTreeViewController.m in Sources */,
53785390
4E4D6A7F1B1C6D1E00FD2E49 /* CommitContentCell.m in Sources */,
53795391
8EA6D13519E240C40076D59C /* ProjectViewController.m in Sources */,
53805392
8EF643AB19FF7E2900F7EEB0 /* TagCCell.m in Sources */,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ForkTreeViewController.h
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/9/18.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#import "BaseViewController.h"
10+
11+
@interface ForkTreeViewController : BaseViewController
12+
@property (strong, nonatomic) NSString *project_owner_user_name, *project_name;
13+
@end
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//
2+
// ForkTreeViewController.m
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/9/18.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#import "ForkTreeViewController.h"
10+
#import "ODRefreshControl.h"
11+
#import "Coding_NetAPIManager.h"
12+
#import "ForkTreeCell.h"
13+
#import "NProjectViewController.h"
14+
15+
@interface ForkTreeViewController ()<UITableViewDataSource, UITableViewDelegate>
16+
@property (assign, nonatomic) BOOL isLoading;
17+
@property (strong, nonatomic) NSArray *forkList;
18+
@property (strong, nonatomic) UITableView *myTableView;
19+
@property (strong, nonatomic) ODRefreshControl *myRefreshControl;
20+
@end
21+
22+
@implementation ForkTreeViewController
23+
- (void)viewDidLoad{
24+
[super viewDidLoad];
25+
self.title = @"Fork项目的人";
26+
_myTableView = ({
27+
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
28+
tableView.backgroundColor = [UIColor clearColor];
29+
tableView.delegate = self;
30+
tableView.dataSource = self;
31+
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
32+
[tableView registerClass:[ForkTreeCell class] forCellReuseIdentifier:kCellIdentifier_ForkTreeCell];
33+
tableView.sectionIndexBackgroundColor = [UIColor clearColor];
34+
tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
35+
tableView.sectionIndexColor = [UIColor colorWithHexString:@"0x666666"];
36+
[self.view addSubview:tableView];
37+
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
38+
make.edges.equalTo(self.view);
39+
}];
40+
tableView;
41+
});
42+
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
43+
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
44+
[self refresh];
45+
}
46+
47+
- (void)refresh{
48+
if (_isLoading) {
49+
return;
50+
}
51+
if (!_forkList) {
52+
[self.view beginLoading];
53+
}
54+
__weak typeof(self) weakSelf = self;
55+
weakSelf.isLoading = YES;
56+
[[Coding_NetAPIManager sharedManager] request_ForkTreeWithOwner:_project_owner_user_name project:_project_name andBlock:^(id data, NSError *error) {
57+
weakSelf.isLoading = NO;
58+
[weakSelf.myRefreshControl endRefreshing];
59+
[weakSelf.view endLoading];
60+
if (data) {
61+
weakSelf.forkList = data;
62+
[weakSelf.myTableView reloadData];
63+
}
64+
}];
65+
}
66+
67+
#pragma mark T
68+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
69+
return 1;
70+
}
71+
72+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
73+
return _forkList.count;
74+
}
75+
76+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
77+
ForkTreeCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ForkTreeCell forIndexPath:indexPath];
78+
cell.project = _forkList[indexPath.row];
79+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
80+
return cell;
81+
}
82+
83+
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
84+
return [ForkTreeCell cellHeight];
85+
}
86+
87+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
88+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
89+
90+
Project *pro = _forkList[indexPath.row];
91+
pro.owner_user_name = pro.owner.global_key;
92+
93+
NProjectViewController *vc = [NProjectViewController new];
94+
vc.myProject = pro;
95+
[self.navigationController pushViewController:vc animated:YES];
96+
}
97+
98+
@end

Coding_iOS/Controllers/NProjectViewController/NProjectViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//#import "FileListViewController.h"
2525
//#import "FileViewController.h"
2626
#import "UsersViewController.h"
27+
#import "ForkTreeViewController.h"
2728

2829
#import "CodeViewController.h"
2930
#import "MRPRListViewController.h"
@@ -357,6 +358,10 @@ - (void)actionWithGitBtnIndex:(NSInteger)index{
357358
- (void)goToUsersWithGitBtnIndex:(NSInteger)index{
358359
if (index == 2) {
359360
//Fork
361+
ForkTreeViewController *vc = [ForkTreeViewController new];
362+
vc.project_owner_user_name = _myProject.owner_user_name;
363+
vc.project_name = _myProject.name;
364+
[self.navigationController pushViewController:vc animated:YES];
360365
NSString *path = [NSString stringWithFormat:@"api/user/%@/project/%@/git/forks", _myProject.owner_user_name, _myProject.name];
361366
NSLog(@"path: %@", path);
362367
}else{

Coding_iOS/Controllers/UsersViewController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ - (void)viewDidLoad{
6565
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(dismissSelf)];
6666
}
6767
break;
68+
case UsersTypeProjectStar:
69+
self.title = @"收藏项目的人";
70+
break;
71+
case UsersTypeProjectWatch:
72+
self.title = @"关注项目的人";
73+
break;
6874
default:
6975
break;
7076
}

Coding_iOS/Models/Project.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
@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, *recommended, *pin, *current_user_role_id;
1414
@property (assign, nonatomic) BOOL isStaring, isWatching, isLoadingMember, isLoadingDetail;
1515

16+
@property (strong, nonatomic) User *owner;
17+
@property (strong, nonatomic) NSDate *created_at;
18+
1619
+ (Project *)project_All;
1720
+ (Project *)project_FeedBack;
1821

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ typedef NS_ENUM(NSUInteger, VerifyType){
195195
- (void)request_ForkProject:(Project *)project andBlock:(void (^)(id data, NSError *error))block;
196196
- (void)request_ReadMeOFProject:(Project *)project andBlock:(void (^)(id data, NSError *error))block;
197197
- (void)request_FileDiffDetailWithPath:(NSString *)path andBlock:(void (^)(id data, NSError *error))block;
198+
- (void)request_ForkTreeWithOwner:(NSString *)owner_name project:(NSString *)project_name andBlock:(void (^)(id data, NSError *error))block;
198199

199200
//Image
200201
- (void)uploadTweetImage:(UIImage *)image

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,19 @@ - (void)request_FileDiffDetailWithPath:(NSString *)path andBlock:(void (^)(id da
20682068
}
20692069
}];
20702070
}
2071+
2072+
- (void)request_ForkTreeWithOwner:(NSString *)owner_name project:(NSString *)project_name andBlock:(void (^)(id data, NSError *error))block{
2073+
NSString *path = [NSString stringWithFormat:@"api/user/%@/project/%@/git/forks", owner_name, project_name];
2074+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) {
2075+
if (data) {
2076+
data = data[@"data"];
2077+
NSArray *resultA = [NSObject arrayFromJSON:data ofObjects:@"Project"];
2078+
block(resultA, nil);
2079+
}else{
2080+
block(nil, error);
2081+
}
2082+
}];
2083+
}
20712084
#pragma mark Image
20722085
- (void)uploadTweetImage:(UIImage *)image
20732086
doneBlock:(void (^)(NSString *imagePath, NSError *error))done

Coding_iOS/Views/Cell/ForkTreeCell.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// ForkTreeCell.h
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/9/19.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#define kCellIdentifier_ForkTreeCell @"ForkTreeCell"
10+
11+
#import <UIKit/UIKit.h>
12+
#import "Project.h"
13+
14+
@interface ForkTreeCell : UITableViewCell
15+
@property (strong, nonatomic) Project *project;
16+
+ (CGFloat)cellHeight;
17+
@end

Coding_iOS/Views/Cell/ForkTreeCell.m

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// ForkTreeCell.m
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/9/19.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#define kForkTreeCell_IconWidth 40.0
10+
11+
#import "ForkTreeCell.h"
12+
13+
@interface ForkTreeCell ()
14+
@property (nonatomic, strong) UIImageView *forkerIconView;
15+
@property (nonatomic, strong) UILabel *projectTitleLabel;
16+
@property (nonatomic, strong) UILabel *forkInfoLabel;
17+
18+
@end
19+
20+
@implementation ForkTreeCell
21+
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
22+
{
23+
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
24+
if (self) {
25+
// Initialization code
26+
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
27+
self.backgroundColor = [UIColor clearColor];
28+
if (!_forkerIconView) {
29+
_forkerIconView = [UIImageView new];
30+
_forkerIconView.layer.masksToBounds = YES;
31+
_forkerIconView.layer.cornerRadius = kForkTreeCell_IconWidth/2;
32+
[self.contentView addSubview:_forkerIconView];
33+
}
34+
35+
if (!_projectTitleLabel) {
36+
_projectTitleLabel = [UILabel new];
37+
_projectTitleLabel.textColor = [UIColor colorWithHexString:@"0x222222"];
38+
_projectTitleLabel.font = [UIFont systemFontOfSize:15];
39+
[self.contentView addSubview:_projectTitleLabel];
40+
}
41+
if (!_forkInfoLabel) {
42+
_forkInfoLabel = [UILabel new];
43+
_forkInfoLabel.textColor = [UIColor colorWithHexString:@"0x999999"];
44+
_forkInfoLabel.font = [UIFont systemFontOfSize:12];
45+
[self.contentView addSubview:_forkInfoLabel];
46+
}
47+
[_forkerIconView mas_makeConstraints:^(MASConstraintMaker *make) {
48+
make.centerY.equalTo(self.contentView);
49+
make.left.equalTo(self.contentView.mas_left).offset(kPaddingLeftWidth);
50+
make.size.mas_equalTo(CGSizeMake(kForkTreeCell_IconWidth, kForkTreeCell_IconWidth));
51+
}];
52+
[_projectTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
53+
make.top.equalTo(self.contentView).offset(5);
54+
make.height.mas_equalTo(20);
55+
make.left.equalTo(self.forkerIconView.mas_right).offset(20);
56+
make.right.lessThanOrEqualTo(self.contentView).offset(0);
57+
}];
58+
[_forkInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
59+
make.left.right.height.equalTo(self.projectTitleLabel);
60+
make.top.equalTo(self.projectTitleLabel.mas_bottom).offset(5);
61+
}];
62+
}
63+
return self;
64+
}
65+
66+
- (void)setProject:(Project *)project{
67+
_project = project;
68+
if (!_project) {
69+
return;
70+
}
71+
[_forkerIconView sd_setImageWithURL:[_project.owner.avatar urlImageWithCodePathResize:2*kForkTreeCell_IconWidth crop:YES] placeholderImage:kPlaceholderCodingSquareWidth(55.0)];
72+
_projectTitleLabel.text = _project.path;
73+
_forkInfoLabel.text = [NSString stringWithFormat:@"%@ Fork于 %@", _project.owner.name, [project.created_at stringDisplay_HHmm]];
74+
}
75+
76+
+ (CGFloat)cellHeight{
77+
return 60.0;
78+
}
79+
@end

Coding_iOS/Views/Cell/ProjectInfoCell.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,24 @@ - (void)layoutSubviews{
108108
BOOL is_recommended = _curProject.recommended.integerValue > 0;
109109
CGFloat titleWidth = [_proTitleL.text getWidthWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(CGFLOAT_MAX, 20)];
110110

111-
[_proImgView mas_makeConstraints:^(MASConstraintMaker *make) {
111+
[_proImgView mas_remakeConstraints:^(MASConstraintMaker *make) {
112112
make.left.equalTo(self.contentView.mas_left).offset(pading);
113113
make.centerY.equalTo(self.contentView.mas_centerY);
114114
make.size.mas_equalTo(CGSizeMake(kProjectInfoCell_ProImgViewWidth, kProjectInfoCell_ProImgViewWidth));
115115
}];
116-
[_proTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
116+
[_proTitleL mas_remakeConstraints:^(MASConstraintMaker *make) {
117117
make.left.equalTo(_proImgView.mas_right).offset(pading);
118118
make.width.mas_lessThanOrEqualTo(titleWidth);
119119
make.centerY.equalTo(_proImgView.mas_centerY).offset(-kProjectInfoCell_ProImgViewWidth/5);
120120
make.height.mas_equalTo(20);
121121
}];
122-
[_recommendedView mas_makeConstraints:^(MASConstraintMaker *make) {
122+
[_recommendedView mas_remakeConstraints:^(MASConstraintMaker *make) {
123123
make.right.mas_lessThanOrEqualTo(self.contentView.mas_right);
124124
make.left.equalTo(_proTitleL.mas_right).offset(5);
125125
make.centerY.equalTo(_proTitleL.mas_centerY);
126126
make.size.mas_equalTo(is_recommended? CGSizeMake(20, 20): CGSizeZero);
127127
}];
128-
[_proInfoL mas_makeConstraints:^(MASConstraintMaker *make) {
128+
[_proInfoL mas_remakeConstraints:^(MASConstraintMaker *make) {
129129
make.left.equalTo(_proTitleL);
130130
make.right.equalTo(self.contentView.mas_right);
131131
make.centerY.equalTo(_proImgView.mas_centerY).offset(kProjectInfoCell_ProImgViewWidth/5);

0 commit comments

Comments
 (0)