From b3f79da341dce582a8a45126fa221ec494c7f3e1 Mon Sep 17 00:00:00 2001
From: Peter Serwylo <peter@serwylo.com>
Date: Mon, 23 May 2016 00:13:16 +1000
Subject: [PATCH] Slow down progress events to ensure notification action
 button can be pressed.

After much consternation and testing, it became apparant that there
was nothing really wrong with our PendingIntent setup or notification
setup. The only problem was the rapidness with which the notification
was being updated. There is something about rapidly updated notificaitons
which makes it not possible to hit the action button. This explains why
the button _would indeed work sometimes_, because the user may have hit
it just in that sweet spot.

This change increases the time between progress events from 100ms to 500ms
which seems to do the job on my Moto X 2nd gen. Perhaps this can be changed
to a larger number if required. When it was set to 300 ms, it _mostly_ worked,
but there was still a few times where hitting the button wouldn't work at all.

Fixes #652.
---
 app/src/main/java/org/fdroid/fdroid/net/Downloader.java        | 2 +-
 app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

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 cb68aa575..6a07de4fe 100644
--- a/app/src/main/java/org/fdroid/fdroid/net/Downloader.java
+++ b/app/src/main/java/org/fdroid/fdroid/net/Downloader.java
@@ -145,7 +145,7 @@ public abstract class Downloader {
             totalBytes = totalDownloadSize();
             byte[] buffer = new byte[bufferSize];
 
-            timer.scheduleAtFixedRate(progressTask, 0, 100);
+            timer.scheduleAtFixedRate(progressTask, 0, 500);
 
             // 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.
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 8dc833d29..3fdb53acf 100644
--- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java
+++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java
@@ -147,8 +147,7 @@ public class DownloaderService extends Service {
     public static PendingIntent getCancelPendingIntent(Context context, String urlString) {
         Intent cancelIntent = new Intent(context.getApplicationContext(), DownloaderService.class)
                 .setData(Uri.parse(urlString))
-                .setAction(ACTION_CANCEL)
-                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
+                .setAction(ACTION_CANCEL);
         return PendingIntent.getService(context.getApplicationContext(),
                 urlString.hashCode(),
                 cancelIntent,