[Modify]私聊获取图片失败bug修复
This commit is contained in:
@@ -229,4 +229,6 @@
|
||||
<string name="msg_search_limit">全文检索显示条数</string>
|
||||
<string name="message_hint">请输入消息</string>
|
||||
|
||||
<string name="photo_file_is_empty"> 为空或者该文件不存在!</string>
|
||||
|
||||
</resources>
|
@@ -14,7 +14,7 @@ import java.io.File;
|
||||
/**
|
||||
* Created by hzxuwen on 2015/6/12.
|
||||
*/
|
||||
public class ImageAction extends PickImageAction {
|
||||
public class ImageAction extends PickImageActionNew {
|
||||
|
||||
public ImageAction() {
|
||||
super(R.drawable.chat_icon_photo, R.string.input_panel_photo, true);
|
||||
|
@@ -0,0 +1,82 @@
|
||||
package com.netease.nim.uikit.business.session.actions
|
||||
|
||||
import android.content.Intent
|
||||
import android.text.TextUtils
|
||||
import com.netease.nim.uikit.R
|
||||
import com.netease.nim.uikit.business.session.helper.SendImageHelper
|
||||
import com.nnbc123.library.common.application.BaseApp
|
||||
import com.nnbc123.library.common.base.BaseDialogFragment
|
||||
import com.nnbc123.library.common.photo.PhotoProviderNew
|
||||
import com.nnbc123.library.common.util.PhotoCompressUtil
|
||||
import com.nnbc123.library.common.util.PhotosCompressCallback
|
||||
import com.nnbc123.library.utils.ResUtil
|
||||
import com.nnbc123.library.utils.SingleToastUtil
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Created by zhoujianghua on 2015/7/31.
|
||||
*/
|
||||
abstract class PickImageActionNew protected constructor(
|
||||
iconResId: Int,
|
||||
titleId: Int,
|
||||
private val multiSelect: Boolean
|
||||
) : BaseAction(iconResId, titleId) {
|
||||
|
||||
companion object {
|
||||
private const val REQUEST_CODE_OPEN_PHOTO_PROVIDER = 111 // 从相册中选择
|
||||
}
|
||||
|
||||
protected abstract fun onPicked(file: File)
|
||||
|
||||
override fun onClick() {
|
||||
checkStoragePermission()
|
||||
}
|
||||
|
||||
private fun checkStoragePermission() {
|
||||
PhotoProviderNew.photoProvider(
|
||||
activity,
|
||||
maxSelect = 9,
|
||||
resultCode = makeRequestCode(REQUEST_CODE_OPEN_PHOTO_PROVIDER)
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
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.photo_file_is_empty))
|
||||
return
|
||||
}
|
||||
onPicked(file)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFail(e: Throwable) {
|
||||
SingleToastUtil.showToastShort(R.string.picker_image_error)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -8,6 +8,8 @@ import android.os.StatFs;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nnbc123.library.common.file.FileHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -65,7 +67,8 @@ public class ExternalStorage {
|
||||
}
|
||||
|
||||
private void loadStorageState(Context context) {
|
||||
String externalPath = Environment.getExternalStorageDirectory().getPath();
|
||||
// String externalPath = Environment.getExternalStorageDirectory().getPath();
|
||||
String externalPath = FileHelper.getRootCacheDir().getPath();
|
||||
this.sdkStorageRoot = externalPath + "/" + context.getPackageName() + "/";
|
||||
}
|
||||
|
||||
@@ -173,7 +176,8 @@ public class ExternalStorage {
|
||||
}
|
||||
|
||||
public boolean isSdkStorageReady() {
|
||||
String externalRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
// String externalRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
String externalRoot = FileHelper.getRootCacheDir().getPath();
|
||||
if (this.sdkStorageRoot.startsWith(externalRoot)) {
|
||||
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user