recordFileCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. [_cellBg2View addSubview:_editButton];
  154. [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.left.mas_equalTo(12.0);
  156. make.bottom.mas_equalTo(-10.0);
  157. make.height.mas_equalTo(24.0);
  158. make.width.mas_equalTo(24.0);
  159. }];
  160. //删除
  161. _deleteButton = [[UIButton alloc] init];
  162. [_deleteButton setImage:[UIImage imageNamed:@"record_delete_icon"] forState:UIControlStateNormal];
  163. [_cellBg2View addSubview:_deleteButton];
  164. [_deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
  165. make.right.mas_equalTo(-12.0);
  166. make.bottom.mas_equalTo(-10.0);
  167. make.height.mas_equalTo(24.0);
  168. make.width.mas_equalTo(24.0);
  169. }];
  170. //播放或暂停
  171. _playOrPauseButton = [[UIButton alloc] init];
  172. [_playOrPauseButton setImage:[UIImage imageNamed:@"record_player_icon"] forState:UIControlStateNormal];
  173. [_playOrPauseButton setImage:[UIImage imageNamed:@"record_pause_icon"] forState:UIControlStateSelected];
  174. [_cellBg2View addSubview:_playOrPauseButton];
  175. [_playOrPauseButton mas_makeConstraints:^(MASConstraintMaker *make) {
  176. make.centerX.mas_equalTo(0.0);
  177. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  178. make.height.mas_equalTo(24.0);
  179. make.width.mas_equalTo(24.0);
  180. }];
  181. //后退
  182. _backwardButton = [[UIButton alloc] init];
  183. [_backwardButton setImage:[UIImage imageNamed:@"record_backward_icon"] forState:UIControlStateNormal];
  184. [_cellBg2View addSubview:_backwardButton];
  185. [_backwardButton mas_makeConstraints:^(MASConstraintMaker *make) {
  186. make.right.equalTo(_playOrPauseButton.mas_left).offset(-32);
  187. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  188. make.height.mas_equalTo(20.0);
  189. make.width.mas_equalTo(20.0);
  190. }];
  191. //前进
  192. _forwardButton = [[UIButton alloc] init];
  193. [_forwardButton setImage:[UIImage imageNamed:@"record_forward_icon"] forState:UIControlStateNormal];
  194. [_cellBg2View addSubview:_forwardButton];
  195. [_forwardButton mas_makeConstraints:^(MASConstraintMaker *make) {
  196. make.left.equalTo(_playOrPauseButton.mas_right).offset(32);
  197. make.centerY.equalTo(_editButton.mas_centerY).offset(0);
  198. make.height.mas_equalTo(20.0);
  199. make.width.mas_equalTo(20.0);
  200. }];
  201. }
  202. - (void)setCurRecordFileModel:(recordFileModel *)curRecordFileModel
  203. {
  204. _curRecordFileModel = curRecordFileModel;
  205. if(_curRecordFileModel.showAllType){
  206. _cellBg2View.hidden = NO;
  207. }
  208. else{
  209. _cellBg2View.hidden = YES;
  210. }
  211. _nameLabel.text = _curRecordFileModel.fileName;
  212. // 创建日期格式化器
  213. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  214. // 设置日期格式
  215. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  216. // 将NSDate转换为NSString
  217. NSString *dateString = [dateFormatter stringFromDate:_curRecordFileModel.modificationDate];
  218. _dataLabel.text = dateString;
  219. //大小
  220. NSString * totalSizeStr = nil;
  221. NSInteger totalSize_k = _curRecordFileModel.fileSize / 1024;
  222. if(totalSize_k < 1024){
  223. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  224. }
  225. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  226. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  227. }
  228. else{
  229. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  230. }
  231. // 时长 totalTime
  232. NSInteger hour = 0;
  233. NSInteger min = 0;
  234. NSInteger second = 0;
  235. hour = _curRecordFileModel.totalTime / 60 /60;
  236. min = (_curRecordFileModel.totalTime -60*hour)/60;
  237. second = _curRecordFileModel.totalTime -60*hour - 60 *min;
  238. NSString* totalTimeStr = [[NSString alloc] initWithFormat:@"%02ld:%02ld:%02ld",hour,min,second];;
  239. _timeAndSizeLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",totalTimeStr,totalSizeStr];
  240. _progressingLabel.text = @"00:00:00";
  241. _totaltimeLabel.text = totalTimeStr;
  242. }
  243. @end