| | |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import retrofit2.Call; |
| | |
| | | RecyclerView mRecyclerView; |
| | | AddPictureAdapter mAdapter; |
| | | int maxSelectNum = 10;//最大照片 |
| | | int maxSelectVideoNum = 0;//最大视频 |
| | | int maxSelectVideoNum = 3;//最大视频 |
| | | |
| | | int videoMaxSecond = 60; |
| | | private final List<LocalMedia> mData = new ArrayList<>(); |
| | | private ActivityResultLauncher<Intent> launcherResult; |
| | | private ImageEngine imageEngine; |
| | | List<UplodFileState> uplodFileStates = new ArrayList<>(); |
| | | Map<String, UplodFileState> uplodFileStates = new HashMap<>(); |
| | | // List<UplodFileState> uplodFileStates = new ArrayList<>(); |
| | | LatLonBean latLonBean; |
| | | |
| | | /** |
| | |
| | | } |
| | | mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(4, |
| | | DensityUtil.dip2px(this, 8), false)); |
| | | mAdapter = new AddPictureAdapter(this, mData); |
| | | mAdapter = new AddPictureAdapter(this, mData, uplodFileStates); |
| | | mAdapter.setSelectMax(maxSelectNum + maxSelectVideoNum); |
| | | mRecyclerView.setAdapter(mAdapter); |
| | | imageEngine = GlideEngine.createGlideEngine(); |
| | |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | | boolean isAllPost = true; |
| | | for (UplodFileState imgData : uplodFileStates) { |
| | | for (UplodFileState imgData : uplodFileStates.values()) { |
| | | if (imgData.getState() == 0) { |
| | | isAllPost = false; |
| | | } |
| | |
| | | |
| | | if (!TextUtils.isEmpty(binding.contentET.getText().toString())) { |
| | | if (isAllPost) { |
| | | if (uplodFileStates.size() > 0) { |
| | | if (!uplodFileStates.isEmpty()) { |
| | | postData(); |
| | | } else { |
| | | ToastUtil.showToast(AddIssueActivity.this, "请上传图片"); |
| | |
| | | private void mOpenPicture() { |
| | | // 进入相册 |
| | | PictureSelectionModel selectionModel = PictureSelector.create(this) |
| | | .openGallery(SelectMimeType.ofImage()) |
| | | .openGallery(SelectMimeType.ofAll()) |
| | | .setMaxSelectNum(maxSelectNum) |
| | | .setMaxVideoSelectNum(maxSelectVideoNum) |
| | | .setImageEngine(imageEngine) |
| | | //设置图片压缩 |
| | | .setCompressEngine(new ImageFileCompressEngine()) |
| | | //设置视频图片一起在相册选择 |
| | | .isWithSelectVideoImage(true) |
| | | //设置最大视频时长 |
| | | .setRecordVideoMaxSecond(videoMaxSecond) |
| | | // 过滤视频最大时长 |
| | | .setFilterVideoMaxSecond(videoMaxSecond) |
| | | // 拍照是否纠正旋转图片 |
| | | .isCameraRotateImage(true) |
| | | .setSelectedData(mAdapter.getData()); |
| | | |
| | | selectionModel.forResult(launcherResult); |
| | |
| | | private void analyticalSelectResults(ArrayList<LocalMedia> result) { |
| | | //获取当前uplodFileStates所有的图片地址 |
| | | Set<String> existingPaths = new HashSet<>(); |
| | | for (UplodFileState uplodData : uplodFileStates) { |
| | | for (UplodFileState uplodData : uplodFileStates.values()) { |
| | | existingPaths.add(uplodData.getFilePath()); |
| | | } |
| | | //获取在PictureSelector的相册时取消选中的图片 |
| | |
| | | Log.i(TAG, "文件时长: " + media.getDuration()); |
| | | String compressPath = media.getCompressPath(); |
| | | //判断是否有这个路径,没有的话上传该图片并添加uplodFileStates中 |
| | | if (TextUtils.isEmpty(compressPath)) { |
| | | compressPath = media.getRealPath(); |
| | | } |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(compressPath); |
| | | uplodFileStates.add(uplodFileState); |
| | | uplodFileStates.put(compressPath, uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | | } |
| | |
| | | if (!existingPaths.isEmpty()) { |
| | | List<UplodFileState> toRemove = new ArrayList<>(); |
| | | for (String path : existingPaths) { |
| | | for (UplodFileState uplodFileState : uplodFileStates) { |
| | | for (UplodFileState uplodFileState : uplodFileStates.values()) { |
| | | if (path.equals(uplodFileState.getFilePath())) { |
| | | uplodFileState.getThisCall().cancel(); |
| | | toRemove.add(uplodFileState); |
| | | } |
| | | } |
| | | } |
| | | uplodFileStates.removeAll(toRemove); |
| | | for (UplodFileState removeFile : toRemove) { |
| | | uplodFileStates.remove(removeFile.getFilePath()); |
| | | } |
| | | } |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | |
| | | |
| | | //上传图片 |
| | | private void uplodeImg(UplodFileState uplodFileState) { |
| | | ApiManager.getInstance().uploadFile(this, uplodFileState, new UploadFileListener() { |
| | | @Override |
| | | public void onBack(UplodFileState state) { |
| | | for (UplodFileState uplodFile : uplodFileStates) { |
| | | if (uplodFile.getFilePath().equals(state.getFilePath())) { |
| | | int index = uplodFileStates.indexOf(uplodFile); |
| | | if (index != -1) { |
| | | uplodFileStates.set(index, uplodFile); // 更新对应的项 |
| | | } |
| | | } |
| | | ApiManager.getInstance().uploadFile(this, uplodFileState, state -> { |
| | | |
| | | } |
| | | } |
| | | }); |
| | | uplodFileStates.replace(state.getFilePath(), state); |
| | | mAdapter.updateProgress(uplodFileState); |
| | | }, mAdapter); |
| | | } |
| | | |
| | | /** |