mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-12-01 12:31:45 +00:00
43 lines
1.5 KiB
Java
43 lines
1.5 KiB
Java
package de.danoeh.antennapod.receiver;
|
|
|
|
import de.danoeh.antennapod.PodcastApp;
|
|
import de.danoeh.antennapod.feed.FeedManager;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.net.ConnectivityManager;
|
|
import android.net.NetworkInfo;
|
|
import android.preference.PreferenceManager;
|
|
import android.util.Log;
|
|
|
|
/** Refreshes all feeds when it receives an intent */
|
|
public class FeedUpdateReceiver extends BroadcastReceiver {
|
|
private static final String TAG = "FeedUpdateReceiver";
|
|
public static final String ACTION_REFRESH_FEEDS = "de.danoeh.antennapod.feedupdatereceiver.refreshFeeds";
|
|
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
if (intent.getAction().equals(ACTION_REFRESH_FEEDS)) {
|
|
Log.d(TAG, "Received intent");
|
|
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();
|
|
}
|
|
|
|
}
|