Report if a failure is following a download abort

This commit is contained in:
Gabriele M
2017-07-05 23:35:14 +02:00
parent 3de555ea06
commit 1795bd8b11
4 changed files with 12 additions and 9 deletions

View File

@@ -43,10 +43,12 @@ public class DownloadClient {
private static final Object DOWNLOAD_TAG = new Object();
private boolean mCancelled = false;
public interface DownloadCallback {
void onResponse(int statusCode, String url, Headers headers);
void onSuccess(String body);
void onFailure();
void onFailure(boolean cancelled);
}
public interface ProgressListener {
@@ -103,6 +105,7 @@ public class DownloadClient {
new Thread(new Runnable() {
@Override
public void run() {
mCancelled = true;
mClient.cancel(DOWNLOAD_TAG);
}
}).start();
@@ -116,8 +119,8 @@ public class DownloadClient {
mClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
Log.d(TAG, "Download failed", e);
callback.onFailure();
Log.d(TAG, "Download failed, cancelled=" + mCancelled, e);
callback.onFailure(mCancelled);
}
@Override
@@ -177,7 +180,7 @@ public class DownloadClient {
@Override
public void onFailure(Request request, IOException e) {
Log.d(TAG, "Download failed", e);
callback.onFailure();
callback.onFailure(mCancelled);
}
@Override
@@ -190,7 +193,7 @@ public class DownloadClient {
Log.d(TAG, "The server fulfilled the partial content request");
} else if (!isSuccessful(response.code())) {
Log.e(TAG, "The server replied with code " + response.code());
callback.onFailure();
callback.onFailure(mCancelled);
return;
}

View File

@@ -156,7 +156,7 @@ public class UpdatesActivity extends AppCompatActivity {
Log.d(TAG, "Checking " + url);
DownloadClient.downloadFile(url, jsonFile, new DownloadClient.DownloadCallback() {
@Override
public void onFailure() {
public void onFailure(boolean cancelled) {
Log.e(TAG, "Could not download updates list");
}

View File

@@ -65,7 +65,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
String url = Utils.getServerURL(context);
DownloadClient.downloadFile(url, jsonNew, new DownloadClient.DownloadCallback() {
@Override
public void onFailure() {
public void onFailure(boolean cancelled) {
Log.e(TAG, "Could not download updates list, scheduling new check");
scheduleUpdatesCheck(context);
}

View File

@@ -177,9 +177,9 @@ public class UpdaterController implements UpdaterControllerInt {
}
@Override
public void onFailure() {
public void onFailure(boolean cancelled) {
// The client is null if we intentionally stopped the download
boolean cancelled = mDownloads.get(downloadId).mDownloadClient == null;
cancelled = mDownloads.get(downloadId).mDownloadClient == null;
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
if (cancelled) {
Log.d(TAG, "Download cancelled");