diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java
index cbd5c0f29..ffac05321 100644
--- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java
+++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java
@@ -195,6 +195,7 @@ public class PreferenceController {
if (newValue instanceof Boolean) {
ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled((Boolean) newValue);
setSelectedNetworksEnabled((Boolean) newValue && UserPreferences.isEnableAutodownloadWifiFilter());
+ ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled((Boolean) newValue);
}
return true;
}
@@ -376,6 +377,8 @@ public class PreferenceController {
setSelectedNetworksEnabled(UserPreferences.isEnableAutodownload()
&& UserPreferences.isEnableAutodownloadWifiFilter());
+ ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY)
+ .setEnabled(UserPreferences.isEnableAutodownload());
}
private void setEpisodeCacheSizeText(int cacheSize) {
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index 5f4a7583d..afb8bb135 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -92,6 +92,11 @@
android:key="prefEnableAutoDl"
android:title="@string/pref_automatic_download_title"
android:defaultValue="false"/>
+
queue = DBReader.getQueue(context);
final List unreadItems = DBReader
.getUnreadItemsList(context);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/PowerUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/PowerUtils.java
new file mode 100644
index 000000000..39deea36a
--- /dev/null
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/PowerUtils.java
@@ -0,0 +1,32 @@
+package de.danoeh.antennapod.core.util;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.BatteryManager;
+
+/**
+ * Created by Tom on 1/5/15.
+ */
+public class PowerUtils {
+
+ private static final String TAG = "PowerUtils";
+
+ private PowerUtils() {
+
+ }
+
+ /**
+ * @return true if the device is charging
+ */
+ public static boolean deviceCharging(Context context) {
+ // from http://developer.android.com/training/monitoring-device-state/battery-monitoring.html
+ IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+ Intent batteryStatus = context.registerReceiver(null, iFilter);
+
+ int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+ return (status == BatteryManager.BATTERY_STATUS_CHARGING ||
+ status == BatteryManager.BATTERY_STATUS_FULL);
+
+ }
+}
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 75376cef8..dcad6c201 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -235,6 +235,8 @@
Configure the automatic download of episodes.
Enable Wi-Fi filter
Allow automatic download only for selected Wi-Fi networks.
+ Automatic download on battery
+ Allow automatic download while on battery
Episode cache
Light
Dark