From 50f9b82ac862652e88444d727a32e0da1d824e9e Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期一, 13 一月 2025 15:57:06 +0800 Subject: [PATCH] 1.分水房相关 2.删除极光推送相关配置 3.优化图片显示相关 --- app/src/main/java/com/dayu/pipirrapp/net/ApiManager.java | 67 ++++++++++++++++++++++++--------- 1 files changed, 49 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/dayu/pipirrapp/net/ApiManager.java b/app/src/main/java/com/dayu/pipirrapp/net/ApiManager.java index b040919..d80da85 100644 --- a/app/src/main/java/com/dayu/pipirrapp/net/ApiManager.java +++ b/app/src/main/java/com/dayu/pipirrapp/net/ApiManager.java @@ -1,5 +1,8 @@ package com.dayu.pipirrapp.net; +import static com.dayu.pipirrapp.bean.net.UplodFileState.STATE_DONE; +import static com.dayu.pipirrapp.bean.net.UplodFileState.STATE_ERROR; +import static com.dayu.pipirrapp.bean.net.UplodFileState.STATE_UPDING; import static com.luck.picture.lib.thread.PictureThreadUtils.runOnUiThread; import android.annotation.SuppressLint; @@ -59,6 +62,7 @@ static ApiManager apiManager; //鏂囦欢涓婁紶澶辫触閲嶅娆℃暟 int uplodFilerepeatSize = 3; + ApiService apiService; // 绠$悊璁㈤槄浜嬩欢 @@ -290,15 +294,17 @@ // } /** - * 涓婁紶鏂囦欢 + * 涓婁紶鍥剧墖鏂囦欢 * * @param context * @param uplodData * @param listener */ public void uploadFile(final Context context, final UplodFileState uplodData, final UploadFileListener listener, final AddPictureAdapter adapter) { - MyLog.d("progressRequestBody>>>" + "path:" + uplodData.getFilePath()); + if (!TextUtils.isEmpty(uplodData.getFilePath())) { + 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); ProgressRequestBody progressRequestBody = new ProgressRequestBody(requestBody, (bytesWritten, contentLength, done) -> { @@ -307,34 +313,57 @@ 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 + "%"); }); }); MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), progressRequestBody); RequestBody description = RequestBody.create(MediaType.parse("text/plain"), "file description"); - Call<BaseResponse> uploadFile = apiService.uploadFile(body, description); + Call<BaseResponse> uploadFile = null; + switch (uplodData.getUploadType()) { + case UplodFileState.IMG_TYPE: + uploadFile = apiService.uploadImgFile(body, description); + break; + case UplodFileState.VIDEO_TYPE: + uploadFile = apiService.uploadVideoFile(body, description); + break; + default: + uploadFile = apiService.uploadImgFile(body, description); + break; + } + uplodData.setThisCall(uploadFile); uploadFile.enqueue(new Callback<BaseResponse>() { @Override public void onResponse(Call<BaseResponse> call, Response<BaseResponse> response) { if (response.body() != null) { if (response.body().isSuccess()) { - uplodData.setState(1); + uplodData.setState(STATE_DONE); uplodData.setPostId(((LinkedTreeMap) response.body().getContent()).get("id").toString()); uplodData.setWebPath(((LinkedTreeMap) response.body().getContent()).get("webPath").toString()); listener.onBack(uplodData); } else { + MyLog.d("progressRequestBody>>>" + response.body().getMsg()); if (uplodData.getNumber() <= uplodFilerepeatSize) { uplodData.setNumber(uplodData.getNumber() + 1); - uplodData.setState(2); + uplodData.setState(STATE_ERROR); uploadFile(context, uplodData, listener, adapter); } else { + uplodData.setState(STATE_ERROR); + uplodData.setNumber(0); listener.onBack(uplodData); } } @@ -343,22 +372,24 @@ @Override public void onFailure(Call<BaseResponse> call, Throwable t) { - MyLog.d("progressRequestBody>>>" + "onFailure:"); - if (uplodData.getNumber() <= uplodFilerepeatSize) { - uplodData.setNumber(uplodData.getNumber() + 1); - uplodData.setState(2); - uploadFile(context, uplodData, listener, adapter); - } else { - listener.onBack(uplodData); + MyLog.d("progressRequestBody>>>" + "onFailure:" + t.getMessage()); + if (!t.getMessage().equals("Canceled")) { + uplodData.setState(STATE_ERROR); + if (uplodData.getNumber() <= uplodFilerepeatSize) { + uplodData.setNumber(uplodData.getNumber() + 1); + uploadFile(context, uplodData, listener, adapter); + } else { + uplodData.setNumber(0); + listener.onBack(uplodData); + } } + } }); } else { - uplodData.setState(UplodFileState.STATE_ERROR); + uplodData.setState(STATE_ERROR); listener.onBack(uplodData); } - - } -- Gitblit v1.8.0