diff --git a/app/src/main/java/org/fdroid/fdroid/ProgressListener.java b/app/src/main/java/org/fdroid/fdroid/ProgressListener.java index 1e71373ad..beb370fd2 100644 --- a/app/src/main/java/org/fdroid/fdroid/ProgressListener.java +++ b/app/src/main/java/org/fdroid/fdroid/ProgressListener.java @@ -19,6 +19,6 @@ import java.net.URL; */ public interface ProgressListener { - void onProgress(URL sourceUrl, int bytesRead, int totalBytes); + void onProgress(URL sourceUrl, long bytesRead, long totalBytes); } diff --git a/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java b/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java index 9c3463b7f..afb3659ab 100644 --- a/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java +++ b/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java @@ -251,14 +251,14 @@ public class RepoUpdater { protected final ProgressListener downloadListener = new ProgressListener() { @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); } }; protected final ProgressListener processIndexListener = new ProgressListener() { @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); } }; diff --git a/app/src/main/java/org/fdroid/fdroid/UpdateService.java b/app/src/main/java/org/fdroid/fdroid/UpdateService.java index 1b9a5a62b..5b233046f 100644 --- a/app/src/main/java/org/fdroid/fdroid/UpdateService.java +++ b/app/src/main/java/org/fdroid/fdroid/UpdateService.java @@ -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 + ")"); String downloadedSizeFriendly = Utils.getFriendlySize(bytesRead); int percent = -1; if (totalBytes > 0) { - percent = (int) ((double) bytesRead / totalBytes * 100); + percent = (int) (bytesRead / (totalBytes * 100L)); } String message; if (totalBytes == -1) { @@ -534,13 +535,14 @@ public class UpdateService extends IntentService { 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 + ")"); String downloadedSize = Utils.getFriendlySize(bytesRead); String totalSize = Utils.getFriendlySize(totalBytes); int percent = -1; 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); sendStatus(context, STATUS_INFO, message, percent); diff --git a/app/src/main/java/org/fdroid/fdroid/net/BluetoothDownloader.java b/app/src/main/java/org/fdroid/fdroid/net/BluetoothDownloader.java index 8ab0c4704..fd9a06379 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/BluetoothDownloader.java +++ b/app/src/main/java/org/fdroid/fdroid/net/BluetoothDownloader.java @@ -73,7 +73,7 @@ public class BluetoothDownloader extends Downloader { } @Override - public int totalDownloadSize() { + public long totalDownloadSize() { FileDetails details = getFileDetails(); return details != null ? details.getFileSize() : -1; } diff --git a/app/src/main/java/org/fdroid/fdroid/net/Downloader.java b/app/src/main/java/org/fdroid/fdroid/net/Downloader.java index 885dc3d79..d391ef2b6 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/Downloader.java +++ b/app/src/main/java/org/fdroid/fdroid/net/Downloader.java @@ -32,8 +32,8 @@ public abstract class Downloader { public static final String EXTRA_MIRROR_URL = "org.fdroid.fdroid.net.Downloader.extra.ERROR_MIRROR_URL"; private volatile boolean cancelled = false; - private volatile int bytesRead; - private volatile int totalBytes; + private volatile long bytesRead; + private volatile long totalBytes; public final File outputFile; @@ -92,7 +92,7 @@ public abstract class Downloader { public abstract boolean hasChanged(); - protected abstract int totalDownloadSize(); + protected abstract long totalDownloadSize(); public abstract void download() throws ConnectException, IOException, InterruptedException; diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java index ca63ec17c..52d474e45 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -199,7 +199,7 @@ public class DownloaderService extends Service { downloader = DownloaderFactory.create(this, uri, localFile); downloader.setListener(new ProgressListener() { @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.setData(uri); intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead); diff --git a/app/src/main/java/org/fdroid/fdroid/net/HttpDownloader.java b/app/src/main/java/org/fdroid/fdroid/net/HttpDownloader.java index c44f94487..05b460473 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/HttpDownloader.java +++ b/app/src/main/java/org/fdroid/fdroid/net/HttpDownloader.java @@ -1,5 +1,7 @@ package org.fdroid.fdroid.net; +import android.annotation.TargetApi; +import android.os.Build; import android.text.TextUtils; import com.nostra13.universalimageloader.core.download.BaseImageDownloader; import info.guardianproject.netcipher.NetCipher; @@ -169,8 +171,13 @@ public class HttpDownloader extends Downloader { // because as the repo grows, the tradeoff will // become more worth it. @Override - public int totalDownloadSize() { - return connection.getContentLength(); + @TargetApi(24) + public long totalDownloadSize() { + if (Build.VERSION.SDK_INT < 24) { + return connection.getContentLength(); + } else { + return connection.getContentLengthLong(); + } } @Override diff --git a/app/src/main/java/org/fdroid/fdroid/net/bluetooth/FileDetails.java b/app/src/main/java/org/fdroid/fdroid/net/bluetooth/FileDetails.java index f7148a91f..96c57f63c 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/bluetooth/FileDetails.java +++ b/app/src/main/java/org/fdroid/fdroid/net/bluetooth/FileDetails.java @@ -3,13 +3,13 @@ package org.fdroid.fdroid.net.bluetooth; public class FileDetails { private String cacheTag; - private int fileSize; + private long fileSize; public String getCacheTag() { return cacheTag; } - public int getFileSize() { + public long getFileSize() { return fileSize; }