Refactoring

This commit is contained in:
Martin Fietz 2015-05-03 18:57:19 +02:00
parent 1bd6bf76f6
commit f8bb78d436
2 changed files with 18 additions and 20 deletions

View File

@ -3,41 +3,28 @@ package de.danoeh.antennapod.core.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
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.util.NetworkUtils;
/**
* Refreshes all feeds when it receives an intent
*/
public class FeedUpdateReceiver extends BroadcastReceiver {
private static final String TAG = "FeedUpdateReceiver";
@Override
public void onReceive(Context context, Intent intent) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Received intent");
Log.d(TAG, "Received intent");
boolean mobileUpdate = UserPreferences.isAllowMobileUpdate();
if (mobileUpdate || connectedToWifi(context)) {
if (mobileUpdate || NetworkUtils.connectedToWifi(context)) {
DBTasks.refreshExpiredFeeds(context);
} else {
if (BuildConfig.DEBUG)
Log.d(TAG,
"Blocking automatic update: no wifi available / no mobile updates allowed");
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();
}
}

View File

@ -6,12 +6,13 @@ import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import java.util.Arrays;
import java.util.List;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.preferences.UserPreferences;
public class NetworkUtils {
private static final String TAG = "NetworkUtils";
@ -66,4 +67,14 @@ public class NetworkUtils {
NetworkInfo info = cm.getActiveNetworkInfo();
return info != null && info.isConnected();
}
public static boolean connectedToWifi(Context context) {
ConnectivityManager connManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return mWifi.isConnected();
}
}