diff --git a/res/values/strings.xml b/res/values/strings.xml index 024321b01..cb4f58987 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -86,8 +86,10 @@ Update intervall Specify an intervall in which the feeds are refreshed automatically or disable it Download media files only over WiFi - Follow queue + Continuous playback WiFi media download Headset disconnect + Mobile Updates + Allow updates over the mobile data connection \ No newline at end of file diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index e7953efc7..b962ec090 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -30,6 +30,13 @@ android:key="prefAutoUpdateIntervall" android:summary="@string/pref_autoUpdateIntervall_sum" android:title="@string/pref_autoUpdateIntervall_title" /> + + diff --git a/src/de/podfetcher/PodcastApp.java b/src/de/podfetcher/PodcastApp.java index 0b2da0e99..4ecc553ba 100644 --- a/src/de/podfetcher/PodcastApp.java +++ b/src/de/podfetcher/PodcastApp.java @@ -24,6 +24,7 @@ public class PodcastApp extends Application implements public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue"; public static final String PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY = "prefDownloadMediaOnWifiOnly"; public static final String PREF_UPDATE_INTERVALL = "prefAutoUpdateIntervall"; + public static final String PREF_MOBILE_UPDATE = "prefMobileUpdate"; private static PodcastApp singleton; diff --git a/src/de/podfetcher/receiver/FeedUpdateReceiver.java b/src/de/podfetcher/receiver/FeedUpdateReceiver.java index 1556a33ef..50b2b0ab5 100644 --- a/src/de/podfetcher/receiver/FeedUpdateReceiver.java +++ b/src/de/podfetcher/receiver/FeedUpdateReceiver.java @@ -1,22 +1,42 @@ package de.podfetcher.receiver; +import de.podfetcher.PodcastApp; import de.podfetcher.feed.FeedManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.preference.PreferenceManager; import android.util.Log; /** Refreshes all feeds when it receives an intent */ public class FeedUpdateReceiver extends BroadcastReceiver { private static final String TAG = "FeedUpdateReceiver"; public static final String ACTION_REFRESH_FEEDS = "de.podfetcher.feedupdatereceiver.refreshFeeds"; - + @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_REFRESH_FEEDS)) { Log.d(TAG, "Received intent"); - FeedManager.getInstance().refreshAllFeeds(context); + boolean mobileUpdate = PreferenceManager + .getDefaultSharedPreferences( + context.getApplicationContext()).getBoolean( + PodcastApp.PREF_MOBILE_UPDATE, false); + if (mobileUpdate || connectedToWifi(context)) { + FeedManager.getInstance().refreshAllFeeds(context); + } else { + Log.d(TAG, + "Blocking automatic update: no wifi available / no mobile updates allowed"); + } } } + private boolean connectedToWifi(Context context) { + ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + + return mWifi.isConnected(); + } + }