Merge branch 'add-option-to-hide-anti-feature-apps' into 'master'

Add option to hide anti feature apps

Added option under Setting to grey out apps requiring anti-features similar to ignoring rooted apps on a non-rooted device.

See merge request !384
This commit is contained in:
Hans-Christoph Steiner 2016-08-30 15:54:44 +00:00
commit 3aa58bc005
7 changed files with 58 additions and 2 deletions

View File

@ -32,7 +32,9 @@ public class AppFilter {
}
}
}
if (app.antiFeatures != null && app.antiFeatures.length > 0 && Preferences.get().filterAppsWithAntiFeatures()) { // NOPMD
return true;
}
return false;
}

View File

@ -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.

View File

@ -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<String, Boolean> initialized = new HashMap<>();
private final List<ChangeListener> filterAppsRequiringRootListeners = new ArrayList<>();
private final List<ChangeListener> filterAppsRequiringAntiFeaturesListeners = new ArrayList<>();
private final List<ChangeListener> updateHistoryListeners = new ArrayList<>();
private final List<ChangeListener> localRepoNameListeners = new ArrayList<>();
private final List<ChangeListener> 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();

View File

@ -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() {

View File

@ -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;

View File

@ -148,6 +148,8 @@
<string name="show_incompat_versions_on">Show app versions incompatible with the device</string>
<string name="rooted">Ignore root</string>
<string name="rooted_on">Do not grey out apps requiring root privileges</string>
<string name="hide_anti_feature_apps">Grey out anti-feature apps</string>
<string name="hide_anti_feature_apps_on">Grey out apps requiring anti-features</string>
<string name="ignoreTouch">Ignore touchscreen</string>
<string name="ignoreTouch_on">Always include apps that require touchscreen</string>

View File

@ -42,6 +42,9 @@
<CheckBoxPreference android:title="@string/rooted"
android:defaultValue="true"
android:key="rooted" />
<CheckBoxPreference android:title="@string/hide_anti_feature_apps"
android:defaultValue="false"
android:key="hideAntiFeatureApps" />
<CheckBoxPreference android:title="@string/ignoreTouch"
android:defaultValue="false"
android:key="ignoreTouchscreen" />