summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-09-14 11:22:32 +0200
committerGitHub <noreply@github.com>2024-09-14 11:22:32 +0200
commitb06caeadec504ef860654e9aca3813bdfabbc2a7 (patch)
tree15c3266f1c1bd586f9c0e10a7c1ba1cb3e9977bc
parent50fa85882e30ceaae38a65aee8f404db854abdf4 (diff)
downloadAntennaPod-b06caeadec504ef860654e9aca3813bdfabbc2a7.zip
Remove WiFi filter setting (#7406)
93% of our users have an Android version modern enough that the setting is not available there anyway. From the remaining 7%, probably only a tiny percentage use that setting. Removing simplifies our code and makes it easier to maintain.
-rw-r--r--net/common/src/main/java/de/danoeh/antennapod/net/common/NetworkUtils.java15
-rw-r--r--storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java20
-rw-r--r--ui/i18n/src/main/res/values/strings.xml2
-rw-r--r--ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/AutoDownloadPreferencesFragment.java145
-rw-r--r--ui/preferences/src/main/res/xml/preferences_autodownload.xml4
5 files changed, 8 insertions, 178 deletions
diff --git a/net/common/src/main/java/de/danoeh/antennapod/net/common/NetworkUtils.java b/net/common/src/main/java/de/danoeh/antennapod/net/common/NetworkUtils.java
index e0559c7ed..ee5897c5e 100644
--- a/net/common/src/main/java/de/danoeh/antennapod/net/common/NetworkUtils.java
+++ b/net/common/src/main/java/de/danoeh/antennapod/net/common/NetworkUtils.java
@@ -5,10 +5,7 @@ import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
-import android.net.wifi.WifiManager;
import android.os.Build;
-import java.util.Arrays;
-import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -30,11 +27,7 @@ public abstract class NetworkUtils {
return false;
}
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
- if (UserPreferences.isEnableAutodownloadWifiFilter()) {
- return isInAllowedWifiNetwork();
- } else {
- return !isNetworkMetered();
- }
+ return !isNetworkMetered();
} else if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
return true;
} else {
@@ -118,12 +111,6 @@ public abstract class NetworkUtils {
}
}
- private static boolean isInAllowedWifiNetwork() {
- WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
- List<String> selectedNetworks = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks());
- return selectedNetworks.contains(Integer.toString(wm.getConnectionInfo().getNetworkId()));
- }
-
public static boolean wasDownloadBlocked(Throwable throwable) {
String message = throwable.getMessage();
if (message != null) {
diff --git a/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
index 608998c00..0162f52bc 100644
--- a/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
+++ b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
@@ -100,8 +100,6 @@ public abstract class UserPreferences {
public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
public static final String PREF_ENABLE_AUTODL = "prefEnableAutoDl";
public static final String PREF_ENABLE_AUTODL_ON_BATTERY = "prefEnableAutoDownloadOnBattery";
- public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter";
- private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks";
private static final String PREF_PROXY_TYPE = "prefProxyType";
private static final String PREF_PROXY_HOST = "prefProxyHost";
private static final String PREF_PROXY_PORT = "prefProxyPort";
@@ -536,19 +534,10 @@ public abstract class UserPreferences {
return prefs.getBoolean(PREF_ENABLE_AUTODL, false);
}
- @VisibleForTesting
- public static void setEnableAutodownload(boolean enabled) {
- prefs.edit().putBoolean(PREF_ENABLE_AUTODL, enabled).apply();
- }
-
public static boolean isEnableAutodownloadOnBattery() {
return prefs.getBoolean(PREF_ENABLE_AUTODL_ON_BATTERY, true);
}
- public static boolean isEnableAutodownloadWifiFilter() {
- return Build.VERSION.SDK_INT < 29 && prefs.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false);
- }
-
public static int getFastForwardSecs() {
return prefs.getInt(PREF_FAST_FORWARD_SECS, 30);
}
@@ -557,11 +546,6 @@ public abstract class UserPreferences {
return prefs.getInt(PREF_REWIND_SECS, 10);
}
- public static String[] getAutodownloadSelectedNetworks() {
- String selectedNetWorks = prefs.getString(PREF_AUTODL_SELECTED_NETWORKS, "");
- return TextUtils.split(selectedNetWorks, ",");
- }
-
public static void setProxyConfig(ProxyConfig config) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PREF_PROXY_TYPE, config.type.name());
@@ -628,10 +612,6 @@ public abstract class UserPreferences {
prefs.edit().putString(PREF_PLAYBACK_SPEED_ARRAY, jsonArray.toString()).apply();
}
- public static void setAutodownloadSelectedNetworks(String[] value) {
- prefs.edit().putString(PREF_AUTODL_SELECTED_NETWORKS, TextUtils.join(",", value)).apply();
- }
-
public static boolean gpodnetNotificationsEnabled() {
if (Build.VERSION.SDK_INT >= 26) {
return true; // System handles notification preferences
diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml
index 268cd6ed3..751dad918 100644
--- a/ui/i18n/src/main/res/values/strings.xml
+++ b/ui/i18n/src/main/res/values/strings.xml
@@ -464,8 +464,6 @@
<string name="pref_nav_drawer_feed_counter_sum">Change the information displayed by the subscription counter. Also affects the sorting of subscriptions if \'Subscription Order\' is set to \'Counter\'.</string>
<string name="pref_automatic_download_title">Automatic download</string>
<string name="pref_automatic_download_sum">Configure the automatic download of episodes</string>
- <string name="pref_autodl_wifi_filter_title">Enable Wi-Fi filter</string>
- <string name="pref_autodl_wifi_filter_sum">Allow automatic download only for selected Wi-Fi networks.</string>
<string name="pref_automatic_download_on_battery_title">Download when not charging</string>
<string name="pref_automatic_download_on_battery_sum">Allow automatic download when the battery is not charging</string>
<string name="pref_episode_cache_title">Episode limit</string>
diff --git a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/AutoDownloadPreferencesFragment.java b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/AutoDownloadPreferencesFragment.java
index 1f0fbfbeb..1660257eb 100644
--- a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/AutoDownloadPreferencesFragment.java
+++ b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/AutoDownloadPreferencesFragment.java
@@ -1,38 +1,24 @@
package de.danoeh.antennapod.ui.preferences.screen;
-import android.annotation.SuppressLint;
-import android.app.Activity;
-import android.content.Context;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiManager;
-import android.os.Build;
import android.os.Bundle;
-import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
-import androidx.preference.CheckBoxPreference;
-import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
-import androidx.preference.PreferenceScreen;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.preferences.R;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
public class AutoDownloadPreferencesFragment extends PreferenceFragmentCompat {
- private static final String TAG = "AutoDnldPrefFragment";
-
- private CheckBoxPreference[] selectedNetworks;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences_autodownload);
- setupAutoDownloadScreen();
- buildAutodownloadSelectedNetworksPreference();
- setSelectedNetworksEnabled(UserPreferences.isEnableAutodownloadWifiFilter());
+ findPreference(UserPreferences.PREF_ENABLE_AUTODL).setOnPreferenceChangeListener(
+ (preference, newValue) -> {
+ if (newValue instanceof Boolean) {
+ checkAutodownloadItemVisibility((Boolean) newValue);
+ }
+ return true;
+ });
}
@Override
@@ -47,125 +33,8 @@ public class AutoDownloadPreferencesFragment extends PreferenceFragmentCompat {
checkAutodownloadItemVisibility(UserPreferences.isEnableAutodownload());
}
- private void setupAutoDownloadScreen() {
- findPreference(UserPreferences.PREF_ENABLE_AUTODL).setOnPreferenceChangeListener(
- (preference, newValue) -> {
- if (newValue instanceof Boolean) {
- checkAutodownloadItemVisibility((Boolean) newValue);
- }
- return true;
- });
- if (Build.VERSION.SDK_INT >= 29) {
- findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setVisible(false);
- }
- findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
- .setOnPreferenceChangeListener(
- (preference, newValue) -> {
- if (newValue instanceof Boolean) {
- setSelectedNetworksEnabled((Boolean) newValue);
- return true;
- } else {
- return false;
- }
- }
- );
- }
-
private void checkAutodownloadItemVisibility(boolean autoDownload) {
findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setEnabled(autoDownload);
findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(autoDownload);
- findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(autoDownload);
- setSelectedNetworksEnabled(autoDownload && UserPreferences.isEnableAutodownloadWifiFilter());
- }
-
- private static String blankIfNull(String val) {
- return val == null ? "" : val;
- }
-
- @SuppressLint("MissingPermission") // getConfiguredNetworks needs location permission starting with API 29
- private void buildAutodownloadSelectedNetworksPreference() {
- if (Build.VERSION.SDK_INT >= 29) {
- return;
- }
-
- final Activity activity = getActivity();
-
- if (selectedNetworks != null) {
- clearAutodownloadSelectedNetworsPreference();
- }
- // get configured networks
- WifiManager wifiservice = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
- List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
-
- if (networks == null) {
- Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
- return;
- }
- Collections.sort(networks, (x, y) ->
- blankIfNull(x.SSID).compareToIgnoreCase(blankIfNull(y.SSID)));
- selectedNetworks = new CheckBoxPreference[networks.size()];
- List<String> prefValues = Arrays.asList(UserPreferences
- .getAutodownloadSelectedNetworks());
- PreferenceScreen prefScreen = getPreferenceScreen();
- Preference.OnPreferenceClickListener clickListener = preference -> {
- if (preference instanceof CheckBoxPreference) {
- String key = preference.getKey();
- List<String> prefValuesList = new ArrayList<>(
- Arrays.asList(UserPreferences
- .getAutodownloadSelectedNetworks())
- );
- boolean newValue = ((CheckBoxPreference) preference)
- .isChecked();
- Log.d(TAG, "Selected network " + key + ". New state: " + newValue);
-
- int index = prefValuesList.indexOf(key);
- if (index >= 0 && !newValue) {
- // remove network
- prefValuesList.remove(index);
- } else if (index < 0 && newValue) {
- prefValuesList.add(key);
- }
-
- UserPreferences.setAutodownloadSelectedNetworks(prefValuesList.toArray(new String[0]));
- return true;
- } else {
- return false;
- }
- };
- // create preference for each known network. attach listener and set
- // value
- for (int i = 0; i < networks.size(); i++) {
- WifiConfiguration config = networks.get(i);
-
- CheckBoxPreference pref = new CheckBoxPreference(activity);
- String key = Integer.toString(config.networkId);
- pref.setTitle(config.SSID);
- pref.setKey(key);
- pref.setOnPreferenceClickListener(clickListener);
- pref.setPersistent(false);
- pref.setChecked(prefValues.contains(key));
- selectedNetworks[i] = pref;
- prefScreen.addPreference(pref);
- }
- }
-
- private void clearAutodownloadSelectedNetworsPreference() {
- if (selectedNetworks != null) {
- PreferenceScreen prefScreen = getPreferenceScreen();
-
- for (CheckBoxPreference network : selectedNetworks) {
- if (network != null) {
- prefScreen.removePreference(network);
- }
- }
- }
- }
-
- private void setSelectedNetworksEnabled(boolean b) {
- if (selectedNetworks != null) {
- for (Preference p : selectedNetworks) {
- p.setEnabled(b);
- }
- }
}
}
diff --git a/ui/preferences/src/main/res/xml/preferences_autodownload.xml b/ui/preferences/src/main/res/xml/preferences_autodownload.xml
index 3ababbf1d..4d33120c5 100644
--- a/ui/preferences/src/main/res/xml/preferences_autodownload.xml
+++ b/ui/preferences/src/main/res/xml/preferences_autodownload.xml
@@ -20,8 +20,4 @@
android:title="@string/pref_automatic_download_on_battery_title"
android:summary="@string/pref_automatic_download_on_battery_sum"
android:defaultValue="true"/>
- <SwitchPreferenceCompat
- android:key="prefEnableAutoDownloadWifiFilter"
- android:title="@string/pref_autodl_wifi_filter_title"
- android:summary="@string/pref_autodl_wifi_filter_sum"/>
</PreferenceScreen>