|
|
@@ -3,8 +3,6 @@ package com.tencent.qcloud.tuikit.tuichat.classicui.widget.input;
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
-import android.content.Intent;
|
|
|
-import android.graphics.Bitmap;
|
|
|
import android.graphics.Rect;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
@@ -20,28 +18,23 @@ import android.view.View;
|
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
-import android.webkit.MimeTypeMap;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
+
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
+
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.JsonSyntaxException;
|
|
|
import com.tencent.imsdk.v2.V2TIMManager;
|
|
|
-import com.tencent.qcloud.tuicore.TUIConstants;
|
|
|
import com.tencent.qcloud.tuicore.TUICore;
|
|
|
-import com.tencent.qcloud.tuicore.interfaces.TUIExtensionEventListener;
|
|
|
-import com.tencent.qcloud.tuicore.interfaces.TUIExtensionInfo;
|
|
|
import com.tencent.qcloud.tuicore.interfaces.TUIValueCallback;
|
|
|
import com.tencent.qcloud.tuicore.util.TUIBuild;
|
|
|
-import com.tencent.qcloud.tuicore.util.ToastUtil;
|
|
|
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
|
|
|
-import com.tencent.qcloud.tuikit.timcommon.component.face.CustomFace;
|
|
|
-import com.tencent.qcloud.tuikit.timcommon.component.face.Emoji;
|
|
|
import com.tencent.qcloud.tuikit.timcommon.component.face.FaceManager;
|
|
|
import com.tencent.qcloud.tuikit.timcommon.interfaces.ChatInputMoreListener;
|
|
|
import com.tencent.qcloud.tuikit.timcommon.util.ActivityResultResolver;
|
|
|
@@ -67,6 +60,7 @@ import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageParser;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.util.PermissionHelper;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatUtils;
|
|
|
+
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
@@ -222,135 +216,105 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mMoreInputButton.setOnClickListener(this);
|
|
|
mSendTextButton.setOnClickListener(this);
|
|
|
mTextInput.addTextChangedListener(this);
|
|
|
- mTextInput.setOnTouchListener(new OnTouchListener() {
|
|
|
- @Override
|
|
|
- public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
|
- if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
- if (presenter != null) {
|
|
|
- presenter.scrollToNewestMessage();
|
|
|
- }
|
|
|
- showSoftInput();
|
|
|
+ mTextInput.setOnTouchListener((view, motionEvent) -> {
|
|
|
+ if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.scrollToNewestMessage();
|
|
|
}
|
|
|
- return false;
|
|
|
+ showSoftInput();
|
|
|
}
|
|
|
+ return false;
|
|
|
});
|
|
|
|
|
|
- mTextInput.setOnKeyListener(new OnKeyListener() {
|
|
|
- @Override
|
|
|
- public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
|
|
|
- if (keyCode == KeyEvent.KEYCODE_DEL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
- if ((isQuoteModel || isReplyModel) && TextUtils.isEmpty(mTextInput.getText().toString())) {
|
|
|
- exitReply();
|
|
|
- }
|
|
|
+ mTextInput.setOnKeyListener((view, keyCode, keyEvent) -> {
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_DEL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
+ if ((isQuoteModel || isReplyModel) && TextUtils.isEmpty(mTextInput.getText().toString())) {
|
|
|
+ exitReply();
|
|
|
}
|
|
|
- return false;
|
|
|
}
|
|
|
+ return false;
|
|
|
});
|
|
|
|
|
|
- mTextInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
- @Override
|
|
|
- public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
+ mTextInput.setOnEditorActionListener((textView, i, keyEvent) -> false);
|
|
|
|
|
|
- mTextInput.setOnFocusChangeListener(new OnFocusChangeListener() {
|
|
|
- @Override
|
|
|
- public void onFocusChange(View view, boolean focus) {
|
|
|
- if (!focus && mChatInputHandler != null) {
|
|
|
- mChatInputHandler.onUserTyping(false, V2TIMManager.getInstance().getServerTime());
|
|
|
- }
|
|
|
+ mTextInput.setOnFocusChangeListener((view, focus) -> {
|
|
|
+ if (!focus && mChatInputHandler != null) {
|
|
|
+ mChatInputHandler.onUserTyping(false, V2TIMManager.getInstance().getServerTime());
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- mSendAudioButton.setOnTouchListener(new OnTouchListener() {
|
|
|
- @Override
|
|
|
- public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
|
- PermissionHelper.requestPermission(PermissionHelper.PERMISSION_MICROPHONE, new PermissionHelper.PermissionCallback() {
|
|
|
- @Override
|
|
|
- public void onGranted() {
|
|
|
- switch (motionEvent.getAction()) {
|
|
|
- case MotionEvent.ACTION_DOWN:
|
|
|
+ mSendAudioButton.setOnTouchListener((view, motionEvent) -> {
|
|
|
+ PermissionHelper.requestPermission(PermissionHelper.PERMISSION_MICROPHONE, new PermissionHelper.PermissionCallback() {
|
|
|
+ @Override
|
|
|
+ public void onGranted() {
|
|
|
+ switch (motionEvent.getAction()) {
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
+ mAudioCancel = true;
|
|
|
+ mStartRecordY = motionEvent.getY();
|
|
|
+ if (mChatInputHandler != null) {
|
|
|
+ mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_START);
|
|
|
+ }
|
|
|
+ mSendAudioButton.setText(TUIChatService.getAppContext().getString(R.string.release_end));
|
|
|
+ AudioRecorder.getInstance().startRecord(new AudioRecorder.Callback() {
|
|
|
+ @Override
|
|
|
+ public void onCompletion(Boolean success) {
|
|
|
+ recordComplete(success);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onVoiceDb(double db) {}
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
+ if (motionEvent.getY() - mStartRecordY < -100) {
|
|
|
mAudioCancel = true;
|
|
|
- mStartRecordY = motionEvent.getY();
|
|
|
if (mChatInputHandler != null) {
|
|
|
- mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_START);
|
|
|
+ mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_CANCEL);
|
|
|
}
|
|
|
- mSendAudioButton.setText(TUIChatService.getAppContext().getString(R.string.release_end));
|
|
|
- AudioRecorder.getInstance().startRecord(new AudioRecorder.Callback() {
|
|
|
- @Override
|
|
|
- public void onCompletion(Boolean success) {
|
|
|
- recordComplete(success);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onVoiceDb(double db) {}
|
|
|
- });
|
|
|
- break;
|
|
|
- case MotionEvent.ACTION_MOVE:
|
|
|
- if (motionEvent.getY() - mStartRecordY < -100) {
|
|
|
- mAudioCancel = true;
|
|
|
+ } else {
|
|
|
+ if (mAudioCancel) {
|
|
|
if (mChatInputHandler != null) {
|
|
|
- mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_CANCEL);
|
|
|
+ mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_START);
|
|
|
}
|
|
|
- } else {
|
|
|
- if (mAudioCancel) {
|
|
|
- if (mChatInputHandler != null) {
|
|
|
- mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_START);
|
|
|
- }
|
|
|
- }
|
|
|
- mAudioCancel = false;
|
|
|
- }
|
|
|
- mSendAudioButton.setText(TUIChatService.getAppContext().getString(R.string.release_end));
|
|
|
- break;
|
|
|
- case MotionEvent.ACTION_CANCEL:
|
|
|
- case MotionEvent.ACTION_UP:
|
|
|
- mAudioCancel = motionEvent.getY() - mStartRecordY < -100;
|
|
|
- if (mChatInputHandler != null) {
|
|
|
- mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_STOP);
|
|
|
}
|
|
|
- AudioRecorder.getInstance().stopRecord();
|
|
|
- mSendAudioButton.setText(TUIChatService.getAppContext().getString(R.string.hold_say));
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+ mAudioCancel = false;
|
|
|
+ }
|
|
|
+ mSendAudioButton.setText(TUIChatService.getAppContext().getString(R.string.release_end));
|
|
|
+ break;
|
|
|
+ case MotionEvent.ACTION_CANCEL:
|
|
|
+ case MotionEvent.ACTION_UP:
|
|
|
+ mAudioCancel = motionEvent.getY() - mStartRecordY < -100;
|
|
|
+ if (mChatInputHandler != null) {
|
|
|
+ mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_STOP);
|
|
|
+ }
|
|
|
+ AudioRecorder.getInstance().stopRecord();
|
|
|
+ mSendAudioButton.setText(TUIChatService.getAppContext().getString(R.string.hold_say));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onDenied() {
|
|
|
- TUIChatLog.i(TAG, "audio record checkPermission failed");
|
|
|
- }
|
|
|
- });
|
|
|
- return false;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onDenied() {
|
|
|
+ TUIChatLog.i(TAG, "audio record checkPermission failed");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return false;
|
|
|
});
|
|
|
|
|
|
- mTextInput.setOnMentionInputListener(new TIMMentionEditText.OnMentionInputListener() {
|
|
|
- @Override
|
|
|
- public void onMentionCharacterInput(String tag) {
|
|
|
- if ((tag.equals(TIMMentionEditText.TIM_MENTION_TAG) || tag.equals(TIMMentionEditText.TIM_MENTION_TAG_FULL))
|
|
|
- && TUIChatUtils.isGroupChat(mChatLayout.getChatInfo().getType())) {
|
|
|
- if (mOnInputViewListener != null) {
|
|
|
- mOnInputViewListener.onStartGroupMemberSelectActivity();
|
|
|
- }
|
|
|
+ mTextInput.setOnMentionInputListener(tag -> {
|
|
|
+ if ((tag.equals(TIMMentionEditText.TIM_MENTION_TAG) || tag.equals(TIMMentionEditText.TIM_MENTION_TAG_FULL))
|
|
|
+ && TUIChatUtils.isGroupChat(mChatLayout.getChatInfo().getType())) {
|
|
|
+ if (mOnInputViewListener != null) {
|
|
|
+ mOnInputViewListener.onStartGroupMemberSelectActivity();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- replyCloseBtn.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- exitReply();
|
|
|
- }
|
|
|
- });
|
|
|
+ replyCloseBtn.setOnClickListener(v -> exitReply());
|
|
|
|
|
|
- quoteCloseBtn.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- exitReply();
|
|
|
- }
|
|
|
- });
|
|
|
+ quoteCloseBtn.setOnClickListener(v -> exitReply());
|
|
|
}
|
|
|
|
|
|
public void addInputText(String name, String id) {
|
|
|
@@ -399,12 +363,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
}
|
|
|
// @ 之后要显示软键盘。Activity 没有 onResume 导致无法显示软键盘
|
|
|
// Afterwards @, the soft keyboard is to be displayed. Activity does not have onResume, so the soft keyboard cannot be displayed
|
|
|
- ThreadUtils.postOnUiThreadDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- showSoftInput();
|
|
|
- }
|
|
|
- }, 200);
|
|
|
+ ThreadUtils.postOnUiThreadDelayed(this::showSoftInput, 200);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -471,109 +430,13 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
super.onDetachedFromWindow();
|
|
|
mTextInput.removeTextChangedListener(this);
|
|
|
atUserInfoMap.clear();
|
|
|
-
|
|
|
if (mChatInputHandler != null) {
|
|
|
mChatInputHandler.onUserTyping(false, V2TIMManager.getInstance().getServerTime());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected void startSendPhoto() {
|
|
|
- TUIChatLog.i(TAG, "startSendPhoto");
|
|
|
- ActivityResultResolver.getMultipleContent(mInputMoreFragment.getActivity(),
|
|
|
- new String[] {ActivityResultResolver.CONTENT_TYPE_IMAGE, ActivityResultResolver.CONTENT_TYPE_VIDEO}, new TUIValueCallback<List<Uri>>() {
|
|
|
- @Override
|
|
|
- public void onSuccess(List<Uri> uris) {
|
|
|
- ThreadUtils.runOnUiThread(() -> sendPhotoVideoMessage(uris));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(int errorCode, String errorMessage) {}
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void sendPhotoVideoMessage(List<Uri> uris) {
|
|
|
- List<TUIMessageBean> messageBeans = new ArrayList<>();
|
|
|
- for (Uri data : uris) {
|
|
|
- TUIChatLog.i(TAG, "onSuccess: " + data);
|
|
|
- if (data == null) {
|
|
|
- TUIChatLog.e(TAG, "data is null");
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- String uri = data.toString();
|
|
|
- if (TextUtils.isEmpty(uri)) {
|
|
|
- TUIChatLog.e(TAG, "uri is empty");
|
|
|
- continue;
|
|
|
- }
|
|
|
- String filePath = FileUtil.getPathFromUri(data);
|
|
|
- String fileName = FileUtil.getName(filePath);
|
|
|
- String fileExtension = FileUtil.getFileExtensionFromUrl(fileName);
|
|
|
- String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
|
|
|
- if (TextUtils.isEmpty(mimeType)) {
|
|
|
- TUIChatLog.e(TAG, "mimeType is empty.");
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (mimeType.contains("video")) {
|
|
|
- TUIMessageBean msg = buildVideoMessage(filePath);
|
|
|
- if (msg == null) {
|
|
|
- ToastUtil.toastShortMessage(getResources().getString(R.string.send_failed_file_not_exists));
|
|
|
- TUIChatLog.e(TAG, "start send video error data: " + data);
|
|
|
- } else {
|
|
|
- messageBeans.add(msg);
|
|
|
- }
|
|
|
- } else if (mimeType.contains("image")) {
|
|
|
- TUIMessageBean msg = ChatMessageBuilder.buildImageMessage(filePath);
|
|
|
- if (msg == null) {
|
|
|
- TUIChatLog.e(TAG, "start send image error data: " + data);
|
|
|
- ToastUtil.toastShortMessage(getResources().getString(R.string.send_failed_file_not_exists));
|
|
|
- } else {
|
|
|
- messageBeans.add(msg);
|
|
|
- }
|
|
|
- } else {
|
|
|
- TUIChatLog.e(TAG, "Send photo or video failed , invalid mimeType : " + mimeType);
|
|
|
- }
|
|
|
- }
|
|
|
- if (mMessageHandler != null) {
|
|
|
- mMessageHandler.sendMessages(messageBeans);
|
|
|
- hideSoftInput();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private TUIMessageBean buildVideoMessage(String videoPath) {
|
|
|
- android.media.MediaMetadataRetriever mmr = new android.media.MediaMetadataRetriever();
|
|
|
- try {
|
|
|
- mmr.setDataSource(videoPath);
|
|
|
- String sDuration = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_DURATION);
|
|
|
- Bitmap bitmap = mmr.getFrameAtTime(0, android.media.MediaMetadataRetriever.OPTION_NEXT_SYNC);
|
|
|
-
|
|
|
- if (bitmap == null) {
|
|
|
- TUIChatLog.e(TAG, "buildVideoMessage() bitmap is null");
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- String bitmapPath = FileUtil.generateImageFilePath();
|
|
|
- boolean result = FileUtil.saveBitmap(bitmapPath, bitmap);
|
|
|
- if (!result) {
|
|
|
- TUIChatLog.e(TAG, "build video message, save bitmap failed.");
|
|
|
- return null;
|
|
|
- }
|
|
|
- int imgWidth = bitmap.getWidth();
|
|
|
- int imgHeight = bitmap.getHeight();
|
|
|
- long duration = Long.parseLong(sDuration);
|
|
|
-
|
|
|
- return ChatMessageBuilder.buildVideoMessage(bitmapPath, videoPath, imgWidth, imgHeight, duration);
|
|
|
- } catch (Exception ex) {
|
|
|
- TUIChatLog.e(TAG, "MediaMetadataRetriever exception " + ex);
|
|
|
- } finally {
|
|
|
- mmr.release();
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
protected void startCaptureCheckPermission() {
|
|
|
TUIChatLog.i(TAG, "startCaptureCheckPermission");
|
|
|
-
|
|
|
PermissionHelper.requestPermission(PermissionHelper.PERMISSION_CAMERA, new PermissionHelper.PermissionCallback() {
|
|
|
@Override
|
|
|
public void onGranted() {
|
|
|
@@ -651,123 +514,6 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- protected void startVideoRecordCheckPermission() {
|
|
|
- TUIChatLog.i(TAG, "startVideoRecordCheckPermission");
|
|
|
-
|
|
|
- PermissionHelper.requestPermission(PermissionHelper.PERMISSION_CAMERA, new PermissionHelper.PermissionCallback() {
|
|
|
- @Override
|
|
|
- public void onGranted() {
|
|
|
- PermissionHelper.requestPermission(PermissionHelper.PERMISSION_MICROPHONE, new PermissionHelper.PermissionCallback() {
|
|
|
- @Override
|
|
|
- public void onGranted() {
|
|
|
- startVideoRecord();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDenied() {
|
|
|
- TUIChatLog.i(TAG, "startVideoRecord checkPermission failed");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDenied() {
|
|
|
- TUIChatLog.i(TAG, "startVideoRecord checkPermission failed");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void startVideoRecord() {
|
|
|
- if (TUIChatConfigs.getConfigs().getGeneralConfig().isUseSystemCamera()) {
|
|
|
- if (TUIBuild.getVersionInt() < Build.VERSION_CODES.N) {
|
|
|
- PermissionHelper.requestPermission(PermissionHelper.PERMISSION_STORAGE, new PermissionHelper.PermissionCallback() {
|
|
|
- @Override
|
|
|
- public void onGranted() {
|
|
|
- String path = FileUtil.generateExternalStorageVideoFilePath();
|
|
|
- systemRecordAndSend(path);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDenied() {
|
|
|
- TUIChatLog.i(TAG, "startVideoRecord checkPermission failed");
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- String path = FileUtil.generateVideoFilePath();
|
|
|
- systemRecordAndSend(path);
|
|
|
- }
|
|
|
- } else {
|
|
|
- chatRecordAndSend();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void systemRecordAndSend(String path) {
|
|
|
- Uri uri = FileUtil.getUriFromPath(path);
|
|
|
- if (uri == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- ActivityResultResolver.takeVideo(mInputMoreFragment, uri, new TUIValueCallback<Boolean>() {
|
|
|
- @Override
|
|
|
- public void onSuccess(Boolean object) {
|
|
|
- File videoFile = new File(path);
|
|
|
- if (videoFile.exists()) {
|
|
|
- TUIMessageBean messageBean = buildVideoMessage(path);
|
|
|
- if (mMessageHandler != null) {
|
|
|
- mMessageHandler.sendMessage(messageBean);
|
|
|
- hideSoftInput();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(int errorCode, String errorMessage) {}
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void chatRecordAndSend() {
|
|
|
- Bundle bundle = new Bundle();
|
|
|
- bundle.putInt(TUIChatConstants.CAMERA_TYPE, CameraActivity.BUTTON_STATE_ONLY_RECORDER);
|
|
|
-
|
|
|
- TUICore.startActivityForResult(mInputMoreFragment, CameraActivity.class, bundle, result -> {
|
|
|
- Intent videoData = result.getData();
|
|
|
- if (videoData == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Uri videoUri = videoData.getData();
|
|
|
- if (videoUri != null) {
|
|
|
- TUIMessageBean messageBean = buildVideoMessage(FileUtil.getPathFromUri(videoUri));
|
|
|
- if (mMessageHandler != null) {
|
|
|
- mMessageHandler.sendMessage(messageBean);
|
|
|
- hideSoftInput();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- protected void startSendFile() {
|
|
|
- TUIChatLog.i(TAG, "startSendFile");
|
|
|
- ActivityResultResolver.getSingleContent(mInputMoreFragment.getActivity(), ActivityResultResolver.CONTENT_TYPE_ALL, new TUIValueCallback<Uri>() {
|
|
|
- @Override
|
|
|
- public void onSuccess(Uri data) {
|
|
|
- if (data == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- TUIMessageBean info = ChatMessageBuilder.buildFileMessage(data);
|
|
|
- if (info == null) {
|
|
|
- ToastUtil.toastShortMessage(getResources().getString(R.string.send_failed_file_not_exists));
|
|
|
- return;
|
|
|
- }
|
|
|
- if (mMessageHandler != null) {
|
|
|
- mMessageHandler.sendMessage(info);
|
|
|
- hideSoftInput();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(int errorCode, String errorMessage) {}
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
public void setChatInputHandler(ChatInputHandler handler) {
|
|
|
this.mChatInputHandler = handler;
|
|
|
}
|
|
|
@@ -872,31 +618,23 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
if (!isSoftInputShown()) {
|
|
|
imm.toggleSoftInput(0, 0);
|
|
|
}
|
|
|
- ThreadUtils.postOnUiThreadDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- hideInputMoreLayout();
|
|
|
- mAudioInputSwitchButton.setImageResource(R.drawable.action_audio_selector);
|
|
|
- mSendAudioButton.setVisibility(GONE);
|
|
|
- mTextInput.setVisibility(VISIBLE);
|
|
|
- mTextInput.requestFocus();
|
|
|
- Context context = getContext();
|
|
|
- if (context instanceof Activity) {
|
|
|
- Window window = ((Activity) context).getWindow();
|
|
|
- if (window != null) {
|
|
|
- window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
- }
|
|
|
+ ThreadUtils.postOnUiThreadDelayed(() -> {
|
|
|
+ hideInputMoreLayout();
|
|
|
+ mAudioInputSwitchButton.setImageResource(R.drawable.action_audio_selector);
|
|
|
+ mSendAudioButton.setVisibility(GONE);
|
|
|
+ mTextInput.setVisibility(VISIBLE);
|
|
|
+ mTextInput.requestFocus();
|
|
|
+ Context context = getContext();
|
|
|
+ if (context instanceof Activity) {
|
|
|
+ Window window = ((Activity) context).getWindow();
|
|
|
+ if (window != null) {
|
|
|
+ window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
}
|
|
|
}
|
|
|
}, 200);
|
|
|
|
|
|
if (mChatInputHandler != null) {
|
|
|
- postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mChatInputHandler.onInputAreaClick();
|
|
|
- }
|
|
|
- }, 200);
|
|
|
+ postDelayed(() -> mChatInputHandler.onInputAreaClick(), 200);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -949,68 +687,6 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
isShowCustomFace = !disable;
|
|
|
}
|
|
|
|
|
|
- private void showFaceViewGroup() {
|
|
|
- TUIChatLog.i(TAG, "showFaceViewGroup");
|
|
|
- if (mFragmentManager == null) {
|
|
|
- mFragmentManager = mActivity.getSupportFragmentManager();
|
|
|
- }
|
|
|
- if (mFaceFragment == null) {
|
|
|
- mFaceFragment = new FaceFragment();
|
|
|
- }
|
|
|
- hideSoftInput();
|
|
|
- mInputMoreView.setVisibility(View.VISIBLE);
|
|
|
- mTextInput.requestFocus();
|
|
|
- mFaceFragment.setShowCustomFace(isShowCustomFace);
|
|
|
- mFaceFragment.setListener(new FaceFragment.OnEmojiClickListener() {
|
|
|
- @Override
|
|
|
- public void onEmojiDelete() {
|
|
|
- int index = mTextInput.getSelectionStart();
|
|
|
- Editable editable = mTextInput.getText();
|
|
|
- boolean isFace = false;
|
|
|
- if (index <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (editable.charAt(index - 1) == ']') {
|
|
|
- for (int i = index - 2; i >= 0; i--) {
|
|
|
- if (editable.charAt(i) == '[') {
|
|
|
- String faceChar = editable.subSequence(i, index).toString();
|
|
|
- if (FaceManager.isFaceChar(faceChar)) {
|
|
|
- editable.delete(i, index);
|
|
|
- isFace = true;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!isFace) {
|
|
|
- editable.delete(index - 1, index);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onEmojiClick(Emoji emoji) {
|
|
|
- int index = mTextInput.getSelectionStart();
|
|
|
- Editable editable = mTextInput.getText();
|
|
|
- editable.insert(index, emoji.getFaceKey());
|
|
|
- FaceManager.handlerEmojiText(mTextInput, editable, true);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCustomFaceClick(int groupIndex, CustomFace customFace) {
|
|
|
- mMessageHandler.sendMessage(ChatMessageBuilder.buildFaceMessage(groupIndex, customFace.getFaceKey()));
|
|
|
- }
|
|
|
- });
|
|
|
- mFragmentManager.beginTransaction().replace(R.id.more_groups, mFaceFragment).commitAllowingStateLoss();
|
|
|
- if (mChatInputHandler != null) {
|
|
|
- postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mChatInputHandler.onInputAreaClick();
|
|
|
- }
|
|
|
- }, 100);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void showCustomInputMoreFragment() {
|
|
|
TUIChatLog.i(TAG, "showCustomInputMoreFragment");
|
|
|
if (mFragmentManager == null) {
|
|
|
@@ -1021,12 +697,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mInputMoreView.setVisibility(View.VISIBLE);
|
|
|
mFragmentManager.beginTransaction().replace(R.id.more_groups, fragment).commitAllowingStateLoss();
|
|
|
if (mChatInputHandler != null) {
|
|
|
- postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mChatInputHandler.onInputAreaClick();
|
|
|
- }
|
|
|
- }, 100);
|
|
|
+ postDelayed(() -> mChatInputHandler.onInputAreaClick(), 100);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1045,12 +716,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mInputMoreView.setVisibility(View.VISIBLE);
|
|
|
mFragmentManager.beginTransaction().replace(R.id.more_groups, mInputMoreFragment).commitAllowingStateLoss();
|
|
|
if (mChatInputHandler != null) {
|
|
|
- postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mChatInputHandler.onInputAreaClick();
|
|
|
- }
|
|
|
- }, 100);
|
|
|
+ postDelayed(() -> mChatInputHandler.onInputAreaClick(), 100);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1265,48 +931,6 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
return getResources().getString(stringID);
|
|
|
}
|
|
|
|
|
|
- private List<InputMoreActionUnit> getExtensionInputMoreList() {
|
|
|
- List<InputMoreActionUnit> list = new ArrayList<>();
|
|
|
-
|
|
|
- Map<String, Object> param = new HashMap<>();
|
|
|
- param.put(TUIConstants.TUIChat.Extension.InputMore.CONTEXT, getContext());
|
|
|
- if (ChatInfo.TYPE_C2C == mChatInfo.getType()) {
|
|
|
- param.put(TUIConstants.TUIChat.Extension.InputMore.USER_ID, mChatInfo.getId());
|
|
|
- } else {
|
|
|
- param.put(TUIConstants.TUIChat.Extension.InputMore.GROUP_ID, mChatInfo.getId());
|
|
|
- }
|
|
|
- if (mChatInfo.getType() == ChatInfo.TYPE_GROUP && TUIChatUtils.isTopicGroup(mChatInfo.getId())) {
|
|
|
- param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_VIDEO_CALL, true);
|
|
|
- param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_VOICE_CALL, true);
|
|
|
- } else {
|
|
|
- param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_VIDEO_CALL, !TUIChatConfigs.getConfigs().getGeneralConfig().isEnableVideoCall());
|
|
|
- param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_VOICE_CALL, !TUIChatConfigs.getConfigs().getGeneralConfig().isEnableVoiceCall());
|
|
|
- }
|
|
|
- param.put(TUIConstants.TUIChat.Extension.InputMore.INPUT_MORE_LISTENER, chatInputMoreListener);
|
|
|
- List<TUIExtensionInfo> extensionList = TUICore.getExtensionList(TUIConstants.TUIChat.Extension.InputMore.CLASSIC_EXTENSION_ID, param);
|
|
|
- for (TUIExtensionInfo extensionInfo : extensionList) {
|
|
|
- if (extensionInfo != null) {
|
|
|
- String name = extensionInfo.getText();
|
|
|
- int icon = (int) extensionInfo.getIcon();
|
|
|
- int priority = extensionInfo.getWeight();
|
|
|
- InputMoreActionUnit unit = new InputMoreActionUnit() {
|
|
|
- @Override
|
|
|
- public void onAction(String chatInfoId, int chatType) {
|
|
|
- TUIExtensionEventListener extensionListener = extensionInfo.getExtensionListener();
|
|
|
- if (extensionListener != null) {
|
|
|
- extensionListener.onClicked(null);
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- unit.setName(name);
|
|
|
- unit.setIconResId(icon);
|
|
|
- unit.setPriority(priority);
|
|
|
- list.add(unit);
|
|
|
- }
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
public void disableAudioInput(boolean disable) {
|
|
|
mAudioInputDisable = disable;
|
|
|
if (disable) {
|