|
|
// |
|
|
// TableCell.m |
|
|
// myWear |
|
|
// |
|
|
// Created by xTT on 2017/1/18. |
|
|
// Copyright © 2017年 xTT. All rights reserved. |
|
|
// |
|
|
|
|
|
#import "TableCell.h" |
|
|
#import "myHelper.h" |
|
|
#import "MyHttp.h" |
|
|
|
|
|
#import "Masonry.h" |
|
|
|
|
|
#import "XHVoiceRecordHelper.h" |
|
|
#import "CJFileUtility.h" |
|
|
#import "VoiceConverter.h" |
|
|
#import "XHAudioPlayerHelper.h" |
|
|
|
|
|
|
|
|
#import "SVProgressHUD.h" |
|
|
|
|
|
#import "VoiceAlarm.h" |
|
|
@class UITableViewCellEditControl; |
|
|
|
|
|
|
|
|
@implementation baseCell |
|
|
|
|
|
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ |
|
|
|
|
|
if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { |
|
|
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
|
[self setSelectionStyle:UITableViewCellSelectionStyleNone]; |
|
|
self.detailTextLabel.textColor = [UIColor darkGrayColor]; |
|
|
self.textLabel.font = DefineFontSize; |
|
|
self.detailTextLabel.font = DefineFontSize; |
|
|
} |
|
|
|
|
|
return self; |
|
|
} |
|
|
-(void)showHiddenAccessoryDisclosureIndicator:(BOOL)state{ |
|
|
if(state){ |
|
|
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
|
}else{ |
|
|
self.accessoryType = UITableViewCellAccessoryNone; |
|
|
} |
|
|
} |
|
|
|
|
|
- (IBAction)cellClick:(id)sender{ |
|
|
self.block(sender,self); |
|
|
} |
|
|
|
|
|
- (void)initCellView:(baseModel *)cModel{ |
|
|
|
|
|
} |
|
|
|
|
|
-(void)setEditing:(BOOL)editing animated:(BOOL)animated{ |
|
|
[super setEditing:editing animated:animated]; |
|
|
for (UIView *subView in self.subviews) { |
|
|
if([NSStringFromClass([subView class]) isEqualToString:@"UITableViewCellEditControl"]){ |
|
|
UIImageView * imgView = (UIImageView*)[subView valueForKey:@"imageView"]; |
|
|
// UIImageView * imgView = [[control subviews] objectAtIndex:0]; |
|
|
imgView.image = [UIImage imageNamed:@"编辑删除"]; |
|
|
} |
|
|
// NSLog(@"%@",NSStringFromClass([subView class])); |
|
|
} |
|
|
|
|
|
} |
|
|
-(void)willTransitionToState:(UITableViewCellStateMask)state |
|
|
{ |
|
|
[super willTransitionToState:state]; |
|
|
if(state == UITableViewCellStateShowingEditControlMask){ |
|
|
for (UIView *subView in self.subviews) { |
|
|
if([NSStringFromClass([subView class]) isEqualToString:@"UITableViewCellEditControl"]){ |
|
|
UIImageView * imgView = (UIImageView*)[subView valueForKey:@"imageView"]; |
|
|
// UIImageView * imgView = [[control subviews] objectAtIndex:0]; |
|
|
imgView.image = [UIImage imageNamed:@"编辑删除"]; |
|
|
|
|
|
} |
|
|
if ([NSStringFromClass([subView class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]){ |
|
|
// NSLog(@"%@",subView); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
if(state == 3){ |
|
|
for (UIView *subView in self.subviews) { |
|
|
if([NSStringFromClass([subView class]) isEqualToString:@"UITableViewCellEditControl"]){ |
|
|
UIImageView * imgView = (UIImageView*)[subView valueForKey:@"imageView"]; |
|
|
// UIImageView * imgView = [[control subviews] objectAtIndex:0]; |
|
|
imgView.image = [UIImage imageNamed:@"编辑删除"]; |
|
|
} |
|
|
// NSLog(@"%@",NSStringFromClass([subView class])); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@end |
|
|
|
|
|
|
|
|
|
|
|
//@interface TextFieldCell ()<UITextFieldDelegate> |
|
|
@interface TextFieldCell ()<UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource> |
|
|
{ |
|
|
NSInteger _startNum; |
|
|
NSInteger _endNum; |
|
|
NSInteger _nowIndex; |
|
|
} |
|
|
@end |
|
|
|
|
|
@implementation TextFieldCell |
|
|
|
|
|
- (UITextField *)textField{ |
|
|
if (!_textField) { |
|
|
_textField = [[UITextField alloc] init]; |
|
|
_textField.textColor = [UIColor darkGrayColor]; |
|
|
_textField.textAlignment = NSTextAlignmentRight; |
|
|
_textField.font = DefineFontSize; |
|
|
_textField.delegate = self; |
|
|
[self.contentView addSubview:_textField]; |
|
|
|
|
|
|
|
|
|
|
|
//取消 输入回调 |
|
|
[_textField addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventEditingChanged]; |
|
|
|
|
|
[_textField mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.mas_equalTo(110); |
|
|
make.centerY.mas_equalTo(self.textLabel); |
|
|
if (self.accessoryType == UITableViewCellAccessoryDisclosureIndicator) { |
|
|
make.right.mas_equalTo(0); |
|
|
}else{ |
|
|
make.right.mas_equalTo(-4); |
|
|
} |
|
|
make.height.mas_equalTo(self); |
|
|
}]; |
|
|
} |
|
|
return _textField; |
|
|
} |
|
|
|
|
|
- (void)timeInputViewWithModel:(UIDatePickerMode)mode WithData:(NSDate *)nowDate{ |
|
|
self.textField.textAlignment = NSTextAlignmentRight; |
|
|
// [self.textField mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
|
// make.right.mas_equalTo(-15); |
|
|
// make.width.mas_equalTo(62); |
|
|
// make.height.mas_equalTo(30); |
|
|
// make.centerY.mas_equalTo(self.textLabel); |
|
|
// }]; |
|
|
// self.textField.layer.cornerRadius = 15; |
|
|
// self.textField.layer.borderColor = RGB(240, 240, 240).CGColor; |
|
|
// self.textField.layer.borderWidth = 1; |
|
|
//self.textField.textAlignment = 1; |
|
|
UIDatePicker *datePicker = [[UIDatePicker alloc] init]; |
|
|
datePicker.datePickerMode = mode; |
|
|
// datePicker.datePickerMode = UIDatePickerModeTime; |
|
|
datePicker.date = nowDate; |
|
|
//datePicker.frame = CGRectMake(0, 40, ScreenWidth, 200); |
|
|
|
|
|
if (@available(iOS 13.4, *)) { |
|
|
datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels; |
|
|
} |
|
|
|
|
|
[datePicker addTarget:self |
|
|
action:@selector(cellClick:) |
|
|
forControlEvents:UIControlEventValueChanged]; |
|
|
|
|
|
self.textField.inputView = datePicker; |
|
|
} |
|
|
- (void)numberInputViewWithStartNum:(NSInteger)startNum EndNum:(NSInteger)endNum WithIndex:(NSInteger)nowIndex{ |
|
|
UIPickerView *numberPickerView = [UIPickerView new]; |
|
|
numberPickerView.delegate = self; |
|
|
numberPickerView.dataSource = self; |
|
|
_endNum = endNum; |
|
|
_startNum = startNum; |
|
|
_nowIndex = nowIndex; |
|
|
self.textField.inputView = numberPickerView; |
|
|
} |
|
|
#pragma mark UIPickerViewDataSource 数据源方法 |
|
|
// 返回多少列 |
|
|
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView |
|
|
{ |
|
|
return 1; |
|
|
} |
|
|
|
|
|
// 返回多少行 |
|
|
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component |
|
|
{ |
|
|
return _endNum-_startNum; |
|
|
} |
|
|
|
|
|
#pragma mark UIPickerViewDelegate 代理方法 |
|
|
|
|
|
// 返回每行的标题 |
|
|
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component |
|
|
{ |
|
|
return [NSString stringWithFormat:@"%d",_endNum+row]; |
|
|
} |
|
|
// 选中行显示在label上 |
|
|
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component |
|
|
{ |
|
|
if (self.block) { |
|
|
self.block ([NSString stringWithFormat:@"%d",_endNum+row],self); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)cellClick:(id)sender{ |
|
|
if (self.block) { |
|
|
if ([sender isKindOfClass:[UITextField class]]) { |
|
|
UITextField *textField = sender; |
|
|
|
|
|
// MARK: 去掉限制 update by lsz 2021-06-23 |
|
|
//if (_maxLimitLength != 0 && [sender text].length > _maxLimitLength) { |
|
|
// textField.text = [textField.text substringToIndex:8]; |
|
|
//} |
|
|
|
|
|
if (textField.keyboardType == UIKeyboardTypePhonePad) { |
|
|
NSString *tmp = textField.text; |
|
|
|
|
|
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789-"] invertedSet]; |
|
|
textField.text = [[tmp componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; |
|
|
} |
|
|
self.block (textField.text,self); |
|
|
return; |
|
|
} |
|
|
|
|
|
if([sender isKindOfClass:[UIDatePicker class]]){ |
|
|
UIDatePicker * datePic = (UIDatePicker*)sender; |
|
|
if (datePic.datePickerMode == UIDatePickerModeTime){ //时间 |
|
|
NSString *text = [myHelper getDateFormatWithStr:@"HH:mm" |
|
|
date:[datePic date]]; |
|
|
self.textField.text = text; |
|
|
self.block(text,self); |
|
|
return; |
|
|
}else if (datePic.datePickerMode == UIDatePickerModeDate){//日期 |
|
|
NSString *text = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" |
|
|
date:[datePic date]]; |
|
|
self.textField.text = text; |
|
|
self.block(text,self); |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
#pragma mark UITextFieldDelegate |
|
|
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string{ |
|
|
NSString *text = [NSString stringWithFormat:@"%@%@",textField.text,string]; |
|
|
|
|
|
if ((self.regularStr.length > 0) && ![self validateNumber:text]) { |
|
|
return NO; |
|
|
} |
|
|
|
|
|
return YES; |
|
|
} |
|
|
|
|
|
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{ |
|
|
if ([textField.inputView isKindOfClass:[UIDatePicker class]]) { |
|
|
UIDatePicker *datePicker = (UIDatePicker *)textField.inputView; |
|
|
|
|
|
if (datePicker.datePickerMode == UIDatePickerModeTime){ //时间 |
|
|
NSString *text = [myHelper getDateFormatWithStr:@"HH:mm" |
|
|
date:[datePicker date]]; |
|
|
textField.text = text; |
|
|
self.block(text,self); |
|
|
}else if (datePicker.datePickerMode == UIDatePickerModeDate){//日期 |
|
|
NSString *text = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" |
|
|
date:[datePicker date]]; |
|
|
textField.text = text; |
|
|
self.block(text,self); |
|
|
} |
|
|
} |
|
|
|
|
|
return YES; |
|
|
} |
|
|
|
|
|
#pragma mark 正则表达式判断 |
|
|
-(BOOL)validateNumber:(NSString *)text |
|
|
{ |
|
|
NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",self.regularStr]; |
|
|
return [numberPre evaluateWithObject:text]; |
|
|
} |
|
|
|
|
|
@end |
|
|
|
|
|
|
|
|
@implementation RailCell |
|
|
|
|
|
- (UILabel *)label_radius{ |
|
|
if (!_label_radius) { |
|
|
_label_radius = [UILabel new]; |
|
|
_label_radius.textColor = RGB(0, 200, 100); |
|
|
_label_radius.font = [myHelper fixFoneSize:12 |
|
|
font:_label_radius.font]; |
|
|
[self.contentView addSubview:_label_radius]; |
|
|
[_label_radius mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.centerY.mas_equalTo(self.textLabel); |
|
|
make.right.mas_equalTo(-15); |
|
|
}]; |
|
|
} |
|
|
return _label_radius; |
|
|
} |
|
|
|
|
|
@end |
|
|
|
|
|
@implementation DailyCell |
|
|
|
|
|
@end |
|
|
|
|
|
|
|
|
@implementation PlayVoiceCell |
|
|
|
|
|
- (UIButton *)newBbtn{ |
|
|
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; |
|
|
[btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; |
|
|
|
|
|
btn.frame = CGRectMake(0, 0, 80 * FIX_SCREEN, 36 * FIX_SCREEN); |
|
|
btn.titleLabel.font = [UIFont systemFontOfSize:17 * FIX_SCREEN]; |
|
|
|
|
|
[btn addTarget:self action:@selector(cellClick:) |
|
|
forControlEvents:UIControlEventTouchUpInside]; |
|
|
|
|
|
UIImageView *imageView = btn.imageView; |
|
|
//设置动画帧 |
|
|
imageView.animationImages = @[[myHelper getImageWithName:@"播放录音1"], |
|
|
[myHelper getImageWithName:@"播放录音2"], |
|
|
[myHelper getImageWithName:@"播放录音3"]]; |
|
|
imageView.animationDuration = 1.0; |
|
|
|
|
|
//交换文字和图片的位置 |
|
|
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -imageView.image.size.width, |
|
|
0, imageView.image.size.width)]; |
|
|
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.bounds.size.width + 5, |
|
|
0, -btn.titleLabel.bounds.size.width)]; |
|
|
|
|
|
|
|
|
btn.layer.borderColor = [UIColor lightGrayColor].CGColor; |
|
|
btn.layer.borderWidth = 1; |
|
|
btn.layer.cornerRadius = 3.0f; |
|
|
[btn.layer setMasksToBounds:YES]; |
|
|
return btn; |
|
|
} |
|
|
|
|
|
- (void)initCellView:(baseModel *)bModel{ |
|
|
UIButton *btn = [self newBbtn]; |
|
|
[btn setTitle:@"未录音" |
|
|
forState:UIControlStateNormal]; |
|
|
[btn setTitleColor:[UIColor lightGrayColor] |
|
|
forState:UIControlStateNormal]; |
|
|
|
|
|
[btn setImage:[myHelper getImageWithName:@"未录音"] |
|
|
forState:UIControlStateNormal]; |
|
|
//交换文字和图片的位置 |
|
|
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.image.size.width, |
|
|
0, btn.imageView.image.size.width)]; |
|
|
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.bounds.size.width + 5, |
|
|
0, -btn.titleLabel.bounds.size.width)]; |
|
|
|
|
|
btn.enabled = NO; |
|
|
|
|
|
self.accessoryView = btn; |
|
|
|
|
|
self.voicePath = [(VoiceAlarm *)bModel voicePath]; |
|
|
if (!self.voicePath) { |
|
|
self.voicePath = [(VoiceAlarm *)bModel voicePath]; |
|
|
} |
|
|
self.voiceUrl = [(VoiceAlarm *)bModel voiceURL]; |
|
|
if (!self.voiceUrl) { |
|
|
self.voiceUrl = [(VoiceAlarm *)bModel voiceURL]; |
|
|
} |
|
|
} |
|
|
|
|
|
- (IBAction)cellClick:(id)sender{ |
|
|
if (self.voicePath) { |
|
|
[self startAnimation]; |
|
|
}else if (self.voiceUrl) { |
|
|
[self palyVoiceWithUrl:self.voiceUrl]; |
|
|
}else{ |
|
|
[UICommon MessageErrorText:@"尚未录制"]; |
|
|
} |
|
|
if (self.block) { |
|
|
self.block(sender,self); |
|
|
} |
|
|
} |
|
|
|
|
|
- (void)startAnimation{ |
|
|
[[XHAudioPlayerHelper shareInstance] setDelegate:self]; |
|
|
[[XHAudioPlayerHelper shareInstance] managerAudioWithFileName:self.voicePath |
|
|
toPlay:YES]; |
|
|
|
|
|
UIButton *btn = (UIButton *)self.accessoryView; |
|
|
[btn setImage:[myHelper getImageWithName:@"播放录音3"] |
|
|
forState:UIControlStateNormal]; |
|
|
[btn.imageView startAnimating]; |
|
|
} |
|
|
|
|
|
- (void)endAnimation{ |
|
|
UIButton *btn = (UIButton *)self.accessoryView; |
|
|
[btn.imageView stopAnimating]; |
|
|
self.accessoryView = nil; |
|
|
|
|
|
btn = [self newBbtn]; |
|
|
[btn setTitle:@"播放" forState:UIControlStateNormal]; |
|
|
[btn setImage:[myHelper getImageWithName:@"播放录音3"] |
|
|
forState:UIControlStateNormal]; |
|
|
//交换文字和图片的位置 |
|
|
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.image.size.width, |
|
|
0, btn.imageView.image.size.width)]; |
|
|
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.bounds.size.width + 5, |
|
|
0, -btn.titleLabel.bounds.size.width)]; |
|
|
[btn setTitleColor:mainColor forState:UIControlStateNormal]; |
|
|
btn.layer.borderColor = mainColor.CGColor; |
|
|
self.accessoryView = btn; |
|
|
} |
|
|
|
|
|
- (void)didAudioPlayerStopPlay:(AVAudioPlayer*)audioPlayer{ |
|
|
[self endAnimation]; |
|
|
} |
|
|
|
|
|
|
|
|
-(void)palyVoiceWithUrl:(NSString *)url{ |
|
|
NSString *path = [CJFileUtility documentsPathSubDir:@"msg_audio" andFile:url]; |
|
|
NSString *wavPath = [path stringByAppendingPathExtension:@"wav"]; |
|
|
NSString *amrPath = [path stringByAppendingPathExtension:@"amr"]; |
|
|
if ([[XHAudioPlayerHelper shareInstance] isPlaying]) { |
|
|
[[XHAudioPlayerHelper shareInstance] pausePlayingAudio]; |
|
|
}else if ([CJFileUtility fileExists:wavPath] || [CJFileUtility fileExists:amrPath]){ |
|
|
if (![CJFileUtility fileExists:wavPath] && [CJFileUtility fileExists:amrPath]) { |
|
|
[self amrToWav:amrPath]; |
|
|
} |
|
|
self.voicePath = wavPath; |
|
|
[self startAnimation]; |
|
|
}else{ |
|
|
WEAKSELF |
|
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; |
|
|
[[xMyHttp downloadTaskWithRequest:request |
|
|
progress:nil |
|
|
|
|
|
destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) { |
|
|
return [NSURL fileURLWithPath:amrPath]; |
|
|
} |
|
|
completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) { |
|
|
if (![CJFileUtility fileExists:wavPath] && [CJFileUtility fileExists:amrPath]) { |
|
|
[weakSelf amrToWav:amrPath]; |
|
|
} |
|
|
weakSelf.voicePath = wavPath; |
|
|
[weakSelf startAnimation]; |
|
|
}] resume]; |
|
|
} |
|
|
} |
|
|
|
|
|
- (void)wavToAmr:(NSString *)path { |
|
|
//转格式 |
|
|
if ([CJFileUtility fileExists:path]) { |
|
|
NSString *armPath = [CJFileUtility changeFileExt:path ext:@"amr"]; |
|
|
[VoiceConverter wavToAmr:path amrSavePath:armPath]; |
|
|
} |
|
|
} |
|
|
|
|
|
//转换后删掉amr文件 |
|
|
- (void)amrToWav:(NSString *)path { |
|
|
//转格式 |
|
|
if ([CJFileUtility fileExists:path]) { |
|
|
NSString *wavPath = [CJFileUtility changeFileExt:path ext:@"wav"]; |
|
|
[VoiceConverter amrToWav:path wavSavePath:wavPath]; |
|
|
[CJFileUtility deleteFile:path]; |
|
|
} |
|
|
} |
|
|
|
|
|
@end |
|
|
|
|
|
#define STRONGSELF typeof(weakSelf) __strong strongSelf = weakSelf; |
|
|
|
|
|
|