|
|
@@ -0,0 +1,425 @@
|
|
|
+//
|
|
|
+// PasteSelectView.m
|
|
|
+// VclustersGemini
|
|
|
+//
|
|
|
+// Created by APPLE on 2019/7/5.
|
|
|
+// Copyright © 2019 APPLE. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "PasteSelectView.h"
|
|
|
+
|
|
|
+#define TAG_PASED_BASE 12345
|
|
|
+
|
|
|
+@interface PasteSelectView ()<UITableViewDelegate,UITableViewDataSource>{
|
|
|
+ NSMutableArray *pasteDataAry;
|
|
|
+ UIView *bgView;
|
|
|
+ UILabel *tipsLabel;
|
|
|
+ UIImageView *noCententImageView;
|
|
|
+ UILabel *noCententLabel;
|
|
|
+ UIButton *clearBtn;
|
|
|
+}
|
|
|
+
|
|
|
+@property (nonatomic, strong, nullable) UITableView *tableView;
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation PasteSelectView
|
|
|
+@synthesize delegate;
|
|
|
+
|
|
|
+- (UITableView *)tableView{
|
|
|
+ if (!_tableView) {
|
|
|
+ _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 304.f, SCREEN_H) style:UITableViewStylePlain];
|
|
|
+ _tableView.delegate = self;
|
|
|
+ _tableView.dataSource = self;
|
|
|
+ _tableView.showsVerticalScrollIndicator = YES;
|
|
|
+ _tableView.showsHorizontalScrollIndicator = NO;
|
|
|
+ [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
|
|
|
+ [_tableView setBackgroundColor:[UIColor clearColor]];
|
|
|
+ [_tableView setTableFooterView:[UIView new]];
|
|
|
+ }
|
|
|
+
|
|
|
+ return _tableView;
|
|
|
+}
|
|
|
+
|
|
|
+- (id)initWithFrame:(CGRect)frame{
|
|
|
+ self = [super initWithFrame:frame];
|
|
|
+
|
|
|
+ if (self){
|
|
|
+ [self setBackgroundColor:[UIColor clearColor]];
|
|
|
+
|
|
|
+ [self initData];
|
|
|
+ [self drawView:frame];
|
|
|
+ }
|
|
|
+
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)initData{
|
|
|
+ UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
|
|
|
+ NSString *str = [pasteboard string];
|
|
|
+ HLog(@"__________%s______%@____",__func__,str);
|
|
|
+
|
|
|
+ if ([str rangeOfString:@"CVLUSTERS_NOUSE_"].location != NSNotFound){
|
|
|
+ str = nil;
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
|
|
|
+ pasteDataAry = [HWDataManager getObjectWithKey:curSn];
|
|
|
+
|
|
|
+ if (str){
|
|
|
+ if (pasteDataAry){
|
|
|
+ if (![pasteDataAry containsObject:str]){
|
|
|
+ if ([pasteDataAry count] == 10){
|
|
|
+ [pasteDataAry removeObjectAtIndex:9];
|
|
|
+ }
|
|
|
+ [pasteDataAry insertObject:str atIndex:0];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ pasteDataAry = [[NSMutableArray alloc] init];
|
|
|
+ [pasteDataAry addObject:str];
|
|
|
+ }
|
|
|
+
|
|
|
+ [HWDataManager setObjectWithKey:curSn value:pasteDataAry];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)drawView:(CGRect)frame{
|
|
|
+ [self setBackgroundColor:[UIColor clearColor]];
|
|
|
+ CGFloat w_left_right = 57.f;
|
|
|
+// if (w_left_right > 67.f/2.f)
|
|
|
+// {
|
|
|
+// w_left_right = 67.f/2.f;
|
|
|
+// }
|
|
|
+
|
|
|
+ if(SCREEN_W > SCREEN_H){
|
|
|
+ w_left_right = SCREEN_W/5.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ CGFloat h_bg = 272.f;
|
|
|
+ UIImage *demoPhoneBtnImage = [UIImage imageNamed:@"jianqieban_guanbi_icon"];
|
|
|
+ bgView = [[UIView alloc] init];
|
|
|
+
|
|
|
+ [bgView setBackgroundColor:RGBACOLOR(0 , 0, 0, 0.6)];
|
|
|
+ [bgView.layer setCornerRadius:20.f];
|
|
|
+ bgView.clipsToBounds = YES;
|
|
|
+ [self addSubview:bgView];
|
|
|
+ [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(w_left_right);
|
|
|
+ make.right.mas_equalTo(-w_left_right);
|
|
|
+ make.height.mas_equalTo(h_bg);
|
|
|
+ make.centerY.equalTo(self.mas_centerY).offset(-(demoPhoneBtnImage.size.height + 30.f/2.f)/2.f);
|
|
|
+ }];
|
|
|
+
|
|
|
+ CGFloat w_left_right_btn = 30.f/2.f;
|
|
|
+
|
|
|
+ /*删除按钮*/
|
|
|
+ UIButton *demoPhoneBtn = [[UIButton alloc] init];
|
|
|
+ [demoPhoneBtn setBackgroundColor:[UIColor clearColor]];
|
|
|
+ [demoPhoneBtn addTarget:self
|
|
|
+ action:@selector(removeFromSuperview)
|
|
|
+ forControlEvents:(UIControlEventTouchUpInside)];
|
|
|
+ [demoPhoneBtn setImage:demoPhoneBtnImage forState:(UIControlStateNormal)];
|
|
|
+ [self addSubview:demoPhoneBtn];
|
|
|
+
|
|
|
+ [demoPhoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.centerX.equalTo(self->bgView.mas_centerX);
|
|
|
+ make.width.mas_equalTo(demoPhoneBtnImage.size.width);
|
|
|
+ make.height.mas_equalTo(demoPhoneBtnImage.size.height);
|
|
|
+ make.top.equalTo(self->bgView.mas_bottom).offset(30.f/2.f);
|
|
|
+ }];
|
|
|
+
|
|
|
+ /*上方文字*/
|
|
|
+ tipsLabel = [[UILabel alloc] init];
|
|
|
+ [tipsLabel setBackgroundColor:[UIColor clearColor]];
|
|
|
+ [tipsLabel setTextColor:[UIColor whiteColor]];
|
|
|
+ [tipsLabel setFont:[UIFont systemFontOfSize:18.f]];
|
|
|
+ [tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
|
|
|
+ NSInteger numStr = 0;
|
|
|
+ if (pasteDataAry){
|
|
|
+ numStr = [pasteDataAry count];
|
|
|
+ }
|
|
|
+ [tipsLabel setText:@"剪贴板"];
|
|
|
+
|
|
|
+ [bgView addSubview:tipsLabel];
|
|
|
+ [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(w_left_right_btn);
|
|
|
+ make.right.mas_equalTo(-w_left_right_btn);
|
|
|
+ make.height.mas_equalTo(21.f);
|
|
|
+ make.top.mas_equalTo(15);
|
|
|
+ }];
|
|
|
+
|
|
|
+ /*清空按钮*/
|
|
|
+ clearBtn = [[UIButton alloc] init];
|
|
|
+ [clearBtn setBackgroundColor:COLOR_ENABLE_BTN];
|
|
|
+ [clearBtn setTitle:@"清空" forState:(UIControlStateNormal)];
|
|
|
+ [clearBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
|
|
|
+ [clearBtn.titleLabel setFont:[UIFont systemFontOfSize:12.f]];
|
|
|
+ [clearBtn addTarget:self action:@selector(clearPasteInfo) forControlEvents:(UIControlEventTouchUpInside)];
|
|
|
+ [clearBtn.layer setCornerRadius:4];
|
|
|
+ [bgView addSubview:clearBtn];
|
|
|
+
|
|
|
+ CGFloat w_clearBtn = 36.f;
|
|
|
+ CGFloat h_clearBtn = 19.f;
|
|
|
+ [clearBtn mas_makeConstraints:^(MASConstraintMaker *make){
|
|
|
+ make.right.mas_equalTo(-w_left_right_btn);
|
|
|
+ make.width.mas_equalTo(w_clearBtn);
|
|
|
+ make.height.mas_equalTo(h_clearBtn);
|
|
|
+ make.centerY.equalTo(tipsLabel.mas_centerY);
|
|
|
+ }];
|
|
|
+
|
|
|
+ noCententImageView = [[UIImageView alloc] init];
|
|
|
+ [noCententImageView setBackgroundColor:[UIColor clearColor]];
|
|
|
+ UIImage *noCententImage = [UIImage imageNamed:@"jianqiebankong_icon"];
|
|
|
+
|
|
|
+ [bgView addSubview:noCententImageView];
|
|
|
+ [noCententImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.centerX.equalTo(self->bgView.mas_centerX);
|
|
|
+ make.width.mas_equalTo(noCententImage.size.width);
|
|
|
+ make.height.mas_equalTo(noCententImage.size.height);
|
|
|
+ make.top.mas_equalTo(40.f);
|
|
|
+ }];
|
|
|
+ [noCententImageView setImage:noCententImage];
|
|
|
+ [noCententImageView setHidden:YES];
|
|
|
+
|
|
|
+
|
|
|
+ noCententLabel = [[UILabel alloc] init];
|
|
|
+ [noCententLabel setBackgroundColor:[UIColor clearColor]];
|
|
|
+ [noCententLabel setTextAlignment:(NSTextAlignmentCenter)];
|
|
|
+ [noCententLabel setText:@"剪贴板为空"];
|
|
|
+ [noCententLabel setFont:[UIFont systemFontOfSize:15.f]];
|
|
|
+ [noCententLabel setTextColor:[UIColor whiteColor]];
|
|
|
+ [bgView addSubview:noCententLabel];
|
|
|
+
|
|
|
+ [noCententLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.height.mas_equalTo(20.f);
|
|
|
+ make.left.mas_equalTo(0);
|
|
|
+ make.right.mas_equalTo(0);
|
|
|
+ make.top.equalTo(noCententImageView.mas_bottom).offset(10.f);
|
|
|
+ }];
|
|
|
+ [noCententLabel setHidden:YES];
|
|
|
+
|
|
|
+ /*添加列表*/
|
|
|
+ [bgView addSubview:self.tableView];
|
|
|
+ [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.equalTo(tipsLabel.mas_bottom).offset(10.f);
|
|
|
+ make.left.mas_equalTo(0);
|
|
|
+ make.right.mas_equalTo(-10);
|
|
|
+ make.bottom.mas_equalTo(-10);
|
|
|
+ }];
|
|
|
+
|
|
|
+ if (pasteDataAry && [pasteDataAry count] > 0){
|
|
|
+ [self haveCentent:YES];
|
|
|
+ [tipsLabel setHidden:NO];
|
|
|
+ }else{
|
|
|
+ [self haveCentent:NO];
|
|
|
+ [tipsLabel setHidden:YES];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)clearPasteInfo{
|
|
|
+ [self setHidden:YES];
|
|
|
+
|
|
|
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
|
|
|
+ message:@""
|
|
|
+ preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+
|
|
|
+ NSString *tipsStr = @"确定清空剪贴板?";
|
|
|
+ NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:tipsStr attributes:@{NSFontAttributeName: [UIFont systemFontOfSize: 15], NSForegroundColorAttributeName: HW333333Color}];
|
|
|
+ [alertController setValue:string forKey:@"_attributedMessage"];
|
|
|
+
|
|
|
+ UIView *subView1 = alertController.view.subviews[0];
|
|
|
+ if (subView1 && [subView1 subviews]){
|
|
|
+ UIView *subView2 = subView1.subviews[0];
|
|
|
+ if (subView2 && [subView2 subviews]){
|
|
|
+ UIView *subView3 = subView2.subviews[0];
|
|
|
+ if (subView3 && [subView3 subviews]){
|
|
|
+ UIView *subView4 = subView3.subviews[0];
|
|
|
+ if (subView4 && [subView4 subviews]){
|
|
|
+ UIView *subView5 = subView4.subviews[0];
|
|
|
+ if (subView5 && [[subView5 subviews] count] > 1){
|
|
|
+ UIView *msg = subView5.subviews[1];
|
|
|
+ if ([msg isKindOfClass:[UILabel class]]){
|
|
|
+ [(UILabel*)msg setTextAlignment:(NSTextAlignmentCenter)];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ [self->pasteDataAry removeAllObjects];
|
|
|
+ UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
|
|
|
+ NSString *str = [pasteboard string];
|
|
|
+ if (str){
|
|
|
+ [pasteboard setString:[@"CVLUSTERS_NOUSE_" stringByAppendingString:str]];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
|
|
|
+ [HWDataManager setObjectWithKey:curSn value:self->pasteDataAry];
|
|
|
+
|
|
|
+ [self.tableView reloadData];
|
|
|
+ [self haveCentent:NO];
|
|
|
+ [self setHidden:NO];
|
|
|
+ }];
|
|
|
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ [self setHidden:NO];
|
|
|
+ }];
|
|
|
+
|
|
|
+ [sureAction setValue:HW3370FFColor forKey:@"titleTextColor"];//iOS8.3
|
|
|
+ [alertController addAction:sureAction];
|
|
|
+ [cancelAction setValue:HW333333Color forKey:@"titleTextColor"];//iOS8.3
|
|
|
+ [alertController addAction:cancelAction];
|
|
|
+
|
|
|
+// // 弹窗边框
|
|
|
+// UIView *subview = alertController.view.subviews.firstObject;
|
|
|
+// UIView *alertContentView = subview.subviews.firstObject;
|
|
|
+// alertContentView.layer.cornerRadius = 10;
|
|
|
+//// alertContentView.layer.shadowColor = HWFFFFFFColor.CGColor;
|
|
|
+// alertContentView.layer.shadowOffset = CGSizeMake(0,0);
|
|
|
+// alertContentView.layer.shadowOpacity = 1;
|
|
|
+// alertContentView.layer.shadowRadius = 7;
|
|
|
+ // 弹窗背景颜色
|
|
|
+ if (@available(iOS 13.0, *)) {
|
|
|
+ alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
|
|
|
+ }
|
|
|
+
|
|
|
+ [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)pastedBtnPressed:(NSString*)centontStr{
|
|
|
+ if ([delegate respondsToSelector:@selector(pastedBtnBePressed: pasteSelectView:)]){
|
|
|
+ [delegate pastedBtnBePressed:centontStr pasteSelectView:self];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+// Only override drawRect: if you perform custom drawing.
|
|
|
+// An empty implementation adversely affects performance during animation.
|
|
|
+- (void)drawRect:(CGRect)rect {
|
|
|
+ // Drawing code
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
+- (void)haveCentent:(BOOL)have{
|
|
|
+ if (have){
|
|
|
+ [tipsLabel setHidden:NO];
|
|
|
+ [clearBtn setHidden:NO];
|
|
|
+ [noCententImageView setHidden:YES];
|
|
|
+ [noCententLabel setHidden:YES];
|
|
|
+ [self.tableView setHidden:NO];
|
|
|
+ }else{
|
|
|
+ [tipsLabel setHidden:NO];
|
|
|
+ [clearBtn setHidden:YES];
|
|
|
+ [noCententImageView setHidden:NO];
|
|
|
+ [noCententLabel setHidden:NO];
|
|
|
+ [self.tableView setHidden:YES];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - 列表委托
|
|
|
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
|
|
+ if (pasteDataAry){
|
|
|
+ return [pasteDataAry count];
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+ static NSString *identifier = @"UseInfoCell";
|
|
|
+ NSInteger row = indexPath.section;
|
|
|
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
|
|
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
+
|
|
|
+ if (!cell){
|
|
|
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
|
|
|
+ [cell setSelectionStyle:UITableViewCellSelectionStyleDefault];
|
|
|
+ [cell setBackgroundColor:[UIColor clearColor]];
|
|
|
+ [cell setAccessoryType:(UITableViewCellAccessoryNone)];
|
|
|
+
|
|
|
+ UILabel *contentLabel = [[UILabel alloc] init];
|
|
|
+ [contentLabel setBackgroundColor:[UIColor whiteColor]];
|
|
|
+ [contentLabel setTextColor:[UIColor hwColor:@"333333"]];
|
|
|
+ [contentLabel setFont:[UIFont systemFontOfSize:12.f]];
|
|
|
+ [contentLabel setClipsToBounds:YES];
|
|
|
+ [contentLabel setTag:12345];
|
|
|
+ [contentLabel.layer setCornerRadius:3.f];
|
|
|
+
|
|
|
+ [cell.contentView addSubview:contentLabel];
|
|
|
+ [cell.contentView.layer setCornerRadius:3.f];
|
|
|
+ [cell.contentView setClipsToBounds:YES];
|
|
|
+
|
|
|
+ [contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.height.mas_equalTo(32.f);
|
|
|
+ make.left.mas_equalTo(10.f);
|
|
|
+ make.right.mas_equalTo(-0);
|
|
|
+ make.top.mas_equalTo(0);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+
|
|
|
+ UILabel *label = [cell.contentView viewWithTag:12345];
|
|
|
+ [label setText:[NSString stringWithFormat:@" %@",[pasteDataAry objectAtIndex:row]]];
|
|
|
+
|
|
|
+ return cell;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
+ NSInteger row = [indexPath section];
|
|
|
+ [self pastedBtnPressed:[pasteDataAry objectAtIndex:row]];
|
|
|
+}
|
|
|
+
|
|
|
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+ return 32.f;
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+// 定义编辑样式
|
|
|
+- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ return UITableViewCellEditingStyleDelete;
|
|
|
+}
|
|
|
+
|
|
|
+// 进入编辑模式,按下出现的编辑按钮后,进行删除操作
|
|
|
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
|
+ [pasteDataAry removeObjectAtIndex:indexPath.section];
|
|
|
+
|
|
|
+ UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
|
|
|
+ NSString *str = [pasteboard string];
|
|
|
+ if (str){
|
|
|
+ [pasteboard setString:[@"CVLUSTERS_NOUSE_" stringByAppendingString:str]];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
|
|
|
+ [HWDataManager setObjectWithKey:curSn value:pasteDataAry];
|
|
|
+
|
|
|
+ [self.tableView reloadData];
|
|
|
+ if ([pasteDataAry count] == 0){
|
|
|
+ [self haveCentent:NO];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 修改编辑按钮文字
|
|
|
+- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+ return @"删除";
|
|
|
+}
|
|
|
+
|
|
|
+- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
|
|
+ return [UIView new];
|
|
|
+}
|
|
|
+
|
|
|
+- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
|
|
+ return 8.f;
|
|
|
+}
|
|
|
+@end
|