|
@@ -6,26 +6,6 @@
|
|
|
// Copyright © 2016年 GSD. All rights reserved.
|
|
|
//
|
|
|
|
|
|
-/*
|
|
|
-
|
|
|
- *********************************************************************************
|
|
|
- *
|
|
|
- * GSD_WeiXin
|
|
|
- *
|
|
|
- * QQ交流群: 459274049
|
|
|
- * Email : gsdios@126.com
|
|
|
- * GitHub: https://github.com/gsdios/GSD_WeiXin
|
|
|
- * 新浪微博:GSD_iOS
|
|
|
- *
|
|
|
- * 此“高仿微信”用到了很高效方便的自动布局库SDAutoLayout(一行代码搞定自动布局)
|
|
|
- * SDAutoLayout地址:https://github.com/gsdios/SDAutoLayout
|
|
|
- * SDAutoLayout视频教程:http://www.letv.com/ptv/vplay/24038772.html
|
|
|
- * SDAutoLayout用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md
|
|
|
- *
|
|
|
- *********************************************************************************
|
|
|
-
|
|
|
- */
|
|
|
-
|
|
|
#import "SDTimeLineCell.h"
|
|
|
|
|
|
#import "SDTimeLineCellModel.h"
|
|
@@ -37,8 +17,9 @@
|
|
|
|
|
|
#import "SDTimeLineCellOperationMenu.h"
|
|
|
|
|
|
-#import "LEETheme.h"
|
|
|
#import "SLFriensInfoVc.h"
|
|
|
+#import "SLMikeSegment.h"
|
|
|
+#import "SLMomentsVc.h"
|
|
|
|
|
|
const CGFloat contentLabelFontSize = 16;
|
|
|
CGFloat maxContentLabelHeight = 0; // 根据具体font而定
|
|
@@ -67,15 +48,9 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
}
|
|
|
|
|
|
|
|
|
-- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
|
|
-{
|
|
|
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
|
-
|
|
|
[self setup];
|
|
|
-
|
|
|
- //设置主题
|
|
|
- [self configTheme];
|
|
|
-
|
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
}
|
|
|
return self;
|
|
@@ -106,10 +81,14 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
_contentLabel = [UILabel new];
|
|
|
_contentLabel.font = [UIFont systemFontOfSize:contentLabelFontSize];
|
|
|
_contentLabel.numberOfLines = 0;
|
|
|
+ _contentLabel.userInteractionEnabled = YES;
|
|
|
_nameLable.isAttributedContent = YES;
|
|
|
if (maxContentLabelHeight == 0) {
|
|
|
maxContentLabelHeight = (_contentLabel.font.lineHeight + 8) * 3;
|
|
|
}
|
|
|
+ UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(contentLabelHandleLongPressGestures:)];
|
|
|
+ gesture.minimumPressDuration= 0.5f;
|
|
|
+ [_contentLabel addGestureRecognizer:gesture];
|
|
|
|
|
|
_moreButton = [UIButton new];
|
|
|
[_moreButton setTitle:@"全文" forState:UIControlStateNormal];
|
|
@@ -228,20 +207,96 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
|
|
|
.topSpaceToView(_timeLabel, 4); // 已经在内部实现高度自适应所以不需要再设置高度
|
|
|
}
|
|
|
|
|
|
-- (void)configTheme{
|
|
|
- self.lee_theme
|
|
|
- .LeeAddBackgroundColor(DAY , [UIColor whiteColor])
|
|
|
- .LeeAddBackgroundColor(NIGHT , [UIColor blackColor]);
|
|
|
-
|
|
|
- _contentLabel.lee_theme
|
|
|
- .LeeAddTextColor(DAY , [UIColor blackColor])
|
|
|
- .LeeAddTextColor(NIGHT , [UIColor grayColor]);
|
|
|
+- (void)contentLabelHandleLongPressGestures:(UILongPressGestureRecognizer *)paramSender {
|
|
|
+ if (paramSender.state == UIGestureRecognizerStateBegan) {
|
|
|
+ _contentLabel.backgroundColor = SLCol205;
|
|
|
+ }
|
|
|
+ if (paramSender.state == UIGestureRecognizerStateEnded) {
|
|
|
+ [self showMsgSegmentWith:_contentLabel];
|
|
|
+ _contentLabel.backgroundColor = [UIColor clearColor];
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- _timeLabel.lee_theme
|
|
|
- .LeeAddTextColor(DAY , SLColor(@"#8E8E93"))
|
|
|
- .LeeAddTextColor(NIGHT , SLColor(@"#8E8E93"));
|
|
|
+- (void)showMsgSegmentWith:(UIView *)bgView {
|
|
|
+ UIViewController *vc = self.viewController;
|
|
|
+ if ([vc isKindOfClass:SLMomentsVc.class]) {
|
|
|
+ CGRect rect = [self convertRect:bgView.frame toView:self.viewController.view];
|
|
|
+ //加一个蒙层
|
|
|
+ __block UIView *bView = [[UIView alloc] initWithFrame:vc.view.frame];
|
|
|
+ bView.backgroundColor = [UIColor clearColor];
|
|
|
+ __block UIView *blockBgView = bView;
|
|
|
+ [bView addTapWithBlock:^{
|
|
|
+ [blockBgView removeFromSuperview];
|
|
|
+ }];
|
|
|
+ [vc.view addSubview:bView];
|
|
|
+ NSMutableArray *arr = [NSMutableArray new];
|
|
|
+
|
|
|
+ [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"复制" segImage:@"" mikeType:SLMsgCopy]];
|
|
|
+ [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);
|
|
|
+ x = MIN((kSCREEN_WIDTH - width) / 2.0 , x);
|
|
|
+ SLMikeSegment *mikeSegment = [[SLMikeSegment alloc] initWithFrame:CGRectMake(x, rect.origin.y - 39, width, 30) titleArray:arr];
|
|
|
+ WS(weakSelf);
|
|
|
+ mikeSegment.mikeSegmentBlock = ^(SLMikeSegmentModel *model) {
|
|
|
+ [bView removeFromSuperview];
|
|
|
+ switch (model.mikeType) {
|
|
|
+ case SLMsgCopy:
|
|
|
+ {
|
|
|
+ [[UIPasteboard generalPasteboard] setString:self->_model.friendContent];
|
|
|
+ }
|
|
|
+ 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 {
|
|
|
+ [ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
+ }
|
|
|
+ } failure:^(SPRequestError *error) {
|
|
|
+ [ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
+ }];
|
|
|
+ }else {
|
|
|
+ [ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
+ }
|
|
|
+ } failure:^(SPRequestError *error) {
|
|
|
+ [ZFToast ShowWithMessage:@"翻译失败"];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ [bView addSubview:mikeSegment];
|
|
|
+ SLMomentsVc *msgVc = (SLMomentsVc *)vc;
|
|
|
+ UIImageView *imgView = [[UIImageView alloc] initWithImage:ImageName(@"icon_dsjx")];
|
|
|
+ [bView addSubview:imgView];
|
|
|
+ [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.centerX.equalTo(mikeSegment);
|
|
|
+ make.top.equalTo(mikeSegment.mas_bottom).offset(0);
|
|
|
+ make.width.mas_equalTo(16);
|
|
|
+ make.height.mas_equalTo(8);
|
|
|
+ }];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
- (void)setDidClickCommentLabelBlock:(void (^)(NSString *, CGRect, NSIndexPath *))didClickCommentLabelBlock {
|
|
|
_didClickCommentLabelBlock = didClickCommentLabelBlock;
|
|
|
_commentView.didClickCommentLabelBlock = _didClickCommentLabelBlock;
|