mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-10 07:53:02 +01:00
Improved behavior of download reports
This commit is contained in:
parent
6ed19acd34
commit
fe2aa9a403
@ -67,9 +67,6 @@ public class DownloadService extends Service {
|
|||||||
public static final String ACTION_CANCEL_DOWNLOAD = "action.de.danoeh.antennapod.service.cancelDownload";
|
public static final String ACTION_CANCEL_DOWNLOAD = "action.de.danoeh.antennapod.service.cancelDownload";
|
||||||
public static final String ACTION_CANCEL_ALL_DOWNLOADS = "action.de.danoeh.antennapod.service.cancelAllDownloads";
|
public static final String ACTION_CANCEL_ALL_DOWNLOADS = "action.de.danoeh.antennapod.service.cancelAllDownloads";
|
||||||
|
|
||||||
/** Is used for sending the delete intent for the report notification */
|
|
||||||
private static final String ACTION_REPORT_DELETED = "action.de.danoeh.antennapod.service.reportDeleted";
|
|
||||||
|
|
||||||
/** Extra for ACTION_CANCEL_DOWNLOAD */
|
/** Extra for ACTION_CANCEL_DOWNLOAD */
|
||||||
public static final String EXTRA_DOWNLOAD_URL = "downloadUrl";
|
public static final String EXTRA_DOWNLOAD_URL = "downloadUrl";
|
||||||
|
|
||||||
@ -150,7 +147,6 @@ public class DownloadService extends Service {
|
|||||||
cancelDownloadReceiverFilter.addAction(ACTION_CANCEL_ALL_DOWNLOADS);
|
cancelDownloadReceiverFilter.addAction(ACTION_CANCEL_ALL_DOWNLOADS);
|
||||||
cancelDownloadReceiverFilter.addAction(ACTION_CANCEL_DOWNLOAD);
|
cancelDownloadReceiverFilter.addAction(ACTION_CANCEL_DOWNLOAD);
|
||||||
registerReceiver(cancelDownloadReceiver, cancelDownloadReceiverFilter);
|
registerReceiver(cancelDownloadReceiver, cancelDownloadReceiverFilter);
|
||||||
registerReceiver(reportDeleted, new IntentFilter(ACTION_REPORT_DELETED));
|
|
||||||
syncExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
|
syncExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -411,36 +407,41 @@ public class DownloadService extends Service {
|
|||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BroadcastReceiver reportDeleted = new BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (intent.getAction().equals(ACTION_REPORT_DELETED)) {
|
|
||||||
completedDownloads.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a notification at the end of the service lifecycle to notify the
|
* Creates a notification at the end of the service lifecycle to notify the
|
||||||
* user about the number of completed downloads. A report will only be
|
* user about the number of completed downloads. A report will only be
|
||||||
* created if the number of feeds is > 1 or if at least one media file was
|
* created if the number of successfully downloaded feeds is bigger than 1
|
||||||
* downloaded.
|
* or if there is at least one failed download or if there is at least
|
||||||
|
* one downloaded media file.
|
||||||
*/
|
*/
|
||||||
private void updateReport() {
|
private void updateReport() {
|
||||||
// check if report should be created
|
// check if report should be created
|
||||||
if (!completedDownloads.isEmpty()) {
|
boolean createReport = false;
|
||||||
if (AppConfig.DEBUG)
|
int successfulFeedDownloads = 0;
|
||||||
Log.d(TAG, "Creating report");
|
|
||||||
int successfulDownloads = 0;
|
int successfulDownloads = 0;
|
||||||
int failedDownloads = 0;
|
int failedDownloads = 0;
|
||||||
|
|
||||||
for (DownloadStatus status : completedDownloads) {
|
for (DownloadStatus status : completedDownloads) {
|
||||||
if (status.isSuccessful()) {
|
if (status.isSuccessful()) {
|
||||||
|
if (status.getFeedFile().getClass() == Feed.class) {
|
||||||
|
successfulFeedDownloads++;
|
||||||
|
} else if (status.getFeedFile().getClass() == FeedMedia.class) {
|
||||||
|
createReport = true;
|
||||||
|
}
|
||||||
successfulDownloads++;
|
successfulDownloads++;
|
||||||
} else {
|
} else {
|
||||||
|
createReport = true;
|
||||||
failedDownloads++;
|
failedDownloads++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (successfulFeedDownloads > 1) {
|
||||||
|
createReport = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createReport) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Creating report");
|
||||||
// create notification object
|
// create notification object
|
||||||
Notification notification = new NotificationCompat.Builder(this)
|
Notification notification = new NotificationCompat.Builder(this)
|
||||||
.setTicker(
|
.setTicker(
|
||||||
@ -457,19 +458,14 @@ public class DownloadService extends Service {
|
|||||||
.setContentIntent(
|
.setContentIntent(
|
||||||
PendingIntent.getActivity(this, 0, new Intent(this,
|
PendingIntent.getActivity(this, 0, new Intent(this,
|
||||||
MainActivity.class), 0))
|
MainActivity.class), 0))
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true).getNotification();
|
||||||
.setDeleteIntent(
|
|
||||||
PendingIntent.getBroadcast(this, 0, new Intent(
|
|
||||||
ACTION_REPORT_DELETED),
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT))
|
|
||||||
.getNotification();
|
|
||||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.notify(REPORT_ID, notification);
|
nm.notify(REPORT_ID, notification);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "No report is created");
|
Log.d(TAG, "No report is created");
|
||||||
}
|
}
|
||||||
|
completedDownloads.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if there's something else to download, otherwise stop */
|
/** Check if there's something else to download, otherwise stop */
|
||||||
|
Loading…
Reference in New Issue
Block a user