| | |
| | | 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.tool.ImageFileCompressEngine; |
| | |
| | | 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<>(); |
| | | Map<String, UplodFileState> uplodFileStates = new HashMap<>(); |
| | | String workOrderId; |
| | | LatLonBean latLonBean; |
| | | |
| | |
| | | @Override |
| | | public void onDeleteClick(int position) { |
| | | deleteItem(position); |
| | | } |
| | | |
| | | @Override |
| | | public void onReUpload(UplodFileState uplodFileState) { |
| | | uplodFileState.setState(UplodFileState.STATE_UPDING); |
| | | uplodeImg(uplodFileState); |
| | | } |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | |
| | | 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); |
| | |
| | | |
| | | //上传图片 |
| | | private void uplodeImg(UplodFileState uplodFileState) { |
| | | ApiManager.getInstance().uploadFile(this, uplodFileState, new UploadFileListener() { |
| | | @Override |
| | | public void onBack(UplodFileState state) { |
| | | uplodFileStates.replace(state.getFilePath(), state); |
| | | mAdapter.updateProgress(uplodFileState); |
| | | } |
| | | }, mAdapter); |
| | | FileUploadUtils.uploadFile(this, uplodFileState, uplodFileStates, mAdapter); |
| | | } |
| | | |
| | | /** |
| | |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); |
| | | FileUploadUtils.cancelAllCall(uplodFileStates); |
| | | } |
| | | |
| | | /** |
| | | * 预览和图片列表删除图片时处理删除事件 |
| | | */ |
| | | private void deleteItem(int position) { |
| | | try { |
| | | Call<BaseResponse> mCall = uplodFileStates.get(position).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | LocalMedia localMedia = mAdapter.getData().get(position); |
| | | String path; |
| | | UplodFileState uplodFileState; |
| | | if (TextUtils.isEmpty(localMedia.getCompressPath())) { |
| | | uplodFileState = uplodFileStates.get(localMedia.getRealPath()); |
| | | } else { |
| | | uplodFileState = uplodFileStates.get(localMedia.getCompressPath()); |
| | | } |
| | | uplodFileStates.remove(position); |
| | | if (uplodFileState != null) { |
| | | path = uplodFileState.getFilePath(); |
| | | try { |
| | | Call<BaseResponse> mCall = uplodFileStates.get(path).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | MyLog.d("progressRequestBody>>>" + "cancel》》》path:" + path); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | uplodFileStates.remove(path); |
| | | } |
| | | } |
| | | } |