diff --git a/F-Droid/res/values/strings.xml b/F-Droid/res/values/strings.xml
index bfc956e78..21fd192b0 100644
--- a/F-Droid/res/values/strings.xml
+++ b/F-Droid/res/values/strings.xml
@@ -211,7 +211,7 @@
- Percentage complete (int between 0-100)
-->
Downloading\n%2$s / %3$s (%4$d%%) from\n%1$s
- Processing application\n%2$d of %3$d from\n%1$s
+ Processing\n%2$s / %3$s (%4$d%%) from\n%1$s
Connecting to\n%1$s
Checking apps compatibility with your deviceā¦
Saving application details (%1$d%%)
diff --git a/F-Droid/src/org/fdroid/fdroid/ProgressBufferedInputStream.java b/F-Droid/src/org/fdroid/fdroid/ProgressBufferedInputStream.java
new file mode 100644
index 000000000..526d91105
--- /dev/null
+++ b/F-Droid/src/org/fdroid/fdroid/ProgressBufferedInputStream.java
@@ -0,0 +1,51 @@
+package org.fdroid.fdroid;
+
+import android.os.Bundle;
+
+import org.fdroid.fdroid.data.Repo;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ProgressBufferedInputStream extends BufferedInputStream {
+ private static final String TAG = "ProgressBufferedInputSt";
+
+ final Repo repo;
+ final ProgressListener progressListener;
+ final Bundle data;
+ final int totalBytes;
+
+ int currentBytes = 0;
+
+ /**
+ * Reports progress to the specified {@link ProgressListener}, with the
+ * progress based on the {@code totalBytes}.
+ */
+ public ProgressBufferedInputStream(InputStream in, ProgressListener progressListener, Repo repo, int totalBytes)
+ throws IOException {
+ super(in);
+ this.progressListener = progressListener;
+ this.repo = repo;
+ this.data = new Bundle(1);
+ this.data.putString(RepoUpdater.PROGRESS_DATA_REPO_ADDRESS, repo.address);
+ this.totalBytes = totalBytes;
+ }
+
+ @Override
+ public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
+ if (progressListener != null) {
+ currentBytes += byteCount;
+ /* don't send every change to keep things efficient. 333333 bytes to keep all
+ * the digits changing because it looks pretty, < 9000 since the reads won't
+ * line up exactly */
+ if (currentBytes % 333333 < 9000) {
+ progressListener.onProgress(
+ new ProgressListener.Event(
+ RepoUpdater.PROGRESS_TYPE_PROCESS_XML,
+ currentBytes, totalBytes, data));
+ }
+ }
+ return super.read(buffer, byteOffset, byteCount);
+ }
+}
diff --git a/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java b/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java
index 0b6e3a0d0..f14a283fa 100644
--- a/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java
+++ b/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java
@@ -18,7 +18,6 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
-import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -136,12 +135,13 @@ public class RepoUpdater {
if (repo.pubkey == null) // new repo, no signing certificate stored
storePubKey = true;
- JarEntry indexEntry = null;
- if (downloadedFile != null && downloadedFile.exists()) {
- JarFile jarFile = new JarFile(downloadedFile, true);
- indexEntry = (JarEntry) jarFile.getEntry("index.xml");
- indexInputStream = new BufferedInputStream(jarFile.getInputStream(indexEntry));
- }
+ if (downloadedFile == null || !downloadedFile.exists())
+ throw new UpdateException(repo, downloadedFile + " does not exist!");
+
+ JarFile jarFile = new JarFile(downloadedFile, true);
+ JarEntry indexEntry = (JarEntry) jarFile.getEntry("index.xml");
+ indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
+ progressListener, repo, (int)indexEntry.getSize());
// Process the index...
final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
diff --git a/F-Droid/src/org/fdroid/fdroid/UpdateService.java b/F-Droid/src/org/fdroid/fdroid/UpdateService.java
index 43f3157bf..b4dc635d8 100644
--- a/F-Droid/src/org/fdroid/fdroid/UpdateService.java
+++ b/F-Droid/src/org/fdroid/fdroid/UpdateService.java
@@ -769,7 +769,6 @@ public class UpdateService extends IntentService implements ProgressListener {
Log.d(TAG, "Removing " + numDeleted + " apks that don't have any apks");
}
-
/**
* Received progress event from the RepoXMLHandler. It could be progress
* downloading from the repo, or perhaps processing the info from the repo.
@@ -780,16 +779,16 @@ public class UpdateService extends IntentService implements ProgressListener {
// TODO: Switch to passing through Bundles of data with the event, rather than a repo address. They are
// now much more general purpose then just repo downloading.
String repoAddress = event.getData().getString(RepoUpdater.PROGRESS_DATA_REPO_ADDRESS);
+ String downloadedSize = Utils.getFriendlySize(event.progress);
+ String totalSize = Utils.getFriendlySize(event.total);
+ int percent = (int) ((double) event.progress / event.total * 100);
switch (event.type) {
- case Downloader.EVENT_PROGRESS:
- String downloadedSize = Utils.getFriendlySize(event.progress);
- String totalSize = Utils.getFriendlySize(event.total);
- int percent = (int)((double)event.progress/event.total * 100);
- message = getString(R.string.status_download, repoAddress, downloadedSize, totalSize, percent);
- break;
- case RepoUpdater.PROGRESS_TYPE_PROCESS_XML:
- message = getString(R.string.status_processing_xml, repoAddress, event.progress, event.total);
- break;
+ case Downloader.EVENT_PROGRESS:
+ message = getString(R.string.status_download, repoAddress, downloadedSize, totalSize, percent);
+ break;
+ case RepoUpdater.PROGRESS_TYPE_PROCESS_XML:
+ message = getString(R.string.status_processing_xml, repoAddress, downloadedSize, totalSize, percent);
+ break;
}
sendStatus(STATUS_INFO, message);
}