recordFileCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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)UIView *cellBg2View;//
  14. @property(nonatomic,strong)UIView *progressBgView;//进度被拒
  15. @property(nonatomic,strong)UIView *progressingView;//进度条
  16. @property(nonatomic,strong)UIView *progressYuanView;//进度小圆点
  17. @property(nonatomic,strong)UILabel *progressingLabel;//已经播放的时长
  18. @property(nonatomic,strong)UILabel *totaltimeLabel;//总时间
  19. @property(nonatomic,strong)UIButton *editButton;//编辑
  20. @property(nonatomic,strong)UIButton *deleteButton;//删除
  21. @property(nonatomic,strong)UIButton *backwardButton;//后退
  22. @property(nonatomic,strong)UIButton *playOrPauseButton;//播放或暂停
  23. @property(nonatomic,strong)UIButton *forwardButton;//前进
  24. @end
  25. @implementation recordFileCell
  26. @synthesize cellBgView;
  27. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  28. {
  29. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  30. if (self)
  31. {
  32. [self drawView];
  33. }
  34. return self;
  35. }
  36. - (void)drawView
  37. {
  38. cellBgView = [[UIView alloc] init];
  39. cellBgView.layer.cornerRadius = 12;
  40. cellBgView.layer.masksToBounds = YES;
  41. [self.contentView addSubview:cellBgView];
  42. cellBgView.backgroundColor = [UIColor whiteColor];
  43. [cellBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.mas_equalTo(15.f);
  45. make.top.mas_equalTo(0);
  46. make.bottom.mas_equalTo(0);
  47. make.width.mas_equalTo(SCREEN_W - 2*15.f);
  48. }];
  49. /**标题*/
  50. _nameLabel = [[UILabel alloc] init];
  51. [cellBgView addSubview:_nameLabel];
  52. _nameLabel.font = [UIFont boldSystemFontOfSize:16.f];
  53. //_nameLabel.numberOfLines = 3;
  54. [_nameLabel setTextColor:HW0A132BColor];
  55. [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(12.0);
  57. make.top.mas_equalTo(10.0);
  58. make.height.mas_equalTo(20.0);
  59. //make.top.mas_equalTo(15.f);
  60. }];
  61. //日期
  62. _dataLabel = [[UILabel alloc] init];
  63. [cellBgView addSubview:_dataLabel];
  64. _dataLabel.font = [UIFont systemFontOfSize:12.f];
  65. [_dataLabel setTextColor:[UIColor hwColor:@"979797"]];
  66. [_dataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.mas_equalTo(12.0);
  68. make.top.equalTo(_nameLabel.mas_bottom).offset(5);
  69. make.height.mas_equalTo(20.0);
  70. //make.top.mas_equalTo(15.f);
  71. }];
  72. //时长和大小
  73. _timeAndSizeLabel = [[UILabel alloc] init];
  74. [cellBgView addSubview:_timeAndSizeLabel];
  75. _timeAndSizeLabel.font = [UIFont systemFontOfSize:12.f];
  76. _timeAndSizeLabel.textAlignment = NSTextAlignmentRight;
  77. [_timeAndSizeLabel setTextColor:[UIColor hwColor:@"979797"]];
  78. [_timeAndSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.right.mas_equalTo(-12.0);
  80. make.top.equalTo(_nameLabel.mas_bottom).offset(5);
  81. make.height.mas_equalTo(20.0);
  82. //make.top.mas_equalTo(15.f);
  83. }];
  84. /********************************************************************************************/
  85. //第二部分
  86. _cellBg2View = [[UIView alloc] init];
  87. [cellBgView addSubview:_cellBg2View];
  88. //_cellBg2View.backgroundColor = [UIColor greenColor];
  89. [_cellBg2View mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.mas_equalTo(0.f);
  91. make.right.mas_equalTo(0);
  92. make.bottom.mas_equalTo(0);
  93. make.height.mas_equalTo(85.f);
  94. }];
  95. _progressBgView = [[UIView alloc] init];
  96. [_cellBg2View addSubview:_progressBgView];
  97. _progressBgView.layer.cornerRadius =1.0;
  98. _progressBgView.layer.masksToBounds = YES;
  99. _progressBgView.backgroundColor = [UIColor hwColor:@"#EEEEEE"];
  100. [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.mas_equalTo(12.f);
  102. make.right.mas_equalTo(-12);
  103. make.top.mas_equalTo(5);
  104. make.height.mas_equalTo(2.f);
  105. }];
  106. _progressingView = [[UIView alloc] init];
  107. [_progressBgView addSubview:_progressingView];
  108. _progressingView.layer.cornerRadius =1.0;
  109. _progressingView.layer.masksToBounds = YES;
  110. _progressingView.backgroundColor = [UIColor hwColor:@"#333333"];
  111. [_progressingView mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.mas_equalTo(0.f);
  113. make.right.mas_equalTo(0);
  114. make.top.mas_equalTo(0);
  115. make.height.mas_equalTo(2.f);
  116. }];
  117. //
  118. _progressYuanView = [[UIView alloc] init];
  119. [_cellBg2View addSubview:_progressYuanView];
  120. _progressYuanView.layer.cornerRadius = 3.0;
  121. _progressYuanView.layer.masksToBounds = YES;
  122. _progressYuanView.backgroundColor = [UIColor hwColor:@"#333333"];
  123. [_progressYuanView mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.left.mas_equalTo(20.f);
  125. make.centerY.equalTo(_progressingView.mas_centerY);
  126. make.width.mas_equalTo(6.f);
  127. make.height.mas_equalTo(6.f);
  128. }];
  129. //已经播放的时长
  130. _progressingLabel = [[UILabel alloc] init];
  131. [_cellBg2View addSubview:_progressingLabel];
  132. _progressingLabel.font = [UIFont systemFontOfSize:12.f];
  133. [_progressingLabel setTextColor:[UIColor hwColor:@"979797"]];
  134. [_progressingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.left.mas_equalTo(12.0);
  136. make.top.equalTo(_progressYuanView.mas_bottom).offset(5);
  137. make.height.mas_equalTo(15.0);
  138. }];
  139. //已经播放的时长
  140. _totaltimeLabel = [[UILabel alloc] init];
  141. [_cellBg2View addSubview:_totaltimeLabel];
  142. _totaltimeLabel.font = [UIFont systemFontOfSize:12.f];
  143. _totaltimeLabel.textAlignment = NSTextAlignmentRight;
  144. [_totaltimeLabel setTextColor:[UIColor hwColor:@"979797"]];
  145. [_totaltimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  146. make.right.mas_equalTo(-12.0);
  147. make.top.equalTo(_progressYuanView.mas_bottom).offset(5);
  148. make.height.mas_equalTo(15.0);
  149. }];
  150. //编辑
  151. _editButton = [[UIButton alloc] init];
  152. [_editButton setImage:[UIImage imageNamed:@"record_edit_icon"] forState:UIControlStateNormal];
  153. _editButton.tag = 1;
  154. [_editButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  155. [_cellBg2View addSubview:_editButton];
  156. [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
  157. make.left.mas_equalTo(12.0);
  158. make.bottom.mas_equalTo(-10.0);
  159. make.height.mas_equalTo(24.0);
  160. make.width.mas_equalTo(24.0);
  161. }];
  162. //删除
  163. _deleteButton = [[UIButton alloc] init];
  164. [_deleteButton setImage:[UIImage imageNamed:@"record_delete_icon"] forState:UIControlStateNormal];
  165. _deleteButton.tag = 2;
  166. [_deleteButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  167. [_cellBg2View addSubview:_deleteButton];
  168. [_deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
  169. make.right.mas_equalTo(-12.0);
  170. make.bottom.mas_equalTo(-10.0);
  171. make.height.mas_equalTo(24.0);
  172. make.width.mas_equalTo(24.0);
  173. }];
  174. //播放或暂停
  175. _playOrPauseButton = [[UIButton alloc] init];
  176. [_playOrPauseButton setImage:[UIImage imageNamed:@"record_player_icon"] forState:UIControlStateNormal];
  177. [_playOrPauseButton setImage:[UIImage imageNamed:@"record_pause_icon"] forState:UIControlStateSelected];
  178. [_cellBg2View addSubview:_playOrPauseButton];
  179. [_playOrPauseButton mas_makeConstraints:^(MASConstraintMaker *make) {
  180. make.centerX.mas_equalTo(0.0);
  181. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  182. make.height.mas_equalTo(24.0);
  183. make.width.mas_equalTo(24.0);
  184. }];
  185. //后退
  186. _backwardButton = [[UIButton alloc] init];
  187. [_backwardButton setImage:[UIImage imageNamed:@"record_backward_icon"] forState:UIControlStateNormal];
  188. [_cellBg2View addSubview:_backwardButton];
  189. [_backwardButton mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.right.equalTo(_playOrPauseButton.mas_left).offset(-32);
  191. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  192. make.height.mas_equalTo(20.0);
  193. make.width.mas_equalTo(20.0);
  194. }];
  195. //前进
  196. _forwardButton = [[UIButton alloc] init];
  197. [_forwardButton setImage:[UIImage imageNamed:@"record_forward_icon"] forState:UIControlStateNormal];
  198. [_cellBg2View addSubview:_forwardButton];
  199. [_forwardButton mas_makeConstraints:^(MASConstraintMaker *make) {
  200. make.left.equalTo(_playOrPauseButton.mas_right).offset(32);
  201. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  202. make.height.mas_equalTo(20.0);
  203. make.width.mas_equalTo(20.0);
  204. }];
  205. }
  206. #pragma mark 按钮点击事件
  207. - (void)didClickButFun:(UIButton*)but
  208. {
  209. NSInteger tag = but.tag;
  210. if (_didClickRecordButFun) {
  211. _didClickRecordButFun(tag);
  212. }
  213. }
  214. - (void)setCurRecordFileModel:(recordFileModel *)curRecordFileModel
  215. {
  216. _curRecordFileModel = curRecordFileModel;
  217. if(_curRecordFileModel.showAllType){
  218. _cellBg2View.hidden = NO;
  219. }
  220. else{
  221. _cellBg2View.hidden = YES;
  222. }
  223. _nameLabel.text = _curRecordFileModel.fileName;
  224. // 创建日期格式化器
  225. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  226. // 设置日期格式
  227. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  228. // 将NSDate转换为NSString
  229. NSString *dateString = [dateFormatter stringFromDate:_curRecordFileModel.modificationDate];
  230. _dataLabel.text = dateString;
  231. //大小
  232. NSString * totalSizeStr = nil;
  233. NSInteger totalSize_k = _curRecordFileModel.fileSize / 1024;
  234. if(totalSize_k < 1024){
  235. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  236. }
  237. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  238. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  239. }
  240. else{
  241. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  242. }
  243. // 时长 totalTime
  244. NSInteger hour = 0;
  245. NSInteger min = 0;
  246. NSInteger second = 0;
  247. hour = _curRecordFileModel.totalTime / 60 /60;
  248. min = (_curRecordFileModel.totalTime -60*hour)/60;
  249. second = _curRecordFileModel.totalTime -60*hour - 60 *min;
  250. NSString* totalTimeStr = [[NSString alloc] initWithFormat:@"%02ld:%02ld:%02ld",hour,min,second];;
  251. _timeAndSizeLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",totalTimeStr,totalSizeStr];
  252. _progressingLabel.text = @"00:00:00";
  253. _totaltimeLabel.text = totalTimeStr;
  254. }
  255. @end