Skip to content

Commit 79d0c2b

Browse files
committed
拆分Git按钮 - Fork还未做
1 parent 60c8d23 commit 79d0c2b

File tree

11 files changed

+121
-47
lines changed

11 files changed

+121
-47
lines changed

Coding_iOS/Controllers/NProjectViewController/NProjectViewController.m

+20-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//#import "TopicDetailViewController.h"
2424
//#import "FileListViewController.h"
2525
//#import "FileViewController.h"
26+
#import "UsersViewController.h"
2627

2728
#import "CodeViewController.h"
2829
#import "MRPRListViewController.h"
@@ -70,8 +71,12 @@ - (void)viewDidLoad{
7071

7172
__weak typeof(self) weakSelf = self;
7273
_gitButtonsView = [EaseGitButtonsView new];
73-
_gitButtonsView.gitButtonClickedBlock = ^(NSInteger index){
74-
[weakSelf gitButtonClicked:index];
74+
_gitButtonsView.gitButtonClickedBlock = ^(NSInteger index, EaseGitButtonPosition position){
75+
if (position == EaseGitButtonPositionLeft) {
76+
[weakSelf actionWithGitBtnIndex:index];
77+
}else{
78+
[weakSelf goToUsersWithGitBtnIndex:index];
79+
}
7580
};
7681
[self.view addSubview:_gitButtonsView];
7782
[_gitButtonsView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -309,7 +314,7 @@ - (void)goTo_MR_PR{
309314
}
310315

311316
#pragma mark Git_Btn
312-
- (void)gitButtonClicked:(NSInteger)index{
317+
- (void)actionWithGitBtnIndex:(NSInteger)index{
313318
__weak typeof(self) weakSelf = self;
314319
switch (index) {
315320
case 0://Star
@@ -349,6 +354,18 @@ - (void)gitButtonClicked:(NSInteger)index{
349354
}
350355
}
351356

357+
- (void)goToUsersWithGitBtnIndex:(NSInteger)index{
358+
if (index == 2) {
359+
//Fork
360+
NSString *path = [NSString stringWithFormat:@"api/user/%@/project/%@/git/forks", _myProject.owner_user_name, _myProject.name];
361+
NSLog(@"path: %@", path);
362+
}else{
363+
UsersViewController *vc = [[UsersViewController alloc] init];
364+
vc.curUsers = [Users usersWithProjectOwner:_myProject.owner_user_name projectName:_myProject.name Type:UsersTypeProjectStar + index];
365+
[self.navigationController pushViewController:vc animated:YES];
366+
}
367+
}
368+
352369
- (void)refreshGitButtonsView{
353370
self.gitButtonsView.curProject = self.myProject;
354371
CGFloat gitButtonsViewHeight = 0;
Loading
Loading
Loading

Coding_iOS/Models/Users.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ typedef NS_ENUM(NSInteger, UsersType) {
1616
UsersTypeFriends_At,
1717
UsersTypeFriends_Transpond,
1818

19+
UsersTypeProjectStar,
20+
UsersTypeProjectWatch,
21+
1922
UsersTypeTweetLikers,
2023
UsersTypeAddToProject,
21-
UsersTypeAddFriend
24+
UsersTypeAddFriend,
2225
};
2326

2427
@interface Users : NSObject
@@ -28,6 +31,7 @@ typedef NS_ENUM(NSInteger, UsersType) {
2831
@property (readwrite, nonatomic, strong) NSMutableArray *list;
2932
@property (assign, nonatomic) UsersType type;
3033
@property (strong, nonatomic) User *owner;
34+
@property (strong, nonatomic) NSString *project_owner_name, *project_name;
3135

3236
- (NSString *)toPath;
3337
- (NSDictionary *)toParams;
@@ -36,4 +40,6 @@ typedef NS_ENUM(NSInteger, UsersType) {
3640
- (NSDictionary *)dictGroupedByPinyin;
3741

3842
+(Users *)usersWithOwner:(User *)owner Type:(UsersType)type;
43+
+(Users *)usersWithProjectOwner:(NSString *)owner_name projectName:(NSString *)name Type:(UsersType)type;
44+
3945
@end

Coding_iOS/Models/Users.m

+27-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ +(Users *)usersWithOwner:(User *)owner Type:(UsersType)type{
3030
return users;
3131
}
3232

33+
+(Users *)usersWithProjectOwner:(NSString *)owner_name projectName:(NSString *)name Type:(UsersType)type{
34+
Users *users = [[Users alloc] init];
35+
users.project_owner_name = owner_name;
36+
users.project_name = name;
37+
users.type = type;
38+
return users;
39+
}
40+
3341
- (NSString *)toPath{
3442
NSString *path;
3543
if (_type == UsersTypeFollowers) {
@@ -40,6 +48,11 @@ - (NSString *)toPath{
4048
if (_owner && _owner.global_key) {
4149
path = [path stringByAppendingFormat:@"/%@", _owner.global_key];
4250
}
51+
if (_type == UsersTypeProjectStar) {
52+
path = [NSString stringWithFormat:@"api/user/%@/project/%@/stargazers", _project_owner_name, _project_name];
53+
}else if (_type == UsersTypeProjectWatch){
54+
path = [NSString stringWithFormat:@"api/user/%@/project/%@/watchers", _project_owner_name, _project_name];
55+
}
4356
return path;
4457
}
4558

@@ -49,16 +62,21 @@ - (NSDictionary *)toParams{
4962
}
5063

5164
- (void)configWithObj:(Users *)resultA{
52-
self.page = resultA.page;
53-
self.pageSize = resultA.pageSize;
54-
self.totalPage = resultA.totalPage;
55-
self.totalRow = resultA.totalRow;
56-
if (_willLoadMore) {
57-
[self.list addObjectsFromArray:resultA.list];
58-
}else{
59-
self.list = [NSMutableArray arrayWithArray:resultA.list];
65+
if ([resultA isKindOfClass:[Users class]]) {
66+
self.page = resultA.page;
67+
self.pageSize = resultA.pageSize;
68+
self.totalPage = resultA.totalPage;
69+
self.totalRow = resultA.totalRow;
70+
if (_willLoadMore) {
71+
[self.list addObjectsFromArray:resultA.list];
72+
}else{
73+
self.list = [NSMutableArray arrayWithArray:resultA.list];
74+
}
75+
self.canLoadMore = self.page.intValue < self.totalPage.intValue;
76+
}else if ([resultA isKindOfClass:[NSArray class]]){
77+
self.list = [(NSArray *)resultA mutableCopy];
78+
self.canLoadMore = NO;
6079
}
61-
self.canLoadMore = self.page.intValue < self.totalPage.intValue;
6280
}
6381

6482
- (NSDictionary *)dictGroupedByPinyin{

Coding_iOS/Util/Common/EaseGitButton.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@
77
//
88

99
#import <UIKit/UIKit.h>
10-
typedef enum {
10+
typedef NS_ENUM(NSInteger, EaseGitButtonType) {
1111
EaseGitButtonTypeStar = 0,
1212
EaseGitButtonTypeWatch,
1313
EaseGitButtonTypeFork
14-
} EaseGitButtonType;
14+
};
15+
16+
typedef NS_ENUM(NSInteger, EaseGitButtonPosition) {
17+
EaseGitButtonPositionLeft = 0,
18+
EaseGitButtonPositionRight
19+
};
1520

1621
@interface EaseGitButton : UIButton
1722
@property (strong, nonatomic) NSString *normalTitle, *checkedTitle, *normalIcon, *checkedIcon;
1823
@property (strong, nonatomic) UIColor *normalBGColor, *checkedBGColor, *normalBorderColor, *checkedBorderColor;
1924
@property (nonatomic, assign) NSInteger userNum;
2025
@property (assign, nonatomic) BOOL checked;
2126
@property (assign, nonatomic) EaseGitButtonType type;
27+
@property (copy, nonatomic) void(^buttonClickedBlock)(EaseGitButton *button, EaseGitButtonPosition position);
2228

2329
- (instancetype)initWithFrame:(CGRect)frame
2430
normalTitle:(NSString *)normalTitle checkedTitle:(NSString *)checkedTitle

Coding_iOS/Util/Common/EaseGitButton.m

+30-15
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ - (instancetype)initWithFrame:(CGRect)frame
2828
self.layer.cornerRadius = 2.0;
2929
self.layer.borderWidth = 0.5;
3030

31-
CGFloat splitX = CGRectGetWidth(frame) *11/18;
31+
CGFloat splitX = floor(CGRectGetWidth(frame) *11/18);
3232
CGFloat frameHeight = CGRectGetHeight(frame);
3333
CGFloat fontSize = 11;
3434
if (kDevice_Is_iPhone6) {
@@ -37,8 +37,8 @@ - (instancetype)initWithFrame:(CGRect)frame
3737
fontSize = 14;
3838
}
3939

40-
_lineView = [[UIView alloc] initWithFrame:CGRectMake(splitX, frameHeight/3, 0.5, frameHeight/3)];
41-
_lineView.backgroundColor = [UIColor colorWithHexString:@"0xcacaca"];
40+
_lineView = [[UIView alloc] initWithFrame:CGRectMake(splitX, 0, 1, frameHeight)];
41+
_lineView.backgroundColor = [UIColor colorWithHexString:@"0xf8f8f8"];
4242
[self addSubview:_lineView];
4343

4444
_leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, splitX, frameHeight)];
@@ -58,7 +58,17 @@ - (instancetype)initWithFrame:(CGRect)frame
5858

5959
[self addSubview:_rightButton];
6060

61-
_leftButton.enabled = _rightButton.enabled = NO;
61+
__weak typeof(self) weakSelf = self;
62+
[_leftButton bk_addEventHandler:^(id sender) {
63+
if (weakSelf.buttonClickedBlock) {
64+
weakSelf.buttonClickedBlock(self, EaseGitButtonPositionLeft);
65+
}
66+
} forControlEvents:UIControlEventTouchUpInside];
67+
[_rightButton bk_addEventHandler:^(id sender) {
68+
if (weakSelf.buttonClickedBlock) {
69+
weakSelf.buttonClickedBlock(self, EaseGitButtonPositionRight);
70+
}
71+
} forControlEvents:UIControlEventTouchUpInside];
6272

6373
_normalTitle = normalTitle;
6474
_checkedTitle = checkedTitle? checkedTitle: normalTitle;
@@ -91,16 +101,17 @@ + (instancetype)gitButtonWithFrame:(CGRect)frame
91101

92102
+ (EaseGitButton *)gitButtonWithFrame:(CGRect)frame type:(EaseGitButtonType)type{
93103
EaseGitButton *button;
104+
UIColor *normalBGColor = [UIColor colorWithHexString:@"0xDDDDDD"];
94105
switch (type) {
95106
case EaseGitButtonTypeStar:
96-
button = [EaseGitButton gitButtonWithFrame:frame normalTitle:@" 收藏" checkedTitle:@" 已收藏" normalIcon:@"git_icon_star" checkedIcon:@"git_icon_stared" normalBGColor:nil checkedBGColor:[UIColor colorWithHexString:@"0x3BBD79"] normalBorderColor:[UIColor colorWithHexString:@"0xB5B5B5"] checkedBorderColor:nil userNum:0 checked:NO];
107+
button = [EaseGitButton gitButtonWithFrame:frame normalTitle:@" 收藏" checkedTitle:@" 已收藏" normalIcon:@"git_icon_star" checkedIcon:@"git_icon_stared" normalBGColor:normalBGColor checkedBGColor:[UIColor colorWithHexString:@"0x3BBD79"] normalBorderColor:nil checkedBorderColor:nil userNum:0 checked:NO];
97108
break;
98109
case EaseGitButtonTypeWatch:
99-
button = [EaseGitButton gitButtonWithFrame:frame normalTitle:@" 关注" checkedTitle:@" 已关注" normalIcon:@"git_icon_watch" checkedIcon:@"git_icon_watched" normalBGColor:nil checkedBGColor:[UIColor colorWithHexString:@"0x4E90BF"] normalBorderColor:[UIColor colorWithHexString:@"0xB5B5B5"] checkedBorderColor:nil userNum:0 checked:NO];
110+
button = [EaseGitButton gitButtonWithFrame:frame normalTitle:@" 关注" checkedTitle:@" 已关注" normalIcon:@"git_icon_watch" checkedIcon:@"git_icon_watched" normalBGColor:normalBGColor checkedBGColor:[UIColor colorWithHexString:@"0x4E90BF"] normalBorderColor:nil checkedBorderColor:nil userNum:0 checked:NO];
100111
break;
101112
case EaseGitButtonTypeFork:
102113
default:
103-
button = [EaseGitButton gitButtonWithFrame:frame normalTitle:@" Fork" checkedTitle:@" Fork" normalIcon:@"git_icon_fork" checkedIcon:nil normalBGColor:nil checkedBGColor:nil normalBorderColor:[UIColor colorWithHexString:@"0xB5B5B5"] checkedBorderColor:[UIColor colorWithHexString:@"0xB5B5B5"] userNum:0 checked:NO];
114+
button = [EaseGitButton gitButtonWithFrame:frame normalTitle:@" Fork" checkedTitle:@" Fork" normalIcon:@"git_icon_fork" checkedIcon:nil normalBGColor:normalBGColor checkedBGColor:normalBGColor normalBorderColor:nil checkedBorderColor:nil userNum:0 checked:NO];
104115
break;
105116
}
106117
button.type = type;
@@ -109,23 +120,27 @@ + (EaseGitButton *)gitButtonWithFrame:(CGRect)frame type:(EaseGitButtonType)type
109120

110121
- (void)updateContent{
111122
if (_checked) {
112-
[_leftButton setTitle:_checkedTitle forState:UIControlStateNormal | UIControlStateDisabled];
113-
[_leftButton setImage:[UIImage imageNamed:_checkedIcon] forState:UIControlStateNormal | UIControlStateDisabled];
123+
[_leftButton setTitle:_checkedTitle forState:UIControlStateNormal];
124+
[_leftButton setImage:[UIImage imageNamed:_checkedIcon] forState:UIControlStateNormal];
114125

115126
self.backgroundColor = _checkedBGColor;
116127
self.layer.borderColor = _checkedBorderColor.CGColor;
117128
}else{
118-
[_leftButton setTitle:_normalTitle forState:UIControlStateNormal | UIControlStateDisabled];
119-
[_leftButton setImage:[UIImage imageNamed:_normalIcon] forState:UIControlStateNormal | UIControlStateDisabled];
129+
[_leftButton setTitle:_normalTitle forState:UIControlStateNormal];
130+
[_leftButton setImage:[UIImage imageNamed:_normalIcon] forState:UIControlStateNormal];
120131

121132
self.backgroundColor = _normalBGColor;
122133
self.layer.borderColor = _normalBorderColor.CGColor;
123-
134+
135+
}
136+
UIColor *titleColor = [UIColor colorWithHexString:!_checked? @"0x222222": @"0xffffff"];
137+
if (self.type == EaseGitButtonTypeFork) {
138+
titleColor = [UIColor colorWithHexString:@"0x222222"];
124139
}
125-
[_leftButton setTitleColor:[UIColor colorWithHexString:self.backgroundColor == [UIColor clearColor]? @"0x222222": @"0xffffff"] forState:UIControlStateNormal | UIControlStateDisabled];
126-
[_rightButton setTitleColor:[UIColor colorWithHexString:self.backgroundColor == [UIColor clearColor]? @"0x222222": @"0xffffff"] forState:UIControlStateNormal | UIControlStateDisabled];
140+
[_leftButton setTitleColor:titleColor forState:UIControlStateNormal];
141+
[_rightButton setTitleColor:titleColor forState:UIControlStateNormal];
127142

128-
[_rightButton setTitle:[NSString stringWithFormat:@"%ld", (long)_userNum] forState:UIControlStateNormal | UIControlStateDisabled];
143+
[_rightButton setTitle:[NSString stringWithFormat:@"%ld", (long)_userNum] forState:UIControlStateNormal];
129144
}
130145

131146
#pragma mark Set

Coding_iOS/Util/Common/EaseGitButtonsView.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
//
88

99
#define EaseGitButtonsView_Height 49.0
10+
#import "EaseGitButton.h"
1011

1112
#import <UIKit/UIKit.h>
1213
#import "Project.h"
1314

1415
@interface EaseGitButtonsView : UIView
1516

1617
@property (strong, nonatomic) Project *curProject;
17-
@property (nonatomic, copy) void(^gitButtonClickedBlock)(NSInteger index);
18+
@property (copy, nonatomic) void(^gitButtonClickedBlock)(NSInteger index, EaseGitButtonPosition position);
1819

1920
@end

Coding_iOS/Util/Common/EaseGitButtonsView.m

+11-8
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,20 @@ - (void)setCurProject:(Project *)curProject{
3737

3838
for (int i = 0; i < gitBtnNum; i++) {
3939
EaseGitButton *gitBtn = [EaseGitButton gitButtonWithFrame:CGRectMake(kPaddingLeftWidth + i *(btnWidth +whiteSpace),(EaseGitButtonsView_Height - 30)/2, btnWidth, 30) type:i];
40-
41-
[gitBtn bk_addEventHandler:^(EaseGitButton *sender) {
42-
if (sender.type == EaseGitButtonTypeStar
43-
|| sender.type == EaseGitButtonTypeWatch) {
44-
gitBtn.checked = !gitBtn.checked;
45-
gitBtn.userNum += gitBtn.checked? 1: -1;
40+
__weak typeof(gitBtn) weakGitBtn = gitBtn;
41+
gitBtn.buttonClickedBlock = ^(EaseGitButton *button, EaseGitButtonPosition position){
42+
if (position == EaseGitButtonPositionLeft) {
43+
if (button.type == EaseGitButtonTypeStar
44+
|| button.type == EaseGitButtonTypeWatch) {
45+
weakGitBtn.checked = !weakGitBtn.checked;
46+
weakGitBtn.userNum += weakGitBtn.checked? 1: -1;
47+
}
4648
}
4749
if (self.gitButtonClickedBlock) {
48-
self.gitButtonClickedBlock(i);
50+
self.gitButtonClickedBlock(i, position);
4951
}
50-
} forControlEvents:UIControlEventTouchUpInside];
52+
};
53+
5154
[self addSubview:gitBtn];
5255
[_gitButtons addObject:gitBtn];
5356
}

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

+16-8
Original file line numberDiff line numberDiff line change
@@ -1661,21 +1661,29 @@ - (void)request_ResetPassword_WithObj:(User *)curUser andBlock:(void (^)(id data
16611661
}
16621662
- (void)request_FollowersOrFriends_WithObj:(Users *)curUsers andBlock:(void (^)(id data, NSError *error))block{
16631663
curUsers.isLoading = YES;
1664-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[curUsers toPath] withParams:[curUsers toParams] withMethodType:Get andBlock:^(id data, NSError *error) {
1664+
NSString *path = [curUsers toPath];
1665+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:[curUsers toParams] withMethodType:Get andBlock:^(id data, NSError *error) {
16651666
curUsers.isLoading = NO;
16661667
if (data) {
16671668
[MobClick event:kUmeng_Event_Request_Get label:@"关注or粉丝列表"];
16681669

16691670
id resultData = [data valueForKeyPath:@"data"];
1670-
User *loginUser = [Login curLoginUser];
1671-
if (resultData
1672-
&& loginUser
1673-
&& (!curUsers.owner||
1674-
(curUsers.owner && curUsers.owner.global_key && [curUsers.owner.global_key isEqualToString:loginUser.global_key]))) {
1671+
1672+
if ([path hasSuffix:@"friends"] && resultData) {//AT某人时的列表数据,要保存在本地
1673+
User *loginUser = [Login curLoginUser];
1674+
if (loginUser) {
16751675
[NSObject saveResponseData:resultData toPath:[loginUser localFriendsPath]];
16761676
}
1677-
Users *users = [NSObject objectOfClass:@"Users" fromJSON:resultData];
1678-
block(users, nil);
1677+
}
1678+
1679+
//处理数据
1680+
NSObject *resultA = nil;
1681+
if ([path hasSuffix:@"stargazers"] || [path hasSuffix:@"watchers"]) {
1682+
resultA = [NSArray arrayFromJSON:resultData ofObjects:@"User"];
1683+
}else{
1684+
resultA = [NSObject objectOfClass:@"Users" fromJSON:resultData];
1685+
}
1686+
block(resultA, nil);
16791687
}else{
16801688
block(nil, error);
16811689
}

0 commit comments

Comments
 (0)