diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails.java b/app/src/main/java/org/fdroid/fdroid/AppDetails.java index 6434eaf7c..1725011b7 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppDetails.java +++ b/app/src/main/java/org/fdroid/fdroid/AppDetails.java @@ -515,7 +515,14 @@ public class AppDetails extends AppCompatActivity { private final BroadcastReceiver interruptedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - Toast.makeText(context, R.string.details_notinstalled, Toast.LENGTH_LONG).show(); + if (intent.hasExtra(Downloader.EXTRA_ERROR_MESSAGE)) { + String msg = intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE) + + " " + intent.getDataString(); + Toast.makeText(context, R.string.download_error, Toast.LENGTH_SHORT).show(); + Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); + } else { // user canceled + Toast.makeText(context, R.string.details_notinstalled, Toast.LENGTH_LONG).show(); + } cleanUpFinishedDownload(); } }; 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 ab5474ffb..86e7f2685 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/Downloader.java +++ b/app/src/main/java/org/fdroid/fdroid/net/Downloader.java @@ -25,6 +25,7 @@ public abstract class Downloader { public static final String EXTRA_DOWNLOAD_PATH = "org.fdroid.fdroid.net.Downloader.extra.DOWNLOAD_PATH"; public static final String EXTRA_BYTES_READ = "org.fdroid.fdroid.net.Downloader.extra.BYTES_READ"; public static final String EXTRA_TOTAL_BYTES = "org.fdroid.fdroid.net.Downloader.extra.TOTAL_BYTES"; + public static final String EXTRA_ERROR_MESSAGE = "org.fdroid.fdroid.net.Downloader.extra.ERROR_MESSAGE"; private volatile boolean cancelled = false; private volatile int bytesRead; 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 aaa6ad423..532a0ffbb 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -180,7 +180,6 @@ public class DownloaderService extends Service { */ protected void handleIntent(Intent intent) { final Uri uri = intent.getData(); - Log.i(TAG, "handleIntent " + uri); File downloadDir = new File(Utils.getApkCacheDir(this), uri.getHost() + "-" + uri.getPort()); downloadDir.mkdirs(); final SanitizedFile localFile = new SanitizedFile(downloadDir, uri.getLastPathSegment()); @@ -190,7 +189,6 @@ public class DownloaderService extends Service { downloader.setListener(new Downloader.DownloaderProgressListener() { @Override public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) { - //Log.i(TAG, "sendProgress " + sourceUrl + " " + bytesRead + " / " + totalBytes); Intent intent = new Intent(Downloader.ACTION_PROGRESS); intent.setData(uri); intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead); @@ -203,22 +201,28 @@ public class DownloaderService extends Service { } catch (InterruptedException e) { sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile); } catch (IOException e) { - sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile); e.printStackTrace(); + sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, + e.getLocalizedMessage()); } finally { if (downloader != null) { downloader.close(); } } downloader = null; - Log.i(TAG, "handleIntent DONE " + uri); } private void sendBroadcast(Uri uri, String action, File file) { - Log.i(TAG, "sendBroadcast " + uri + " " + action + " " + file); + sendBroadcast(uri, action, file, null); + } + + private void sendBroadcast(Uri uri, String action, File file, String errorMessage) { Intent intent = new Intent(action); intent.setData(uri); intent.putExtra(Downloader.EXTRA_DOWNLOAD_PATH, file.getAbsolutePath()); + if (!TextUtils.isEmpty(errorMessage)) { + intent.putExtra(Downloader.EXTRA_ERROR_MESSAGE, errorMessage); + } localBroadcastManager.sendBroadcast(intent); } diff --git a/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java b/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java index 190cd747e..ef4080b87 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java +++ b/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java @@ -36,6 +36,7 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; @@ -268,6 +269,21 @@ public class SwapAppsView extends ListView implements } }; + private final BroadcastReceiver interruptedReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.hasExtra(Downloader.EXTRA_ERROR_MESSAGE)) { + String msg = intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE) + + " " + intent.getDataString(); + Toast.makeText(context, R.string.download_error, Toast.LENGTH_SHORT).show(); + Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); + } else { // user canceled + Toast.makeText(context, R.string.details_notinstalled, Toast.LENGTH_LONG).show(); + } + resetView(); + } + }; + private final ContentObserver appObserver = new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { @@ -293,7 +309,7 @@ public class SwapAppsView extends ListView implements DownloaderService.getIntentFilter(url, Downloader.ACTION_PROGRESS)); localBroadcastManager.registerReceiver(appListViewResetReceiver, DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE)); - localBroadcastManager.registerReceiver(appListViewResetReceiver, + localBroadcastManager.registerReceiver(interruptedReceiver, DownloaderService.getIntentFilter(url, Downloader.ACTION_INTERRUPTED)); }