|
|
@@ -2,17 +2,11 @@ package com.tencent.qcloud.tuikit.tuichat.classicui.widget.input;
|
|
|
|
|
|
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;
|
|
|
-import android.os.Bundle;
|
|
|
import android.text.Editable;
|
|
|
import android.text.TextUtils;
|
|
|
import android.text.TextWatcher;
|
|
|
import android.util.AttributeSet;
|
|
|
-import android.util.DisplayMetrics;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
@@ -20,14 +14,14 @@ import android.view.ViewGroup;
|
|
|
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.FragmentActivity;
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.JsonSyntaxException;
|
|
|
@@ -37,7 +31,6 @@ 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.ChatFace;
|
|
|
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
|
|
|
@@ -51,25 +44,27 @@ import com.tencent.qcloud.tuikit.tuichat.R;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.bean.CustomHelloMessage;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.bean.DraftInfo;
|
|
|
-import com.tencent.qcloud.tuikit.tuichat.bean.InputMoreActionUnit;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.bean.InputMoreItem;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.bean.ReplyPreviewBean;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.bean.message.FileMessageBean;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.classicui.interfaces.IChatLayout;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.classicui.widget.input.inputmore.InputMoreFragment;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.component.album.AlbumPicker;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.component.album.VideoRecorder;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.component.audio.AudioRecorder;
|
|
|
-import com.tencent.qcloud.tuikit.tuichat.component.camera.CameraActivity;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.component.face.FaceFragment;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.component.inputedittext.TIMMentionEditText;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.config.GeneralConfig;
|
|
|
-import com.tencent.qcloud.tuikit.tuichat.config.TUIChatConfigs;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.config.classicui.TUIChatConfigClassic;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.interfaces.AlbumPickerListener;
|
|
|
+import com.tencent.qcloud.tuikit.tuichat.interfaces.IMultimediaRecorder;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.presenter.ChatPresenter;
|
|
|
import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageBuilder;
|
|
|
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.Collections;
|
|
|
import java.util.Comparator;
|
|
|
@@ -132,11 +127,10 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
protected TIMMentionEditText mTextInput;
|
|
|
private boolean mIsSending = false;
|
|
|
|
|
|
- protected AppCompatActivity mActivity;
|
|
|
+ protected FragmentActivity mActivity;
|
|
|
protected View mInputMoreView;
|
|
|
protected ChatInfo mChatInfo;
|
|
|
- protected List<InputMoreActionUnit> mInputMoreActionList = new ArrayList<>();
|
|
|
- protected List<InputMoreActionUnit> mInputMoreCustomActionList = new ArrayList<>();
|
|
|
+ protected List<InputMoreItem> mInputMoreActionList = new ArrayList<>();
|
|
|
|
|
|
private FaceFragment mFaceFragment;
|
|
|
private ChatInputHandler mChatInputHandler;
|
|
|
@@ -167,6 +161,9 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
private ImageView quoteCloseBtn;
|
|
|
private boolean isShowCustomFace = true;
|
|
|
private ChatInputMoreListener chatInputMoreListener;
|
|
|
+ private IMultimediaRecorder defaultVideoRecorder;
|
|
|
+ private IMultimediaRecorder extVideoRecorder;
|
|
|
+ private AudioRecorder defaultAudioRecorder;
|
|
|
|
|
|
public InputView(Context context) {
|
|
|
super(context);
|
|
|
@@ -188,7 +185,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
}
|
|
|
|
|
|
private void initViews() {
|
|
|
- mActivity = (AppCompatActivity) getContext();
|
|
|
+ mActivity = (FragmentActivity) getContext();
|
|
|
inflate(mActivity, R.layout.chat_input_layout, this);
|
|
|
mInputMoreView = findViewById(R.id.more_groups);
|
|
|
mSendAudioButton = findViewById(R.id.chat_voice_input);
|
|
|
@@ -280,15 +277,15 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
switch (motionEvent.getAction()) {
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
mStartRecordY = motionEvent.getY();
|
|
|
- startRecord();
|
|
|
+ startRecordAudio();
|
|
|
break;
|
|
|
case MotionEvent.ACTION_MOVE:
|
|
|
if (motionEvent.getY() - mStartRecordY < -100) {
|
|
|
readyToCancel = true;
|
|
|
- readyToCancelRecord();
|
|
|
+ readyToCancelRecordAudio();
|
|
|
} else {
|
|
|
if (readyToCancel) {
|
|
|
- continueRecord();
|
|
|
+ continueRecordAudio();
|
|
|
}
|
|
|
readyToCancel = false;
|
|
|
}
|
|
|
@@ -296,9 +293,9 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
case MotionEvent.ACTION_CANCEL:
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
if (readyToCancel) {
|
|
|
- cancelRecord();
|
|
|
+ cancelRecordAudio();
|
|
|
} else {
|
|
|
- stopRecord();
|
|
|
+ stopRecordAudio();
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
@@ -364,7 +361,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void startRecord() {
|
|
|
+ private void startRecordAudio() {
|
|
|
AudioRecorder.startRecord(new AudioRecorder.AudioRecorderCallback() {
|
|
|
@Override
|
|
|
public void onStarted() {
|
|
|
@@ -418,23 +415,23 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void readyToCancelRecord() {
|
|
|
+ private void readyToCancelRecordAudio() {
|
|
|
if (mChatInputHandler != null) {
|
|
|
mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_READY_TO_CANCEL);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void continueRecord() {
|
|
|
+ private void continueRecordAudio() {
|
|
|
if (mChatInputHandler != null) {
|
|
|
mChatInputHandler.onRecordStatusChanged(ChatInputHandler.RECORD_CONTINUE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void cancelRecord() {
|
|
|
+ private void cancelRecordAudio() {
|
|
|
AudioRecorder.cancelRecord();
|
|
|
}
|
|
|
|
|
|
- private void stopRecord() {
|
|
|
+ private void stopRecordAudio() {
|
|
|
AudioRecorder.stopRecord();
|
|
|
}
|
|
|
|
|
|
@@ -454,7 +451,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
FaceUtil.handlerEmojiText(mTextInput, text, true);
|
|
|
mTextInput.setSelection(selectedIndex + displayInputString.length());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 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
|
|
|
@@ -536,266 +533,69 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
|
|
|
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")) {
|
|
|
- if (FileUtil.isFileSizeExceedsLimit(data, GeneralConfig.VIDEO_MAX_SIZE)) {
|
|
|
- ToastUtil.toastShortMessage(getResources().getString(com.tencent.qcloud.tuicore.R.string.TUIKitErrorFileTooLarge));
|
|
|
- continue;
|
|
|
- }
|
|
|
- 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")) {
|
|
|
- if (TextUtils.equals(mimeType, "image/gif")) {
|
|
|
- if (FileUtil.isFileSizeExceedsLimit(data, GeneralConfig.GIF_IMAGE_MAX_SIZE)) {
|
|
|
- ToastUtil.toastShortMessage(getResources().getString(com.tencent.qcloud.tuicore.R.string.TUIKitErrorFileTooLarge));
|
|
|
- continue;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (FileUtil.isFileSizeExceedsLimit(data, GeneralConfig.IMAGE_MAX_SIZE)) {
|
|
|
- ToastUtil.toastShortMessage(getResources().getString(com.tencent.qcloud.tuicore.R.string.TUIKitErrorFileTooLarge));
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- 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;
|
|
|
+ AlbumPicker.pickMedia(mInputMoreFragment.getActivity(), new AlbumPickerListener() {
|
|
|
+ @Override
|
|
|
+ public void onFinished(Uri originalUri, Uri transcodeUri) {
|
|
|
+ sendPhotoVideoMessage(originalUri, transcodeUri);
|
|
|
}
|
|
|
|
|
|
- String bitmapPath = FileUtil.generateImageFilePath();
|
|
|
- boolean result = FileUtil.saveBitmap(bitmapPath, bitmap);
|
|
|
- if (!result) {
|
|
|
- TUIChatLog.e(TAG, "build video message, save bitmap failed.");
|
|
|
- return null;
|
|
|
+ @Override
|
|
|
+ public void onProgress(Uri originalUri, int progress) {
|
|
|
+ presenter.updateMessageProgress(originalUri, progress);
|
|
|
}
|
|
|
- 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() {
|
|
|
- startCapture();
|
|
|
+ public void onOriginalMediaPicked(Uri originalUri) {
|
|
|
+ presenter.addPlaceholderMessage(originalUri);
|
|
|
+ hideSoftInput();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onDenied() {
|
|
|
- TUIChatLog.i(TAG, "startCapture checkPermission failed");
|
|
|
+ public void onCancel() {
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void startCapture() {
|
|
|
- if (TUIChatConfigs.getGeneralConfig().isUseSystemCamera()) {
|
|
|
- if (TUIBuild.getVersionInt() < Build.VERSION_CODES.N) {
|
|
|
- PermissionHelper.requestPermission(PermissionHelper.PERMISSION_STORAGE, new PermissionHelper.PermissionCallback() {
|
|
|
- @Override
|
|
|
- public void onGranted() {
|
|
|
- String path = FileUtil.generateExternalStorageImageFilePath();
|
|
|
- systemCaptureAndSend(path);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDenied() {
|
|
|
- TUIChatLog.i(TAG, "startCapture checkPermission failed");
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- String path = FileUtil.generateImageFilePath();
|
|
|
- systemCaptureAndSend(path);
|
|
|
- }
|
|
|
- } else {
|
|
|
- chatCaptureAndSend();
|
|
|
- }
|
|
|
+ private void sendPhotoVideoMessage(Uri uri) {
|
|
|
+ presenter.sendPhotoVideoMessages(uri, null);
|
|
|
+ hideSoftInput();
|
|
|
}
|
|
|
|
|
|
- private void chatCaptureAndSend() {
|
|
|
- Bundle bundle = new Bundle();
|
|
|
- bundle.putInt(TUIChatConstants.CAMERA_TYPE, CameraActivity.BUTTON_STATE_ONLY_CAPTURE);
|
|
|
- TUICore.startActivityForResult(mInputMoreFragment, CameraActivity.class, bundle, result -> {
|
|
|
- if (result.getData() != null) {
|
|
|
- Uri uri = result.getData().getData();
|
|
|
- if (uri != null) {
|
|
|
- sendPhotoVideoMessage(Collections.singletonList(uri));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ private void sendPhotoVideoMessage(Uri original, Uri transcodeUri) {
|
|
|
+ presenter.sendPhotoVideoMessages(original, transcodeUri);
|
|
|
+ ThreadUtils.runOnUiThread(this::hideSoftInput);
|
|
|
}
|
|
|
|
|
|
- private void systemCaptureAndSend(String path) {
|
|
|
- Uri uri = FileUtil.getUriFromPath(path);
|
|
|
- if (uri == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- ActivityResultResolver.takePicture(mInputMoreFragment, uri, new TUIValueCallback<Boolean>() {
|
|
|
- @Override
|
|
|
- public void onSuccess(Boolean object) {
|
|
|
- File imageFile = new File(path);
|
|
|
- if (imageFile.exists()) {
|
|
|
- sendPhotoVideoMessage(Collections.singletonList(uri));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(int errorCode, String errorMessage) {}
|
|
|
- });
|
|
|
- }
|
|
|
+ protected void takePhoto() {
|
|
|
+ TUIChatLog.i(TAG, "takePhoto");
|
|
|
|
|
|
- protected void startVideoRecordCheckPermission() {
|
|
|
- TUIChatLog.i(TAG, "startVideoRecordCheckPermission");
|
|
|
+ VideoRecorder.openCamera(mInputMoreFragment, new TUIValueCallback<Uri>() {
|
|
|
|
|
|
- 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");
|
|
|
- }
|
|
|
- });
|
|
|
+ public void onSuccess(Uri uri) {
|
|
|
+ sendPhotoVideoMessage(uri);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onDenied() {
|
|
|
- TUIChatLog.i(TAG, "startVideoRecord checkPermission failed");
|
|
|
+ public void onError(int errorCode, String errorMessage) {
|
|
|
+ TUIChatLog.e(TAG, "takePhoto errorCode: " + errorCode + " errorMessage: " + errorMessage);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void startVideoRecord() {
|
|
|
- if (TUIChatConfigs.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();
|
|
|
- }
|
|
|
- }
|
|
|
+ protected void recordVideo() {
|
|
|
+ TUIChatLog.i(TAG, "openVideoRecord");
|
|
|
|
|
|
- private void systemRecordAndSend(String path) {
|
|
|
- Uri uri = FileUtil.getUriFromPath(path);
|
|
|
- if (uri == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- ActivityResultResolver.takeVideo(mInputMoreFragment, uri, new TUIValueCallback<Boolean>() {
|
|
|
+ VideoRecorder.openVideoRecorder(mInputMoreFragment, new TUIValueCallback<Uri>() {
|
|
|
@Override
|
|
|
- public void onSuccess(Boolean object) {
|
|
|
- File videoFile = new File(path);
|
|
|
- if (videoFile.exists()) {
|
|
|
- sendPhotoVideoMessage(Collections.singletonList(uri));
|
|
|
- }
|
|
|
+ public void onSuccess(Uri uri) {
|
|
|
+ sendPhotoVideoMessage(uri);
|
|
|
}
|
|
|
|
|
|
@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 data = result.getData();
|
|
|
- if (data == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Uri uri = data.getData();
|
|
|
- if (uri != null) {
|
|
|
- sendPhotoVideoMessage(Collections.singletonList(uri));
|
|
|
+ public void onError(int errorCode, String errorMessage) {
|
|
|
+ TUIChatLog.i(TAG, "openVideoRecord errorCode: " + errorCode + " errorMessage: " + errorMessage);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -1218,9 +1018,19 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
|
|
|
protected void assembleActions() {
|
|
|
mInputMoreActionList.clear();
|
|
|
- InputMoreActionUnit actionUnit;
|
|
|
- if (TUIChatConfigs.getGeneralConfig().isEnableAlbum() && getChatInfo().isEnableAlbum()) {
|
|
|
- actionUnit = new InputMoreActionUnit() {
|
|
|
+
|
|
|
+ List<Integer> excludeItems = new ArrayList<>();
|
|
|
+ TUIChatConfigClassic.ChatInputMoreDataSource dataSource = TUIChatConfigClassic.getChatInputMoreDataSource();
|
|
|
+ if (dataSource != null) {
|
|
|
+ excludeItems.addAll(dataSource.inputBarShouldHideItemsInMoreMenuOfInfo(mChatInfo));
|
|
|
+ mInputMoreActionList.addAll(dataSource.inputBarShouldAddNewItemToMoreMenuOfInfo(mChatInfo));
|
|
|
+ }
|
|
|
+
|
|
|
+ InputMoreItem actionUnit;
|
|
|
+ if (TUIChatConfigClassic.isShowInputBarAlbum()
|
|
|
+ && getChatInfo().isEnableAlbum()
|
|
|
+ && !excludeItems.contains(TUIChatConfigClassic.ALBUM)) {
|
|
|
+ actionUnit = new InputMoreItem() {
|
|
|
@Override
|
|
|
public void onAction(String chatInfoId, int chatType) {
|
|
|
startSendPhoto();
|
|
|
@@ -1232,11 +1042,13 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mInputMoreActionList.add(actionUnit);
|
|
|
}
|
|
|
|
|
|
- if (TUIChatConfigs.getGeneralConfig().isEnableTakePhoto() && getChatInfo().isEnableTakePhoto()) {
|
|
|
- actionUnit = new InputMoreActionUnit() {
|
|
|
+ if (TUIChatConfigClassic.isShowInputBarTakePhoto()
|
|
|
+ && getChatInfo().isEnableTakePhoto()
|
|
|
+ && !excludeItems.contains(TUIChatConfigClassic.TAKE_PHOTO)) {
|
|
|
+ actionUnit = new InputMoreItem() {
|
|
|
@Override
|
|
|
public void onAction(String chatInfoId, int chatType) {
|
|
|
- startCaptureCheckPermission();
|
|
|
+ takePhoto();
|
|
|
}
|
|
|
};
|
|
|
actionUnit.setIconResId(R.drawable.ic_more_camera);
|
|
|
@@ -1245,11 +1057,13 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mInputMoreActionList.add(actionUnit);
|
|
|
}
|
|
|
|
|
|
- if (TUIChatConfigs.getGeneralConfig().isEnableRecordVideo() && getChatInfo().isEnableRecordVideo()) {
|
|
|
- actionUnit = new InputMoreActionUnit() {
|
|
|
+ if (TUIChatConfigClassic.isShowInputBarRecordVideo()
|
|
|
+ && getChatInfo().isEnableRecordVideo()
|
|
|
+ && !excludeItems.contains(TUIChatConfigClassic.RECORD_VIDEO)) {
|
|
|
+ actionUnit = new InputMoreItem() {
|
|
|
@Override
|
|
|
public void onAction(String chatInfoId, int chatType) {
|
|
|
- startVideoRecordCheckPermission();
|
|
|
+ recordVideo();
|
|
|
}
|
|
|
};
|
|
|
actionUnit.setIconResId(R.drawable.ic_more_video);
|
|
|
@@ -1258,8 +1072,10 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mInputMoreActionList.add(actionUnit);
|
|
|
}
|
|
|
|
|
|
- if (TUIChatConfigs.getGeneralConfig().isEnableFile() && getChatInfo().isEnableFile()) {
|
|
|
- actionUnit = new InputMoreActionUnit() {
|
|
|
+ if (TUIChatConfigClassic.isShowInputBarFile()
|
|
|
+ && getChatInfo().isEnableFile()
|
|
|
+ && !excludeItems.contains(TUIChatConfigClassic.FILE)) {
|
|
|
+ actionUnit = new InputMoreItem() {
|
|
|
@Override
|
|
|
public void onAction(String chatInfoId, int chatType) {
|
|
|
startSendFile();
|
|
|
@@ -1271,16 +1087,36 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mInputMoreActionList.add(actionUnit);
|
|
|
}
|
|
|
|
|
|
- List<InputMoreActionUnit> extensionList = getExtensionInputMoreList();
|
|
|
- mInputMoreActionList.addAll(extensionList);
|
|
|
- clearCustomActionList();
|
|
|
- if (mChatLayout != null) {
|
|
|
- mChatLayout.customizeInputMoreLayout();
|
|
|
+ // Add a welcome prompt with rich text
|
|
|
+ if (TUIChatConfigClassic.isShowInputBarCustom()
|
|
|
+ && getChatInfo().isEnableCustomHelloMessage()
|
|
|
+ && !excludeItems.contains(TUIChatConfigClassic.CUSTOM)) {
|
|
|
+ actionUnit = new InputMoreItem() {};
|
|
|
+ actionUnit.setIconResId(R.drawable.custom);
|
|
|
+ actionUnit.setName(getResources().getString(R.string.test_custom_action));
|
|
|
+ actionUnit.setActionId(CustomHelloMessage.CUSTOM_HELLO_ACTION_ID);
|
|
|
+ actionUnit.setPriority(10);
|
|
|
+ actionUnit.setOnClickListener(actionUnit.new OnActionClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick() {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ CustomHelloMessage customHelloMessage = new CustomHelloMessage();
|
|
|
+ customHelloMessage.version = TUIChatConstants.version;
|
|
|
+
|
|
|
+ String data = gson.toJson(customHelloMessage);
|
|
|
+ TUIMessageBean info = ChatMessageBuilder.buildCustomMessage(data, customHelloMessage.text, customHelloMessage.text.getBytes());
|
|
|
+ mChatLayout.sendMessage(info, false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mInputMoreActionList.add(actionUnit);
|
|
|
}
|
|
|
- mInputMoreActionList.addAll(mInputMoreCustomActionList);
|
|
|
- Collections.sort(mInputMoreActionList, new Comparator<InputMoreActionUnit>() {
|
|
|
+
|
|
|
+ List<InputMoreItem> extensionList = getExtensionInputMoreList();
|
|
|
+ mInputMoreActionList.addAll(extensionList);
|
|
|
+
|
|
|
+ Collections.sort(mInputMoreActionList, new Comparator<InputMoreItem>() {
|
|
|
@Override
|
|
|
- public int compare(InputMoreActionUnit o1, InputMoreActionUnit o2) {
|
|
|
+ public int compare(InputMoreItem o1, InputMoreItem o2) {
|
|
|
return o2.getPriority() - o1.getPriority();
|
|
|
}
|
|
|
});
|
|
|
@@ -1290,9 +1126,13 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
return getResources().getString(stringID);
|
|
|
}
|
|
|
|
|
|
- private List<InputMoreActionUnit> getExtensionInputMoreList() {
|
|
|
- List<InputMoreActionUnit> list = new ArrayList<>();
|
|
|
-
|
|
|
+ private List<InputMoreItem> getExtensionInputMoreList() {
|
|
|
+ List<InputMoreItem> list = new ArrayList<>();
|
|
|
+ List<Integer> excludeItems = new ArrayList<>();
|
|
|
+ TUIChatConfigClassic.ChatInputMoreDataSource dataSource = TUIChatConfigClassic.getChatInputMoreDataSource();
|
|
|
+ if (dataSource != null) {
|
|
|
+ excludeItems.addAll(dataSource.inputBarShouldHideItemsInMoreMenuOfInfo(mChatInfo));
|
|
|
+ }
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
param.put(TUIConstants.TUIChat.Extension.InputMore.CONTEXT, getContext());
|
|
|
if (ChatInfo.TYPE_C2C == mChatInfo.getType()) {
|
|
|
@@ -1306,15 +1146,18 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_ROOM, true);
|
|
|
} else {
|
|
|
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_VIDEO_CALL,
|
|
|
- !TUIChatConfigs.getGeneralConfig().isEnableVideoCall() || !getChatInfo().isEnableVideoCall());
|
|
|
+ !TUIChatConfigClassic.isShowInputBarVideoCall() || !getChatInfo().isEnableVideoCall()
|
|
|
+ || excludeItems.contains(TUIChatConfigClassic.VIDEO_CALL));
|
|
|
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_VOICE_CALL,
|
|
|
- !TUIChatConfigs.getGeneralConfig().isEnableAudioCall() || !getChatInfo().isEnableAudioCall());
|
|
|
+ !TUIChatConfigClassic.isShowInputBarAudioCall() || !getChatInfo().isEnableAudioCall()
|
|
|
+ || excludeItems.contains(TUIChatConfigClassic.AUDIO_CALL));
|
|
|
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_ROOM,
|
|
|
- !TUIChatConfigs.getGeneralConfig().isEnableRoomKit() || !getChatInfo().isEnableRoom());
|
|
|
+ !TUIChatConfigClassic.isShowInputBarRoomKit() || !getChatInfo().isEnableRoom() || excludeItems.contains(TUIChatConfigClassic.ROOM_KIT));
|
|
|
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_GROUP_NOTE,
|
|
|
- !TUIChatConfigs.getGeneralConfig().isEnableGroupNote() || !getChatInfo().isEnableGroupNote());
|
|
|
+ !TUIChatConfigClassic.isShowInputBarGroupNote() || !getChatInfo().isEnableGroupNote()
|
|
|
+ || excludeItems.contains(TUIChatConfigClassic.GROUP_NOTE));
|
|
|
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_POLL,
|
|
|
- !TUIChatConfigs.getGeneralConfig().isEnablePoll() || !getChatInfo().isEnablePoll());
|
|
|
+ !TUIChatConfigClassic.isShowInputBarPoll() || !getChatInfo().isEnablePoll() || excludeItems.contains(TUIChatConfigClassic.POLL));
|
|
|
}
|
|
|
param.put(TUIConstants.TUIChat.Extension.InputMore.INPUT_MORE_LISTENER, chatInputMoreListener);
|
|
|
List<TUIExtensionInfo> extensionList = TUICore.getExtensionList(TUIConstants.TUIChat.Extension.InputMore.CLASSIC_EXTENSION_ID, param);
|
|
|
@@ -1323,7 +1166,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
String name = extensionInfo.getText();
|
|
|
int icon = (int) extensionInfo.getIcon();
|
|
|
int priority = extensionInfo.getWeight();
|
|
|
- InputMoreActionUnit unit = new InputMoreActionUnit() {
|
|
|
+ InputMoreItem unit = new InputMoreItem() {
|
|
|
@Override
|
|
|
public void onAction(String chatInfoId, int chatType) {
|
|
|
TUIExtensionEventListener extensionListener = extensionInfo.getExtensionListener();
|
|
|
@@ -1378,10 +1221,6 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mMoreInputEvent = listener;
|
|
|
}
|
|
|
|
|
|
- public void addAction(InputMoreActionUnit action) {
|
|
|
- mInputMoreCustomActionList.add(action);
|
|
|
- }
|
|
|
-
|
|
|
public EditText getInputText() {
|
|
|
return mTextInput;
|
|
|
}
|
|
|
@@ -1456,10 +1295,6 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
|
|
|
mEmojiInputButton.setVisibility(visibility);
|
|
|
}
|
|
|
|
|
|
- public void clearCustomActionList() {
|
|
|
- mInputMoreCustomActionList.clear();
|
|
|
- }
|
|
|
-
|
|
|
public ChatInfo getChatInfo() {
|
|
|
return mChatInfo;
|
|
|
}
|