recordFileCell.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. //
  2. // recordFileCell.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2025/3/31.
  6. //
  7. #import "recordFileCell.h"
  8. @interface recordFileCell ()
  9. @property(nonatomic,strong)UIView *cellBgView;
  10. @property(nonatomic,strong)UILabel *nameLabel;//名称
  11. @property(nonatomic,strong)UILabel *dataLabel;//日期
  12. @property(nonatomic,strong)UILabel *timeAndSizeLabel;//时长和大小
  13. @property(nonatomic, strong) UIButton *checkButton;
  14. @property(nonatomic,strong)UIView *cellBg2View;//
  15. @property(nonatomic,strong)UIView *progressBgView;//进度被拒
  16. @property(nonatomic,strong)UIView *progressingView;//进度条
  17. @property(nonatomic,strong)UIView *progressYuanView;//进度小圆点
  18. @property(nonatomic,strong)UILabel *progressingLabel;//已经播放的时长
  19. @property(nonatomic,strong)UILabel *totaltimeLabel;//总时间
  20. @property(nonatomic,strong)UIButton *editButton;//编辑
  21. @property(nonatomic,strong)UIButton *deleteButton;//删除
  22. @property(nonatomic,strong)UIButton *backwardButton;//后退
  23. @property(nonatomic,strong)UIButton *playOrPauseButton;//播放或暂停
  24. @property(nonatomic,strong)UIButton *forwardButton;//前进
  25. @end
  26. @implementation recordFileCell
  27. @synthesize cellBgView;
  28. @synthesize checkButton;
  29. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  30. {
  31. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  32. if (self)
  33. {
  34. [self drawView];
  35. }
  36. return self;
  37. }
  38. - (void)drawView
  39. {
  40. cellBgView = [[UIView alloc] init];
  41. cellBgView.layer.cornerRadius = 12;
  42. cellBgView.layer.masksToBounds = YES;
  43. [self.contentView addSubview:cellBgView];
  44. cellBgView.backgroundColor = [UIColor whiteColor];
  45. [cellBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.mas_equalTo(15.f);
  47. make.top.mas_equalTo(0);
  48. make.bottom.mas_equalTo(0);
  49. make.width.mas_equalTo(SCREEN_W - 2*15.f);
  50. }];
  51. checkButton = [[UIButton alloc] init];
  52. [checkButton setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
  53. [checkButton setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  54. [cellBgView addSubview:checkButton];
  55. checkButton.hidden = YES;
  56. [checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.left.mas_equalTo(5.f);
  58. make.centerY.equalTo(cellBgView.mas_centerY);
  59. make.width.mas_equalTo(36.f);
  60. make.height.mas_equalTo(36.f);
  61. }];
  62. [checkButton addTarget:self action:@selector(maskSwitchPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  63. /**标题*/
  64. _nameLabel = [[UILabel alloc] init];
  65. [cellBgView addSubview:_nameLabel];
  66. _nameLabel.font = [UIFont boldSystemFontOfSize:16.f];
  67. //_nameLabel.numberOfLines = 3;
  68. [_nameLabel setTextColor:HW0A132BColor];
  69. [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.mas_equalTo(12.0);
  71. make.top.mas_equalTo(10.0);
  72. make.height.mas_equalTo(20.0);
  73. //make.top.mas_equalTo(15.f);
  74. }];
  75. //日期
  76. _dataLabel = [[UILabel alloc] init];
  77. [cellBgView addSubview:_dataLabel];
  78. _dataLabel.font = [UIFont systemFontOfSize:12.f];
  79. [_dataLabel setTextColor:[UIColor hwColor:@"979797"]];
  80. [_dataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.mas_equalTo(12.0);
  82. make.top.equalTo(_nameLabel.mas_bottom).offset(5);
  83. make.height.mas_equalTo(20.0);
  84. //make.top.mas_equalTo(15.f);
  85. }];
  86. //时长和大小
  87. _timeAndSizeLabel = [[UILabel alloc] init];
  88. [cellBgView addSubview:_timeAndSizeLabel];
  89. _timeAndSizeLabel.font = [UIFont systemFontOfSize:12.f];
  90. _timeAndSizeLabel.textAlignment = NSTextAlignmentRight;
  91. [_timeAndSizeLabel setTextColor:[UIColor hwColor:@"979797"]];
  92. [_timeAndSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.right.mas_equalTo(-12.0);
  94. make.top.equalTo(_nameLabel.mas_bottom).offset(5);
  95. make.height.mas_equalTo(20.0);
  96. //make.top.mas_equalTo(15.f);
  97. }];
  98. /********************************************************************************************/
  99. //第二部分
  100. _cellBg2View = [[UIView alloc] init];
  101. [cellBgView addSubview:_cellBg2View];
  102. //_cellBg2View.backgroundColor = [UIColor greenColor];
  103. [_cellBg2View mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.mas_equalTo(0.f);
  105. make.right.mas_equalTo(0);
  106. make.bottom.mas_equalTo(0);
  107. make.height.mas_equalTo(85.f);
  108. }];
  109. _progressBgView = [[UIView alloc] init];
  110. [_cellBg2View addSubview:_progressBgView];
  111. _progressBgView.layer.cornerRadius =1.0;
  112. _progressBgView.layer.masksToBounds = YES;
  113. _progressBgView.backgroundColor = [UIColor hwColor:@"#EEEEEE"];
  114. [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.left.mas_equalTo(12.f);
  116. make.right.mas_equalTo(-12);
  117. make.top.mas_equalTo(5);
  118. make.height.mas_equalTo(2.f);
  119. }];
  120. _progressingView = [[UIView alloc] init];
  121. [_progressBgView addSubview:_progressingView];
  122. _progressingView.layer.cornerRadius =1.0;
  123. _progressingView.layer.masksToBounds = YES;
  124. _progressingView.backgroundColor = [UIColor hwColor:@"#333333"];
  125. [_progressingView mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.mas_equalTo(0.f);
  127. make.width.mas_equalTo(0);
  128. make.top.mas_equalTo(0);
  129. make.height.mas_equalTo(2.f);
  130. }];
  131. //
  132. _progressYuanView = [[UIView alloc] init];
  133. [_cellBg2View addSubview:_progressYuanView];
  134. _progressYuanView.layer.cornerRadius = 3.0;
  135. _progressYuanView.layer.masksToBounds = YES;
  136. _progressYuanView.backgroundColor = [UIColor hwColor:@"#333333"];
  137. [_progressYuanView mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.left.equalTo(_progressBgView.mas_left).offset(0.0);
  139. make.centerY.equalTo(_progressingView.mas_centerY);
  140. make.width.mas_equalTo(6.f);
  141. make.height.mas_equalTo(6.f);
  142. }];
  143. //已经播放的时长
  144. _progressingLabel = [[UILabel alloc] init];
  145. [_cellBg2View addSubview:_progressingLabel];
  146. _progressingLabel.font = [UIFont systemFontOfSize:12.f];
  147. [_progressingLabel setTextColor:[UIColor hwColor:@"979797"]];
  148. [_progressingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.left.mas_equalTo(12.0);
  150. make.top.equalTo(_progressYuanView.mas_bottom).offset(5);
  151. make.height.mas_equalTo(15.0);
  152. }];
  153. //已经播放的时长
  154. _totaltimeLabel = [[UILabel alloc] init];
  155. [_cellBg2View addSubview:_totaltimeLabel];
  156. _totaltimeLabel.font = [UIFont systemFontOfSize:12.f];
  157. _totaltimeLabel.textAlignment = NSTextAlignmentRight;
  158. [_totaltimeLabel setTextColor:[UIColor hwColor:@"979797"]];
  159. [_totaltimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  160. make.right.mas_equalTo(-12.0);
  161. make.top.equalTo(_progressYuanView.mas_bottom).offset(5);
  162. make.height.mas_equalTo(15.0);
  163. }];
  164. //编辑
  165. _editButton = [[UIButton alloc] init];
  166. [_editButton setImage:[UIImage imageNamed:@"record_edit_icon"] forState:UIControlStateNormal];
  167. _editButton.tag = 1;
  168. [_editButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  169. [_cellBg2View addSubview:_editButton];
  170. [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.left.mas_equalTo(12.0);
  172. make.bottom.mas_equalTo(-10.0);
  173. make.height.mas_equalTo(24.0);
  174. make.width.mas_equalTo(24.0);
  175. }];
  176. //删除
  177. _deleteButton = [[UIButton alloc] init];
  178. [_deleteButton setImage:[UIImage imageNamed:@"record_delete_icon"] forState:UIControlStateNormal];
  179. _deleteButton.tag = 2;
  180. [_deleteButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  181. [_cellBg2View addSubview:_deleteButton];
  182. [_deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.right.mas_equalTo(-12.0);
  184. make.bottom.mas_equalTo(-10.0);
  185. make.height.mas_equalTo(24.0);
  186. make.width.mas_equalTo(24.0);
  187. }];
  188. //播放或暂停
  189. _playOrPauseButton = [[UIButton alloc] init];
  190. [_playOrPauseButton setImage:[UIImage imageNamed:@"record_player_icon"] forState:UIControlStateNormal];
  191. [_playOrPauseButton setImage:[UIImage imageNamed:@"record_pause_icon"] forState:UIControlStateSelected];
  192. _playOrPauseButton.tag = 10;
  193. [_playOrPauseButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  194. [_cellBg2View addSubview:_playOrPauseButton];
  195. [_playOrPauseButton mas_makeConstraints:^(MASConstraintMaker *make) {
  196. make.centerX.mas_equalTo(0.0);
  197. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  198. make.height.mas_equalTo(24.0);
  199. make.width.mas_equalTo(24.0);
  200. }];
  201. //后退
  202. _backwardButton = [[UIButton alloc] init];
  203. [_backwardButton setImage:[UIImage imageNamed:@"record_backward_icon"] forState:UIControlStateNormal];
  204. _backwardButton.tag = 11;
  205. [_backwardButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  206. [_cellBg2View addSubview:_backwardButton];
  207. [_backwardButton mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.right.equalTo(_playOrPauseButton.mas_left).offset(-32);
  209. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  210. make.height.mas_equalTo(20.0);
  211. make.width.mas_equalTo(20.0);
  212. }];
  213. //前进
  214. _forwardButton = [[UIButton alloc] init];
  215. [_forwardButton setImage:[UIImage imageNamed:@"record_forward_icon"] forState:UIControlStateNormal];
  216. _forwardButton.tag = 12;
  217. [_forwardButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  218. [_cellBg2View addSubview:_forwardButton];
  219. [_forwardButton mas_makeConstraints:^(MASConstraintMaker *make) {
  220. make.left.equalTo(_playOrPauseButton.mas_right).offset(32);
  221. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  222. make.height.mas_equalTo(20.0);
  223. make.width.mas_equalTo(20.0);
  224. }];
  225. }
  226. #pragma mark 按钮点击事件
  227. - (void)didClickButFun:(UIButton*)but
  228. {
  229. NSInteger tag = but.tag;
  230. if(but == _playOrPauseButton){
  231. if (_playOrPauseButton.selected) {
  232. tag = 100;
  233. }
  234. _playOrPauseButton.selected = !_playOrPauseButton.selected;
  235. }
  236. if (_didClickRecordButFun) {
  237. _didClickRecordButFun(tag);
  238. }
  239. }
  240. - (void)setCurRecordFileModel:(recordFileModel *)curRecordFileModel
  241. {
  242. _curRecordFileModel = curRecordFileModel;
  243. if(_curRecordFileModel.showAllType){
  244. _cellBg2View.hidden = NO;
  245. }
  246. else{
  247. _cellBg2View.hidden = YES;
  248. }
  249. _nameLabel.text = _curRecordFileModel.fileName;
  250. // 创建日期格式化器
  251. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  252. // 设置日期格式
  253. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  254. // 将NSDate转换为NSString
  255. NSString *dateString = [dateFormatter stringFromDate:_curRecordFileModel.modificationDate];
  256. _dataLabel.text = dateString;
  257. //大小
  258. NSString * totalSizeStr = nil;
  259. NSInteger totalSize_k = _curRecordFileModel.fileSize / 1024;
  260. if(totalSize_k < 1024){
  261. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  262. }
  263. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  264. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  265. }
  266. else{
  267. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  268. }
  269. if (_curRecordFileModel.isPlayingType) {
  270. _playOrPauseButton.selected = YES;
  271. }
  272. else{
  273. _playOrPauseButton.selected = NO;
  274. }
  275. // 时长 totalTime
  276. NSInteger hour = 0;
  277. NSInteger min = 0;
  278. NSInteger second = 0;
  279. hour = _curRecordFileModel.totalTime / 60 /60;
  280. min = (_curRecordFileModel.totalTime -60*hour)/60;
  281. second = _curRecordFileModel.totalTime -60*hour - 60 *min;
  282. NSString* totalTimeStr = [[NSString alloc] initWithFormat:@"%02ld:%02ld:%02ld",hour,min,second];
  283. _timeAndSizeLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",totalTimeStr,totalSizeStr];
  284. _totaltimeLabel.text = totalTimeStr;
  285. //进度相关
  286. // 播放时长 curPlayerTime
  287. NSInteger playerhour = 0;
  288. NSInteger playerMin = 0;
  289. NSInteger playerSecond = 0;
  290. if (_curRecordFileModel.curPlayerTime == 0) {
  291. _progressingLabel.text = @"00:00:00";
  292. }
  293. else{
  294. playerhour = _curRecordFileModel.curPlayerTime / 60 /60;
  295. playerMin = (_curRecordFileModel.curPlayerTime -60*playerhour)/60;
  296. playerSecond = _curRecordFileModel.curPlayerTime -60*playerhour - 60 *playerMin;
  297. NSString* playingTimeStr = [[NSString alloc] initWithFormat:@"%02ld:%02ld:%02ld",playerhour,playerMin,playerSecond];
  298. _progressingLabel.text = playingTimeStr;
  299. CGFloat progress = _curRecordFileModel.curPlayerTime *1.0 /_curRecordFileModel.totalTime;
  300. CGFloat BgWidth = _progressBgView.hw_w;
  301. CGFloat progressingWidth = BgWidth* progress;
  302. [_progressingView mas_remakeConstraints:^(MASConstraintMaker *make) {
  303. make.left.mas_equalTo(0.f);
  304. make.width.mas_equalTo(progressingWidth);
  305. make.top.mas_equalTo(0);
  306. make.height.mas_equalTo(2.f);
  307. }];
  308. [_progressYuanView mas_remakeConstraints:^(MASConstraintMaker *make) {
  309. make.left.equalTo(_progressingView.mas_right).offset(-2);
  310. make.centerY.equalTo(_progressingView.mas_centerY);
  311. make.width.mas_equalTo(6.f);
  312. make.height.mas_equalTo(6.f);
  313. }];
  314. }
  315. if(curRecordFileModel.isEditType){
  316. checkButton.hidden = NO;
  317. checkButton.selected = curRecordFileModel.isSelectType;
  318. [_nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  319. make.left.equalTo(checkButton.mas_right).offset(10);
  320. make.top.mas_equalTo(10.0);
  321. make.height.mas_equalTo(20.0);
  322. //make.top.mas_equalTo(15.f);
  323. }];
  324. //日期
  325. [_dataLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  326. make.left.equalTo(checkButton.mas_right).offset(10);
  327. make.top.equalTo(_nameLabel.mas_bottom).offset(5);
  328. make.height.mas_equalTo(20.0);
  329. //make.top.mas_equalTo(15.f);
  330. }];
  331. }
  332. else{
  333. checkButton.hidden = YES;
  334. [_nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  335. make.left.mas_equalTo(12.0);
  336. make.top.mas_equalTo(10.0);
  337. make.height.mas_equalTo(20.0);
  338. //make.top.mas_equalTo(15.f);
  339. }];
  340. //日期
  341. [_dataLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  342. make.left.mas_equalTo(12.0);
  343. make.top.equalTo(_nameLabel.mas_bottom).offset(5);
  344. make.height.mas_equalTo(20.0);
  345. //make.top.mas_equalTo(15.f);
  346. }];
  347. }
  348. }
  349. - (void)maskSwitchPressed:(UIButton *)maskSwitch{
  350. maskSwitch.selected = !maskSwitch.selected;
  351. if(_didClickSwitch){
  352. _didClickSwitch(maskSwitch.selected);
  353. }
  354. }
  355. @end