From 5387cbaca4fea6bbf055e7b284821699546eb7e9 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 22 一月 2025 14:56:53 +0800
Subject: [PATCH] 1.视频播放兼容高低版本手机 2.优化工单icon 3.修复修改经纬度因js中添加了减少调用频率的代码导致的修改经纬度bug 4.修复了切换界面webView白屏的bug
---
app/src/main/java/com/dayu/pipirrapp/net/upload/ProgressRequestBody.java | 52 +++++++++++++++++++++++++++++-----------------------
1 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/app/src/main/java/com/dayu/pipirrapp/net/upload/ProgressRequestBody.java b/app/src/main/java/com/dayu/pipirrapp/net/upload/ProgressRequestBody.java
index 964c1c4..eacf50d 100644
--- a/app/src/main/java/com/dayu/pipirrapp/net/upload/ProgressRequestBody.java
+++ b/app/src/main/java/com/dayu/pipirrapp/net/upload/ProgressRequestBody.java
@@ -1,14 +1,14 @@
package com.dayu.pipirrapp.net.upload;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.RequestBody;
+import okio.Buffer;
import okio.BufferedSink;
-import okio.BufferedSource;
+import okio.ForwardingSink;
import okio.Okio;
+import okio.Sink;
/**
* ProgressRequestBody -
@@ -18,36 +18,42 @@
* @since 2024-11-28
*/
public class ProgressRequestBody extends RequestBody {
- private File file;
- private ProgressListener listener;
- private MediaType mediaType;
+ private final RequestBody requestBody;
+ private final ProgressListener progressListener;
- public ProgressRequestBody(File file, ProgressListener listener, String mimeType) {
- this.file = file;
- this.listener = listener;
- this.mediaType = MediaType.parse(mimeType);
+ public ProgressRequestBody(RequestBody requestBody, ProgressListener progressListener) {
+ this.requestBody = requestBody;
+ this.progressListener = progressListener;
}
@Override
public MediaType contentType() {
- return mediaType;
+ return requestBody.contentType();
+ }
+
+ @Override
+ public long contentLength() throws IOException {
+ return requestBody.contentLength();
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
- try (FileInputStream fileInputStream = new FileInputStream(file);
- BufferedSource source = (BufferedSource) Okio.source(fileInputStream)) {
- long totalBytes = file.length();
- long bytesWritten = 0;
- long read;
- byte[] buffer = new byte[2048];
- while ((read = source.read(buffer)) != -1) {
- sink.write(buffer, 0, (int) read);
- bytesWritten += read;
- if (listener != null) {
- listener.onProgress(bytesWritten, totalBytes);
+ Sink progressSink = new ForwardingSink(sink) {
+ long totalBytesWritten = 0;
+
+ @Override
+ public void write(Buffer source, long byteCount) throws IOException {
+ super.write(source, byteCount);
+ totalBytesWritten += byteCount;
+ if (progressListener != null) {
+ progressListener.onProgress(totalBytesWritten, contentLength(),false);
}
}
- }
+ };
+ BufferedSink bufferedSink = Okio.buffer(progressSink);
+ requestBody.writeTo(bufferedSink);
+ bufferedSink.flush();
}
+
+
}
\ No newline at end of file
--
Gitblit v1.8.0