|
//
// msgBottomCell.m
// ThePaperBase
//
// Created by YoungLee on 15/11/19.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "msgBottomCell.h"
@implementation msgBottomCell
@synthesize comment = _comment;
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.timeLabel];
[self.backView addSubview:self.okBtn];
[self.backView addSubview:self.shadowLine];
[self.okBtn changeButtonImage];
// 个人主页(我的提问,关注的问题,私信等):个人主页(我的提问,关注的问题,私信等)进入原新闻切换成夜间模式返回,显示异常(bug:6153)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.timeLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
self.shadowLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
-(UIView *)backView {
if(!_backView){
_backView = [UIView new];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
- (UILabel *)timeLabel {
if (!_timeLabel) {
_timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_timeLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
_timeLabel.backgroundColor = [UIColor clearColor];
_timeLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
}
return _timeLabel;
}
-(UIView *)shadowLine{
if (!_shadowLine) {
_shadowLine = [UIView new];
_shadowLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _shadowLine;
}
-(commentOkButton *)okBtn{
if (!_okBtn) {
_okBtn = [[commentOkButton alloc]initWithFrame:CGRectZero];
[_okBtn addTarget:self action:@selector(commentOK:) forControlEvents:UIControlEventTouchUpInside];
}
return _okBtn;
}
-(void)setComment:(commentObjectVO *)commentBo{
if (commentBo.answerList.count >0) {
_comment = setJsonDicToDataModel(commentBo.answerList[0], [commentObjectVO class]);
}else{
_comment = commentBo;
}
self.timeLabel.text = _comment.pubTime;
// self.okBtn.text = @"127.5k";
if (!isBlankString(_comment.praiseTimes)) {
self.okBtn.text = _comment.praiseTimes;
}else{
self.okBtn.text = @"0";
}
if (_comment.isPraised && [_comment.isPraised intValue] == 1) {
[self.okBtn setSelected:YES];
}else {
[self.okBtn setSelected:NO];
}
}
- (void)commentOK:(UIButton*)btn {
if (btn.selected) {
return;
}
[self.okBtn setSelected:YES animated:YES];
NSDictionary *dic = @{@"commentId":self.comment.commentId};
__weak typeof(self) Self = self;
[Remote doJsonActionWithBlock:2000 requestUrl:commentPraiseURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
NSString *praseNumStr = responseData[@"praiseTimes"];
if([praseNumStr intValue] <1000){// 点赞数:当点赞数达到1K以上时,点赞后点赞数异常(bug:5372)
Self.okBtn.text = praseNumStr;
Self.comment.praiseTimes = praseNumStr;
TPLOG(@"点赞成功");
}
Self.comment.isPraised = @"1";
if ([Self.delegate respondsToSelector:@selector(hasPraisedAnswer:withCommentBO:)]) {
[Self.delegate hasPraisedAnswer:Self.indexPath withCommentBO:Self.comment];
}
}else {
ShowMessage(@"点赞失败", NO);
}
}];
}
-(void)layoutSubviews{
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.right.equalTo(self.contentView.right).offset(-10);
make.top.equalTo(self.contentView.top);
make.bottom.equalTo(self.contentView.bottom);
}];
[self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(10);
make.width.mas_equalTo(100);
make.top.equalTo(self.backView.top).offset(7);
make.height.mas_equalTo(15);
}];
[self.okBtn makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView.right).offset(-10);
make.width.mas_equalTo(50);
make.top.equalTo(self.backView.top);
make.height.mas_equalTo(30);
}];
[self.shadowLine makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.top.equalTo(self.backView.bottom).offset(-1);
make.height.mas_equalTo(1);
}];
[super layoutSubviews];
}
@end
|