editShareView.m 14 KB

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