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.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.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.BuildConfig;
|
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Received intent");
|
Log.d(TAG, "Received intent");
|
||||||
boolean mobileUpdate = UserPreferences.isAllowMobileUpdate();
|
boolean mobileUpdate = UserPreferences.isAllowMobileUpdate();
|
||||||
if (mobileUpdate || connectedToWifi(context)) {
|
if (mobileUpdate || NetworkUtils.connectedToWifi(context)) {
|
||||||
DBTasks.refreshExpiredFeeds(context);
|
DBTasks.refreshExpiredFeeds(context);
|
||||||
} else {
|
} 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.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import de.danoeh.antennapod.core.BuildConfig;
|
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.BuildConfig;
|
||||||
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
|
||||||
public class NetworkUtils {
|
public class NetworkUtils {
|
||||||
private static final String TAG = "NetworkUtils";
|
private static final String TAG = "NetworkUtils";
|
||||||
|
|
||||||
|
@ -66,4 +67,14 @@ public class NetworkUtils {
|
||||||
NetworkInfo info = cm.getActiveNetworkInfo();
|
NetworkInfo info = cm.getActiveNetworkInfo();
|
||||||
return info != null && info.isConnected();
|
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