管灌系统巡查员智能手机App
zuoxiao
2025-01-13 50f9b82ac862652e88444d727a32e0da1d824e9e
app/src/main/java/com/dayu/pipirrapp/net/ApiManager.java
@@ -63,6 +63,7 @@
    //文件上传失败重复次数
    int uplodFilerepeatSize = 3;
    ApiService apiService;
    // 管理订阅事件
    private final CompositeDisposable compositeDisposable = new CompositeDisposable();
@@ -302,7 +303,7 @@
    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);
@@ -312,12 +313,20 @@
                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 + "%");
                });
            });