diff --git a/app/src/main/java/org/fdroid/fdroid/AppFilter.java b/app/src/main/java/org/fdroid/fdroid/AppFilter.java index 4983d922e..53f4fb28e 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppFilter.java +++ b/app/src/main/java/org/fdroid/fdroid/AppFilter.java @@ -32,7 +32,9 @@ public class AppFilter { } } } - + if (app.antiFeatures != null && app.antiFeatures.length > 0 && Preferences.get().filterAppsWithAntiFeatures()) { // NOPMD + return true; + } return false; } diff --git a/app/src/main/java/org/fdroid/fdroid/FDroidApp.java b/app/src/main/java/org/fdroid/fdroid/FDroidApp.java index 79fe4cdf3..873a5c08d 100644 --- a/app/src/main/java/org/fdroid/fdroid/FDroidApp.java +++ b/app/src/main/java/org/fdroid/fdroid/FDroidApp.java @@ -234,6 +234,16 @@ public class FDroidApp extends Application { } }); + // If the user changes the preference to do with filtering anti-feature apps, + // it is easier to just notify a change in the app provider, + // so that the newly updated list will correctly filter relevant apps. + Preferences.get().registerAppsRequiringAntiFeaturesChangeListener(new Preferences.ChangeListener() { + @Override + public void onPreferenceChange() { + getContentResolver().notifyChange(AppProvider.getContentUri(), null); + } + }); + // This is added so that the bluetooth:// scheme we use for URLs the BluetoothDownloader // understands is not treated as invalid by the java.net.URL class. The actual Handler does // nothing, but its presence is enough. diff --git a/app/src/main/java/org/fdroid/fdroid/Preferences.java b/app/src/main/java/org/fdroid/fdroid/Preferences.java index a85b4a552..64d6ad5c7 100644 --- a/app/src/main/java/org/fdroid/fdroid/Preferences.java +++ b/app/src/main/java/org/fdroid/fdroid/Preferences.java @@ -49,6 +49,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh public static final String PREF_UPD_NOTIFY = "updateNotify"; public static final String PREF_UPD_HISTORY = "updateHistoryDays"; public static final String PREF_ROOTED = "rooted"; + public static final String PREF_HIDE_ANTI_FEATURE_APPS = "hideAntiFeatureApps"; public static final String PREF_INCOMP_VER = "incompatibleVersions"; public static final String PREF_THEME = "theme"; public static final String PREF_IGN_TOUCH = "ignoreTouchscreen"; @@ -68,6 +69,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh public static final String PREF_POST_PRIVILEGED_INSTALL = "postPrivilegedInstall"; private static final boolean DEFAULT_ROOTED = true; + private static final boolean DEFAULT_HIDE_ANTI_FEATURE_APPS = false; private static final int DEFAULT_UPD_HISTORY = 14; private static final boolean DEFAULT_PRIVILEGED_INSTALLER = true; //private static final boolean DEFAULT_LOCAL_REPO_BONJOUR = true; @@ -92,10 +94,12 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh } private boolean filterAppsRequiringRoot = DEFAULT_ROOTED; + private boolean filterAppsWithAntiFeatures = DEFAULT_HIDE_ANTI_FEATURE_APPS; private final Map initialized = new HashMap<>(); private final List filterAppsRequiringRootListeners = new ArrayList<>(); + private final List filterAppsRequiringAntiFeaturesListeners = new ArrayList<>(); private final List updateHistoryListeners = new ArrayList<>(); private final List localRepoNameListeners = new ArrayList<>(); private final List localRepoHttpsListeners = new ArrayList<>(); @@ -300,6 +304,20 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh return filterAppsRequiringRoot; } + /** + * This is cached as it is called several times inside the AppListAdapter. + * Providing it here means the shared preferences file only needs to be + * read once, and we will keep our copy up to date by listening to changes + * in PREF_HIDE_ANTI_FEATURE_APPS. + */ + public boolean filterAppsWithAntiFeatures() { + if (!isInitialized(PREF_HIDE_ANTI_FEATURE_APPS)) { + initialize(PREF_HIDE_ANTI_FEATURE_APPS); + filterAppsWithAntiFeatures = preferences.getBoolean(PREF_HIDE_ANTI_FEATURE_APPS, DEFAULT_HIDE_ANTI_FEATURE_APPS); + } + return filterAppsWithAntiFeatures; + } + public void registerAppsRequiringRootChangeListener(ChangeListener listener) { filterAppsRequiringRootListeners.add(listener); } @@ -308,6 +326,14 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh filterAppsRequiringRootListeners.remove(listener); } + public void registerAppsRequiringAntiFeaturesChangeListener(ChangeListener listener) { + filterAppsRequiringAntiFeaturesListeners.add(listener); + } + + public void unregisterAppsRequiringAntiFeaturesChangeListener(ChangeListener listener) { + filterAppsRequiringAntiFeaturesListeners.remove(listener); + } + public void registerUnstableUpdatesChangeListener(ChangeListener listener) { unstableUpdatesListeners.add(listener); } @@ -327,6 +353,11 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh listener.onPreferenceChange(); } break; + case PREF_HIDE_ANTI_FEATURE_APPS: + for (ChangeListener listener : filterAppsRequiringAntiFeaturesListeners) { + listener.onPreferenceChange(); + } + break; case PREF_UPD_HISTORY: for (ChangeListener listener : updateHistoryListeners) { listener.onPreferenceChange(); diff --git a/app/src/main/java/org/fdroid/fdroid/views/fragments/AppListFragment.java b/app/src/main/java/org/fdroid/fdroid/views/fragments/AppListFragment.java index 3487ee72e..7ffa038b5 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/fragments/AppListFragment.java +++ b/app/src/main/java/org/fdroid/fdroid/views/fragments/AppListFragment.java @@ -51,6 +51,7 @@ public abstract class AppListFragment extends ListFragment implements AppMetadataTable.Cols.SuggestedApk.VERSION_NAME, AppMetadataTable.Cols.SUGGESTED_VERSION_CODE, AppMetadataTable.Cols.REQUIREMENTS, // Needed for filtering apps that require root. + AppMetadataTable.Cols.ANTI_FEATURES, // Needed for filtering apps that require anti-features. }; private static final String APP_SORT = AppMetadataTable.Cols.NAME; @@ -85,6 +86,7 @@ public abstract class AppListFragment extends ListFragment implements /** * Alerts the child class that the user is no longer performing a search. * This is triggered every time the search query is blank. + * * @see AppListFragment#onSearch() */ protected void onSearchStopped() { @@ -166,7 +168,7 @@ public abstract class AppListFragment extends ListFragment implements Bundle bundle = ActivityOptionsCompat .makeSceneTransitionAnimation(getActivity(), iconTransitionPair) - .toBundle(); + .toBundle(); startActivityForResult(intent, REQUEST_APPDETAILS, bundle); } else { startActivityForResult(intent, REQUEST_APPDETAILS); @@ -204,6 +206,7 @@ public abstract class AppListFragment extends ListFragment implements * Notifies the subclass via {@link AppListFragment#onSearch()} and {@link AppListFragment#onSearchStopped()} * about whether or not a search is taking place and changes empty message * appropriately. + * * @return True if a user is searching. */ private boolean updateSearchStatus() { diff --git a/app/src/main/java/org/fdroid/fdroid/views/fragments/PreferencesFragment.java b/app/src/main/java/org/fdroid/fdroid/views/fragments/PreferencesFragment.java index 02c9c86c6..e61f4a9a8 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/fragments/PreferencesFragment.java +++ b/app/src/main/java/org/fdroid/fdroid/views/fragments/PreferencesFragment.java @@ -33,6 +33,7 @@ public class PreferencesFragment extends PreferenceFragment Preferences.PREF_UPD_NOTIFY, Preferences.PREF_UPD_HISTORY, Preferences.PREF_ROOTED, + Preferences.PREF_HIDE_ANTI_FEATURE_APPS, Preferences.PREF_INCOMP_VER, Preferences.PREF_THEME, Preferences.PREF_IGN_TOUCH, @@ -123,6 +124,10 @@ public class PreferencesFragment extends PreferenceFragment checkSummary(key, R.string.rooted_on); break; + case Preferences.PREF_HIDE_ANTI_FEATURE_APPS: + checkSummary(key, R.string.hide_anti_feature_apps_on); + break; + case Preferences.PREF_IGN_TOUCH: checkSummary(key, R.string.ignoreTouch_on); break; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1820746a3..bb03f4fbc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -148,6 +148,8 @@ Show app versions incompatible with the device Ignore root Do not grey out apps requiring root privileges + Grey out anti-feature apps + Grey out apps requiring anti-features Ignore touchscreen Always include apps that require touchscreen diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 2cccd9eb3..aa80594bd 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -42,6 +42,9 @@ +