| | |
| | | //文件上传失败重复次数 |
| | | int uplodFilerepeatSize = 3; |
| | | |
| | | |
| | | ApiService apiService; |
| | | // 管理订阅事件 |
| | | private final CompositeDisposable compositeDisposable = new CompositeDisposable(); |
| | |
| | | public void uploadFile(final Context context, final UplodFileState uplodData, final UploadFileListener listener, final AddPictureAdapter adapter) { |
| | | |
| | | if (!TextUtils.isEmpty(uplodData.getFilePath())) { |
| | | MyLog.d("progressRequestBody>>>" + "path:" + uplodData.getFilePath()+">>>uploadType:"+uplodData.getUploadType()); |
| | | MyLog.d("progressRequestBody_uploadFile>>>" + "path:" + uplodData.getFilePath() + ">>>uploadType:" + uplodData.getUploadType()); |
| | | uplodData.setState(STATE_UPDING); |
| | | File file = new File(uplodData.getFilePath()); |
| | | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| | |
| | | int progress = (int) (100 * bytesWritten / contentLength); |
| | | // 例如:更新 ProgressBar 或显示进度 |
| | | runOnUiThread(() -> { |
| | | uplodData.setProgress(progress); |
| | | if (progress <5) { |
| | | uplodData.setProgress(0); |
| | | } |
| | | // 进度条更新代码 |
| | | if (adapter != null && uplodData.getAdapterPosition() != -1) { |
| | | adapter.updateProgress(uplodData); |
| | | //优化不频繁更新进度 |
| | | if (progress - uplodData.getProgress() > 5 || progress == 100) { |
| | | uplodData.setProgress(progress); |
| | | adapter.updateProgress(uplodData); |
| | | |
| | | } |
| | | |
| | | } |
| | | MyLog.d("progressRequestBody>>>" + "adapterPosition:" + uplodData.getAdapterPosition() + ">>>上传进度: " + progress + "%"); |
| | | MyLog.d("progressRequestBodyHolder>>>path" + "adapterPosition:" + uplodData.getAdapterPosition() + ">>>上传进度: " + progress + "%"); |
| | | }); |
| | | |
| | | }); |