Skip to content

Commit 548f8e3

Browse files
committed
讨论改版 - 还要改
1 parent b2bebb3 commit 548f8e3

13 files changed

+107
-2
lines changed

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@
368368
4E6CBE4B1D8E71DC00644086 /* TopicAnswerCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6CBE4A1D8E71DC00644086 /* TopicAnswerCell.m */; };
369369
4E6CBE4E1D8E7E8000644086 /* TopicAnswerCommentMoreCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6CBE4D1D8E7E8000644086 /* TopicAnswerCommentMoreCell.m */; };
370370
4E6CBE511D8E962300644086 /* TopicAnswerDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6CBE501D8E962300644086 /* TopicAnswerDetailViewController.m */; };
371+
4E6CBE541D8EA9D100644086 /* icon_best_answer@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E6CBE521D8EA9D100644086 /* icon_best_answer@2x.png */; };
372+
4E6CBE551D8EA9D100644086 /* icon_best_answer@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E6CBE531D8EA9D100644086 /* icon_best_answer@3x.png */; };
371373
4E6D71891A75F00E005AD988 /* YLGIFImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6D71861A75F00E005AD988 /* YLGIFImage.m */; };
372374
4E6D718A1A75F00E005AD988 /* YLImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6D71881A75F00E005AD988 /* YLImageView.m */; };
373375
4E6FB0551B5799B100B0A17B /* ProjectTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6FB0541B5799B100B0A17B /* ProjectTag.m */; };
@@ -1696,6 +1698,8 @@
16961698
4E6CBE4D1D8E7E8000644086 /* TopicAnswerCommentMoreCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopicAnswerCommentMoreCell.m; sourceTree = "<group>"; };
16971699
4E6CBE4F1D8E962300644086 /* TopicAnswerDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopicAnswerDetailViewController.h; sourceTree = "<group>"; };
16981700
4E6CBE501D8E962300644086 /* TopicAnswerDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopicAnswerDetailViewController.m; sourceTree = "<group>"; };
1701+
4E6CBE521D8EA9D100644086 /* icon_best_answer@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_best_answer@2x.png"; sourceTree = "<group>"; };
1702+
4E6CBE531D8EA9D100644086 /* icon_best_answer@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_best_answer@3x.png"; sourceTree = "<group>"; };
16991703
4E6D71851A75F00E005AD988 /* YLGIFImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLGIFImage.h; sourceTree = "<group>"; };
17001704
4E6D71861A75F00E005AD988 /* YLGIFImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YLGIFImage.m; sourceTree = "<group>"; };
17011705
4E6D71871A75F00E005AD988 /* YLImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLImageView.h; sourceTree = "<group>"; };
@@ -4970,6 +4974,8 @@
49704974
4ECEFA001D1D0B4B002A27D3 /* tip_bg@2x.png */,
49714975
4ECEFA011D1D0B4B002A27D3 /* tip_bg@3x.png */,
49724976
4E59D3301D409C8C008C914B /* topic_add_watcher_btn@2x.png */,
4977+
4E6CBE521D8EA9D100644086 /* icon_best_answer@2x.png */,
4978+
4E6CBE531D8EA9D100644086 /* icon_best_answer@3x.png */,
49734979
);
49744980
path = Images;
49754981
sourceTree = "<group>";
@@ -5875,6 +5881,7 @@
58755881
8E97CE721A0B8C6C006F9AD7 /* emotion_list.plist in Resources */,
58765882
4EC461B21B39360F00D08970 /* file_changeType_ADD@2x.png in Resources */,
58775883
13FB5D3E1CA17A6400EE127C /* EPointLikeHead@1x.png in Resources */,
5884+
4E6CBE541D8EA9D100644086 /* icon_best_answer@2x.png in Resources */,
58785885
4E4D6ACC1B2571B100FD2E49 /* git_icon_watched@2x.png in Resources */,
58795886
8E97CEB11A0C7E26006F9AD7 /* coding_emoji_26@2x.png in Resources */,
58805887
8E97CEBA1A0C7E26006F9AD7 /* coding_emoji_35@2x.png in Resources */,
@@ -6186,6 +6193,7 @@
61866193
8EA6D19719E240C40076D59C /* tipIcon_Project@2x.png in Resources */,
61876194
D0C447CF1C02DB6700DC1C4B /* pop_Task@3x.png in Resources */,
61886195
4EB52F1F1C76BA3B00B5EBEA /* tag_button_editColor@2x.png in Resources */,
6196+
4E6CBE551D8EA9D100644086 /* icon_best_answer@3x.png in Resources */,
61896197
4EF17ED31B3C3112003CDD2D /* intro_icon_2@2x.png in Resources */,
61906198
4ECEFA031D1D0B4B002A27D3 /* tip_bg@3x.png in Resources */,
61916199
D0C448091C02DCAC00DC1C4B /* addUserBtn_Nav@3x.png in Resources */,

Coding_iOS/Controllers/TopicAnswerDetailViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
169169
TopicCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:toComment.htmlMedia.imageItems.count > 0? kCellIdentifier_TopicComment_Media: kCellIdentifier_TopicComment forIndexPath:indexPath];
170170
cell.toComment = toComment;
171171
cell.isAnswer = indexPath.row == 0;
172+
cell.projectId = _curTopic.project.id;
172173
cell.contentLabel.delegate = self;
173174
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth + (indexPath.row == 0? 0: 40) hasSectionLine:YES];
174175
return cell;

Coding_iOS/Controllers/TopicDetailViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
348348

349349
TopicAnswerCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TopicAnswerCell forIndexPath:indexPath];
350350
cell.curAnswer = toComment;
351+
cell.projectId = _curTopic.project.id;
351352
cell.linkStrBlock = ^(NSString *linkStr){
352353
[weakSelf analyseLinkStr:linkStr];
353354
};
474 Bytes
Loading
698 Bytes
Loading

Coding_iOS/Models/ProjectTopic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@
6565

6666
- (BOOL)canEdit;
6767
- (NSInteger)commentsDisplayNum;
68+
- (void)change_is_up_voted;
6869
@end

Coding_iOS/Models/ProjectTopic.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,26 @@ - (BOOL)canEdit
201201
- (NSInteger)commentsDisplayNum{
202202
return MIN(_child_comments.count, 2);
203203
}
204+
- (void)change_is_up_voted{
205+
_is_up_voted = @(!self.is_up_voted.boolValue);
206+
if (_is_up_voted.boolValue) {//原来没有,现在需要添加
207+
if (!_up_vote_users) {
208+
_up_vote_users = @[].mutableCopy;
209+
}
210+
[_up_vote_users addObject:[Login curLoginUser]];
211+
_up_vote_counts = @(_up_vote_counts.integerValue + 1);
212+
}else{//原来有,现在需要移除
213+
User *meUser = nil;
214+
for (User *user in _up_vote_users) {
215+
if ([user.global_key isEqualToString:[Login curLoginUser].global_key]) {
216+
meUser = user;
217+
break;
218+
}
219+
}
220+
if (meUser) {
221+
[_up_vote_users removeObject:meUser];
222+
_up_vote_counts = @(_up_vote_counts.integerValue - 1);
223+
}
224+
}
225+
}
204226
@end

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ typedef NS_ENUM(NSInteger, PurposeType) {
171171
- (void)request_AddProjectTpoic:(ProjectTopic *)proTopic andBlock:(void (^)(id data, NSError *error))block;
172172
- (void)request_Comments_WithProjectTpoic:(ProjectTopic *)proTopic andBlock:(void (^)(id data, NSError *error))block;
173173
- (void)request_Comments_WithAnswer:(ProjectTopic *)proTopic inProjectId:(NSNumber *)projectId andBlock:(void (^)(id data, NSError *error))block;
174+
- (void)request_UpvoteAnswer:(ProjectTopic *)proTopic inProjectId:(NSNumber *)projectId andBlock:(void (^)(id data, NSError *error))block;
174175
- (void)request_DoComment_WithProjectTpoic:(ProjectTopic *)proTopic andAnswerId:(NSNumber *)answerId andBlock:(void (^)(id data, NSError *error))block;
175176
- (void)request_ProjectTopic_Delete_WithObj:(ProjectTopic *)proTopic andBlock:(void (^)(id data, NSError *error))block;
176177
- (void)request_ProjectTopicComment_Delete_WithObj:(ProjectTopic *)proTopic projectId:(NSNumber *)projectId andBlock:(void (^)(id data, NSError *error))block;

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,21 @@ - (void)request_Comments_WithAnswer:(ProjectTopic *)proTopic inProjectId:(NSNumb
15881588
}
15891589
}];
15901590
}
1591+
1592+
- (void)request_UpvoteAnswer:(ProjectTopic *)proTopic inProjectId:(NSNumber *)projectId andBlock:(void (^)(id data, NSError *error))block{
1593+
NSString *path = [NSString stringWithFormat:@"api/project/%@/topic/%@/comment/%@/upvote", projectId, proTopic.parent_id, proTopic.id];
1594+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:nil withMethodType:proTopic.is_up_voted.boolValue? Delete: Post andBlock:^(id data, NSError *error) {
1595+
if (data) {
1596+
[MobClick event:kUmeng_Event_Request_Get label:@"讨论_答案_点赞"];
1597+
1598+
[proTopic change_is_up_voted];
1599+
block(data, nil);
1600+
}else{
1601+
block(nil, error);
1602+
}
1603+
}];
1604+
1605+
}
15911606
- (void)request_DoComment_WithProjectTpoic:(ProjectTopic *)proTopic andAnswerId:(NSNumber *)answerId andBlock:(void (^)(id data, NSError *error))block{
15921607
NSMutableDictionary *params = @{@"content" : [proTopic.nextCommentStr aliasedString]}.mutableCopy;
15931608
params[@"type"] = answerId? @1: @0;

Coding_iOS/Views/Cell/TopicAnswerCell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
@interface TopicAnswerCell : UITableViewCell
1414
@property (strong, nonatomic) ProjectTopic *curAnswer;
15+
@property (strong, nonatomic) NSNumber *projectId;
1516

1617
@property (copy, nonatomic) void(^linkStrBlock)(NSString *linkStr);
1718
@property (copy, nonatomic) void(^commentClickedBlock)(ProjectTopic *curAnswer, ProjectTopic *toComment, id sender);

Coding_iOS/Views/Cell/TopicAnswerCell.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
9292
TopicCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:toComment.htmlMedia.imageItems.count > 0? kCellIdentifier_TopicComment_Media: kCellIdentifier_TopicComment forIndexPath:indexPath];
9393
cell.toComment = toComment;
9494
cell.isAnswer = indexPath.row == 0;
95+
cell.projectId = _projectId;
9596
cell.contentLabel.delegate = self;
9697
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:leftSpace hasSectionLine:NO];
9798
return cell;

Coding_iOS/Views/Cell/TopicCommentCell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@property (strong, nonatomic) ProjectTopic *toComment;
1717
@property (strong, nonatomic) UITTTAttributedLabel *contentLabel;
1818
@property (assign, nonatomic) BOOL isAnswer;
19+
@property (strong, nonatomic) NSNumber *projectId;
1920
+ (CGFloat)cellHeightWithObj:(id)obj;
2021

2122
@end

Coding_iOS/Views/Cell/TopicCommentCell.m

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
#import "TopicCommentCCell.h"
1515

1616
#import "MJPhotoBrowser.h"
17+
#import "Coding_NetAPIManager.h"
1718

1819
@interface TopicCommentCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
1920
@property (strong, nonatomic) UIImageView *ownerIconView;
21+
@property (strong, nonatomic) UIView *bestAnswerV;
22+
@property (strong, nonatomic) UIButton *voteBtn;
2023
@property (strong, nonatomic) UILabel *timeLabel;
2124
@property (strong, nonatomic) UICustomCollectionView *imageCollectionView;
2225
@end
@@ -29,12 +32,40 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
2932
if (self) {
3033
// Initialization code
3134
self.backgroundColor = [UIColor clearColor];
35+
if (!_bestAnswerV) {
36+
_bestAnswerV = [[UIView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 0, 80, 24)];
37+
_bestAnswerV.backgroundColor = kColorBrandGreen;
38+
UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_best_answer"]];
39+
[_bestAnswerV addSubview:imageV];
40+
UILabel *label = [UILabel labelWithSystemFontSize:11 textColorHexString:@"0xFFFFFF"];
41+
label.textAlignment = NSTextAlignmentCenter;
42+
label.text = @"最佳答案";
43+
[_bestAnswerV addSubview:label];
44+
[imageV mas_makeConstraints:^(MASConstraintMaker *make) {
45+
make.centerY.equalTo(_bestAnswerV);
46+
make.left.equalTo(_bestAnswerV).offset(10);
47+
make.size.mas_offset(CGSizeMake(11, 12));
48+
}];
49+
[label mas_makeConstraints:^(MASConstraintMaker *make) {
50+
make.centerY.equalTo(_bestAnswerV);
51+
make.left.equalTo(imageV.mas_right);
52+
make.right.equalTo(_bestAnswerV);
53+
}];
54+
[self.contentView addSubview:_bestAnswerV];
55+
}
3256
CGFloat curBottomY = 10;
3357
if (!_ownerIconView) {
3458
_ownerIconView = [[UIImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, curBottomY, 33, 33)];
3559
[_ownerIconView doCircleFrame];
3660
[self.contentView addSubview:_ownerIconView];
3761
}
62+
if (!_voteBtn) {
63+
_voteBtn = [[UIButton alloc] initWithFrame:CGRectMake(kPaddingLeftWidth + 1.5, _ownerIconView.bottom, 30, 18)];
64+
[_voteBtn doBorderWidth:0.5 color:nil cornerRadius:2.0];
65+
_voteBtn.titleLabel.font = [UIFont systemFontOfSize:11];
66+
[_voteBtn addTarget:self action:@selector(voteBtnClicked) forControlEvents:UIControlEventTouchUpInside];
67+
[self.contentView addSubview:_voteBtn];
68+
}
3869
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
3970
if (!_contentLabel) {
4071
_contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth + 40, curBottomY, curWidth, 30)];
@@ -69,6 +100,21 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
69100
return self;
70101
}
71102

103+
- (void)voteBtnClicked{
104+
__weak typeof(self) weakSelf = self;
105+
[[Coding_NetAPIManager sharedManager] request_UpvoteAnswer:_toComment inProjectId:_projectId andBlock:^(id data, NSError *error) {
106+
if (data) {
107+
[weakSelf setVoteCount:weakSelf.toComment.up_vote_counts isVoted:weakSelf.toComment.is_up_voted.boolValue];
108+
}
109+
}];
110+
}
111+
112+
- (void)setVoteCount:(NSNumber *)voteCount isVoted:(BOOL)isVoted{
113+
[_voteBtn setBackgroundColor:isVoted? kColorBrandGreen: [UIColor whiteColor]];
114+
[_voteBtn setTitleColor:[UIColor colorWithHexString:isVoted? @"0xFFFFFF": @"0x999999"] forState:UIControlStateNormal];
115+
[_voteBtn setTitle:[NSString stringWithFormat:@"+%@", voteCount] forState:UIControlStateNormal];
116+
}
117+
72118
- (void)setToComment:(ProjectTopic *)toComment{
73119
_toComment = toComment;
74120

@@ -78,10 +124,16 @@ - (void)setToComment:(ProjectTopic *)toComment{
78124
CGFloat curBottomY = 10;
79125
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
80126

127+
_bestAnswerV.hidden = !_toComment.is_recommended.boolValue;
128+
if (_toComment.is_recommended.boolValue) {
129+
curBottomY = 35;
130+
}
81131

132+
_ownerIconView.y = _contentLabel.y = curBottomY;
133+
_voteBtn.y = _ownerIconView.bottom + 2;
134+
[self setVoteCount:_toComment.up_vote_counts isVoted:_toComment.is_up_voted.boolValue];
82135
[_ownerIconView sd_setImageWithURL:[_toComment.owner.avatar urlImageWithCodePathResizeToView:_ownerIconView] placeholderImage:kPlaceholderMonkeyRoundView(_ownerIconView)];
83136
[_contentLabel setLongString:_toComment.content withFitWidth:curWidth];
84-
85137
for (HtmlMediaItem *item in _toComment.htmlMedia.mediaItems) {
86138
if (item.displayStr.length > 0 && !(item.type == HtmlMediaItemType_Code ||item.type == HtmlMediaItemType_EmotionEmoji)) {
87139
[_contentLabel addLinkToTransitInformation:[NSDictionary dictionaryWithObject:item forKey:@"value"] withRange:item.range];
@@ -107,7 +159,7 @@ - (void)setToComment:(ProjectTopic *)toComment{
107159

108160
- (void)setIsAnswer:(BOOL)isAnswer{
109161
_isAnswer = isAnswer;
110-
_ownerIconView.hidden = !_isAnswer;
162+
_ownerIconView.hidden = _voteBtn.hidden = !_isAnswer;
111163
_contentLabel.textColor = [UIColor colorWithHexString:_isAnswer? @"0x222222": @"0x666666"];
112164
}
113165

@@ -118,6 +170,7 @@ + (CGFloat)cellHeightWithObj:(id)obj{
118170
CGFloat curWidth = kScreen_Width - 40 - 2*kPaddingLeftWidth;
119171
cellHeight += 10 +[toComment.content getHeightWithFont:kTopicCommentCell_FontContent constrainedToSize:CGSizeMake(curWidth, CGFLOAT_MAX)] + 5 +20 +10;
120172
cellHeight += [self imageCollectionViewHeightWithCount:toComment.htmlMedia.imageItems.count];
173+
cellHeight += toComment.is_recommended.boolValue? 25: 0;
121174
}
122175
return cellHeight;
123176
}

0 commit comments

Comments
 (0)