[Modify]圖片保存到本地適配
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package com.netease.nim.uikit.business.session.activity;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -29,11 +27,8 @@ import com.netease.nim.uikit.common.ui.dialog.CustomAlertDialog;
|
||||
import com.netease.nim.uikit.common.ui.dialog.CustomAlertDialog.onSeparateItemClickListener;
|
||||
import com.netease.nim.uikit.common.ui.imageview.BaseZoomableImageView;
|
||||
import com.netease.nim.uikit.common.ui.imageview.ImageGestureListener;
|
||||
import com.netease.nim.uikit.common.util.C;
|
||||
import com.netease.nim.uikit.common.util.file.AttachmentStore;
|
||||
import com.netease.nim.uikit.common.util.media.BitmapDecoder;
|
||||
import com.netease.nim.uikit.common.util.media.ImageUtil;
|
||||
import com.netease.nim.uikit.common.util.storage.StorageUtil;
|
||||
import com.netease.nim.uikit.common.util.sys.TimeUtil;
|
||||
import com.netease.nimlib.sdk.AbortableFuture;
|
||||
import com.netease.nimlib.sdk.NIMClient;
|
||||
@@ -47,6 +42,8 @@ import com.netease.nimlib.sdk.msg.constant.AttachStatusEnum;
|
||||
import com.netease.nimlib.sdk.msg.constant.MsgDirectionEnum;
|
||||
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
|
||||
import com.netease.nimlib.sdk.msg.model.IMMessage;
|
||||
import com.yizhuan.xchat_android_library.common.util.AlbumUtils;
|
||||
import com.yizhuan.xchat_android_library.common.util.ExecutorCenter;
|
||||
import com.yizhuan.xchat_android_library.utils.ResUtil;
|
||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||
|
||||
@@ -55,6 +52,9 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
|
||||
|
||||
/**
|
||||
* 查看聊天消息原图
|
||||
@@ -222,7 +222,7 @@ public class WatchMessagePictureActivity extends UI {
|
||||
@Override
|
||||
public void onSuccess(List<IMMessage> param) {
|
||||
for (IMMessage imMessage : param) {
|
||||
if (!ImageUtil.isGif(((ImageAttachment) imMessage.getAttachment()).getExtension())){
|
||||
if (!ImageUtil.isGif(((ImageAttachment) imMessage.getAttachment()).getExtension())) {
|
||||
imageMsgList.add(imMessage);
|
||||
}
|
||||
}
|
||||
@@ -558,29 +558,41 @@ public class WatchMessagePictureActivity extends UI {
|
||||
return;
|
||||
}
|
||||
|
||||
String srcFilename = attachment.getFileName();
|
||||
//默认jpg
|
||||
String extension = TextUtils.isEmpty(attachment.getExtension()) ? "jpg" : attachment.getExtension();
|
||||
srcFilename += ("." + extension);
|
||||
ExecutorCenter.getInstance().post(() -> {
|
||||
AlbumUtils.INSTANCE.addUrlToAlbum(this, path, new Function1<Boolean, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
SingleToastUtil.showToastShort(R.string.picture_save_to);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
String picPath = StorageUtil.getSystemImagePath();
|
||||
String dstPath = picPath + srcFilename;
|
||||
if (AttachmentStore.copy(path, dstPath) != -1) {
|
||||
try {
|
||||
ContentValues values = new ContentValues(2);
|
||||
values.put(MediaStore.Images.Media.MIME_TYPE, C.MimeType.MIME_JPEG);
|
||||
values.put(MediaStore.Images.Media.DATA, dstPath);
|
||||
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||
// Toast.makeText(WatchMessagePictureActivity.this, getString(R.string.picture_save_to), Toast.LENGTH_LONG).show();
|
||||
SingleToastUtil.showToastShort(R.string.picture_save_to);
|
||||
} catch (Exception e) {
|
||||
// may be java.lang.UnsupportedOperationException
|
||||
// Toast.makeText(WatchMessagePictureActivity.this, getString(R.string.picture_save_fail), Toast.LENGTH_LONG).show();
|
||||
SingleToastUtil.showToastShort(R.string.picture_save_fail);
|
||||
}
|
||||
} else {
|
||||
// Toast.makeText(WatchMessagePictureActivity.this, getString(R.string.picture_save_fail), Toast.LENGTH_LONG).show();
|
||||
SingleToastUtil.showToastShort(R.string.picture_save_fail);
|
||||
}
|
||||
// String srcFilename = attachment.getFileName();
|
||||
// //默认jpg
|
||||
// String extension = TextUtils.isEmpty(attachment.getExtension()) ? "jpg" : attachment.getExtension();
|
||||
// srcFilename += ("." + extension);
|
||||
//
|
||||
// String picPath = StorageUtil.getSystemImagePath();
|
||||
// String dstPath = picPath + srcFilename;
|
||||
// if (AttachmentStore.copy(path, dstPath) != -1) {
|
||||
// try {
|
||||
// ContentValues values = new ContentValues(2);
|
||||
// values.put(MediaStore.Images.Media.MIME_TYPE, C.MimeType.MIME_JPEG);
|
||||
// values.put(MediaStore.Images.Media.DATA, dstPath);
|
||||
// getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||
//// Toast.makeText(WatchMessagePictureActivity.this, getString(R.string.picture_save_to), Toast.LENGTH_LONG).show();
|
||||
// SingleToastUtil.showToastShort(R.string.picture_save_to);
|
||||
// } catch (Exception e) {
|
||||
// // may be java.lang.UnsupportedOperationException
|
||||
//// Toast.makeText(WatchMessagePictureActivity.this, getString(R.string.picture_save_fail), Toast.LENGTH_LONG).show();
|
||||
// SingleToastUtil.showToastShort(R.string.picture_save_fail);
|
||||
// }
|
||||
// } else {
|
||||
//// Toast.makeText(WatchMessagePictureActivity.this, getString(R.string.picture_save_fail), Toast.LENGTH_LONG).show();
|
||||
// SingleToastUtil.showToastShort(R.string.picture_save_fail);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user