editShareView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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(315 -50+ 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. }
  186. - (void)didClickButFun:(UIButton*)but
  187. {
  188. NSInteger tag = but.tag;
  189. //防止重复点击
  190. but.userInteractionEnabled = NO;
  191. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  192. but.userInteractionEnabled = YES;
  193. });
  194. if(tag==1 && !_day7Button.selected){
  195. _day7Button.selected = YES;
  196. _dayForeverButton.selected = NO;
  197. //私密分享
  198. _PrivacyShareButton.hidden = NO;
  199. }
  200. else if(tag==2 && !_dayForeverButton.selected){
  201. _day7Button.selected = NO;
  202. _dayForeverButton.selected = YES;
  203. //私密分享
  204. _PrivacyShareButton.hidden = YES;
  205. }
  206. else if(tag == 100){
  207. [self removeFromSuperview];
  208. }
  209. else{
  210. if(tag == 11){
  211. if(![QQApiInterface isSupportShareToQQ])
  212. {
  213. [[iToast makeText:@"未安装QQ,请先安装QQ"] show];
  214. return;
  215. }
  216. }
  217. else if (tag == 10 || tag == 12){
  218. if(![WXApi isWXAppInstalled])
  219. {
  220. [[iToast makeText:@"未安装微信,请先安装微信"] show];
  221. return;
  222. }
  223. }
  224. //请求服务器处理分享数据
  225. [self addShareDataBy:tag];
  226. }
  227. }
  228. //添加分享
  229. - (void)addShareDataBy:(NSInteger)tag
  230. {
  231. NSString *curSn = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  232. NSString *platformType = [[NSString alloc] initWithFormat:@"%ld", tag - 9];
  233. //_shareFileType
  234. NSInteger expirationDay = _day7Button.selected ? 7 : 0;
  235. NSMutableArray * boxShareFileDTOList = [NSMutableArray new];
  236. for (NASFilePicDataArrModel*dataModel in _didSelectListArr) {
  237. NSMutableDictionary *modelDict = [NSMutableDictionary new];
  238. if(dataModel.name){
  239. [modelDict setValue:dataModel.name forKey:@"fileName"];
  240. NSArray * nameArr = [dataModel.name componentsSeparatedByString:@"."];
  241. if(nameArr.count >= 2){
  242. NSString*fileSuffix = nameArr.lastObject;
  243. if(fileSuffix && fileSuffix.length > 0){
  244. [modelDict setValue:fileSuffix forKey:@"fileSuffix"];
  245. }
  246. }
  247. }
  248. if(dataModel.size >= 0){
  249. [modelDict setValue:[NSNumber numberWithLong:dataModel.size] forKey:@"fileSize"];
  250. }
  251. if(dataModel.time){
  252. [modelDict setValue:dataModel.time forKey:@"fileTime"];
  253. }
  254. if(dataModel.path){
  255. NSString *filePath = dataModel.path;
  256. NSString *urlStr = ksharedAppDelegate.NASShareFileService;
  257. NSString *headUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  258. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  259. if(headUrl){
  260. [modelDict setValue:headUrl forKey:@"headUrl"];
  261. }
  262. if(headUrl){
  263. [modelDict setValue:fileUrl forKey:@"fileUrl"];
  264. }
  265. }
  266. [boxShareFileDTOList addObject:modelDict];
  267. }
  268. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  269. if(!curSn){
  270. return;
  271. }
  272. [paraDict setValue:curSn forKey:@"sn"];
  273. [paraDict setValue:platformType forKey:@"platformType"];
  274. if(_shareFileType){
  275. [paraDict setValue:_shareFileType forKey:@"fileType"];
  276. }
  277. [paraDict setValue:[NSNumber numberWithInteger:expirationDay] forKey:@"expirationDay"];
  278. [paraDict setValue:boxShareFileDTOList forKey:@"boxShareFileDTOList"];
  279. KWeakSelf
  280. //[ showNewIndicatorWithCanBack:NO canTouch:NO];
  281. [[netWorkManager shareInstance] CommonPostCallBackCode:addShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  282. addShareModel *model = [[addShareModel alloc] initWithDictionary:responseObject error:nil];
  283. if(model && model.code == 0){
  284. [weakSelf gotoShareFunWith:tag with:model];
  285. }
  286. else{
  287. [[iToast makeText:NSLocalizedString(@"share_fail_msg",nil)] show];//
  288. }
  289. } failure:^(NSError * _Nonnull error) {
  290. [[iToast makeText:NSLocalizedString(@"share_fail_msg",nil)] show];
  291. }];
  292. }
  293. - (void)gotoShareFunWith:(NSInteger)tag with:(addShareModel*)model
  294. {
  295. //type1 朋友圈 2 微信好友 3 QQ
  296. NSInteger shareType = 1;
  297. if(tag == 10){
  298. shareType =2;
  299. }
  300. else if(tag == 11){
  301. shareType = 3;
  302. }
  303. else if(tag == 12){
  304. shareType = 1;
  305. }
  306. else if(tag == 13){
  307. [self showSecretShareViewFunwith:model];
  308. return;;
  309. }
  310. NSString *serUrl = shareService;
  311. NSString *shareUrl = [[NSString alloc] initWithFormat:@"%@%@",serUrl,model.data.token];
  312. //NSString *shareTitle = [[NSString alloc] initWithFormat:@"Private-X%@",NSLocalizedString(@"common_edit_share",nil)];
  313. NSString *shareTitle = @"Private-X分享";
  314. NSString *firstname = nil;
  315. if (_didSelectListArr.count > 0) {
  316. NASFilePicDataArrModel*dataModel = _didSelectListArr[0];
  317. firstname = dataModel.name;
  318. }
  319. //我正在使用Private-X魔盒,给大家分享 文件名称文件名称.jpg 等 2 个文件 ,快来看看吧~
  320. NSString *shareContent = [[NSString alloc] initWithFormat:@"我正在使用Private-X魔盒,给大家分享%@等%ld个文件 ,快来看看吧~",firstname,_didSelectListArr.count];
  321. if(_didSelectListArr.count == 1){
  322. shareContent = [[NSString alloc] initWithFormat:@"我正在使用Private-X魔盒,给大家分享%@ ,快来看看吧~",firstname];
  323. }
  324. [[customShareManageTool sharedManager] shareType:shareType withShareUrl:shareUrl withShareTitle:shareTitle withShareContent:shareContent];
  325. }
  326. - (void)showSecretShareViewFunwith:(addShareModel*)model
  327. {
  328. [self removeFromSuperview];
  329. shareBySecretView *secretView = [[shareBySecretView alloc] init];
  330. secretView.addShareMod = model;
  331. secretView.didSelectListArr = _didSelectListArr;
  332. [ksharedAppDelegate.window addSubview:secretView];
  333. [secretView mas_makeConstraints:^(MASConstraintMaker *make) {
  334. make.left.mas_equalTo(0);
  335. make.right.mas_equalTo(0);
  336. make.top.mas_equalTo(0);
  337. make.bottom.mas_equalTo(0);
  338. }];
  339. }
  340. @end