| | |
| | | |
| | | @Override |
| | | public void onReUpload(UplodFileState uplodFileState) { |
| | | uplodFileState.setState(UplodFileState.STATE_UPDING); |
| | | uplodeImg(uplodFileState); |
| | | FileUploadUtils.uploadFile(OrderDealActivity.this, uplodFileState, uplodFileStates, mAdapter); |
| | | } |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | |
| | | * @param result |
| | | */ |
| | | private void analyticalSelectResults(ArrayList<LocalMedia> result) { |
| | | //获取当前uplodFileStates所有的图片地址 |
| | | Set<String> existingPaths = new HashSet<>(); |
| | | for (UplodFileState uplodData : uplodFileStates.values()) { |
| | | existingPaths.add(uplodData.getFilePath()); |
| | | } |
| | | //获取在PictureSelector的相册时取消选中的图片 |
| | | Set<String> resultPaths = new HashSet<>(); |
| | | for (LocalMedia media : result) { |
| | | if (media.getWidth() == 0 || media.getHeight() == 0) { |
| | | if (PictureMimeType.isHasImage(media.getMimeType())) { |
| | |
| | | Log.i(TAG, "裁剪宽高: " + media.getCropImageWidth() + "x" + media.getCropImageHeight()); |
| | | Log.i(TAG, "文件大小: " + PictureFileUtils.formatAccurateUnitFileSize(media.getSize())); |
| | | Log.i(TAG, "文件时长: " + media.getDuration()); |
| | | String compressPath = media.getCompressPath(); |
| | | //判断是否有这个路径,没有的话上传该图片 |
| | | if (TextUtils.isEmpty(compressPath)) { |
| | | compressPath = media.getRealPath(); |
| | | Log.i(TAG, "扩展名: " + media.getMimeType()); |
| | | FileUploadUtils.creatAndUploadFile(this, media, uplodFileStates, mAdapter); |
| | | } |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(compressPath); |
| | | if (compressPath.toLowerCase().endsWith(".mp4") || compressPath.toLowerCase().endsWith(".avi") || compressPath.toLowerCase().endsWith(".mkv") || compressPath.toLowerCase().endsWith(".mov")) { |
| | | // 这是视频文件 |
| | | uplodFileState.setUploadType(UplodFileState.VIDEO_TYPE); |
| | | }else { |
| | | uplodFileState.setUploadType(UplodFileState.IMG_TYPE); |
| | | } |
| | | uplodFileStates.put(compressPath, uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | | } |
| | | |
| | | resultPaths.add(media.getCompressPath()); |
| | | } |
| | | //处理从相册返回时取消的图片处理 |
| | | existingPaths.removeAll(resultPaths); |
| | | if (!existingPaths.isEmpty()) { |
| | | List<UplodFileState> toRemove = new ArrayList<>(); |
| | | for (String path : existingPaths) { |
| | | for (UplodFileState uplodFileState : uplodFileStates.values()) { |
| | | if (path.equals(uplodFileState.getFilePath())) { |
| | | uplodFileState.getThisCall().cancel(); |
| | | toRemove.add(uplodFileState); |
| | | } |
| | | } |
| | | } |
| | | for (UplodFileState removeFile : toRemove) { |
| | | uplodFileStates.remove(removeFile.getFilePath()); |
| | | } |
| | | } |
| | | runOnUiThread(() -> { |
| | | boolean isMaxSize = result.size() == mAdapter.getSelectMax(); |
| | | int oldSize = mAdapter.getData().size(); |
| | | mAdapter.notifyItemRangeRemoved(0, isMaxSize ? oldSize + 1 : oldSize); |
| | | mAdapter.getData().clear(); |
| | | |
| | | mAdapter.getData().addAll(result); |
| | | mAdapter.notifyItemRangeInserted(0, result.size()); |
| | | |
| | | }); |
| | | // 获取 result 中没有而 uplodFileStates 中有的地址 |
| | | FileUploadUtils.cancelRemovedUploads(result, uplodFileStates); |
| | | // 更新UI |
| | | FileUploadUtils.updateUI(result, mAdapter); |
| | | } |
| | | |
| | | |
| | | //上传图片 |
| | | private void uplodeImg(UplodFileState uplodFileState) { |
| | | FileUploadUtils.uploadFile(this, uplodFileState, uplodFileStates, mAdapter); |
| | | } |
| | | |
| | | /** |
| | | * 上报处理结果 |