shareBySecretView.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. //
  2. // shareBySecretView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/17.
  6. //
  7. #import "shareBySecretView.h"
  8. #import "shareSecretTableViewCell.h"
  9. @interface shareBySecretView ()<UITableViewDelegate,UITableViewDataSource>
  10. @property (nonatomic,strong)UITableView*tableView;
  11. @end
  12. @implementation shareBySecretView
  13. - (id)initWithFrame:(CGRect)frame{
  14. self = [super initWithFrame:frame];
  15. self.backgroundColor = [UIColor hwColor:@"#000000" alpha:0.6];
  16. return self;
  17. }
  18. - (void)setDidSelectListArr:(NSMutableArray *)didSelectListArr
  19. {
  20. _didSelectListArr = didSelectListArr;
  21. [self drawAnyView];
  22. }
  23. - (void)drawAnyView{
  24. NSInteger showCellNum = _didSelectListArr.count >=3 ? 3 :_didSelectListArr.count;
  25. CGFloat curTableViewCellH = 70;
  26. CGFloat curTableViewH = curTableViewCellH *showCellNum;
  27. CGFloat curWhiteBgH = 64 + curTableViewH + 194;
  28. UIView *whiteBgView = [[UIView alloc] init];
  29. whiteBgView.backgroundColor = [UIColor whiteColor];
  30. [self addSubview:whiteBgView];
  31. whiteBgView.layer.cornerRadius = 8;
  32. whiteBgView.layer.masksToBounds = YES;
  33. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.mas_equalTo(40);
  35. make.right.mas_equalTo(-40);
  36. make.centerY.equalTo(self.mas_centerY).offset(-40);
  37. make.height.mas_equalTo(curWhiteBgH);
  38. }];
  39. if(_didSelectListArr.count <=0 ){
  40. return;
  41. }
  42. NASFilePicDataArrModel *dataModel = _didSelectListArr.firstObject;
  43. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@%@%ld%@",dataModel.name,NSLocalizedString(@"share_file_more_tip",nil), _didSelectListArr.count,NSLocalizedString(@"share_file_Numbers_tip",nil)];
  44. if(_didSelectListArr.count == 1){
  45. titleStr = dataModel.name;
  46. }
  47. UILabel *titleLabel = [[UILabel alloc] init];
  48. titleLabel.text = titleStr;
  49. titleLabel.textAlignment = NSTextAlignmentCenter;
  50. titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
  51. titleLabel.font = [UIFont systemFontOfSize:18.0];
  52. titleLabel.textColor = [UIColor hwColor:@"#151515"];
  53. [whiteBgView addSubview:titleLabel];
  54. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(15);
  56. make.right.mas_equalTo(-15);
  57. make.top.mas_equalTo(25);
  58. make.height.mas_equalTo(25);
  59. }];
  60. [whiteBgView addSubview:self.tableView];
  61. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.mas_equalTo(15);
  63. make.right.mas_equalTo(-15);
  64. make.top.mas_equalTo(64);
  65. make.height.mas_equalTo(curTableViewH);
  66. }];
  67. //文件分享有效期
  68. UIView *expirationDateBgView = [[UIView alloc] init];
  69. expirationDateBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9"];
  70. [whiteBgView addSubview:expirationDateBgView];
  71. expirationDateBgView.layer.cornerRadius = 8;
  72. expirationDateBgView.layer.masksToBounds = YES;
  73. [expirationDateBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(15);
  75. make.right.mas_equalTo(-15);
  76. make.top.equalTo(self.tableView.mas_bottom).offset(15);
  77. make.height.mas_equalTo(36);
  78. }];
  79. UILabel *expDateTipLab = [[UILabel alloc] init];
  80. expDateTipLab.font = [UIFont systemFontOfSize:14.f];
  81. //[expDateTipLab setTextAlignment:(NSTextAlignmentRight)];
  82. [expDateTipLab setTextColor:HW0A132BColor];
  83. expDateTipLab.text = NSLocalizedString(@"share_expiration_date_tip",nil);
  84. [expirationDateBgView addSubview:expDateTipLab];
  85. [expDateTipLab mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.left.mas_equalTo(15);
  87. make.right.mas_equalTo(-80);
  88. make.top.mas_equalTo(0);
  89. make.bottom.mas_equalTo(0);
  90. }];
  91. UILabel *expDateTip2Lab = [[UILabel alloc] init];
  92. expDateTip2Lab.font = [UIFont systemFontOfSize:14.f];
  93. [expDateTip2Lab setTextAlignment:(NSTextAlignmentRight)];
  94. [expDateTip2Lab setTextColor:HW0A132BColor];
  95. [expirationDateBgView addSubview:expDateTip2Lab];
  96. NSString * expDateStr = [[NSString alloc] initWithFormat:@"7%@",NSLocalizedString(@"share_expiration_date_unit_tip",nil)];
  97. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:expDateStr];
  98. NSRange redRange = NSMakeRange(0, 1);
  99. UIColor *noteColor =[UIColor hwColor:@"#01B7EA" alpha:1.0];
  100. [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  101. expDateTip2Lab.attributedText = attrStr;
  102. [expDateTip2Lab mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.left.mas_equalTo(expDateTipLab.mas_right);
  104. make.right.mas_equalTo(-15);
  105. make.top.mas_equalTo(0);
  106. make.bottom.mas_equalTo(0);
  107. }];
  108. //提取码
  109. UIView *extractCodeBgView = [[UIView alloc] init];
  110. extractCodeBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9"];
  111. [whiteBgView addSubview:extractCodeBgView];
  112. extractCodeBgView.layer.cornerRadius = 8;
  113. extractCodeBgView.layer.masksToBounds = YES;
  114. [extractCodeBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.left.mas_equalTo(15);
  116. make.right.mas_equalTo(-15);
  117. make.top.equalTo(expirationDateBgView.mas_bottom).offset(15);
  118. make.height.mas_equalTo(36);
  119. }];
  120. UILabel *extractCodeTipLab = [[UILabel alloc] init];
  121. extractCodeTipLab.font = [UIFont systemFontOfSize:14.f];
  122. [extractCodeTipLab setTextColor:HW0A132BColor];
  123. extractCodeTipLab.text = NSLocalizedString(@"share_Extract_code_tip",nil);
  124. [extractCodeBgView addSubview:extractCodeTipLab];
  125. [extractCodeTipLab mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.mas_equalTo(15);
  127. make.right.mas_equalTo(-80);
  128. make.top.mas_equalTo(0);
  129. make.bottom.mas_equalTo(0);
  130. }];
  131. UILabel *extractCodeTip2Lab = [[UILabel alloc] init];
  132. extractCodeTip2Lab.font = [UIFont systemFontOfSize:14.f];
  133. [extractCodeTip2Lab setTextAlignment:(NSTextAlignmentRight)];
  134. [extractCodeTip2Lab setTextColor:[UIColor hwColor:@"#01B7EA" alpha:1.0]];
  135. [extractCodeBgView addSubview:extractCodeTip2Lab];
  136. extractCodeTip2Lab.text = _addShareMod.data.extractionCode;
  137. [extractCodeTip2Lab mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.left.mas_equalTo(expDateTipLab.mas_right);
  139. make.right.mas_equalTo(-15);
  140. make.top.mas_equalTo(0);
  141. make.bottom.mas_equalTo(0);
  142. }];
  143. UIButton*cancleButton = [[UIButton alloc] init];
  144. [cancleButton setTitle:NSLocalizedString(@"cancel_share_title",nil) forState:UIControlStateNormal];
  145. [cancleButton setTitleColor:HW0A132BColor forState:UIControlStateNormal];
  146. cancleButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
  147. [cancleButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  148. cancleButton.tag = 10;
  149. [whiteBgView addSubview:cancleButton];
  150. cancleButton.layer.cornerRadius = 8;
  151. cancleButton.layer.masksToBounds = YES;
  152. cancleButton.backgroundColor = [UIColor hwColor:@"#E3E8F1"];
  153. [cancleButton mas_makeConstraints:^(MASConstraintMaker *make) {
  154. make.left.mas_equalTo(30);
  155. make.right.equalTo(whiteBgView.mas_centerX).offset(-10);
  156. make.bottom.mas_equalTo(-30);
  157. make.height.mas_equalTo(40);
  158. }];
  159. UIButton*copyButton = [[UIButton alloc] init];
  160. CGFloat w_btn = SCREEN_W/2.0 -15 -10;
  161. // gradient
  162. CAGradientLayer *gl = [CAGradientLayer layer];
  163. gl.frame = CGRectMake(0,0,w_btn,40.f);
  164. gl.startPoint = CGPointMake(0, 0.5);
  165. gl.endPoint = CGPointMake(1, 0.5);
  166. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  167. gl.locations = @[@(0), @(1.0f)];
  168. [copyButton.layer addSublayer:gl];
  169. [copyButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  170. [copyButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:(UIControlEventTouchUpInside)];
  171. [copyButton setTitle:NSLocalizedString(@"share_copy_link_tip",nil) forState:(UIControlStateNormal)];
  172. [copyButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  173. [copyButton.layer setCornerRadius:8.f];
  174. copyButton.clipsToBounds = YES;
  175. copyButton.tag = 11;
  176. [whiteBgView addSubview:copyButton];
  177. [copyButton mas_makeConstraints:^(MASConstraintMaker *make) {
  178. make.right.mas_equalTo(-30);
  179. make.left.equalTo(whiteBgView.mas_centerX).offset(10);
  180. make.bottom.mas_equalTo(-30);
  181. make.height.mas_equalTo(40);
  182. }];
  183. }
  184. #pragma mark - 懒加载
  185. - (UITableView *)tableView{
  186. if (!_tableView) {
  187. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  188. _tableView.delegate = self;
  189. _tableView.dataSource = self;
  190. _tableView.showsVerticalScrollIndicator = NO;
  191. _tableView.showsHorizontalScrollIndicator = NO;
  192. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  193. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  194. [_tableView setSeparatorColor:[UIColor clearColor]];
  195. [_tableView setBackgroundColor:[UIColor hwColor:@"#F9F9F9"]];
  196. [_tableView setTableFooterView:[UIView new]];
  197. [_tableView setBounces:YES];
  198. if (@available(iOS 15.0, *)) {
  199. _tableView.sectionHeaderTopPadding = 0;
  200. }
  201. _tableView.layer.cornerRadius = 8;
  202. _tableView.layer.masksToBounds = YES;
  203. }
  204. return _tableView;
  205. }
  206. #pragma mark - 列表委托
  207. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  208. return 1;
  209. }
  210. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  211. return _didSelectListArr.count;
  212. }
  213. - (shareSecretTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  214. __block NSInteger row = indexPath.row;
  215. static NSString *identifier = @"shareSecretTableViewCell";
  216. shareSecretTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  217. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  218. if (!cell){
  219. cell = [[shareSecretTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  220. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  221. [cell setBackgroundColor:[UIColor clearColor]];
  222. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  223. }
  224. if(row < _didSelectListArr.count){
  225. NASFilePicDataArrModel*dataModel = _didSelectListArr[row];
  226. cell.dataModel = dataModel;
  227. }
  228. return cell;
  229. }
  230. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  231. return 70;
  232. }
  233. - (void)didClickButtonFun:(UIButton*)but
  234. {
  235. NSInteger tag = but.tag;
  236. if(tag == 10){
  237. [self removeFromSuperview];
  238. }
  239. else if(tag == 11){
  240. [self copyLinkFun];
  241. }
  242. }
  243. - (void)copyLinkFun
  244. {
  245. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  246. if(_addShareMod.data.addShareId){
  247. [paraDict setValue:_addShareMod.data.addShareId forKey:@"id"];
  248. }
  249. [paraDict setValue:@0 forKey:@"status"];
  250. KWeakSelf
  251. //[ showNewIndicatorWithCanBack:NO canTouch:NO];
  252. [[netWorkManager shareInstance] CommonPostCallBackCode:updateShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  253. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  254. if(model && model.code == 0){
  255. [weakSelf copyLinkOkFun];
  256. }
  257. else{
  258. [[iToast makeText:NSLocalizedString(@"share_fail_msg",nil)] show];
  259. }
  260. } failure:^(NSError * _Nonnull error) {
  261. [[iToast makeText:NSLocalizedString(@"share_fail_msg",nil)] show];
  262. }];
  263. }
  264. //【私密分享】通过Private-X分享到文件:文件名称文件名称文件名称..称.jpg等2个文件
  265. //链接:https//Private-X.com/s/hj_w
  266. //密码:Gj1u
  267. //点击链接即可打开查看好友分享的文件
  268. - (void)copyLinkOkFun{
  269. if(_didSelectListArr.count <=0 ){
  270. return;
  271. }
  272. [self removeFromSuperview];
  273. NASFilePicDataArrModel *dataModel = _didSelectListArr.firstObject;
  274. NSString *copyStr1 = [[NSString alloc] initWithFormat:@"%@%@%@%@%ld%@",NSLocalizedString(@"share_secret_titile_1",nil),NSLocalizedString(@"share_secret_titile_1_1",nil),dataModel.name,NSLocalizedString(@"share_file_more_tip",nil), _didSelectListArr.count,NSLocalizedString(@"share_file_Numbers_tip",nil)];
  275. if(_didSelectListArr.count == 1){
  276. copyStr1 = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"share_secret_titile_1",nil),dataModel.name];
  277. }
  278. NSString *serUrl = @"http://192.168.12.253:8080/#/pages/fileSharing/index?token=";
  279. NSString *shareUrl = [[NSString alloc] initWithFormat:@"%@%@",serUrl,_addShareMod.data.token];
  280. NSString *copyStr2 = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"share_secret_titile_2",nil),shareUrl];
  281. NSString *copyStr3 = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"share_secret_titile_3",nil),_addShareMod.data.extractionCode];
  282. NSString *copyStr4 = NSLocalizedString(@"share_secret_titile_4",nil);
  283. NSString *copyTotalStr = [[NSString alloc] initWithFormat:@"%@\n%@\n%@\n%@",copyStr1,copyStr2,copyStr3,copyStr4];
  284. UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  285. pasteboard.string = copyTotalStr;
  286. [[iToast makeText:NSLocalizedString(@"copy_share_link_suc_tip",nil)] show];
  287. }
  288. @end