Add option to grey out apps requiring anti-features.
This commit is contained in:
		
							parent
							
								
									fde227e889
								
							
						
					
					
						commit
						1f354a1b3f
					
				| @ -32,7 +32,9 @@ public class AppFilter { | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (app.antiFeatures != null && Preferences.get().filterAppsWithAntiFeatures()) { | ||||
|             return true; | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -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. | ||||
|  | ||||
| @ -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_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_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_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_ANTI_FEATURE_APPS. | ||||
|      */ | ||||
|     public boolean filterAppsWithAntiFeatures() { | ||||
|         if (!isInitialized(PREF_ANTI_FEATURE_APPS)) { | ||||
|             initialize(PREF_ANTI_FEATURE_APPS); | ||||
|             filterAppsWithAntiFeatures = preferences.getBoolean(PREF_ANTI_FEATURE_APPS, DEFAULT_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_ANTI_FEATURE_APPS: | ||||
|                 for (ChangeListener listener : filterAppsRequiringAntiFeaturesListeners) { | ||||
|                     listener.onPreferenceChange(); | ||||
|                 } | ||||
|                 break; | ||||
|             case PREF_UPD_HISTORY: | ||||
|                 for (ChangeListener listener : updateHistoryListeners) { | ||||
|                     listener.onPreferenceChange(); | ||||
|  | ||||
| @ -51,13 +51,15 @@ 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; | ||||
| 
 | ||||
|     private AppListAdapter appAdapter; | ||||
| 
 | ||||
|     @Nullable private String searchQuery; | ||||
|     @Nullable | ||||
|     private String searchQuery; | ||||
| 
 | ||||
|     protected abstract AppListAdapter getAppListAdapter(); | ||||
| 
 | ||||
| @ -85,6 +87,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 +169,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 +207,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() { | ||||
|  | ||||
| @ -33,6 +33,7 @@ public class PreferencesFragment extends PreferenceFragment | ||||
|         Preferences.PREF_UPD_NOTIFY, | ||||
|         Preferences.PREF_UPD_HISTORY, | ||||
|         Preferences.PREF_ROOTED, | ||||
|         Preferences.PREF_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_ANTI_FEATURE_APPS: | ||||
|                 checkSummary(key, R.string.anti_feature_apps_on); | ||||
|                 break; | ||||
| 
 | ||||
|             case Preferences.PREF_IGN_TOUCH: | ||||
|                 checkSummary(key, R.string.ignoreTouch_on); | ||||
|                 break; | ||||
|  | ||||
| @ -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="anti_feature_apps">Grey out anti-feature apps</string> | ||||
|     <string name="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> | ||||
| 
 | ||||
|  | ||||
| @ -42,6 +42,9 @@ | ||||
|         <CheckBoxPreference android:title="@string/rooted" | ||||
|             android:defaultValue="true" | ||||
|             android:key="rooted" /> | ||||
|         <CheckBoxPreference android:title="@string/anti_feature_apps" | ||||
|             android:defaultValue="false" | ||||
|             android:key="hideAntiFeatureApps" /> | ||||
|         <CheckBoxPreference android:title="@string/ignoreTouch" | ||||
|             android:defaultValue="false" | ||||
|             android:key="ignoreTouchscreen" /> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Aditya Bharadwaj
						Aditya Bharadwaj