You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Remove old download progress update system
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
package com.topjohnwu.net;
|
||||
|
||||
public interface DownloadProgressListener {
|
||||
void onProgress(long bytesDownloaded, long totalBytes);
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import java.net.URL;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
@Deprecated
|
||||
public class Networking {
|
||||
|
||||
private static final int READ_TIMEOUT = 15000;
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.topjohnwu.net;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ProgressInputStream extends FilterInputStream {
|
||||
|
||||
private long totalBytes;
|
||||
private long bytesDownloaded;
|
||||
private DownloadProgressListener progress;
|
||||
|
||||
public ProgressInputStream(InputStream in, long total, DownloadProgressListener listener) {
|
||||
super(in);
|
||||
totalBytes = total;
|
||||
progress = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int b = super.read();
|
||||
if (totalBytes > 0 && b >= 0) {
|
||||
bytesDownloaded++;
|
||||
Networking.mainHandler.post(() -> progress.onProgress(bytesDownloaded, totalBytes));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int sz = super.read(b, off, len);
|
||||
if (totalBytes > 0 && sz > 0) {
|
||||
bytesDownloaded += sz;
|
||||
Networking.mainHandler.post(() -> progress.onProgress(bytesDownloaded, totalBytes));
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import java.util.concurrent.Executor;
|
||||
public class Request implements Closeable {
|
||||
private HttpURLConnection conn;
|
||||
private Executor executor = null;
|
||||
private DownloadProgressListener progress = null;
|
||||
private int code = -1;
|
||||
|
||||
ErrorHandler err = null;
|
||||
@@ -66,11 +65,6 @@ public class Request implements Closeable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request setDownloadProgressListener(DownloadProgressListener listener) {
|
||||
progress = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Request setErrorHandler(ErrorHandler handler) {
|
||||
err = handler;
|
||||
return this;
|
||||
@@ -169,24 +163,13 @@ public class Request implements Closeable {
|
||||
|
||||
private BufferedInputStream getInputStream() throws IOException {
|
||||
connect0();
|
||||
InputStream in = conn.getInputStream();
|
||||
if (progress != null) {
|
||||
in = new ProgressInputStream(in, conn.getContentLength(), progress) {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
conn.disconnect();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
in = new FilterInputStream(in) {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
conn.disconnect();
|
||||
}
|
||||
};
|
||||
}
|
||||
InputStream in = new FilterInputStream(conn.getInputStream()) {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
conn.disconnect();
|
||||
}
|
||||
};
|
||||
return new BufferedInputStream(in);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user