Refactoring
This commit is contained in:
parent
1bd6bf76f6
commit
f8bb78d436
|
@ -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");
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue