[Modify]私聊頁面修改

This commit is contained in:
wushaocheng
2022-12-02 09:19:21 +08:00
parent c10aa4af68
commit a8924d73c4
10 changed files with 174 additions and 73 deletions

View File

@@ -429,4 +429,5 @@
<string name="impl_customization_defaultrecentcustomization_06">[通知提醒]</string>
<string name="impl_customization_defaultrecentcustomization_07">[機器人消息]</string>
<string name="impl_customization_defaultrecentcustomization_08">[自定義消息] </string>
<string name="xchat_android_core_file_filemodel_01"> 為空或者該文件不存在!</string>
</resources>

View File

@@ -6,6 +6,7 @@ import com.netease.nimlib.sdk.chatroom.ChatRoomMessageBuilder;
import com.netease.nimlib.sdk.msg.MessageBuilder;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.yizhuan.xchat_android_library.common.util.Logger;
import org.greenrobot.eventbus.EventBus;

View File

@@ -2,10 +2,12 @@ package com.netease.nim.uikit.business.session.actions
import android.content.Intent
import com.netease.nim.uikit.R
import com.netease.nim.uikit.business.session.constant.Extras
import com.netease.nim.uikit.business.session.constant.RequestCode
import com.netease.nim.uikit.business.session.helper.SendImageHelper
import com.yizhuan.xchat_android_library.easypermisssion.EasyPermissions
import com.yizhuan.xchat_android_library.common.application.BaseApp
import com.yizhuan.xchat_android_library.common.base.BaseDialogFragment
import com.yizhuan.xchat_android_library.common.photo.PhotoProvider
import com.yizhuan.xchat_android_library.common.util.PhotoCompressUtil
import com.yizhuan.xchat_android_library.common.util.PhotosCompressCallback
import com.yizhuan.xchat_android_library.utils.SingleToastUtil
import java.io.File
@@ -16,9 +18,9 @@ abstract class PickImageActionNew protected constructor(
iconResId: Int,
titleId: Int,
private val multiSelect: Boolean
) : BaseAction(iconResId, titleId), EasyPermissions.PermissionCallbacks {
) : BaseAction(iconResId, titleId) {
companion object{
companion object {
private const val REQUEST_CODE_OPEN_PHOTO_PROVIDER = 111 // 从相册中选择
}
@@ -29,71 +31,61 @@ abstract class PickImageActionNew protected constructor(
}
private fun checkStoragePermission() {
// if (!EasyPermissions.hasPermissions(
// this,
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
// Manifest.permission.READ_EXTERNAL_STORAGE
// )
// ) {
// EasyPermissions.requestPermissions(
// this,
// getString(R.string.permission_storage_rationale),
// PERMISSION_CODE_STORAGE,
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
// Manifest.permission.READ_EXTERNAL_STORAGE
// )
// } else {
// PhotoProvider.photoProvider(
// this,
// resultCode = REQUEST_CODE_OPEN_PHOTO_PROVIDER
// )
// }
PhotoProvider.photoProvider(
activity,
maxSelect = 9,
resultCode = makeRequestCode(REQUEST_CODE_OPEN_PHOTO_PROVIDER)
)
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == BaseDialogFragment.RESULT_OK) {
when (requestCode) {
REQUEST_CODE_OPEN_PHOTO_PROVIDER -> {
if (data == null) return
PhotoProvider.getResultPathListAsync(data) { list ->
val paths = list?.toMutableList() ?: ArrayList()
if (paths.isEmpty()) {
SingleToastUtil.showToastShort(R.string.picker_image_error)
} else {
PhotoCompressUtil.compress(
BaseApp.getContext(),
paths,
PhotoCompressUtil.getCompressCachePath(),
object : PhotosCompressCallback {
override fun onSuccess(compressedImgList: ArrayList<String>) {
sendImageAfterSelfImagePicker(compressedImgList)
// for (path in compressedImgList) {
// val file = File(path)
// if (TextUtils.isEmpty(path) || !file.exists()) {
// SingleToastUtil.showToastShort(path + ResUtil.getString(R.string.xchat_android_core_file_filemodel_01))
// return
// }
// onPicked(file)
// }
}
override fun onPermissionsGranted(requestCode: Int, perms: List<String>) {
override fun onFail(e: Throwable) {
SingleToastUtil.showToastShort(R.string.picker_image_error)
}
}
override fun onPermissionsDenied(requestCode: Int, perms: List<String>) {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
when (requestCode) {
RequestCode.PICK_IMAGE -> onPickImageActivityResult(requestCode, data)
}
}
/**
* 图片选取回调
*/
private fun onPickImageActivityResult(requestCode: Int, data: Intent?) {
if (data == null) {
SingleToastUtil.showToastShort(R.string.picker_image_error)
return
}
val local = data.getBooleanExtra(Extras.EXTRA_FROM_LOCAL, false)
if (local) {
// 本地相册
sendImageAfterSelfImagePicker(data)
})
}
}
}
}
}
}
/**
* 发送图片
*/
private fun sendImageAfterSelfImagePicker(data: Intent) {
SendImageHelper.sendImageAfterSelfImagePicker(activity, data) { file, isOrig ->
onPicked(
file
)
private fun sendImageAfterSelfImagePicker(compressedImgList: List<String>) {
SendImageHelper.sendImageAfterSelfImagePickerNew(
activity,
compressedImgList
) { file, isOrig ->
onPicked(file)
}
}
}

View File

@@ -64,6 +64,101 @@ public class SendImageHelper {
}
}
public static void sendImageAfterSelfImagePickerNew(Context context, List<String> photos, final Callback callback) {
boolean isOrig = false;
if (photos == null) {
SingleToastUtil.showToastShort("AFAKSSLDF");
return;
}
for (String photoInfo : photos) {
new SendImageTaskNew(context, isOrig, photoInfo, new Callback() {
@Override
public void sendImage(File file, boolean isOrig) {
if (callback != null) {
callback.sendImage(file, isOrig);
}
}
}).execute();
}
}
// 从相册选择图片进行发送(Added by NYB)
public static class SendImageTaskNew extends AsyncTask<Void, Void, File> {
private Context context;
private boolean isOrig;
private String info;
private Callback callback;
public SendImageTaskNew(Context context, boolean isOrig, String info,
Callback callback) {
this.context = context;
this.isOrig = isOrig;
this.info = info;
this.callback = callback;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected File doInBackground(Void... params) {
String photoPath = info;
if (TextUtils.isEmpty(photoPath))
return null;
String extension = FileUtil.getExtensionName(photoPath);
// gif 强制设置成原图
boolean gif = ImageUtil.isGif(extension);
isOrig |= gif;
if (isOrig) {
// 把原图按md5存放
String origMD5 = MD5.getStreamMD5(photoPath);
String origMD5Path = StorageUtil.getWritePath(origMD5 + "."
+ extension, StorageType.TYPE_IMAGE);
AttachmentStore.copy(photoPath, origMD5Path);
// 生成缩略图
if (!gif) {
File imageFile = new File(origMD5Path);
ImageUtil.makeThumbnail(context, imageFile);
}
return new File(origMD5Path);
} else {
// File imageFile = new File(photoPath);
// extension = FileUtil.getExtensionName(photoPath);
// imageFile = ImageUtil.getScaledImageFileWithMD5(imageFile, extension);
// if (imageFile == null) {
// new Handler(context.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// SingleToastUtil.showToastShort("是会计法规很少看见");
// }
// });
// return null;
// } else {
// ImageUtil.makeThumbnail(context, imageFile);
// }
return new File(photoPath);
}
}
@Override
protected void onPostExecute(File result) {
super.onPostExecute(result);
if (result != null) {
if (callback != null) {
callback.sendImage(result, isOrig);
}
}
}
}
public static void sendImageAfterSelfImagePicker(Context context, Intent data, final Callback callback) {
boolean isOrig = data.getBooleanExtra(Extras.EXTRA_IS_ORIGINAL, false);