|
@@ -31,6 +31,7 @@
|
|
|
YMBarButtonItem *rightBarItem =[[YMBarButtonItem alloc]initWithImage:creatImage style:YMBarButtonItemPlain target:self action:@selector(moreBtnClick)];
|
|
|
rightBarItem.titleInsets = UIEdgeInsetsMake(0, 0, 0, 20);
|
|
|
self.navigationBar.rightBarButtonItem = rightBarItem;
|
|
|
+ [self.view bringSubviewToFront:self.navigationBar];
|
|
|
}
|
|
|
|
|
|
- (void)moreBtnClick {
|
|
@@ -44,43 +45,34 @@
|
|
|
// Do any additional setup after loading the view from its nib.
|
|
|
self.title = self.friendModel.userName;
|
|
|
[self configNavigationBar];
|
|
|
- NSString *key = [NSString stringWithFormat:@"%@--to--%@",[SLGlobalInfo SharedInstance].loginInfo.user.userId, self.friendModel.userId];
|
|
|
- NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:key];
|
|
|
- if (arr) {
|
|
|
- NSArray *models = [MessageModel mj_objectArrayWithKeyValuesArray:arr];
|
|
|
- self.chatServiceView.messageView.chatDataManager = [NSMutableArray arrayWithArray:models];
|
|
|
- }
|
|
|
+ dispatch_async(dispatch_queue_create("sl.cache.chat.date", DISPATCH_QUEUE_CONCURRENT), ^{
|
|
|
+ NSString *key = [NSString stringWithFormat:@"%@--to--%@",[SLGlobalInfo SharedInstance].loginInfo.user.userId, self.friendModel.userId];
|
|
|
+ NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:key];
|
|
|
+ if (arr.count) {
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ NSArray *models = [MessageModel mj_objectArrayWithKeyValuesArray:arr];
|
|
|
+ self.chatServiceView.messageView.chatDataManager = [NSMutableArray arrayWithArray:models];
|
|
|
+ [self.chatServiceView.messageView.messageCollectionView reloadData];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
self.chatServiceView.friendModel = self.friendModel;
|
|
|
self.chatServiceView.messageView.friendModel = self.friendModel;
|
|
|
[self.chatServiceView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
make.top.mas_equalTo(kNavBarHeight);
|
|
|
make.left.bottom.right.equalTo(self.view);
|
|
|
}];
|
|
|
- self.mikeInputView = [[SLMikeInputView alloc] initWithFrame:CGRectZero];
|
|
|
- WS(weakSelf);
|
|
|
- self.mikeInputView.nuiSpeechRecognizer.recognizerResultBlock = ^(NSString * _Nonnull text, NSString * _Nonnull voicePath) {
|
|
|
- MessageModel *model = [MessageModel initWithSendText:text isReceive:NO showMike:YES showText:NO isMike:YES voicePath:voicePath];
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
- if (model.audioDuration < 1.2) {
|
|
|
- [ZFToast ShowWithMessage:@"说话时间太短!"];
|
|
|
- }else {
|
|
|
- model.toId = weakSelf.friendModel.userId;
|
|
|
- [weakSelf.chatServiceView.messageView appendMessage:model];
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
- self.mikeInputView.hidden = YES;
|
|
|
- [self.view addSubview:self.mikeInputView];
|
|
|
- [self.view bringSubviewToFront:self.navigationBar];
|
|
|
- [self.view bringSubviewToFront:self.mikeInputView];
|
|
|
|
|
|
- [self nuisdkPlay];
|
|
|
+
|
|
|
+ WS(weakSelf);
|
|
|
+// [self nuisdkPlay];
|
|
|
[self.KVOController observe:self.mikeInputView.contentView keyPath:@"hidden" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
|
|
|
if (![change[NSKeyValueChangeNewKey] boolValue]) {
|
|
|
[weakSelf.nuisdkPlay stopNuisdkPlay];
|
|
|
}
|
|
|
}];
|
|
|
- //
|
|
|
+//
|
|
|
self.chatServiceView.messageView.broadcastBlock = ^(MessageModel * _Nonnull msgModel) {
|
|
|
if (!msgModel.isReceive && msgModel.showMike) {
|
|
|
[weakSelf.nuisdkPlay playSendVoice:msgModel];
|
|
@@ -113,8 +105,10 @@
|
|
|
- (void)saveChatData {
|
|
|
NSString *key = [NSString stringWithFormat:@"%@--to--%@",[SLGlobalInfo SharedInstance].loginInfo.user.userId, self.friendModel.userId];
|
|
|
NSArray *dictArr = [NSObject mj_keyValuesArrayWithObjectArray:self.chatServiceView.messageView.chatDataManager];
|
|
|
- [[NSUserDefaults standardUserDefaults] setObject:dictArr forKey:key];
|
|
|
- [[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
+ dispatch_async(dispatch_queue_create("sl.save.chat.date", DISPATCH_QUEUE_CONCURRENT), ^{
|
|
|
+ [[NSUserDefaults standardUserDefaults] setObject:dictArr forKey:key];
|
|
|
+ [[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
@@ -203,6 +197,27 @@
|
|
|
return _nuisdkPlay;
|
|
|
}
|
|
|
|
|
|
+- (SLMikeInputView *)mikeInputView {
|
|
|
+ if (!_mikeInputView) {
|
|
|
+ _mikeInputView = [[SLMikeInputView alloc] initWithFrame:CGRectZero];
|
|
|
+ WS(weakSelf);
|
|
|
+ _mikeInputView.nuiSpeechRecognizer.recognizerResultBlock = ^(NSString * _Nonnull text, NSString * _Nonnull voicePath) {
|
|
|
+ MessageModel *model = [MessageModel initWithSendText:text isReceive:NO showMike:YES showText:NO isMike:YES voicePath:voicePath];
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ if (model.audioDuration < 1.2) {
|
|
|
+ [ZFToast ShowWithMessage:@"说话时间太短!"];
|
|
|
+ }else {
|
|
|
+ model.toId = weakSelf.friendModel.userId;
|
|
|
+ [weakSelf.chatServiceView.messageView appendMessage:model];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ [self.view addSubview:_mikeInputView];
|
|
|
+ [self.view bringSubviewToFront:self.mikeInputView];
|
|
|
+ }
|
|
|
+ return _mikeInputView;
|
|
|
+}
|
|
|
+
|
|
|
- (IBAction)backBtnClick:(id)sender {
|
|
|
[self.navigationController popToRootViewControllerAnimated:YES];
|
|
|
}
|