From 4f7f99c6ea914bcd38de78bd8371be566026b905 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 26 二月 2025 15:54:14 +0800
Subject: [PATCH] -为按钮和列表项添加波纹效果,以获得更好的视觉反馈 -改进MapFragment中的底部布局动画 -在MapFragment中添加设备状态和RTU地址显示 -更新BaseListResult以支持泛型类型 -为设备数据添加IntakeListResult和IntakeResult -通过数据库支持增强标记位置更新功能 -添加电话拨号意图以分隔标记详细信息 -通过过期检查改进磁贴缓存 -添加问题报告的确认对话框 -更新登录活动以限制用户名长度 -为波纹效果和UI元素添加新颜色 -重构XML布局以使用新的波纹图 -改进MapFragment中的错误处理和用户反馈
---
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