editShareView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. //
  2. // editShareView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/14.
  6. //
  7. #import "editShareView.h"
  8. #import "addShareModel.h"
  9. #import "customShareManageTool.h"
  10. #import "shareBySecretView.h"
  11. @interface editShareView ()
  12. @property(nonatomic,strong) UIButton*day7Button;
  13. @property(nonatomic,strong) UIButton*dayForeverButton;
  14. @property(nonatomic,strong) UIButton*PrivacyShareButton;
  15. @end
  16. @implementation editShareView
  17. - (id)initWithFrame:(CGRect)frame{
  18. self = [super initWithFrame:frame];
  19. self.backgroundColor = [UIColor hwColor:@"#000000" alpha:0.6];
  20. [self drawAnyView];
  21. return self;
  22. }
  23. - (void)drawAnyView{
  24. UIView *whiteBgView = [[UIView alloc] init];
  25. whiteBgView.backgroundColor = [UIColor whiteColor];
  26. [self addSubview:whiteBgView];
  27. whiteBgView.layer.cornerRadius = 32;
  28. whiteBgView.layer.masksToBounds = YES;
  29. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.mas_equalTo(0);
  31. make.right.mas_equalTo(0);
  32. make.bottom.mas_equalTo(0);
  33. make.height.mas_equalTo(315 -50+ AdaptTabHeight);
  34. }];
  35. UILabel *titleLabel = [[UILabel alloc] init];
  36. titleLabel.font = [UIFont systemFontOfSize:18.0];
  37. titleLabel.textColor = [UIColor hwColor:@"#0A132B" alpha:1.0];
  38. [whiteBgView addSubview:titleLabel];
  39. NSString *leftText = NSLocalizedString(@"share_title_left",nil);
  40. NSString *rightText = NSLocalizedString(@"share_title_right",nil);
  41. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@ %@",leftText,rightText];
  42. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  43. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightText].location, [totalStr rangeOfString:rightText].length);
  44. UIColor *noteColor =[UIColor hwColor:@"#959799" alpha:1.0];
  45. [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
  46. [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  47. titleLabel.attributedText = attrStr;
  48. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.mas_equalTo(25);
  50. make.right.mas_equalTo(0);
  51. make.top.mas_equalTo(20);
  52. make.height.mas_equalTo(40);
  53. }];
  54. NSString *secondTitleStr = NSLocalizedString(@"share_expiration_date",nil);
  55. UILabel *secondTitleLabel = [[UILabel alloc] init];
  56. secondTitleLabel.font = [UIFont systemFontOfSize:14.0];
  57. secondTitleLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
  58. secondTitleLabel.text = secondTitleStr;
  59. [whiteBgView addSubview:secondTitleLabel];
  60. CGFloat secondWith = [secondTitleStr boundingRectWithSize:CGSizeMake(300, 20) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.width;
  61. [secondTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.mas_equalTo(25);
  63. make.width.mas_equalTo(secondWith);
  64. make.top.equalTo(titleLabel.mas_bottom).offset(10);
  65. make.height.mas_equalTo(25);
  66. }];
  67. _day7Button = [[UIButton alloc] init];
  68. [_day7Button setImage:[UIImage imageNamed:@"common_did_check"] forState:UIControlStateSelected];
  69. [_day7Button setImage:[UIImage imageNamed:@"common_un_check"] forState:UIControlStateNormal];
  70. [_day7Button setTitle:NSLocalizedString(@"share_expiration_date_7",nil) forState:UIControlStateNormal];
  71. [_day7Button setTitleColor:[UIColor hwColor:@"#0A132B"] forState:UIControlStateNormal];
  72. [_day7Button addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  73. _day7Button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  74. _day7Button.tag = 1;
  75. [whiteBgView addSubview:_day7Button];
  76. _day7Button.selected = YES;
  77. [_day7Button mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.equalTo(secondTitleLabel.mas_right).offset(5);
  79. make.width.mas_equalTo(100);
  80. make.top.equalTo(secondTitleLabel.mas_top).offset(0);
  81. make.height.mas_equalTo(25);
  82. }];
  83. _dayForeverButton = [[UIButton alloc] init];
  84. [_dayForeverButton setImage:[UIImage imageNamed:@"common_did_check"] forState:UIControlStateSelected];
  85. [_dayForeverButton setImage:[UIImage imageNamed:@"common_un_check"] forState:UIControlStateNormal];
  86. [_dayForeverButton setTitle:NSLocalizedString(@"share_expiration_date_forever",nil) forState:UIControlStateNormal];
  87. [_dayForeverButton setTitleColor:[UIColor hwColor:@"#0A132B"] forState:UIControlStateNormal];
  88. [_dayForeverButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  89. _dayForeverButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  90. _dayForeverButton.tag = 2;
  91. [whiteBgView addSubview:_dayForeverButton];
  92. [_dayForeverButton mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.equalTo(_day7Button.mas_right).offset(15);
  94. make.width.mas_equalTo(100);
  95. make.top.equalTo(secondTitleLabel.mas_top).offset(0);
  96. make.height.mas_equalTo(25);
  97. }];
  98. NSArray *titleArr = @[NSLocalizedString(@"share_by_weixin",nil),
  99. NSLocalizedString(@"share_by_QQ",nil),
  100. NSLocalizedString(@"share_by_timeLine",nil),
  101. NSLocalizedString(@"share_by_secret",nil)];
  102. NSArray *imageStrArr = @[@"share_weixin_icon",
  103. @"share_qq_icon",
  104. @"share_weixin_Timeline_icon",
  105. @"share_secret_icon"];
  106. CGFloat curButFullWidth = SCREEN_W/4.0;
  107. for (int i = 0; i< titleArr.count; i++) {
  108. UIButton*curButton = [[UIButton alloc] init];
  109. [curButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  110. curButton.tag = 10+i;
  111. [whiteBgView addSubview:curButton];
  112. [curButton mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.width.mas_equalTo(curButFullWidth);
  114. make.left.mas_equalTo(i*curButFullWidth);
  115. make.height.mas_equalTo(80);
  116. make.top.equalTo(secondTitleLabel.mas_bottom).offset(20);
  117. }];
  118. if(i== titleArr.count -1){
  119. _PrivacyShareButton = curButton;
  120. }
  121. UIView *imageBgView = [[UIView alloc] init];
  122. imageBgView.backgroundColor = [UIColor hwColor:@"#F5F7FA"];
  123. imageBgView.layer.cornerRadius = 8;
  124. imageBgView.layer.masksToBounds = YES;
  125. [curButton addSubview:imageBgView];
  126. imageBgView.userInteractionEnabled = NO;
  127. [imageBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  128. make.width.mas_equalTo(64);
  129. make.height.mas_equalTo(52);
  130. make.centerX.equalTo(curButton.mas_centerX);
  131. make.top.mas_equalTo(0);
  132. }];
  133. UIImageView *leftImageV = [[UIImageView alloc] init];
  134. leftImageV.image = [UIImage imageNamed:imageStrArr[i]];
  135. [imageBgView addSubview:leftImageV];
  136. [leftImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.width.mas_equalTo(25);
  138. make.height.mas_equalTo(25);
  139. make.centerX.equalTo(imageBgView.mas_centerX);
  140. make.centerY.equalTo(imageBgView.mas_centerY).offset(0);
  141. }];
  142. UILabel *leftLabel = [[UILabel alloc] init];
  143. leftLabel.textColor = [UIColor hwColor:@"#0A132B"];
  144. leftLabel.textAlignment = NSTextAlignmentCenter;
  145. leftLabel.font = [UIFont systemFontOfSize:12.0];
  146. leftLabel.text = titleArr[i];
  147. [curButton addSubview:leftLabel];
  148. [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.width.mas_equalTo(curButFullWidth);
  150. make.height.mas_equalTo(25);
  151. make.centerX.equalTo(curButton.mas_centerX);
  152. //make.top.equalTo(imageBgView.mas_bottom).offset(10);
  153. make.bottom.mas_equalTo(0);
  154. }];
  155. }
  156. UIButton*cancelButton = [[UIButton alloc] init];
  157. [cancelButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal];
  158. [cancelButton setTitleColor:[UIColor hwColor:@"#0A132B"] forState:UIControlStateNormal];
  159. [cancelButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  160. cancelButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  161. cancelButton.tag = 100;
  162. [whiteBgView addSubview:cancelButton];
  163. [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
  164. make.left.mas_equalTo(0);
  165. make.right.mas_equalTo(0);
  166. make.bottom.mas_equalTo(-AdaptTabHeight);
  167. make.height.mas_equalTo(40);
  168. }];
  169. UIView *lineView = [[UIView alloc] init];
  170. lineView.backgroundColor = [UIColor hwColor:@"#EAEAEA"];
  171. [whiteBgView addSubview:lineView];
  172. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  173. make.left.mas_equalTo(25);
  174. make.right.mas_equalTo(-25);
  175. make.bottom.equalTo(cancelButton.mas_top).offset(-5);
  176. make.height.mas_equalTo(1);
  177. }];
  178. }
  179. - (void)didClickButFun:(UIButton*)but
  180. {
  181. NSInteger tag = but.tag;
  182. //防止重复点击
  183. but.userInteractionEnabled = NO;
  184. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  185. but.userInteractionEnabled = YES;
  186. });
  187. if(tag==1 && !_day7Button.selected){
  188. _day7Button.selected = YES;
  189. _dayForeverButton.selected = NO;
  190. //私密分享
  191. _PrivacyShareButton.hidden = NO;
  192. }
  193. else if(tag==2 && !_dayForeverButton.selected){
  194. _day7Button.selected = NO;
  195. _dayForeverButton.selected = YES;
  196. //私密分享
  197. _PrivacyShareButton.hidden = YES;
  198. }
  199. else if(tag == 100){
  200. [self removeFromSuperview];
  201. }
  202. else{
  203. //请求服务器处理分享数据
  204. [self addShareDataBy:tag];
  205. }
  206. }
  207. //添加分享
  208. - (void)addShareDataBy:(NSInteger)tag
  209. {
  210. NSString *curSn = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  211. NSString *platformType = [[NSString alloc] initWithFormat:@"%ld", tag - 9];
  212. //_shareFileType
  213. NSInteger expirationDay = _day7Button.selected ? 7 : 0;
  214. NSMutableArray * boxShareFileDTOList = [NSMutableArray new];
  215. for (NASFilePicDataArrModel*dataModel in _didSelectListArr) {
  216. NSMutableDictionary *modelDict = [NSMutableDictionary new];
  217. if(dataModel.name){
  218. [modelDict setValue:dataModel.name forKey:@"fileName"];
  219. NSArray * nameArr = [dataModel.name componentsSeparatedByString:@"."];
  220. if(nameArr.count >= 2){
  221. NSString*fileSuffix = nameArr.lastObject;
  222. if(fileSuffix && fileSuffix.length > 0){
  223. [modelDict setValue:fileSuffix forKey:@"fileSuffix"];
  224. }
  225. }
  226. }
  227. if(dataModel.size >= 0){
  228. [modelDict setValue:[NSNumber numberWithLong:dataModel.size] forKey:@"fileSize"];
  229. }
  230. if(dataModel.time){
  231. [modelDict setValue:dataModel.time forKey:@"fileTime"];
  232. }
  233. if(dataModel.path){
  234. NSString *filePath = dataModel.path;
  235. NSString *urlStr = ksharedAppDelegate.NASShareFileService;
  236. NSString *headUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  237. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  238. if(headUrl){
  239. [modelDict setValue:headUrl forKey:@"headUrl"];
  240. }
  241. if(headUrl){
  242. [modelDict setValue:fileUrl forKey:@"fileUrl"];
  243. }
  244. }
  245. [boxShareFileDTOList addObject:modelDict];
  246. }
  247. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  248. if(!curSn){
  249. return;
  250. }
  251. [paraDict setValue:curSn forKey:@"sn"];
  252. [paraDict setValue:platformType forKey:@"platformType"];
  253. if(_shareFileType){
  254. [paraDict setValue:_shareFileType forKey:@"fileType"];
  255. }
  256. [paraDict setValue:[NSNumber numberWithInteger:expirationDay] forKey:@"expirationDay"];
  257. [paraDict setValue:boxShareFileDTOList forKey:@"boxShareFileDTOList"];
  258. KWeakSelf
  259. //[ showNewIndicatorWithCanBack:NO canTouch:NO];
  260. [[netWorkManager shareInstance] CommonPostCallBackCode:addShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  261. addShareModel *model = [[addShareModel alloc] initWithDictionary:responseObject error:nil];
  262. if(model && model.code == 0){
  263. [weakSelf gotoShareFunWith:tag with:model];
  264. }
  265. else{
  266. [[iToast makeText:NSLocalizedString(@"share_fail_msg",nil)] show];//
  267. }
  268. } failure:^(NSError * _Nonnull error) {
  269. [[iToast makeText:NSLocalizedString(@"share_fail_msg",nil)] show];
  270. }];
  271. }
  272. - (void)gotoShareFunWith:(NSInteger)tag with:(addShareModel*)model
  273. {
  274. //type1 朋友圈 2 微信好友 3 QQ
  275. NSInteger shareType = 1;
  276. if(tag == 10){
  277. shareType =2;
  278. }
  279. else if(tag == 11){
  280. shareType = 3;
  281. }
  282. else if(tag == 12){
  283. shareType = 1;
  284. }
  285. else if(tag == 13){
  286. [self showSecretShareViewFunwith:model];
  287. return;;
  288. }
  289. NSString *serUrl = shareService;
  290. NSString *shareUrl = [[NSString alloc] initWithFormat:@"%@%@",serUrl,model.data.token];
  291. //NSString *shareTitle = [[NSString alloc] initWithFormat:@"Private-X%@",NSLocalizedString(@"common_edit_share",nil)];
  292. NSString *shareTitle = @"Private-X分享";
  293. NSString *firstname = nil;
  294. if (_didSelectListArr.count > 0) {
  295. NASFilePicDataArrModel*dataModel = _didSelectListArr[0];
  296. firstname = dataModel.name;
  297. }
  298. //我正在使用Private-X魔盒,给大家分享 文件名称文件名称.jpg 等 2 个文件 ,快来看看吧~
  299. NSString *shareContent = [[NSString alloc] initWithFormat:@"我正在使用Private-X魔盒,给大家分享%@等%ld个文件 ,快来看看吧~",firstname,_didSelectListArr.count];
  300. if(_didSelectListArr.count == 1){
  301. shareContent = [[NSString alloc] initWithFormat:@"我正在使用Private-X魔盒,给大家分享%@ ,快来看看吧~",firstname];
  302. }
  303. [[customShareManageTool sharedManager] shareType:shareType withShareUrl:shareUrl withShareTitle:shareTitle withShareContent:shareContent];
  304. }
  305. - (void)showSecretShareViewFunwith:(addShareModel*)model
  306. {
  307. [self removeFromSuperview];
  308. shareBySecretView *secretView = [[shareBySecretView alloc] init];
  309. secretView.addShareMod = model;
  310. secretView.didSelectListArr = _didSelectListArr;
  311. [ksharedAppDelegate.window addSubview:secretView];
  312. [secretView mas_makeConstraints:^(MASConstraintMaker *make) {
  313. make.left.mas_equalTo(0);
  314. make.right.mas_equalTo(0);
  315. make.top.mas_equalTo(0);
  316. make.bottom.mas_equalTo(0);
  317. }];
  318. }
  319. @end