switch Downloader total download size to long to support >16MB
This was int because it was written arond UrlConnection.getContentLength() which returns an int. But that doesn't make sense since this will definitely handle files large than 16MB. !647 #1192
This commit is contained in:
parent
a88b9c924e
commit
195aaae7e5
@ -19,6 +19,6 @@ import java.net.URL;
|
|||||||
*/
|
*/
|
||||||
public interface ProgressListener {
|
public interface ProgressListener {
|
||||||
|
|
||||||
void onProgress(URL sourceUrl, int bytesRead, int totalBytes);
|
void onProgress(URL sourceUrl, long bytesRead, long totalBytes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -251,14 +251,14 @@ public class RepoUpdater {
|
|||||||
|
|
||||||
protected final ProgressListener downloadListener = new ProgressListener() {
|
protected final ProgressListener downloadListener = new ProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(URL sourceUrl, int bytesRead, int totalBytes) {
|
public void onProgress(URL sourceUrl, long bytesRead, long totalBytes) {
|
||||||
UpdateService.reportDownloadProgress(context, RepoUpdater.this, bytesRead, totalBytes);
|
UpdateService.reportDownloadProgress(context, RepoUpdater.this, bytesRead, totalBytes);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected final ProgressListener processIndexListener = new ProgressListener() {
|
protected final ProgressListener processIndexListener = new ProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(URL sourceUrl, int bytesRead, int totalBytes) {
|
public void onProgress(URL sourceUrl, long bytesRead, long totalBytes) {
|
||||||
UpdateService.reportProcessIndexProgress(context, RepoUpdater.this, bytesRead, totalBytes);
|
UpdateService.reportProcessIndexProgress(context, RepoUpdater.this, bytesRead, totalBytes);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -516,12 +516,13 @@ public class UpdateService extends IntentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reportDownloadProgress(Context context, RepoUpdater updater, int bytesRead, int totalBytes) {
|
public static void reportDownloadProgress(Context context, RepoUpdater updater,
|
||||||
|
long bytesRead, long totalBytes) {
|
||||||
Utils.debugLog(TAG, "Downloading " + updater.indexUrl + "(" + bytesRead + "/" + totalBytes + ")");
|
Utils.debugLog(TAG, "Downloading " + updater.indexUrl + "(" + bytesRead + "/" + totalBytes + ")");
|
||||||
String downloadedSizeFriendly = Utils.getFriendlySize(bytesRead);
|
String downloadedSizeFriendly = Utils.getFriendlySize(bytesRead);
|
||||||
int percent = -1;
|
int percent = -1;
|
||||||
if (totalBytes > 0) {
|
if (totalBytes > 0) {
|
||||||
percent = (int) ((double) bytesRead / totalBytes * 100);
|
percent = (int) (bytesRead / (totalBytes * 100L));
|
||||||
}
|
}
|
||||||
String message;
|
String message;
|
||||||
if (totalBytes == -1) {
|
if (totalBytes == -1) {
|
||||||
@ -534,13 +535,14 @@ public class UpdateService extends IntentService {
|
|||||||
sendStatus(context, STATUS_INFO, message, percent);
|
sendStatus(context, STATUS_INFO, message, percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reportProcessIndexProgress(Context context, RepoUpdater updater, int bytesRead, int totalBytes) {
|
public static void reportProcessIndexProgress(Context context, RepoUpdater updater,
|
||||||
|
long bytesRead, long totalBytes) {
|
||||||
Utils.debugLog(TAG, "Processing " + updater.indexUrl + "(" + bytesRead + "/" + totalBytes + ")");
|
Utils.debugLog(TAG, "Processing " + updater.indexUrl + "(" + bytesRead + "/" + totalBytes + ")");
|
||||||
String downloadedSize = Utils.getFriendlySize(bytesRead);
|
String downloadedSize = Utils.getFriendlySize(bytesRead);
|
||||||
String totalSize = Utils.getFriendlySize(totalBytes);
|
String totalSize = Utils.getFriendlySize(totalBytes);
|
||||||
int percent = -1;
|
int percent = -1;
|
||||||
if (totalBytes > 0) {
|
if (totalBytes > 0) {
|
||||||
percent = (int) ((double) bytesRead / totalBytes * 100);
|
percent = (int) (bytesRead / (totalBytes * 100L));
|
||||||
}
|
}
|
||||||
String message = context.getString(R.string.status_processing_xml_percent, updater.indexUrl, downloadedSize, totalSize, percent);
|
String message = context.getString(R.string.status_processing_xml_percent, updater.indexUrl, downloadedSize, totalSize, percent);
|
||||||
sendStatus(context, STATUS_INFO, message, percent);
|
sendStatus(context, STATUS_INFO, message, percent);
|
||||||
|
@ -73,7 +73,7 @@ public class BluetoothDownloader extends Downloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int totalDownloadSize() {
|
public long totalDownloadSize() {
|
||||||
FileDetails details = getFileDetails();
|
FileDetails details = getFileDetails();
|
||||||
return details != null ? details.getFileSize() : -1;
|
return details != null ? details.getFileSize() : -1;
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ public abstract class Downloader {
|
|||||||
public static final String EXTRA_MIRROR_URL = "org.fdroid.fdroid.net.Downloader.extra.ERROR_MIRROR_URL";
|
public static final String EXTRA_MIRROR_URL = "org.fdroid.fdroid.net.Downloader.extra.ERROR_MIRROR_URL";
|
||||||
|
|
||||||
private volatile boolean cancelled = false;
|
private volatile boolean cancelled = false;
|
||||||
private volatile int bytesRead;
|
private volatile long bytesRead;
|
||||||
private volatile int totalBytes;
|
private volatile long totalBytes;
|
||||||
|
|
||||||
public final File outputFile;
|
public final File outputFile;
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ public abstract class Downloader {
|
|||||||
|
|
||||||
public abstract boolean hasChanged();
|
public abstract boolean hasChanged();
|
||||||
|
|
||||||
protected abstract int totalDownloadSize();
|
protected abstract long totalDownloadSize();
|
||||||
|
|
||||||
public abstract void download() throws ConnectException, IOException, InterruptedException;
|
public abstract void download() throws ConnectException, IOException, InterruptedException;
|
||||||
|
|
||||||
|
@ -199,7 +199,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(URL sourceUrl, int bytesRead, int totalBytes) {
|
public void onProgress(URL sourceUrl, 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);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.fdroid.fdroid.net;
|
package org.fdroid.fdroid.net;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||||
import info.guardianproject.netcipher.NetCipher;
|
import info.guardianproject.netcipher.NetCipher;
|
||||||
@ -169,8 +171,13 @@ public class HttpDownloader extends Downloader {
|
|||||||
// because as the repo grows, the tradeoff will
|
// because as the repo grows, the tradeoff will
|
||||||
// become more worth it.
|
// become more worth it.
|
||||||
@Override
|
@Override
|
||||||
public int totalDownloadSize() {
|
@TargetApi(24)
|
||||||
return connection.getContentLength();
|
public long totalDownloadSize() {
|
||||||
|
if (Build.VERSION.SDK_INT < 24) {
|
||||||
|
return connection.getContentLength();
|
||||||
|
} else {
|
||||||
|
return connection.getContentLengthLong();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,13 +3,13 @@ package org.fdroid.fdroid.net.bluetooth;
|
|||||||
public class FileDetails {
|
public class FileDetails {
|
||||||
|
|
||||||
private String cacheTag;
|
private String cacheTag;
|
||||||
private int fileSize;
|
private long fileSize;
|
||||||
|
|
||||||
public String getCacheTag() {
|
public String getCacheTag() {
|
||||||
return cacheTag;
|
return cacheTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFileSize() {
|
public long getFileSize() {
|
||||||
return fileSize;
|
return fileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user