purge urlString from ProgressListener, it is unused and confusing

This commit is contained in:
Hans-Christoph Steiner 2019-03-28 11:41:03 +01:00
parent 6b0a784a26
commit d794c5a77c
7 changed files with 11 additions and 13 deletions

View File

@ -70,7 +70,7 @@ public class HttpDownloaderTest {
final HttpDownloader httpDownloader = new HttpDownloader(uri, destFile); final HttpDownloader httpDownloader = new HttpDownloader(uri, destFile);
httpDownloader.setListener(new ProgressListener() { httpDownloader.setListener(new ProgressListener() {
@Override @Override
public void onProgress(String urlString, long bytesRead, long totalBytes) { public void onProgress(long bytesRead, long totalBytes) {
receivedProgress = true; receivedProgress = true;
} }
}); });
@ -132,7 +132,7 @@ public class HttpDownloaderTest {
final HttpDownloader httpDownloader = new HttpDownloader(uri, destFile); final HttpDownloader httpDownloader = new HttpDownloader(uri, destFile);
httpDownloader.setListener(new ProgressListener() { httpDownloader.setListener(new ProgressListener() {
@Override @Override
public void onProgress(String urlString, long bytesRead, long totalBytes) { public void onProgress(long bytesRead, long totalBytes) {
receivedProgress = true; receivedProgress = true;
latch.countDown(); latch.countDown();
} }

View File

@ -216,7 +216,7 @@ public class IndexUpdater {
JarFile jarFile = new JarFile(downloadedFile, true); JarFile jarFile = new JarFile(downloadedFile, true);
JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexUpdater.DATA_FILE_NAME); JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexUpdater.DATA_FILE_NAME);
indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry), indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
processIndexListener, repo.address, (int) indexEntry.getSize()); processIndexListener, (int) indexEntry.getSize());
// Process the index... // Process the index...
SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParserFactory factory = SAXParserFactory.newInstance();
@ -254,14 +254,14 @@ public class IndexUpdater {
protected final ProgressListener downloadListener = new ProgressListener() { protected final ProgressListener downloadListener = new ProgressListener() {
@Override @Override
public void onProgress(String urlString, long bytesRead, long totalBytes) { public void onProgress(long bytesRead, long totalBytes) {
UpdateService.reportDownloadProgress(context, IndexUpdater.this, bytesRead, totalBytes); UpdateService.reportDownloadProgress(context, IndexUpdater.this, bytesRead, totalBytes);
} }
}; };
protected final ProgressListener processIndexListener = new ProgressListener() { protected final ProgressListener processIndexListener = new ProgressListener() {
@Override @Override
public void onProgress(String urlString, long bytesRead, long totalBytes) { public void onProgress(long bytesRead, long totalBytes) {
UpdateService.reportProcessIndexProgress(context, IndexUpdater.this, bytesRead, totalBytes); UpdateService.reportProcessIndexProgress(context, IndexUpdater.this, bytesRead, totalBytes);
} }
}; };

View File

@ -198,7 +198,7 @@ public class IndexV1Updater extends IndexUpdater {
JarFile jarFile = new JarFile(outputFile, true); JarFile jarFile = new JarFile(outputFile, true);
JarEntry indexEntry = (JarEntry) jarFile.getEntry(DATA_FILE_NAME); JarEntry indexEntry = (JarEntry) jarFile.getEntry(DATA_FILE_NAME);
InputStream indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry), InputStream indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
processIndexListener, repo.address, (int) indexEntry.getSize()); processIndexListener, (int) indexEntry.getSize());
processIndexV1(indexInputStream, indexEntry, cacheTag); processIndexV1(indexInputStream, indexEntry, cacheTag);
} }

View File

@ -9,7 +9,6 @@ import java.io.InputStream;
class ProgressBufferedInputStream extends BufferedInputStream { class ProgressBufferedInputStream extends BufferedInputStream {
private final ProgressListener progressListener; private final ProgressListener progressListener;
private final String urlString;
private final int totalBytes; private final int totalBytes;
private int currentBytes; private int currentBytes;
@ -18,10 +17,9 @@ class ProgressBufferedInputStream extends BufferedInputStream {
* Reports progress to the specified {@link ProgressListener}, with the * Reports progress to the specified {@link ProgressListener}, with the
* progress based on the {@code totalBytes}. * progress based on the {@code totalBytes}.
*/ */
ProgressBufferedInputStream(InputStream in, ProgressListener progressListener, String urlString, int totalBytes) { ProgressBufferedInputStream(InputStream in, ProgressListener progressListener, int totalBytes) {
super(in); super(in);
this.progressListener = progressListener; this.progressListener = progressListener;
this.urlString = urlString;
this.totalBytes = totalBytes; this.totalBytes = totalBytes;
} }
@ -33,7 +31,7 @@ class ProgressBufferedInputStream extends BufferedInputStream {
* the digits changing because it looks pretty, < 9000 since the reads won't * the digits changing because it looks pretty, < 9000 since the reads won't
* line up exactly */ * line up exactly */
if (currentBytes % 333333 < 9000) { if (currentBytes % 333333 < 9000) {
progressListener.onProgress(urlString, currentBytes, totalBytes); progressListener.onProgress(currentBytes, totalBytes);
} }
} }
return super.read(buffer, byteOffset, byteCount); return super.read(buffer, byteOffset, byteCount);

View File

@ -19,6 +19,6 @@ import java.net.URL;
*/ */
public interface ProgressListener { public interface ProgressListener {
void onProgress(String urlString, long bytesRead, long totalBytes); void onProgress(long bytesRead, long totalBytes);
} }

View File

@ -207,7 +207,7 @@ public abstract class Downloader {
@Override @Override
public void run() { public void run() {
if (downloaderProgressListener != null) { if (downloaderProgressListener != null) {
downloaderProgressListener.onProgress(urlString, bytesRead, totalBytes); downloaderProgressListener.onProgress(bytesRead, totalBytes);
} }
} }
}; };

View File

@ -207,7 +207,7 @@ public class DownloaderService extends Service {
downloader = DownloaderFactory.create(this, uri, localFile); downloader = DownloaderFactory.create(this, uri, localFile);
downloader.setListener(new ProgressListener() { downloader.setListener(new ProgressListener() {
@Override @Override
public void onProgress(String urlString, long bytesRead, long totalBytes) { public void onProgress(long bytesRead, long totalBytes) {
Intent intent = new Intent(Downloader.ACTION_PROGRESS); Intent intent = new Intent(Downloader.ACTION_PROGRESS);
intent.setData(uri); intent.setData(uri);
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead); intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);