-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathEaseGitButtonsView.m
88 lines (78 loc) · 2.91 KB
/
EaseGitButtonsView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// EaseGitButtonsView.m
// Coding_iOS
//
// Created by Ease on 15/5/29.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "EaseGitButtonsView.h"
#import "EaseGitButton.h"
@interface EaseGitButtonsView ()
@property (strong, nonatomic) NSMutableArray *gitButtons;
@end
@implementation EaseGitButtonsView
- (instancetype)init
{
self = [super init];
if (self) {
[self addLineUp:YES andDown:NO];
self.backgroundColor = kColorWhite;
}
return self;
}
- (void)setCurProject:(Project *)curProject{
_curProject = curProject;
if (_curProject.is_public.boolValue) {
if (!_gitButtons) {
NSInteger gitBtnNum = 3;
CGFloat whiteSpace = 7.0;
CGFloat btnWidth = (kScreen_Width - 2*kPaddingLeftWidth - whiteSpace *2) /3;
_gitButtons = [[NSMutableArray alloc] initWithCapacity:gitBtnNum];
for (int i = 0; i < gitBtnNum; i++) {
EaseGitButton *gitBtn = [EaseGitButton gitButtonWithFrame:CGRectMake(kPaddingLeftWidth + i *(btnWidth +whiteSpace),(EaseGitButtonsView_Height - kSafeArea_Bottom - 36)/2, btnWidth, 36) type:i];
__weak typeof(gitBtn) weakGitBtn = gitBtn;
gitBtn.buttonClickedBlock = ^(EaseGitButton *button, EaseGitButtonPosition position){
if (position == EaseGitButtonPositionLeft) {
if (button.type == EaseGitButtonTypeStar
|| button.type == EaseGitButtonTypeWatch) {
weakGitBtn.checked = !weakGitBtn.checked;
weakGitBtn.userNum += weakGitBtn.checked? 1: -1;
}
}
if (self.gitButtonClickedBlock) {
self.gitButtonClickedBlock(i, position);
}
};
[self addSubview:gitBtn];
[_gitButtons addObject:gitBtn];
}
}
[_gitButtons enumerateObjectsUsingBlock:^(EaseGitButton *obj, NSUInteger idx, BOOL *stop) {
switch (idx) {
case EaseGitButtonTypeStar:
{
obj.userNum = _curProject.star_count.integerValue;
obj.checked = _curProject.stared.boolValue;
}
break;
case EaseGitButtonTypeWatch:
{
obj.userNum = _curProject.watch_count.integerValue;
obj.checked = _curProject.watched.boolValue;
}
break;
case EaseGitButtonTypeFork:
default:
{
obj.userNum = _curProject.fork_count.integerValue;
obj.checked = NO;
}
break;
}
}];
self.hidden = NO;
}else{
self.hidden = YES;
}
}
@end