|
@@ -39,6 +39,8 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
UIImageView *_iconView;
|
|
|
UILabel *_nameLable;
|
|
|
UILabel *_contentLabel;
|
|
|
+ UIView *_transSpaceLineView;
|
|
|
+ UILabel *_contentTransLabel;
|
|
|
SDWeiXinPhotoContainerView *_picContainerView;
|
|
|
UILabel *_timeLabel;
|
|
|
UIButton *_moreButton;
|
|
@@ -90,6 +92,19 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
gesture.minimumPressDuration= 0.5f;
|
|
|
[_contentLabel addGestureRecognizer:gesture];
|
|
|
|
|
|
+ _contentTransLabel = [UILabel new];
|
|
|
+ _contentTransLabel.font = [UIFont systemFontOfSize:contentLabelFontSize];
|
|
|
+ _contentTransLabel.numberOfLines = 0;
|
|
|
+ _contentTransLabel.userInteractionEnabled = YES;
|
|
|
+ _contentTransLabel.isAttributedContent = YES;
|
|
|
+ UILongPressGestureRecognizer *gesture1=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(contentLabelHandleLongPressGestures:)];
|
|
|
+ gesture.minimumPressDuration= 0.5f;
|
|
|
+ [_contentTransLabel addGestureRecognizer:gesture1];
|
|
|
+ _transSpaceLineView = [UIView new];
|
|
|
+ _transSpaceLineView.backgroundColor = SLColLine;
|
|
|
+ _transSpaceLineView.hidden = YES;
|
|
|
+
|
|
|
+
|
|
|
_moreButton = [UIButton new];
|
|
|
[_moreButton setTitle:@"全文" forState:UIControlStateNormal];
|
|
|
[_moreButton setTitleColor:TimeLineCellHighlightedColor forState:UIControlStateNormal];
|
|
@@ -142,7 +157,7 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
_timeLabel.font = [UIFont systemFontOfSize:10];
|
|
|
|
|
|
|
|
|
- NSArray *views = @[_iconView, _nameLable, _contentLabel, _moreButton, _picContainerView, _timeLabel, _operationLikeButton, _operationCommentButton, _delButton, _commentView];
|
|
|
+ NSArray *views = @[_iconView, _nameLable, _contentLabel, _contentTransLabel, _transSpaceLineView, _moreButton, _picContainerView, _timeLabel, _operationLikeButton, _operationCommentButton, _delButton, _commentView];
|
|
|
|
|
|
[self.contentView sd_addSubviews:views];
|
|
|
|
|
@@ -173,6 +188,19 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
.topSpaceToView(_contentLabel, 0)
|
|
|
.widthIs(30);
|
|
|
|
|
|
+ _contentTransLabel.sd_layout
|
|
|
+ .leftEqualToView(_contentLabel)
|
|
|
+ .topSpaceToView(_moreButton, 2)
|
|
|
+ .rightSpaceToView(contentView, 12)
|
|
|
+ .autoHeightRatio(0);
|
|
|
+
|
|
|
+ _transSpaceLineView.sd_layout
|
|
|
+ .leftEqualToView(_contentLabel)
|
|
|
+ .topSpaceToView(_moreButton, 8)
|
|
|
+ .rightSpaceToView(contentView, 12)
|
|
|
+ .heightIs(1);
|
|
|
+
|
|
|
+// _contentTransLabel.text = @"我没有\n是的";
|
|
|
|
|
|
_picContainerView.sd_layout
|
|
|
.leftEqualToView(_contentLabel); // 已经在内部实现宽度和高度自适应所以不需要再设置宽度高度,top值是具体有无图片在setModel方法中设置
|
|
@@ -209,11 +237,11 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
|
|
|
- (void)contentLabelHandleLongPressGestures:(UILongPressGestureRecognizer *)paramSender {
|
|
|
if (paramSender.state == UIGestureRecognizerStateBegan) {
|
|
|
- _contentLabel.backgroundColor = SLCol205;
|
|
|
+ paramSender.view.backgroundColor = SLCol205;
|
|
|
}
|
|
|
if (paramSender.state == UIGestureRecognizerStateEnded) {
|
|
|
- [self showMsgSegmentWith:_contentLabel];
|
|
|
- _contentLabel.backgroundColor = [UIColor clearColor];
|
|
|
+ [self showMsgSegmentWith:paramSender.view];
|
|
|
+ paramSender.view.backgroundColor = [UIColor clearColor];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -232,7 +260,13 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
NSMutableArray *arr = [NSMutableArray new];
|
|
|
|
|
|
[arr addObject:[SLMikeSegmentModel initWithSegTitle: @"复制" segImage:@"" mikeType:SLMsgCopy]];
|
|
|
- [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"翻译" segImage:@"" mikeType:SLMikeInputTrans]];
|
|
|
+ if (bgView == _contentLabel) {
|
|
|
+ if (_model.showTrans) {
|
|
|
+ [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"原文" segImage:@"" mikeType:SLMikeInputTransHidden]];
|
|
|
+ }else {
|
|
|
+ [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"翻译" segImage:@"" mikeType:SLMikeInputTrans]];
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
CGFloat width = arr.count * 45 + 20;
|
|
|
CGFloat x = bgView.frame.origin.x + MAX(0, (rect.size.width - width) / 2.0);
|
|
@@ -244,39 +278,53 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
switch (model.mikeType) {
|
|
|
case SLMsgCopy:
|
|
|
{
|
|
|
- [[UIPasteboard generalPasteboard] setString:self->_model.friendContent];
|
|
|
+ NSString *str = (bgView == self->_contentLabel) ? self->_model.friendContent : self->_model.friendContentTrans;
|
|
|
+ [[UIPasteboard generalPasteboard] setString:str];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case SLMikeInputTransHidden:
|
|
|
+ {
|
|
|
+ self->_model.showTrans = NO;
|
|
|
+ [weakSelf.delegate didClickTransInCell:self];
|
|
|
}
|
|
|
break;
|
|
|
case SLMikeInputTrans:
|
|
|
{
|
|
|
- //百度智能云
|
|
|
- [[SLHttpCenter SharedInstance] getWithUrl:@"https://aip.baidubce.com/oauth/2.0/token" parameter:@{@"grant_type":@"client_credentials", @"client_id":@"0VhDeLqdcbLamGENfw4c24aq", @"client_secret": @"92qphFKyc0uXGktqFLtfdmqlojt9MsgG"} success:^(id responseObject) {
|
|
|
- NSString *accessToken = [responseObject objectForKey:@"access_token"];
|
|
|
- if (accessToken) {
|
|
|
- NSString *bdUrl = [NSString stringWithFormat:@"https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1?access_token=%@",accessToken];
|
|
|
- NSDictionary *dict = @{@"q":self->_model.friendContent,
|
|
|
- @"from":@"auto",
|
|
|
- @"to":@"zh"};
|
|
|
- [[SLHttpCenter SharedInstance] postWithUrl:bdUrl parameter:dict success:^(id responseObject) {
|
|
|
- NSDictionary *reslut = [responseObject objectForKey:@"result"];
|
|
|
- NSArray *arr = [reslut objectForKey:@"trans_result"];
|
|
|
- if (arr && arr.count) {
|
|
|
- NSDictionary *resultDict = arr.firstObject;
|
|
|
- NSString *dst = [resultDict objectForKey:@"dst"];
|
|
|
- self->_model.friendContentTrans = dst;
|
|
|
-// self->_contentLabel.text = self->_model.friendContentTrans;
|
|
|
- }else {
|
|
|
+ if (self->_model.friendContentTrans) {
|
|
|
+ self->_model.showTrans = YES;
|
|
|
+ [weakSelf.delegate didClickTransInCell:self];
|
|
|
+ }else {
|
|
|
+ //百度智能云
|
|
|
+ [[SLHttpCenter SharedInstance] getWithUrl:@"https://aip.baidubce.com/oauth/2.0/token" parameter:@{@"grant_type":@"client_credentials", @"client_id":@"0VhDeLqdcbLamGENfw4c24aq", @"client_secret": @"92qphFKyc0uXGktqFLtfdmqlojt9MsgG"} success:^(id responseObject) {
|
|
|
+ NSString *accessToken = [responseObject objectForKey:@"access_token"];
|
|
|
+ if (accessToken) {
|
|
|
+ NSString *bdUrl = [NSString stringWithFormat:@"https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1?access_token=%@",accessToken];
|
|
|
+ NSDictionary *dict = @{@"q":self->_model.friendContent,
|
|
|
+ @"from":@"auto",
|
|
|
+ @"to":@"zh"};
|
|
|
+ [[SLHttpCenter SharedInstance] postWithUrl:bdUrl parameter:dict success:^(id responseObject) {
|
|
|
+ NSDictionary *reslut = [responseObject objectForKey:@"result"];
|
|
|
+ NSArray *arr = [reslut objectForKey:@"trans_result"];
|
|
|
+ if (arr && arr.count) {
|
|
|
+ NSDictionary *resultDict = arr.firstObject;
|
|
|
+ NSString *dst = [resultDict objectForKey:@"dst"];
|
|
|
+ self->_model.friendContentTrans = dst;
|
|
|
+ self->_contentTransLabel.text = self->_model.friendContentTrans;
|
|
|
+ self->_model.showTrans = YES;
|
|
|
+ [weakSelf.delegate didClickTransInCell:self];
|
|
|
+ }else {
|
|
|
+ [ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
+ }
|
|
|
+ } failure:^(SPRequestError *error) {
|
|
|
[ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
- }
|
|
|
- } failure:^(SPRequestError *error) {
|
|
|
+ }];
|
|
|
+ }else {
|
|
|
[ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
- }];
|
|
|
- }else {
|
|
|
+ }
|
|
|
+ } failure:^(SPRequestError *error) {
|
|
|
[ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
- }
|
|
|
- } failure:^(SPRequestError *error) {
|
|
|
- [ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
- }];
|
|
|
+ }];
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -284,7 +332,6 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
}
|
|
|
};
|
|
|
[bView addSubview:mikeSegment];
|
|
|
- SLMomentsVc *msgVc = (SLMomentsVc *)vc;
|
|
|
UIImageView *imgView = [[UIImageView alloc] initWithImage:ImageName(@"icon_dsjx")];
|
|
|
[bView addSubview:imgView];
|
|
|
[imgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
@@ -316,6 +363,11 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
{
|
|
|
_model = model;
|
|
|
_commentView.userId = _model.userId;
|
|
|
+ _contentTransLabel.text = _model.showTrans ? _model.friendContentTrans : @"";
|
|
|
+ _contentTransLabel.sd_layout
|
|
|
+ .topSpaceToView(_moreButton, _model.showTrans ? 16 : 2);
|
|
|
+
|
|
|
+ _transSpaceLineView.hidden = !_model.showTrans;
|
|
|
[_commentView setupWithLikeItemsArray:model.likeItemsArray commentItemsArray:model.list];
|
|
|
NSString *userImg = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, model.userImg];
|
|
|
[_iconView sd_setImageWithURL:[NSURL URLWithString:userImg] placeholderImage:ImageName(@"icon_ellipse")];
|
|
@@ -329,7 +381,7 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
_picContainerView.cellModel = _model;
|
|
|
_picContainerView.picPathStringsArray = friendImgUrls;
|
|
|
|
|
|
- if (model.shouldShowMoreButton) { // 如果文字高度超过60
|
|
|
+ if (model.shouldShowMoreButton && !model.showTrans) { // 如果文字高度超过60
|
|
|
_moreButton.sd_layout.heightIs(20);
|
|
|
_moreButton.hidden = NO;
|
|
|
if (model.isOpening) { // 如果需要展开
|
|
@@ -340,6 +392,7 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
[_moreButton setTitle:@"全文" forState:UIControlStateNormal];
|
|
|
}
|
|
|
} else {
|
|
|
+ _contentLabel.sd_layout.maxHeightIs(MAXFLOAT);
|
|
|
_moreButton.sd_layout.heightIs(0);
|
|
|
_moreButton.hidden = YES;
|
|
|
}
|
|
@@ -348,7 +401,7 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
if (friendImgUrls.count) {
|
|
|
picContainerTopMargin = 10;
|
|
|
}
|
|
|
- _picContainerView.sd_layout.topSpaceToView(_moreButton, picContainerTopMargin);
|
|
|
+ _picContainerView.sd_layout.topSpaceToView(_contentTransLabel, picContainerTopMargin);
|
|
|
|
|
|
UIView *bottomView;
|
|
|
|