| | |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.net.Uri; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | |
| | | import com.dayu.pipirrapp.service.MyLocationService; |
| | | import com.dayu.pipirrapp.tool.FullyGridLayoutManager; |
| | | import com.dayu.pipirrapp.tool.GlideEngine; |
| | | import com.dayu.pipirrapp.tool.ImageFileCompressEngine; |
| | | import com.dayu.pipirrapp.utils.CommonKeyName; |
| | | import com.dayu.pipirrapp.utils.ToastUtil; |
| | | import com.dayu.pipirrapp.view.TitleBar; |
| | |
| | | import com.luck.picture.lib.config.PictureMimeType; |
| | | import com.luck.picture.lib.config.SelectMimeType; |
| | | import com.luck.picture.lib.decoration.GridSpacingItemDecoration; |
| | | import com.luck.picture.lib.engine.CompressFileEngine; |
| | | import com.luck.picture.lib.engine.ImageEngine; |
| | | import com.luck.picture.lib.entity.LocalMedia; |
| | | import com.luck.picture.lib.entity.MediaExtraInfo; |
| | | import com.luck.picture.lib.interfaces.OnExternalPreviewEventListener; |
| | | import com.luck.picture.lib.interfaces.OnKeyValueResultCallbackListener; |
| | | import com.luck.picture.lib.utils.DateUtils; |
| | | import com.luck.picture.lib.utils.DensityUtil; |
| | | import com.luck.picture.lib.utils.MediaUtils; |
| | | import com.luck.picture.lib.utils.PictureFileUtils; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import top.zibin.luban.CompressionPredicate; |
| | | import top.zibin.luban.Luban; |
| | | import top.zibin.luban.OnNewCompressListener; |
| | | import top.zibin.luban.OnRenameListener; |
| | | import retrofit2.Call; |
| | | |
| | | /** |
| | | * OrderDealDetailActivity - |
| | |
| | | //添加图片 |
| | | mOpenPicture(); |
| | | } |
| | | |
| | | @Override |
| | | public void onDeleteClick(int position) { |
| | | deleteItem(position); |
| | | } |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | | boolean isAllPost = true; |
| | |
| | | |
| | | @Override |
| | | public void onPreviewDelete(int position) { |
| | | deleteItem(position); |
| | | mAdapter.remove(position); |
| | | mAdapter.notifyItemRemoved(position); |
| | | } |
| | |
| | | //判断是否有这个路径,没有的话上传该图片 |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(media.getRealPath()); |
| | | uplodFileState.setFilePath(compressPath); |
| | | uplodFileStates.add(uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 自定义图片压缩 |
| | | */ |
| | | private static class ImageFileCompressEngine implements CompressFileEngine { |
| | | |
| | | @Override |
| | | public void onStartCompress(Context context, ArrayList<Uri> source, OnKeyValueResultCallbackListener call) { |
| | | Luban.with(context).load(source).ignoreBy(100).setRenameListener(new OnRenameListener() { |
| | | @Override |
| | | public String rename(String filePath) { |
| | | int indexOf = filePath.lastIndexOf("."); |
| | | String postfix = indexOf != -1 ? filePath.substring(indexOf) : ".jpg"; |
| | | return DateUtils.getCreateFileName("CMP_") + postfix; |
| | | } |
| | | }).filter(new CompressionPredicate() { |
| | | @Override |
| | | public boolean apply(String path) { |
| | | if (PictureMimeType.isUrlHasImage(path) && !PictureMimeType.isHasHttp(path)) { |
| | | return true; |
| | | } |
| | | return !PictureMimeType.isUrlHasGif(path); |
| | | } |
| | | }).setCompressListener(new OnNewCompressListener() { |
| | | @Override |
| | | public void onStart() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccess(String source, File compressFile) { |
| | | if (call != null) { |
| | | call.onCallback(source, compressFile.getAbsolutePath()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(String source, Throwable e) { |
| | | if (call != null) { |
| | | call.onCallback(source, null); |
| | | } |
| | | } |
| | | }).launch(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | super.onDestroy(); |
| | | LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); |
| | | } |
| | | |
| | | /** |
| | | * 预览和图片列表删除图片时处理删除事件 |
| | | */ |
| | | private void deleteItem(int position) { |
| | | try { |
| | | Call<BaseResponse> mCall = uplodFileStates.get(position).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | uplodFileStates.remove(position); |
| | | } |
| | | } |