Implemented report in Downloadservice
This commit is contained in:
parent
8d065864c5
commit
00c9422191
|
@ -87,7 +87,7 @@
|
||||||
<string name="pref_pauseOnHeadsetDisconnect_title">Headphones disconnect</string>
|
<string name="pref_pauseOnHeadsetDisconnect_title">Headphones disconnect</string>
|
||||||
<string name="pref_mobileUpdate_title">Mobile updates</string>
|
<string name="pref_mobileUpdate_title">Mobile updates</string>
|
||||||
<string name="pref_mobileUpdate_sum">Allow updates over the mobile data connection</string>
|
<string name="pref_mobileUpdate_sum">Allow updates over the mobile data connection</string>
|
||||||
<string name="download_report_title">All downloads completed</string>
|
<string name="download_report_title">Downloads completed</string>
|
||||||
<string name="refresh_label">Refresh</string>
|
<string name="refresh_label">Refresh</string>
|
||||||
<string name="external_storage_error_msg">No external storage is available. Please make sure that external storage is mounted so that the app can work properly.</string>
|
<string name="external_storage_error_msg">No external storage is available. Please make sure that external storage is mounted so that the app can work properly.</string>
|
||||||
<string name="share_link_label">Share link</string>
|
<string name="share_link_label">Share link</string>
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
@ -70,6 +71,9 @@ 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";
|
||||||
|
|
||||||
|
@ -91,7 +95,7 @@ public class DownloadService extends Service {
|
||||||
public static final int DOWNLOAD_TYPE_MEDIA = 2;
|
public static final int DOWNLOAD_TYPE_MEDIA = 2;
|
||||||
public static final int DOWNLOAD_TYPE_IMAGE = 3;
|
public static final int DOWNLOAD_TYPE_IMAGE = 3;
|
||||||
|
|
||||||
private ArrayList<DownloadStatus> completedDownloads;
|
private CopyOnWriteArrayList<DownloadStatus> completedDownloads;
|
||||||
|
|
||||||
private ExecutorService syncExecutor;
|
private ExecutorService syncExecutor;
|
||||||
private ExecutorService downloadExecutor;
|
private ExecutorService downloadExecutor;
|
||||||
|
@ -135,7 +139,8 @@ public class DownloadService extends Service {
|
||||||
Log.d(TAG, "Service started");
|
Log.d(TAG, "Service started");
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
completedDownloads = new ArrayList<DownloadStatus>();
|
completedDownloads = new CopyOnWriteArrayList<DownloadStatus>(
|
||||||
|
new ArrayList<DownloadStatus>());
|
||||||
downloads = new ArrayList<Downloader>();
|
downloads = new ArrayList<Downloader>();
|
||||||
registerReceiver(downloadQueued, new IntentFilter(
|
registerReceiver(downloadQueued, new IntentFilter(
|
||||||
ACTION_ENQUEUE_DOWNLOAD));
|
ACTION_ENQUEUE_DOWNLOAD));
|
||||||
|
@ -144,6 +149,7 @@ 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
|
||||||
|
@ -191,7 +197,6 @@ public class DownloadService extends Service {
|
||||||
mediaplayer.release();
|
mediaplayer.release();
|
||||||
unregisterReceiver(cancelDownloadReceiver);
|
unregisterReceiver(cancelDownloadReceiver);
|
||||||
unregisterReceiver(downloadQueued);
|
unregisterReceiver(downloadQueued);
|
||||||
createReport();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupNotification() {
|
private void setupNotification() {
|
||||||
|
@ -414,29 +419,25 @@ 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 feeds is > 1 or if at least one media file was
|
||||||
* downloaded.
|
* downloaded.
|
||||||
*/
|
*/
|
||||||
private void createReport() {
|
private void updateReport() {
|
||||||
// check if report should be created
|
// check if report should be created
|
||||||
boolean createReport = false;
|
if (!completedDownloads.isEmpty()) {
|
||||||
int feedCount = 0;
|
|
||||||
for (DownloadStatus status : completedDownloads) {
|
|
||||||
if (status.getFeedFile().getClass() == Feed.class) {
|
|
||||||
feedCount++;
|
|
||||||
if (feedCount > 1) {
|
|
||||||
createReport = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (status.getFeedFile().getClass() == FeedMedia.class) {
|
|
||||||
createReport = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (createReport) {
|
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Creating report");
|
Log.d(TAG, "Creating report");
|
||||||
int successfulDownloads = 0;
|
int successfulDownloads = 0;
|
||||||
|
@ -464,7 +465,12 @@ 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).getNotification();
|
.setAutoCancel(true)
|
||||||
|
.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);
|
||||||
|
|
||||||
|
@ -494,6 +500,7 @@ public class DownloadService extends Service {
|
||||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.notify(NOTIFICATION_ID, notificationBuilder.getNotification());
|
nm.notify(NOTIFICATION_ID, notificationBuilder.getNotification());
|
||||||
}
|
}
|
||||||
|
updateReport();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Is called whenever a Feed is downloaded */
|
/** Is called whenever a Feed is downloaded */
|
||||||
|
|
Loading…
Reference in New Issue