Selaa lähdekoodia

朋友圈内容复制翻译

桂欢 1 vuosi sitten
vanhempi
commit
dcb358f440

+ 3 - 0
SLAiELTS/SLAiELTS/AppMarcos/GlobalDefines.h

@@ -37,6 +37,9 @@
 
 #define TimeLineCellHighlightedColor [UIColor colorWithRed:92/255.0 green:140/255.0 blue:193/255.0 alpha:1.0]
 
+
+#define SLCol205 SDColor(205, 205, 205, 1)
+
 #define DAY @"day"
 
 #define NIGHT @"night"

+ 2 - 0
SLAiELTS/SLAiELTS/AppMarcos/PrefixHeader.pch

@@ -54,6 +54,8 @@
 
 #import "SLWebViewController.h"
 
+#import "GlobalDefines.h"
+
 //#ifdef DEBUG
 //# define NSLog(...) NSLog(__VA_ARGS__)
 //#else

+ 2 - 0
SLAiELTS/SLAiELTS/Tool/MLEmojiLabel/MLLabel/Classes/MLLinkLabel.m

@@ -456,8 +456,10 @@ static NSArray * kAllRegexps() {
                 [self.delegate didLongPressLink:link linkText:linkText linkLabel:self];
             }
         }
+        self.backgroundColor = SLCol205;
     }
     if (sender.state == UIGestureRecognizerStateEnded) {
+        self.backgroundColor = [UIColor clearColor];
         if (self.labelLongTouchBlock) {
             self.labelLongTouchBlock();
         }

+ 2 - 2
SLAiELTS/SLAiELTS/Tool/ZFToast/ZFToast.m

@@ -1,7 +1,7 @@
 #import "ZFToast.h"
 #import "NSString+Category.h"
-NSTimeInterval const kShowLabelTime = 2.0;
-NSInteger const kRemoveTime = 3.0;
+NSTimeInterval const kShowLabelTime = 1.5;
+NSInteger const kRemoveTime = 2.0;
 @interface ZFToast ()
 
 /// @brief 存放文本的UILabel

+ 1 - 0
SLAiELTS/SLAiELTS/ViewControllers/Moments/Model/SDTimeLineCellModel.h

@@ -44,6 +44,7 @@ typedef enum {
 @property (nonatomic, copy) NSString *userName;
 @property (nonatomic, copy) NSString *friendId;
 @property (nonatomic, copy) NSString *friendContent;
+@property (nonatomic, copy) NSString *friendContentTrans;
 @property (nonatomic, copy) NSString *friendImgUrl;
 @property (nonatomic, copy) NSString *time;
 @property (nonatomic, assign) BOOL isLike;

+ 0 - 1
SLAiELTS/SLAiELTS/ViewControllers/Moments/MomentsVc/SLMomentsVc.m

@@ -14,7 +14,6 @@
 #import "UITableView+SDAutoTableViewCellHeight.h"
 
 #import "UIView+SDAutoLayout.h"
-#import "GlobalDefines.h"
 
 #import "SLMoentsChatView.h"
 #import "SLMomentsCommentVc.h"

+ 94 - 39
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/Cell/SDTimeLineCell.m

@@ -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;

+ 0 - 2
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/CommentView/SDTimeLineCellCommentView.h

@@ -28,8 +28,6 @@
 
 #import <UIKit/UIKit.h>
 
-#import "GlobalDefines.h"
-
 @interface SDTimeLineCellCommentView : UIView
 
 @property (nonatomic, strong) NSIndexPath *indexPath;

+ 3 - 7
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/CommentView/SDTimeLineCellCommentView.m

@@ -165,7 +165,9 @@
         }
         
         CGFloat width = arr.count * 45 + 20;
-        SLMikeSegment *mikeSegment = [[SLMikeSegment alloc] initWithFrame:CGRectMake(bgView.frame.origin.x + rect.size.width / 2.0, rect.origin.y - 39, width, 30) titleArray:arr];
+        CGFloat x = bgView.frame.origin.x + MAX(0, rect.size.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];
@@ -173,11 +175,6 @@
                 case SLMsgCopy:
                 {
                     [[UIPasteboard generalPasteboard] setString:commentItemModel.content];
-                }
-                    break;
-                case SLMikeInputTrans:
-                {
-                    
                 }
                     break;
                 case SLMikeInputDelete:
@@ -206,7 +203,6 @@
     }
 }
 
-
 - (void)setLikeItemsArray:(NSArray *)likeItemsArray
 {
     

+ 0 - 1
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/OperationMenu/SDTimeLineCellOperationMenu.m

@@ -8,7 +8,6 @@
 
 #import "SDTimeLineCellOperationMenu.h"
 #import "UIView+SDAutoLayout.h"
-#import "GlobalDefines.h"
 
 @implementation SDTimeLineCellOperationMenu
 {