Merge pull request #3461 from ByteHamster/do-not-notify-cancelled-downloads
Do not notify cancelled downloads
This commit is contained in:
commit
fb377258f2
@ -13,6 +13,7 @@ import android.os.Build;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -190,10 +191,8 @@ public class DownloadService extends Service {
|
|||||||
handleFailedDownload(status, downloader.getDownloadRequest());
|
handleFailedDownload(status, downloader.getDownloadRequest());
|
||||||
|
|
||||||
if (type == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
if (type == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
long id = status.getFeedfileId();
|
FeedItem item = getFeedItemFromId(status.getFeedfileId());
|
||||||
FeedMedia media = DBReader.getFeedMedia(id);
|
if (item == null) {
|
||||||
FeedItem item;
|
|
||||||
if (media == null || (item = media.getItem()) == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean httpNotFound = status.getReason() == DownloadError.ERROR_HTTP_DATA_ERROR
|
boolean httpNotFound = status.getReason() == DownloadError.ERROR_HTTP_DATA_ERROR
|
||||||
@ -213,9 +212,8 @@ public class DownloadService extends Service {
|
|||||||
// if FeedMedia download has been canceled, fake FeedItem update
|
// if FeedMedia download has been canceled, fake FeedItem update
|
||||||
// so that lists reload that it
|
// so that lists reload that it
|
||||||
if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
|
FeedItem item = getFeedItemFromId(status.getFeedfileId());
|
||||||
FeedItem item;
|
if (item == null) {
|
||||||
if (media == null || (item = media.getItem()) == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EventBus.getDefault().post(FeedItemEvent.updated(item));
|
EventBus.getDefault().post(FeedItemEvent.updated(item));
|
||||||
@ -386,6 +384,12 @@ public class DownloadService extends Service {
|
|||||||
Downloader d = getDownloader(url);
|
Downloader d = getDownloader(url);
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
d.cancel();
|
d.cancel();
|
||||||
|
DownloadRequester.getInstance().removeDownload(d.getDownloadRequest());
|
||||||
|
|
||||||
|
FeedItem item = getFeedItemFromId(d.getDownloadRequest().getFeedfileId());
|
||||||
|
if (item != null) {
|
||||||
|
EventBus.getDefault().post(FeedItemEvent.updated(item));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Could not cancel download with url " + url);
|
Log.e(TAG, "Could not cancel download with url " + url);
|
||||||
}
|
}
|
||||||
@ -578,6 +582,16 @@ public class DownloadService extends Service {
|
|||||||
syncExecutor.execute(new FailedDownloadHandler(status, request));
|
syncExecutor.execute(new FailedDownloadHandler(status, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private FeedItem getFeedItemFromId(long id) {
|
||||||
|
FeedMedia media = DBReader.getFeedMedia(id);
|
||||||
|
if (media != null) {
|
||||||
|
return media.getItem();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a single Feed, parses the corresponding file and refreshes
|
* Takes a single Feed, parses the corresponding file and refreshes
|
||||||
* information in the manager
|
* information in the manager
|
||||||
@ -1058,7 +1072,13 @@ public class DownloadService extends Service {
|
|||||||
private final Runnable postDownloaderTask = new Runnable() {
|
private final Runnable postDownloaderTask = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
List<Downloader> list = Collections.unmodifiableList(downloads);
|
List<Downloader> runningDownloads = new ArrayList<>();
|
||||||
|
for (Downloader downloader : downloads) {
|
||||||
|
if (!downloader.cancelled) {
|
||||||
|
runningDownloads.add(downloader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Downloader> list = Collections.unmodifiableList(runningDownloads);
|
||||||
EventBus.getDefault().postSticky(DownloadEvent.refresh(list));
|
EventBus.getDefault().postSticky(DownloadEvent.refresh(list));
|
||||||
postHandler.postDelayed(postDownloaderTask, 1500);
|
postHandler.postDelayed(postDownloaderTask, 1500);
|
||||||
}
|
}
|
||||||
@ -1076,6 +1096,9 @@ public class DownloadService extends Service {
|
|||||||
private static String compileNotificationString(List<Downloader> downloads) {
|
private static String compileNotificationString(List<Downloader> downloads) {
|
||||||
List<String> lines = new ArrayList<>(downloads.size());
|
List<String> lines = new ArrayList<>(downloads.size());
|
||||||
for (Downloader downloader : downloads) {
|
for (Downloader downloader : downloads) {
|
||||||
|
if (downloader.cancelled) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
StringBuilder line = new StringBuilder("• ");
|
StringBuilder line = new StringBuilder("• ");
|
||||||
DownloadRequest request = downloader.getDownloadRequest();
|
DownloadRequest request = downloader.getDownloadRequest();
|
||||||
switch (request.getFeedfileType()) {
|
switch (request.getFeedfileType()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user