shareBySecretView.m 15 KB

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