Added preference to block updates over mobile internet

This commit is contained in:
daniel oeh 2012-07-09 12:05:09 +02:00
parent a05edcb0a4
commit fcbb28981f
4 changed files with 33 additions and 3 deletions

View File

@ -86,8 +86,10 @@
<string name="pref_autoUpdateIntervall_title">Update intervall</string> <string name="pref_autoUpdateIntervall_title">Update intervall</string>
<string name="pref_autoUpdateIntervall_sum">Specify an intervall in which the feeds are refreshed automatically or disable it</string> <string name="pref_autoUpdateIntervall_sum">Specify an intervall in which the feeds are refreshed automatically or disable it</string>
<string name="pref_downloadMediaOnWifiOnly_sum">Download media files only over WiFi</string> <string name="pref_downloadMediaOnWifiOnly_sum">Download media files only over WiFi</string>
<string name="pref_followQueue_title">Follow queue</string> <string name="pref_followQueue_title">Continuous playback</string>
<string name="pref_downloadMediaOnWifiOnly_title">WiFi media download</string> <string name="pref_downloadMediaOnWifiOnly_title">WiFi media download</string>
<string name="pref_pauseOnHeadsetDisconnect_title">Headset disconnect</string> <string name="pref_pauseOnHeadsetDisconnect_title">Headset disconnect</string>
<string name="pref_mobileUpdate_title">Mobile Updates</string>
<string name="pref_mobileUpdate_sum">Allow updates over the mobile data connection</string>
</resources> </resources>

View File

@ -30,6 +30,13 @@
android:key="prefAutoUpdateIntervall" android:key="prefAutoUpdateIntervall"
android:summary="@string/pref_autoUpdateIntervall_sum" android:summary="@string/pref_autoUpdateIntervall_sum"
android:title="@string/pref_autoUpdateIntervall_title" /> android:title="@string/pref_autoUpdateIntervall_title" />
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
android:key="prefMobileUpdate"
android:summary="@string/pref_mobileUpdate_sum"
android:title="@string/pref_mobileUpdate_title" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/other_pref" > <PreferenceCategory android:title="@string/other_pref" >
<Preference android:title="@string/version_pref" /> <Preference android:title="@string/version_pref" />

View File

@ -24,6 +24,7 @@ public class PodcastApp extends Application implements
public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue"; public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue";
public static final String PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY = "prefDownloadMediaOnWifiOnly"; public static final String PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY = "prefDownloadMediaOnWifiOnly";
public static final String PREF_UPDATE_INTERVALL = "prefAutoUpdateIntervall"; public static final String PREF_UPDATE_INTERVALL = "prefAutoUpdateIntervall";
public static final String PREF_MOBILE_UPDATE = "prefMobileUpdate";
private static PodcastApp singleton; private static PodcastApp singleton;

View File

@ -1,22 +1,42 @@
package de.podfetcher.receiver; package de.podfetcher.receiver;
import de.podfetcher.PodcastApp;
import de.podfetcher.feed.FeedManager; import de.podfetcher.feed.FeedManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
/** Refreshes all feeds when it receives an intent */ /** Refreshes all feeds when it receives an intent */
public class FeedUpdateReceiver extends BroadcastReceiver { public class FeedUpdateReceiver extends BroadcastReceiver {
private static final String TAG = "FeedUpdateReceiver"; private static final String TAG = "FeedUpdateReceiver";
public static final String ACTION_REFRESH_FEEDS = "de.podfetcher.feedupdatereceiver.refreshFeeds"; public static final String ACTION_REFRESH_FEEDS = "de.podfetcher.feedupdatereceiver.refreshFeeds";
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_REFRESH_FEEDS)) { if (intent.getAction().equals(ACTION_REFRESH_FEEDS)) {
Log.d(TAG, "Received intent"); 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();
}
} }