shareRecordViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. //
  2. // shareRecordViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/14.
  6. //
  7. #import "shareRecordViewController.h"
  8. #import "shareRecordTableViewCell.h"
  9. #import "shareRecordDetailsHWViewController.h"
  10. #import "ShareRecordModel.h"
  11. @interface shareRecordViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  12. {
  13. BOOL isEditType;
  14. }
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @property (nonatomic, strong) UIButton *ruleBottomButton;
  17. @property (nonatomic, strong) UIButton *delRuleButton;
  18. @property (nonatomic, strong) UIButton *cancelShareButton;
  19. @property (nonatomic, strong) UIButton *rightEditButton;
  20. @property (nonatomic, strong) UIButton *leftCancleButton;
  21. @property (nonatomic, strong) UIButton *rightSelectAllButton;
  22. @property (nonatomic, strong) ShareRecordModel * ShareRecordMod;
  23. @end
  24. @implementation shareRecordViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. [self.toolBar setHidden:YES];
  29. [self.navigationBar setHidden:YES];
  30. [self.navBarBGView setHidden:NO];
  31. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  32. //[self.view setBackgroundColor:[UIColor hwColor:@"#F5F7FA"]];
  33. [self.view setBackgroundColor:[UIColor whiteColor]];
  34. self.titleLabel.text = NSLocalizedString(@"my_set_no_share",nil);
  35. [self drawAnyView];
  36. [self getShareFileListFun];
  37. }
  38. - (void)drawAnyView{
  39. [self initNavHeadUIFun];
  40. [self.view addSubview:self.tableView];
  41. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.mas_equalTo(0);
  43. make.right.mas_equalTo(0);
  44. make.bottom.mas_equalTo(-(60 + safeArea));
  45. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  46. }];
  47. _ruleBottomButton = [[UIButton alloc] init];
  48. [_ruleBottomButton setTitle:NSLocalizedString(@"share_rule_but_title",nil) forState:UIControlStateNormal];
  49. [_ruleBottomButton setTitleColor:[UIColor hwColor:@"#01B7EA"] forState:UIControlStateNormal];
  50. _ruleBottomButton.titleLabel.font = [UIFont boldSystemFontOfSize:14.0];
  51. [_ruleBottomButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  52. _ruleBottomButton.tag = 1;
  53. [self.view addSubview:_ruleBottomButton];
  54. _ruleBottomButton.layer.cornerRadius = 8;
  55. _ruleBottomButton.layer.masksToBounds = YES;
  56. _ruleBottomButton.backgroundColor = [UIColor whiteColor];
  57. _ruleBottomButton.layer.borderWidth = 1;
  58. _ruleBottomButton.layer.borderColor = [UIColor hwColor:@"#01B7EA"].CGColor;
  59. [_ruleBottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(15);
  61. make.right.mas_equalTo(-15);
  62. make.bottom.mas_equalTo(-(safeArea));
  63. make.height.mas_equalTo(48);
  64. }];
  65. _delRuleButton = [[UIButton alloc] init];
  66. [_delRuleButton setTitle:NSLocalizedString(@"share_del_record",nil) forState:UIControlStateNormal];
  67. [_delRuleButton setTitleColor:HW0A132BColor forState:UIControlStateNormal];
  68. _delRuleButton.titleLabel.font = [UIFont boldSystemFontOfSize:14.0];
  69. [_delRuleButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  70. _delRuleButton.tag = 10;
  71. [self.view addSubview:_delRuleButton];
  72. _delRuleButton.layer.cornerRadius = 8;
  73. _delRuleButton.layer.masksToBounds = YES;
  74. _delRuleButton.backgroundColor = [UIColor hwColor:@"#E3E8F1"];
  75. _delRuleButton.hidden = YES;
  76. [_delRuleButton mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.mas_equalTo(15);
  78. make.right.equalTo(self.view.mas_centerX).offset(-10);
  79. make.bottom.mas_equalTo(-(safeArea));
  80. make.height.mas_equalTo(48);
  81. }];
  82. _cancelShareButton = [[UIButton alloc] init];
  83. CGFloat w_btn = SCREEN_W/2.0 -15 -10;
  84. // gradient
  85. CAGradientLayer *gl = [CAGradientLayer layer];
  86. gl.frame = CGRectMake(0,0,w_btn,48.f);
  87. gl.startPoint = CGPointMake(0, 0.5);
  88. gl.endPoint = CGPointMake(1, 0.5);
  89. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  90. gl.locations = @[@(0), @(1.0f)];
  91. [_cancelShareButton.layer addSublayer:gl];
  92. [_cancelShareButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  93. [_cancelShareButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:(UIControlEventTouchUpInside)];
  94. [_cancelShareButton setTitle:NSLocalizedString(@"cancel_share_title",nil) forState:(UIControlStateNormal)];
  95. [_cancelShareButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  96. [_cancelShareButton.layer setCornerRadius:8.f];
  97. _cancelShareButton.clipsToBounds = YES;
  98. _cancelShareButton.tag = 11;
  99. [self.view addSubview:_cancelShareButton];
  100. _cancelShareButton.hidden = YES;
  101. [_cancelShareButton mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.right.mas_equalTo(-15);
  103. make.left.equalTo(self.view.mas_centerX).offset(10);
  104. make.bottom.mas_equalTo(-(safeArea));
  105. make.height.mas_equalTo(48);
  106. }];
  107. }
  108. - (void)initNavHeadUIFun
  109. {
  110. _rightEditButton = [[UIButton alloc] init];
  111. [_rightEditButton setTitle:NSLocalizedString(@"edit_common",nil) forState:UIControlStateNormal];
  112. _rightEditButton.tag = 2;
  113. [_rightEditButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  114. _rightEditButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
  115. _rightEditButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  116. [_rightEditButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  117. [self.navBarBGView addSubview:_rightEditButton];
  118. [_rightEditButton mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.width.mas_equalTo(80);
  120. make.height.mas_equalTo(40);
  121. make.right.mas_equalTo(-15);
  122. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  123. }];
  124. _leftCancleButton = [[UIButton alloc] init];
  125. [_leftCancleButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  126. _leftCancleButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  127. _leftCancleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  128. [_leftCancleButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  129. _leftCancleButton.tag = 3;
  130. [_leftCancleButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal];
  131. [self.navBarBGView addSubview:_leftCancleButton];
  132. _leftCancleButton.hidden = YES;
  133. [_leftCancleButton mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.width.mas_equalTo(80);
  135. make.left.mas_equalTo(15);
  136. make.height.mas_equalTo(30);
  137. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  138. }];
  139. _rightSelectAllButton = [[UIButton alloc] init];
  140. [_rightSelectAllButton setImage:[UIImage imageNamed:@"edit_select_all_h"] forState:UIControlStateSelected];
  141. [_rightSelectAllButton setImage:[UIImage imageNamed:@"edit_select_all_n"] forState:UIControlStateNormal];
  142. [_rightSelectAllButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  143. _rightSelectAllButton.tag = 4;
  144. [self.navBarBGView addSubview:_rightSelectAllButton];
  145. _rightSelectAllButton.hidden = YES;
  146. [_rightSelectAllButton mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.width.mas_equalTo(80);
  148. make.right.mas_equalTo(0);
  149. make.height.mas_equalTo(30);
  150. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  151. }];
  152. }
  153. #pragma mark - 懒加载
  154. - (UITableView *)tableView{
  155. if (!_tableView) {
  156. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  157. _tableView.delegate = self;
  158. _tableView.dataSource = self;
  159. _tableView.showsVerticalScrollIndicator = NO;
  160. _tableView.showsHorizontalScrollIndicator = NO;
  161. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  162. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  163. [_tableView setSeparatorColor:[UIColor clearColor]];
  164. [_tableView setBackgroundColor:[UIColor clearColor]];
  165. [_tableView setTableFooterView:[UIView new]];
  166. [_tableView setBounces:YES];
  167. if (@available(iOS 15.0, *)) {
  168. _tableView.sectionHeaderTopPadding = 0;
  169. }
  170. //空数据引入第三方开源处理
  171. _tableView.emptyDataSetSource = self;
  172. _tableView.emptyDataSetDelegate = self;
  173. }
  174. return _tableView;
  175. }
  176. #pragma mark - 列表委托
  177. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  178. return 1;
  179. }
  180. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  181. if (_ShareRecordMod && _ShareRecordMod.data.count>0) {
  182. return _ShareRecordMod.data.count;
  183. }
  184. return 0;
  185. }
  186. - (shareRecordTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  187. __block NSInteger row = indexPath.row;
  188. static NSString *identifier = @"shareRecordTableViewCell";
  189. shareRecordTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  190. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  191. if (!cell){
  192. cell = [[shareRecordTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  193. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  194. [cell setBackgroundColor:[UIColor clearColor]];
  195. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  196. }
  197. cell.isEditType = isEditType;
  198. if(row < _ShareRecordMod.data.count){
  199. ShareRecordListModel* model = _ShareRecordMod.data[row];
  200. cell.dataModel = model;
  201. KWeakSelf
  202. // cell.didClickSwitch = ^(BOOL SwitchOn) {
  203. // if([weakSelf userCheckFileModel:fileModel withShowTip:YES]){
  204. // [weakSelf userCheckFilePreviewByRow:row];
  205. // }
  206. // };
  207. }
  208. return cell;
  209. }
  210. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  211. return 70;
  212. }
  213. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  214. NSInteger row = indexPath.row;
  215. if(isEditType){
  216. return;
  217. }
  218. shareRecordDetailsHWViewController *vc = [shareRecordDetailsHWViewController new];
  219. [self.navigationController pushViewController:vc animated:YES];
  220. if(row < _ShareRecordMod.data.count){
  221. ShareRecordListModel* model = _ShareRecordMod.data[row];
  222. vc.dataModel = model;
  223. }
  224. KWeakSelf
  225. vc.didCancelShareLinkFun = ^{
  226. [weakSelf getShareFileListFun];
  227. };
  228. }
  229. #pragma mark 空数据
  230. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  231. NSString *imageName = @"common_no_data_pic";
  232. return [UIImage imageNamed:imageName];
  233. }
  234. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  235. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  236. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  237. NSForegroundColorAttributeName: HW999999Color};
  238. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  239. }
  240. //调整图片位置
  241. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  242. return -150;
  243. }
  244. - (void)didClickButtonFun:(UIButton*)but
  245. {
  246. NSInteger tag = but.tag;
  247. if(tag == 1){
  248. [[iToast makeText:@"分享规则"] show];
  249. }
  250. else if(tag == 2){
  251. [self setEditTypeFun];
  252. }
  253. else if(tag == 3){
  254. [self cancelEditTypeFun];
  255. }
  256. else if(tag == 4){
  257. but.selected = !but.selected;
  258. }
  259. }
  260. #pragma mark 进入编辑
  261. - (void)setEditTypeFun
  262. {
  263. isEditType = YES;
  264. _rightEditButton.hidden = YES;
  265. _ruleBottomButton.hidden = YES;
  266. self.backBtn.hidden = YES;
  267. _leftCancleButton.hidden = NO;
  268. _rightSelectAllButton.hidden = NO;
  269. _delRuleButton.hidden = NO;
  270. _delRuleButton.userInteractionEnabled = NO;
  271. // [_delRuleButton setTitleColor:[UIColor hwColor:@"#0A132B" alpha:0.5] forState:UIControlStateNormal];
  272. // _delRuleButton.backgroundColor = [UIColor hwColor:@"#E3E8F1" alpha:0.5];
  273. _delRuleButton.alpha = 0.5;
  274. _cancelShareButton.hidden = NO;
  275. _cancelShareButton.userInteractionEnabled = NO;
  276. _cancelShareButton.alpha = 0.5;
  277. [self.tableView reloadData];
  278. }
  279. #pragma mark 取消编辑
  280. - (void)cancelEditTypeFun
  281. {
  282. isEditType = NO;
  283. _rightEditButton.hidden = NO;
  284. _ruleBottomButton.hidden = NO;
  285. self.backBtn.hidden = NO;
  286. _leftCancleButton.hidden = YES;
  287. _rightSelectAllButton.hidden = YES;
  288. _delRuleButton.hidden = YES;
  289. _cancelShareButton.hidden = YES;
  290. [self.tableView reloadData];
  291. }
  292. #pragma mark 分享记录列表
  293. - (void)getShareFileListFun
  294. {
  295. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  296. NSString *SNStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  297. if(SNStr){
  298. [paraDict setValue:SNStr forKey:@"sn"];
  299. }
  300. else{
  301. return;;
  302. }
  303. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  304. KWeakSelf
  305. [[netWorkManager shareInstance] CommonPostCallBackCode:queryShareRecordFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  306. [weakSelf removeNewIndicator];
  307. weakSelf.ShareRecordMod = [[ShareRecordModel alloc] initWithDictionary:responseObject error:nil];
  308. if(weakSelf.ShareRecordMod && weakSelf.ShareRecordMod.status == 0){
  309. [weakSelf.tableView reloadData];
  310. }
  311. else{
  312. }
  313. } failure:^(NSError * _Nonnull error) {
  314. [weakSelf removeNewIndicator];
  315. }];
  316. }
  317. @end