[Modify]修改圖片選擇邏輯和更改版本為1.3.0

This commit is contained in:
wushaocheng
2022-12-02 18:32:14 +08:00
parent 19b368d54e
commit 62702c9650
10 changed files with 86 additions and 208 deletions

View File

@@ -1,12 +1,13 @@
package com.netease.nim.uikit.business.session.actions;
import androidx.annotation.NonNull;
import com.netease.nim.uikit.R;
import com.netease.nim.uikit.business.session.event.ActiveEvent;
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;
@@ -15,14 +16,14 @@ import java.io.File;
/**
* Created by hzxuwen on 2015/6/12.
*/
public class ImageAction extends PickImageActionNew{
public class ImageAction extends PickImageAction {
public ImageAction() {
super(R.drawable.chat_icon_photo, R.string.input_panel_photo, true);
}
@Override
protected void onPicked(File file) {
protected void onPicked(@NonNull File file) {
IMMessage message;
if (getContainer() != null && getContainer().sessionType == SessionTypeEnum.ChatRoom) {
message = ChatRoomMessageBuilder.createChatRoomImageMessage(getAccount(), file, file.getName());

View File

@@ -3,11 +3,8 @@ 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.helper.SendImageHelper
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.common.photo.PhotoProviderNew
import com.yizhuan.xchat_android_library.utils.SingleToastUtil
import java.io.File
@@ -31,7 +28,7 @@ abstract class PickImageActionNew protected constructor(
}
private fun checkStoragePermission() {
PhotoProvider.photoProvider(
PhotoProviderNew.photoProvider(
activity,
maxSelect = 9,
resultCode = makeRequestCode(REQUEST_CODE_OPEN_PHOTO_PROVIDER)
@@ -43,33 +40,34 @@ abstract class PickImageActionNew protected constructor(
when (requestCode) {
REQUEST_CODE_OPEN_PHOTO_PROVIDER -> {
if (data == null) return
PhotoProvider.getResultPathListAsync(data) { list ->
PhotoProviderNew.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 onFail(e: Throwable) {
SingleToastUtil.showToastShort(R.string.picker_image_error)
}
})
sendImageAfterSelfImagePicker(paths)
// 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 onFail(e: Throwable) {
// SingleToastUtil.showToastShort(R.string.picker_image_error)
// }
//
// })
}
}
}

View File

@@ -128,22 +128,22 @@ public class SendImageHelper {
}
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);
// }
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);
return imageFile;
}
}