|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | private final List<LocalMedia> mData = new ArrayList<>(); | 
|---|
|  |  |  | private ActivityResultLauncher<Intent> launcherResult; | 
|---|
|  |  |  | private ImageEngine imageEngine; | 
|---|
|  |  |  | List<UplodFileState> uplodFileStates = new ArrayList<>(); | 
|---|
|  |  |  | //    List<UplodFileState> uplodFileStates = new ArrayList<>(); | 
|---|
|  |  |  | Map<String, UplodFileState> uplodFileStates = new HashMap<>(); | 
|---|
|  |  |  | String workOrderId; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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的相册时取消选中的图片 | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!existingPaths.contains(compressPath)) { | 
|---|
|  |  |  | UplodFileState uplodFileState = new UplodFileState(); | 
|---|
|  |  |  | uplodFileState.setFilePath(compressPath); | 
|---|
|  |  |  | uplodFileStates.add(uplodFileState); | 
|---|
|  |  |  | uplodFileStates.put(compressPath, uplodFileState); | 
|---|
|  |  |  | // 执行上传图片的操作 | 
|---|
|  |  |  | uplodeImg(uplodFileState); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //处理从相册返回时取消的图片处理 | 
|---|
|  |  |  | existingPaths.removeAll(resultPaths); | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | uplodFileStates.remove(uplodFileState); | 
|---|
|  |  |  | toRemove.add(uplodFileState); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | runOnUiThread(new Runnable() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void run() { | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); // 更新对应的项 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | uplodFileStates.replace(state.getFilePath(), state); | 
|---|
|  |  |  | mAdapter.updateProgress(uplodFileState); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }, mAdapter); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | * 开始定位相关逻辑 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void startLocation() { | 
|---|
|  |  |  | ServiceUtils.startLocationService(this,true); | 
|---|
|  |  |  | ServiceUtils.startLocationService(this, true); | 
|---|
|  |  |  | //获取定位服务传过来的坐标点 | 
|---|
|  |  |  | LiveEventBus.get(CommonKeyName.locationData).observeForever(locationObserver); | 
|---|
|  |  |  | } | 
|---|