{"action":"created","comment":{"url":"https://api.github.com/repos/novoda/download-manager/pulls/comments/34460880","id":34460880,"diff_hunk":"@@ -842,14 +866,40 @@ private void addRequestHeaders(State state, HttpURLConnection conn) {\n     private void notifyDownloadCompleted(State state, int finalStatus, String errorMsg, int numFailed) {\n         notifyThroughDatabase(state, finalStatus, errorMsg, numFailed);\n         if (DownloadStatus.isCompleted(finalStatus)) {\n-            originalDownloadInfo.broadcastIntentDownloadComplete(finalStatus);\n+            broadcastIntentDownloadComplete(finalStatus);\n         } else if (DownloadStatus.isInsufficientSpace(finalStatus)) {\n-            originalDownloadInfo.broadcastIntentDownloadFailedInsufficientSpace();\n+            broadcastIntentDownloadFailedInsufficientSpace();\n         }\n     }\n \n+    public void broadcastIntentDownloadComplete(int finalStatus) {\n+        Intent intent = new Intent(DownloadManager.ACTION_DOWNLOAD_COMPLETE);\n+        intent.setPackage(getPackageName());\n+        intent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, originalDownloadInfo.getId());\n+        intent.putExtra(DownloadManager.EXTRA_DOWNLOAD_STATUS, finalStatus);\n+        intent.setData(originalDownloadInfo.getMyDownloadsUri());\n+        if (originalDownloadInfo.getExtras() != null) {\n+            intent.putExtra(DownloadManager.EXTRA_EXTRA, originalDownloadInfo.getExtras());\n+        }\n+        context.sendBroadcast(intent);\n+    }\n+\n+    public void broadcastIntentDownloadFailedInsufficientSpace() {\n+        Intent intent = new Intent(DownloadManager.ACTION_DOWNLOAD_INSUFFICIENT_SPACE);\n+        intent.setPackage(getPackageName());\n+        intent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, originalDownloadInfo.getId());\n+        intent.setData(originalDownloadInfo.getMyDownloadsUri());\n+        if (originalDownloadInfo.getExtras() != null) {\n+            intent.putExtra(DownloadManager.EXTRA_EXTRA, originalDownloadInfo.getExtras());","path":"library/src/main/java/com/novoda/downloadmanager/lib/DownloadThread.java","position":151,"original_position":151,"commit_id":"a2268c12a4fff43432f3682dcfd98202adc95bfd","original_commit_id":"a2268c12a4fff43432f3682dcfd98202adc95bfd","user":{"login":"blundell","id":655860,"avatar_url":"https://avatars.githubusercontent.com/u/655860?v=3","gravatar_id":"","url":"https://api.github.com/users/blundell","html_url":"https://github.com/blundell","followers_url":"https://api.github.com/users/blundell/followers","following_url":"https://api.github.com/users/blundell/following{/other_user}","gists_url":"https://api.github.com/users/blundell/gists{/gist_id}","starred_url":"https://api.github.com/users/blundell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blundell/subscriptions","organizations_url":"https://api.github.com/users/blundell/orgs","repos_url":"https://api.github.com/users/blundell/repos","events_url":"https://api.github.com/users/blundell/events{/privacy}","received_events_url":"https://api.github.com/users/blundell/received_events","type":"User","site_admin":false},"body":"literally I had `private static final String EXTRA_EXTRA = \"read all about it\";` Xavi was not amused","created_at":"2015-07-13T13:14:37Z","updated_at":"2015-07-13T13:14:37Z","html_url":"https://github.com/novoda/download-manager/pull/89#discussion_r34460880","pull_request_url":"https://api.github.com/repos/novoda/download-manager/pulls/89","_links":{"self":{"href":"https://api.github.com/repos/novoda/download-manager/pulls/comments/34460880"},"html":{"href":"https://github.com/novoda/download-manager/pull/89#discussion_r34460880"},"pull_request":{"href":"https://api.github.com/repos/novoda/download-manager/pulls/89"}}},"pull_request":{"url":"https://api.github.com/repos/novoda/download-manager/pulls/89","id":39606581,"html_url":"https://github.com/novoda/download-manager/pull/89","diff_url":"https://github.com/novoda/download-manager/pull/89.diff","patch_url":"https://github.com/novoda/download-manager/pull/89.patch","issue_url":"https://api.github.com/repos/novoda/download-manager/issues/89","number":89,"state":"open","locked":false,"title":"Only run can download checks against the current download","user":{"login":"ouchadam","id":1848238,"avatar_url":"https://avatars.githubusercontent.com/u/1848238?v=3","gravatar_id":"","url":"https://api.github.com/users/ouchadam","html_url":"https://github.com/ouchadam","followers_url":"https://api.github.com/users/ouchadam/followers","following_url":"https://api.github.com/users/ouchadam/following{/other_user}","gists_url":"https://api.github.com/users/ouchadam/gists{/gist_id}","starred_url":"https://api.github.com/users/ouchadam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ouchadam/subscriptions","organizations_url":"https://api.github.com/users/ouchadam/orgs","repos_url":"https://api.github.com/users/ouchadam/repos","events_url":"https://api.github.com/users/ouchadam/events{/privacy}","received_events_url":"https://api.github.com/users/ouchadam/received_events","type":"User","site_admin":false},"body":"`isAllowedToDownload` was still being called on queued downloads whilst the download table changed! But it also ran the check for each item within a batch.\r\n\r\nThis PR introduced refactorings around the `canDownload` checks to be able to use them on a batch level. We also now query for the batches by their _id ordering to make sure the most recently added item is checked first.\r\n\r\n- Adds a top level `isActive` flag from all the batches instead of iterating through, this allows us to only ask if the client is ready if a download is currently not in progress (we had this before on each iteration but the ordering meant we were out of sync).\r\n\r\n- extracts all the `downloadManagerIsReady` logic into the DownloadReadyChecker instead of living on the `FileDownloadInfo` and separates out the networking logic.\r\n\r\n- moves the download deletion and next retry time to the batch level\r\n\r\n- big ol' refactoring of the FileDownloadInfo to pull out as much behaviour and dependencies as possible #92 ","created_at":"2015-07-09T17:13:41Z","updated_at":"2015-07-13T13:14:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"28ea8154480527656ce77b2b6304fe66c7ddb12f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/novoda/download-manager/pulls/89/commits","review_comments_url":"https://api.github.com/repos/novoda/download-manager/pulls/89/comments","review_comment_url":"https://api.github.com/repos/novoda/download-manager/pulls/comments{/number}","comments_url":"https://api.github.com/repos/novoda/download-manager/issues/89/comments","statuses_url":"https://api.github.com/repos/novoda/download-manager/statuses/a2268c12a4fff43432f3682dcfd98202adc95bfd","head":{"label":"novoda:only-check-current-download","ref":"only-check-current-download","sha":"a2268c12a4fff43432f3682dcfd98202adc95bfd","user":{"login":"novoda","id":74874,"avatar_url":"https://avatars.githubusercontent.com/u/74874?v=3","gravatar_id":"","url":"https://api.github.com/users/novoda","html_url":"https://github.com/novoda","followers_url":"https://api.github.com/users/novoda/followers","following_url":"https://api.github.com/users/novoda/following{/other_user}","gists_url":"https://api.github.com/users/novoda/gists{/gist_id}","starred_url":"https://api.github.com/users/novoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/novoda/subscriptions","organizations_url":"https://api.github.com/users/novoda/orgs","repos_url":"https://api.github.com/users/novoda/repos","events_url":"https://api.github.com/users/novoda/events{/privacy}","received_events_url":"https://api.github.com/users/novoda/received_events","type":"Organization","site_admin":false},"repo":{"id":35211795,"name":"download-manager","full_name":"novoda/download-manager","owner":{"login":"novoda","id":74874,"avatar_url":"https://avatars.githubusercontent.com/u/74874?v=3","gravatar_id":"","url":"https://api.github.com/users/novoda","html_url":"https://github.com/novoda","followers_url":"https://api.github.com/users/novoda/followers","following_url":"https://api.github.com/users/novoda/following{/other_user}","gists_url":"https://api.github.com/users/novoda/gists{/gist_id}","starred_url":"https://api.github.com/users/novoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/novoda/subscriptions","organizations_url":"https://api.github.com/users/novoda/orgs","repos_url":"https://api.github.com/users/novoda/repos","events_url":"https://api.github.com/users/novoda/events{/privacy}","received_events_url":"https://api.github.com/users/novoda/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/novoda/download-manager","description":"Download manager based on AOSP DM but allowing downloading to internal private storage","fork":false,"url":"https://api.github.com/repos/novoda/download-manager","forks_url":"https://api.github.com/repos/novoda/download-manager/forks","keys_url":"https://api.github.com/repos/novoda/download-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/novoda/download-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/novoda/download-manager/teams","hooks_url":"https://api.github.com/repos/novoda/download-manager/hooks","issue_events_url":"https://api.github.com/repos/novoda/download-manager/issues/events{/number}","events_url":"https://api.github.com/repos/novoda/download-manager/events","assignees_url":"https://api.github.com/repos/novoda/download-manager/assignees{/user}","branches_url":"https://api.github.com/repos/novoda/download-manager/branches{/branch}","tags_url":"https://api.github.com/repos/novoda/download-manager/tags","blobs_url":"https://api.github.com/repos/novoda/download-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/novoda/download-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/novoda/download-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/novoda/download-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/novoda/download-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/novoda/download-manager/languages","stargazers_url":"https://api.github.com/repos/novoda/download-manager/stargazers","contributors_url":"https://api.github.com/repos/novoda/download-manager/contributors","subscribers_url":"https://api.github.com/repos/novoda/download-manager/subscribers","subscription_url":"https://api.github.com/repos/novoda/download-manager/subscription","commits_url":"https://api.github.com/repos/novoda/download-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/novoda/download-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/novoda/download-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/novoda/download-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/novoda/download-manager/contents/{+path}","compare_url":"https://api.github.com/repos/novoda/download-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/novoda/download-manager/merges","archive_url":"https://api.github.com/repos/novoda/download-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/novoda/download-manager/downloads","issues_url":"https://api.github.com/repos/novoda/download-manager/issues{/number}","pulls_url":"https://api.github.com/repos/novoda/download-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/novoda/download-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/novoda/download-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/novoda/download-manager/labels{/name}","releases_url":"https://api.github.com/repos/novoda/download-manager/releases{/id}","created_at":"2015-05-07T09:41:52Z","updated_at":"2015-07-09T19:32:16Z","pushed_at":"2015-07-13T11:24:25Z","git_url":"git://github.com/novoda/download-manager.git","ssh_url":"git@github.com:novoda/download-manager.git","clone_url":"https://github.com/novoda/download-manager.git","svn_url":"https://github.com/novoda/download-manager","homepage":"","size":3762,"stargazers_count":51,"watchers_count":51,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":18,"forks":4,"open_issues":18,"watchers":51,"default_branch":"master"}},"base":{"label":"novoda:master","ref":"master","sha":"a589cc8235bbc105a05fbc0025b54ea4796198c0","user":{"login":"novoda","id":74874,"avatar_url":"https://avatars.githubusercontent.com/u/74874?v=3","gravatar_id":"","url":"https://api.github.com/users/novoda","html_url":"https://github.com/novoda","followers_url":"https://api.github.com/users/novoda/followers","following_url":"https://api.github.com/users/novoda/following{/other_user}","gists_url":"https://api.github.com/users/novoda/gists{/gist_id}","starred_url":"https://api.github.com/users/novoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/novoda/subscriptions","organizations_url":"https://api.github.com/users/novoda/orgs","repos_url":"https://api.github.com/users/novoda/repos","events_url":"https://api.github.com/users/novoda/events{/privacy}","received_events_url":"https://api.github.com/users/novoda/received_events","type":"Organization","site_admin":false},"repo":{"id":35211795,"name":"download-manager","full_name":"novoda/download-manager","owner":{"login":"novoda","id":74874,"avatar_url":"https://avatars.githubusercontent.com/u/74874?v=3","gravatar_id":"","url":"https://api.github.com/users/novoda","html_url":"https://github.com/novoda","followers_url":"https://api.github.com/users/novoda/followers","following_url":"https://api.github.com/users/novoda/following{/other_user}","gists_url":"https://api.github.com/users/novoda/gists{/gist_id}","starred_url":"https://api.github.com/users/novoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/novoda/subscriptions","organizations_url":"https://api.github.com/users/novoda/orgs","repos_url":"https://api.github.com/users/novoda/repos","events_url":"https://api.github.com/users/novoda/events{/privacy}","received_events_url":"https://api.github.com/users/novoda/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/novoda/download-manager","description":"Download manager based on AOSP DM but allowing downloading to internal private storage","fork":false,"url":"https://api.github.com/repos/novoda/download-manager","forks_url":"https://api.github.com/repos/novoda/download-manager/forks","keys_url":"https://api.github.com/repos/novoda/download-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/novoda/download-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/novoda/download-manager/teams","hooks_url":"https://api.github.com/repos/novoda/download-manager/hooks","issue_events_url":"https://api.github.com/repos/novoda/download-manager/issues/events{/number}","events_url":"https://api.github.com/repos/novoda/download-manager/events","assignees_url":"https://api.github.com/repos/novoda/download-manager/assignees{/user}","branches_url":"https://api.github.com/repos/novoda/download-manager/branches{/branch}","tags_url":"https://api.github.com/repos/novoda/download-manager/tags","blobs_url":"https://api.github.com/repos/novoda/download-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/novoda/download-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/novoda/download-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/novoda/download-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/novoda/download-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/novoda/download-manager/languages","stargazers_url":"https://api.github.com/repos/novoda/download-manager/stargazers","contributors_url":"https://api.github.com/repos/novoda/download-manager/contributors","subscribers_url":"https://api.github.com/repos/novoda/download-manager/subscribers","subscription_url":"https://api.github.com/repos/novoda/download-manager/subscription","commits_url":"https://api.github.com/repos/novoda/download-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/novoda/download-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/novoda/download-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/novoda/download-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/novoda/download-manager/contents/{+path}","compare_url":"https://api.github.com/repos/novoda/download-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/novoda/download-manager/merges","archive_url":"https://api.github.com/repos/novoda/download-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/novoda/download-manager/downloads","issues_url":"https://api.github.com/repos/novoda/download-manager/issues{/number}","pulls_url":"https://api.github.com/repos/novoda/download-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/novoda/download-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/novoda/download-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/novoda/download-manager/labels{/name}","releases_url":"https://api.github.com/repos/novoda/download-manager/releases{/id}","created_at":"2015-05-07T09:41:52Z","updated_at":"2015-07-09T19:32:16Z","pushed_at":"2015-07-13T11:24:25Z","git_url":"git://github.com/novoda/download-manager.git","ssh_url":"git@github.com:novoda/download-manager.git","clone_url":"https://github.com/novoda/download-manager.git","svn_url":"https://github.com/novoda/download-manager","homepage":"","size":3762,"stargazers_count":51,"watchers_count":51,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":18,"forks":4,"open_issues":18,"watchers":51,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/novoda/download-manager/pulls/89"},"html":{"href":"https://github.com/novoda/download-manager/pull/89"},"issue":{"href":"https://api.github.com/repos/novoda/download-manager/issues/89"},"comments":{"href":"https://api.github.com/repos/novoda/download-manager/issues/89/comments"},"review_comments":{"href":"https://api.github.com/repos/novoda/download-manager/pulls/89/comments"},"review_comment":{"href":"https://api.github.com/repos/novoda/download-manager/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/novoda/download-manager/pulls/89/commits"},"statuses":{"href":"https://api.github.com/repos/novoda/download-manager/statuses/a2268c12a4fff43432f3682dcfd98202adc95bfd"}}}}