Reinstate code to allow resumed activity to query download status (rather than wait for broadcasts).
This commit is contained in:
parent
b2bde89834
commit
a0bf49d1ea
@ -464,11 +464,10 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A
|
|||||||
new IntentFilter(Downloader.LOCAL_ACTION_PROGRESS));
|
new IntentFilter(Downloader.LOCAL_ACTION_PROGRESS));
|
||||||
downloadHandler.setProgressListener(this);
|
downloadHandler.setProgressListener(this);
|
||||||
|
|
||||||
if (downloadHandler.getTotalSize() == 0)
|
if (downloadHandler.getTotalBytes() == 0)
|
||||||
mHeaderFragment.startProgress();
|
mHeaderFragment.startProgress();
|
||||||
else
|
else
|
||||||
mHeaderFragment.updateProgress(downloadHandler.getProgress(),
|
mHeaderFragment.updateProgress(downloadHandler.getBytesRead(), downloadHandler.getTotalBytes());
|
||||||
downloadHandler.getTotalSize());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,6 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener {
|
|||||||
|
|
||||||
public static final int ERROR_HASH_MISMATCH = 101;
|
public static final int ERROR_HASH_MISMATCH = 101;
|
||||||
public static final int ERROR_DOWNLOAD_FAILED = 102;
|
public static final int ERROR_DOWNLOAD_FAILED = 102;
|
||||||
public static final int ERROR_UNKNOWN = 103;
|
|
||||||
|
|
||||||
private static final String EVENT_SOURCE_ID = "sourceId";
|
private static final String EVENT_SOURCE_ID = "sourceId";
|
||||||
private static long downloadIdCounter = 0;
|
private static long downloadIdCounter = 0;
|
||||||
@ -70,8 +69,6 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener {
|
|||||||
|
|
||||||
private ProgressListener listener;
|
private ProgressListener listener;
|
||||||
private AsyncDownloadWrapper dlWrapper = null;
|
private AsyncDownloadWrapper dlWrapper = null;
|
||||||
private int progress = 0;
|
|
||||||
private int totalSize = 0;
|
|
||||||
private boolean isComplete = false;
|
private boolean isComplete = false;
|
||||||
|
|
||||||
private final long id = ++downloadIdCounter;
|
private final long id = ++downloadIdCounter;
|
||||||
@ -274,7 +271,7 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener {
|
|||||||
|
|
||||||
public Apk getApk() { return curApk; }
|
public Apk getApk() { return curApk; }
|
||||||
|
|
||||||
public int getProgress() { return progress; }
|
public int getBytesRead() { return dlWrapper != null ? dlWrapper.getBytesRead() : 0; }
|
||||||
|
|
||||||
public int getTotalSize() { return totalSize; }
|
public int getTotalBytes() { return dlWrapper != null ? dlWrapper.getTotalBytes() : 0; }
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,14 @@ public class AsyncDownloadWrapper extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBytesRead() {
|
||||||
|
return downloader.getBytesRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalBytes() {
|
||||||
|
return downloader.getTotalBytes();
|
||||||
|
}
|
||||||
|
|
||||||
public interface Listener extends ProgressListener {
|
public interface Listener extends ProgressListener {
|
||||||
void onErrorDownloading(String localisedExceptionDetails);
|
void onErrorDownloading(String localisedExceptionDetails);
|
||||||
void onDownloadComplete();
|
void onDownloadComplete();
|
||||||
|
@ -33,6 +33,8 @@ public abstract class Downloader {
|
|||||||
|
|
||||||
protected final URL sourceUrl;
|
protected final URL sourceUrl;
|
||||||
protected String cacheTag = null;
|
protected String cacheTag = null;
|
||||||
|
protected int bytesRead = 0;
|
||||||
|
protected int totalBytes = 0;
|
||||||
|
|
||||||
public abstract InputStream getInputStream() throws IOException;
|
public abstract InputStream getInputStream() throws IOException;
|
||||||
|
|
||||||
@ -145,7 +147,7 @@ public abstract class Downloader {
|
|||||||
|
|
||||||
byte[] buffer = new byte[Utils.BUFFER_SIZE];
|
byte[] buffer = new byte[Utils.BUFFER_SIZE];
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
int totalBytes = totalDownloadSize();
|
this.totalBytes = totalDownloadSize();
|
||||||
|
|
||||||
// Getting the total download size could potentially take time, depending on how
|
// Getting the total download size could potentially take time, depending on how
|
||||||
// it is implemented, so we may as well check this before we proceed.
|
// it is implemented, so we may as well check this before we proceed.
|
||||||
@ -169,6 +171,7 @@ public abstract class Downloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void sendProgress(int bytesRead, int totalBytes) {
|
protected void sendProgress(int bytesRead, int totalBytes) {
|
||||||
|
this.bytesRead = bytesRead;
|
||||||
Intent intent = new Intent(LOCAL_ACTION_PROGRESS);
|
Intent intent = new Intent(LOCAL_ACTION_PROGRESS);
|
||||||
intent.putExtra(EXTRA_ADDRESS, sourceUrl.toString());
|
intent.putExtra(EXTRA_ADDRESS, sourceUrl.toString());
|
||||||
intent.putExtra(EXTRA_BYTES_READ, bytesRead);
|
intent.putExtra(EXTRA_BYTES_READ, bytesRead);
|
||||||
@ -176,4 +179,11 @@ public abstract class Downloader {
|
|||||||
localBroadcastManager.sendBroadcast(intent);
|
localBroadcastManager.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBytesRead() {
|
||||||
|
return bytesRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalBytes() {
|
||||||
|
return totalBytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user