Initialize NetworkUtils, set context once
Had some issues with the new NetworkAllowanceInterceptor. When I gave it a constructor that would hold the context (to use it with NetworkUtils), the whole Glide image loading process would not work.
This commit is contained in:
parent
65d470043b
commit
ab116ee6be
@ -8,6 +8,7 @@ import de.danoeh.antennapod.core.feed.EventDistributor;
|
|||||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.service.FeedMediaSizeService;
|
import de.danoeh.antennapod.core.service.FeedMediaSizeService;
|
||||||
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
import de.danoeh.antennapod.spa.SPAUtil;
|
import de.danoeh.antennapod.spa.SPAUtil;
|
||||||
|
|
||||||
/** Main application class. */
|
/** Main application class. */
|
||||||
@ -41,6 +42,7 @@ public class PodcastApp extends Application {
|
|||||||
UpdateManager.init(this);
|
UpdateManager.init(this);
|
||||||
UserPreferences.init(this);
|
UserPreferences.init(this);
|
||||||
PlaybackPreferences.init(this);
|
PlaybackPreferences.init(this);
|
||||||
|
NetworkUtils.init(this);
|
||||||
EventDistributor.getInstance();
|
EventDistributor.getInstance();
|
||||||
|
|
||||||
SPAUtil.sendSPAppsQueryFeedsIntent(this);
|
SPAUtil.sendSPAppsQueryFeedsIntent(this);
|
||||||
|
@ -12,11 +12,8 @@ import de.danoeh.antennapod.R;
|
|||||||
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
|
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||||
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction;
|
|
||||||
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
|
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
@ -61,7 +58,7 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||||||
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
|
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
|
||||||
if (!isDownloading && !media.isDownloaded()) {
|
if (!isDownloading && !media.isDownloaded()) {
|
||||||
LongList queueIds = DBReader.getQueueIDList(context);
|
LongList queueIds = DBReader.getQueueIDList(context);
|
||||||
if (NetworkUtils.isDownloadAllowed(context) || userAllowedMobileDownloads()) {
|
if (NetworkUtils.isDownloadAllowed() || userAllowedMobileDownloads()) {
|
||||||
try {
|
try {
|
||||||
DBTasks.downloadFeedItems(context, item);
|
DBTasks.downloadFeedItems(context, item);
|
||||||
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
|
||||||
|
@ -9,7 +9,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.BuildConfig;
|
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||||
@ -20,13 +19,10 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(final Context context, Intent intent) {
|
public void onReceive(final Context context, Intent intent) {
|
||||||
if (StringUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) {
|
if (StringUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "Received intent");
|
||||||
Log.d(TAG, "Received intent");
|
|
||||||
|
|
||||||
if (NetworkUtils.autodownloadNetworkAvailable(context)) {
|
if (NetworkUtils.autodownloadNetworkAvailable()) {
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "auto-dl network available, starting auto-download");
|
||||||
Log.d(TAG,
|
|
||||||
"auto-dl network available, starting auto-download");
|
|
||||||
DBTasks.autodownloadUndownloadedItems(context);
|
DBTasks.autodownloadUndownloadedItems(context);
|
||||||
} else { // if new network is Wi-Fi, finish ongoing downloads,
|
} else { // if new network is Wi-Fi, finish ongoing downloads,
|
||||||
// otherwise cancel all downloads
|
// otherwise cancel all downloads
|
||||||
@ -34,12 +30,9 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
|
|||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
NetworkInfo ni = cm.getActiveNetworkInfo();
|
NetworkInfo ni = cm.getActiveNetworkInfo();
|
||||||
if (ni == null || ni.getType() != ConnectivityManager.TYPE_WIFI) {
|
if (ni == null || ni.getType() != ConnectivityManager.TYPE_WIFI) {
|
||||||
if (BuildConfig.DEBUG)
|
Log.i(TAG, "Device is no longer connected to Wi-Fi. Cancelling ongoing downloads");
|
||||||
Log.i(TAG,
|
|
||||||
"Device is no longer connected to Wi-Fi. Cancelling ongoing downloads");
|
|
||||||
DownloadRequester.getInstance().cancelAllDownloads(context);
|
DownloadRequester.getInstance().cancelAllDownloads(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public class FlattrClickWorker extends AsyncTask<Void, Integer, FlattrClickWorke
|
|||||||
return ExitCode.NO_TOKEN;
|
return ExitCode.NO_TOKEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NetworkUtils.networkAvailable(context)) {
|
if (!NetworkUtils.networkAvailable()) {
|
||||||
return ExitCode.NO_NETWORK;
|
return ExitCode.NO_NETWORK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public class FeedUpdateReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.d(TAG, "Received intent");
|
Log.d(TAG, "Received intent");
|
||||||
if (NetworkUtils.isDownloadAllowed(context)) {
|
if (NetworkUtils.isDownloadAllowed()) {
|
||||||
DBTasks.refreshAllFeeds(context, null);
|
DBTasks.refreshAllFeeds(context, null);
|
||||||
} else {
|
} else {
|
||||||
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");
|
||||||
|
@ -28,13 +28,13 @@ public class FeedMediaSizeService extends IntentService {
|
|||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
Log.d(TAG, "onHandleIntent()");
|
Log.d(TAG, "onHandleIntent()");
|
||||||
if(false == NetworkUtils.isDownloadAllowed(this)) {
|
if(false == NetworkUtils.isDownloadAllowed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<FeedMedia> list = DBReader.getFeedMediaUnknownSize(this);
|
List<FeedMedia> list = DBReader.getFeedMediaUnknownSize(this);
|
||||||
for (FeedMedia media : list) {
|
for (FeedMedia media : list) {
|
||||||
Log.d(TAG, "Getting size currently " + media.getSize() + " for " + media.getDownload_url());
|
Log.d(TAG, "Getting size currently " + media.getSize() + " for " + media.getDownload_url());
|
||||||
if(false == NetworkUtils.isDownloadAllowed(this)) {
|
if(false == NetworkUtils.isDownloadAllowed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long size = Integer.MIN_VALUE;
|
long size = Integer.MIN_VALUE;
|
||||||
|
@ -108,7 +108,7 @@ public class GpodnetSyncService extends Service {
|
|||||||
|
|
||||||
|
|
||||||
private synchronized void sync() {
|
private synchronized void sync() {
|
||||||
if (GpodnetPreferences.loggedIn() == false || NetworkUtils.networkAvailable(this) == false) {
|
if (GpodnetPreferences.loggedIn() == false || NetworkUtils.networkAvailable() == false) {
|
||||||
stopSelf();
|
stopSelf();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
|||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
// true if we should auto download based on network status
|
// true if we should auto download based on network status
|
||||||
boolean networkShouldAutoDl = NetworkUtils.autodownloadNetworkAvailable(context)
|
boolean networkShouldAutoDl = NetworkUtils.autodownloadNetworkAvailable()
|
||||||
&& UserPreferences.isEnableAutodownload();
|
&& UserPreferences.isEnableAutodownload();
|
||||||
|
|
||||||
// true if we should auto download based on power status
|
// true if we should auto download based on power status
|
||||||
|
@ -10,14 +10,16 @@ import android.util.Log;
|
|||||||
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;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
|
||||||
public class NetworkUtils {
|
public class NetworkUtils {
|
||||||
private static final String TAG = "NetworkUtils";
|
|
||||||
|
|
||||||
private NetworkUtils() {
|
private static final String TAG = NetworkUtils.class.getSimpleName();
|
||||||
|
|
||||||
|
private static Context context;
|
||||||
|
|
||||||
|
public static void init(Context context) {
|
||||||
|
NetworkUtils.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,18 +28,16 @@ public class NetworkUtils {
|
|||||||
* network that is on the 'selected networks' list of the Wi-Fi filter for
|
* network that is on the 'selected networks' list of the Wi-Fi filter for
|
||||||
* automatic downloads and false otherwise.
|
* automatic downloads and false otherwise.
|
||||||
* */
|
* */
|
||||||
public static boolean autodownloadNetworkAvailable(Context context) {
|
public static boolean autodownloadNetworkAvailable() {
|
||||||
ConnectivityManager cm = (ConnectivityManager) context
|
ConnectivityManager cm = (ConnectivityManager) context
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||||
if (networkInfo != null) {
|
if (networkInfo != null) {
|
||||||
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "Device is connected to Wi-Fi");
|
||||||
Log.d(TAG, "Device is connected to Wi-Fi");
|
|
||||||
if (networkInfo.isConnected()) {
|
if (networkInfo.isConnected()) {
|
||||||
if (!UserPreferences.isEnableAutodownloadWifiFilter()) {
|
if (!UserPreferences.isEnableAutodownloadWifiFilter()) {
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "Auto-dl filter is disabled");
|
||||||
Log.d(TAG, "Auto-dl filter is disabled");
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
WifiManager wm = (WifiManager) context
|
WifiManager wm = (WifiManager) context
|
||||||
@ -48,31 +48,28 @@ public class NetworkUtils {
|
|||||||
.getAutodownloadSelectedNetworks());
|
.getAutodownloadSelectedNetworks());
|
||||||
if (selectedNetworks.contains(Integer.toString(wifiInfo
|
if (selectedNetworks.contains(Integer.toString(wifiInfo
|
||||||
.getNetworkId()))) {
|
.getNetworkId()))) {
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "Current network is on the selected networks list");
|
||||||
Log.d(TAG,
|
|
||||||
"Current network is on the selected networks list");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "Network for auto-dl is not available");
|
||||||
Log.d(TAG, "Network for auto-dl is not available");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean networkAvailable(Context context) {
|
public static boolean networkAvailable() {
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
NetworkInfo info = cm.getActiveNetworkInfo();
|
NetworkInfo info = cm.getActiveNetworkInfo();
|
||||||
return info != null && info.isConnected();
|
return info != null && info.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDownloadAllowed(Context context) {
|
public static boolean isDownloadAllowed() {
|
||||||
return UserPreferences.isAllowMobileUpdate() || NetworkUtils.connectedToWifi(context);
|
return UserPreferences.isAllowMobileUpdate() || NetworkUtils.connectedToWifi();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean connectedToWifi(Context context) {
|
public static boolean connectedToWifi() {
|
||||||
ConnectivityManager connManager = (ConnectivityManager) context
|
ConnectivityManager connManager = (ConnectivityManager) context
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
NetworkInfo mWifi = connManager
|
NetworkInfo mWifi = connManager
|
||||||
|
Loading…
x
Reference in New Issue
Block a user