editShareView.m 16 KB

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