|  |  |  | 
|---|
|  |  |  | import com.dayu.pipirrapp.net.ApiManager; | 
|---|
|  |  |  | import com.dayu.pipirrapp.net.BaseResponse; | 
|---|
|  |  |  | import com.dayu.pipirrapp.net.subscribers.SubscriberListener; | 
|---|
|  |  |  | import com.dayu.pipirrapp.net.upload.UploadFileListener; | 
|---|
|  |  |  | import com.dayu.pipirrapp.tool.FileUploadUtils; | 
|---|
|  |  |  | import com.dayu.pipirrapp.tool.FullyGridLayoutManager; | 
|---|
|  |  |  | import com.dayu.pipirrapp.tool.GlideEngine; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.dayu.pipirrapp.utils.ToastUtil; | 
|---|
|  |  |  | import com.dayu.pipirrapp.view.TitleBar; | 
|---|
|  |  |  | import com.jeremyliao.liveeventbus.LiveEventBus; | 
|---|
|  |  |  | import com.loper7.date_time_picker.DateTimeConfig; | 
|---|
|  |  |  | import com.loper7.date_time_picker.dialog.CardDatePickerDialog; | 
|---|
|  |  |  | import com.luck.picture.lib.basic.PictureSelectionModel; | 
|---|
|  |  |  | import com.luck.picture.lib.basic.PictureSelector; | 
|---|
|  |  |  | import com.luck.picture.lib.config.PictureMimeType; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | AddPictureAdapter mAdapter; | 
|---|
|  |  |  | int maxSelectNum = 10;//最大照片 | 
|---|
|  |  |  | int maxSelectVideoNum = 0;//最大视频 | 
|---|
|  |  |  | int videoMaxSecond = 60; | 
|---|
|  |  |  | private final List<LocalMedia> mData = new ArrayList<>(); | 
|---|
|  |  |  | private ActivityResultLauncher<Intent> launcherResult; | 
|---|
|  |  |  | private ImageEngine imageEngine; | 
|---|
|  |  |  | 
|---|
|  |  |  | Map<String, UplodFileState> uplodFileStates = new HashMap<>(); | 
|---|
|  |  |  | String workOrderId; | 
|---|
|  |  |  | LatLonBean latLonBean; | 
|---|
|  |  |  | String strCompleteTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 定位监听 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void initView() { | 
|---|
|  |  |  | new TitleBar(this).setTitleText("处理工单").setLeftIco().setLeftIcoListening(v -> OrderDealActivity.this.finish()); | 
|---|
|  |  |  | binding.timeLL.setOnClickListener(v -> { | 
|---|
|  |  |  | long time = System.currentTimeMillis(); | 
|---|
|  |  |  | List<Integer> list = new ArrayList<>(); | 
|---|
|  |  |  | list.add(DateTimeConfig.YEAR); | 
|---|
|  |  |  | list.add(DateTimeConfig.MONTH); | 
|---|
|  |  |  | list.add(DateTimeConfig.DAY); | 
|---|
|  |  |  | list.add(DateTimeConfig.HOUR); | 
|---|
|  |  |  | list.add(DateTimeConfig.MIN); | 
|---|
|  |  |  | new CardDatePickerDialog.Builder(this) | 
|---|
|  |  |  | .setTitle("选择处理时间") | 
|---|
|  |  |  | .setOnChoose("确定", aLong -> { | 
|---|
|  |  |  | //aLong = millisecond | 
|---|
|  |  |  | strCompleteTime = com.dayu.pipirrapp.utils.DateUtils.formatTimestamp(aLong); | 
|---|
|  |  |  | binding.timeData.setText(strCompleteTime); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .showBackNow(true) | 
|---|
|  |  |  | .setDefaultTime(time) | 
|---|
|  |  |  | .setMaxTime(time) | 
|---|
|  |  |  | .setMinTime(time - 365L * 24 * 60 * 60 * 1000) // 设置最小时间为一年前 | 
|---|
|  |  |  | .setDisplayType(list) | 
|---|
|  |  |  | .build().show(); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | mRecyclerView = binding.recycler; | 
|---|
|  |  |  | FullyGridLayoutManager manager = new FullyGridLayoutManager(this, | 
|---|
|  |  |  | 4, GridLayoutManager.VERTICAL, false); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onReUpload(UplodFileState uplodFileState) { | 
|---|
|  |  |  | uplodFileState.setState(UplodFileState.STATE_UPDING); | 
|---|
|  |  |  | uplodeImg(uplodFileState); | 
|---|
|  |  |  | FileUploadUtils.uploadFile(OrderDealActivity.this, uplodFileState, uplodFileStates, mAdapter); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | binding.dealButton.setOnClickListener(v -> { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | Log.i(TAG, "扩展名: " + media.getMimeType()); | 
|---|
|  |  |  | FileUploadUtils.creatAndUploadFile(this, media, uplodFileStates, mAdapter); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //处理从相册返回时取消的图片处理 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 上报处理结果 | 
|---|
|  |  |  | 
|---|
|  |  |  | result.setContent(binding.contentET.getText().toString()); | 
|---|
|  |  |  | result.setInspectorId(MyApplication.myApplication.userId); | 
|---|
|  |  |  | result.setWorkOrderId(workOrderId); | 
|---|
|  |  |  | result.setCompleteTime(com.dayu.pipirrapp.utils.DateUtils.getNowDateToMMStr()); | 
|---|
|  |  |  | result.setCompleteTime(strCompleteTime); | 
|---|
|  |  |  | if (latLonBean != null) { | 
|---|
|  |  |  | result.setLat(String.valueOf(latLonBean.getLatitude())); | 
|---|
|  |  |  | result.setLng(String.valueOf(latLonBean.getLongitude())); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (uplodFileState != null) { | 
|---|
|  |  |  | path = uplodFileState.getFilePath(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Call<BaseResponse> mCall = uplodFileStates.get(path).getThisCall(); | 
|---|
|  |  |  | Call mCall = uplodFileStates.get(path).getThisCall(); | 
|---|
|  |  |  | if (mCall != null) { | 
|---|
|  |  |  | mCall.cancel(); | 
|---|
|  |  |  | MyLog.d("progressRequestBody>>>" + "cancel》》》path:" + path); | 
|---|