summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTORS1
-rw-r--r--app/src/main/AndroidManifest.xml7
-rw-r--r--app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java45
3 files changed, 53 insertions, 0 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 0d83fd483..2c8c15bf5 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -9,6 +9,7 @@ wseemann
hzulla
andrewgaul
peschmae0
+TomHennen
Translations:
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 50d1d2874..1da507c84 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -304,6 +304,13 @@
</intent-filter>
</receiver>
+ <receiver android:name=".receiver.PowerConnectionReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
+ <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
+ </intent-filter>
+ </receiver>
+
<receiver android:name=".receiver.SPAReceiver">
<intent-filter>
<action android:name="de.danoeh.antennapdsp.intent.SP_APPS_QUERY_FEEDS_RESPONSE"/>
diff --git a/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java b/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java
new file mode 100644
index 000000000..0e7784381
--- /dev/null
+++ b/app/src/main/java/de/danoeh/antennapod/receiver/PowerConnectionReceiver.java
@@ -0,0 +1,45 @@
+package de.danoeh.antennapod.receiver;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.BatteryManager;
+import android.util.Log;
+
+import de.danoeh.antennapod.core.BuildConfig;
+import de.danoeh.antennapod.core.preferences.UserPreferences;
+import de.danoeh.antennapod.core.storage.DBTasks;
+import de.danoeh.antennapod.core.storage.DownloadRequester;
+
+// modified from http://developer.android.com/training/monitoring-device-state/battery-monitoring.html
+// and ConnectivityActionReceiver.java
+public class PowerConnectionReceiver extends BroadcastReceiver {
+ private static final String TAG = "PowerConnectionReceiver";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+ boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
+ status == BatteryManager.BATTERY_STATUS_FULL;
+
+ if (isCharging) {
+ Log.d(TAG, "charging, starting auto-download");
+ // we're plugged in, this is a great time to auto-download if everything else is
+ // right. So, even if the user allows auto-dl on battery, let's still start
+ // downloading now. They shouldn't mind.
+ // autodownloadUndownloadedItems will make sure we're on the right wifi networks,
+ // etc... so we don't have to worry about it.
+ DBTasks.autodownloadUndownloadedItems(context);
+ } else {
+ // if we're not supposed to be auto-downloading when we're not charging, stop it
+ if (!UserPreferences.isEnableAutodownloadOnBattery()) {
+ Log.d(TAG, "not charging anymore, canceling auto-download");
+ DownloadRequester.getInstance().cancelAllDownloads(context);
+ } else {
+ Log.d(TAG, "not charging anymore, but the user allows auto-download " +
+ "when on battery so we'll keep going");
+ }
+ }
+
+ }
+}