diff --git a/CHANGELOG.md b/CHANGELOG.md index a21aee85e..dd39bef86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Test and beta releases will have experimental functions enabled by default. **Next release** * Sharper check marks, thanks @[jpeg729](https://github.com/jpeg729) +* Toggle (clear/set) selected * Updated simplified Chinese translation * Updated traditional Chinese translation * Updated French translation diff --git a/src/biz/bokhorst/xprivacy/ActivityMain.java b/src/biz/bokhorst/xprivacy/ActivityMain.java index 7d3bb46fd..6003c60f5 100644 --- a/src/biz/bokhorst/xprivacy/ActivityMain.java +++ b/src/biz/bokhorst/xprivacy/ActivityMain.java @@ -661,8 +661,7 @@ private void applyFilter() { private void optionAll() { // Check if some restricted boolean some = false; - for (int pos = 0; pos < mAppAdapter.getCount(); pos++) { - ApplicationInfoEx xAppInfo = mAppAdapter.getItem(pos); + for (ApplicationInfoEx xAppInfo : mAppAdapter.getSelected(false)) { for (boolean restricted : PrivacyManager.getRestricted(ActivityMain.this, xAppInfo.getUid(), mAppAdapter.getRestrictionName())) if (restricted) { @@ -1011,10 +1010,11 @@ protected Boolean doInBackground(Boolean... params) { boolean someRestricted = params[0]; // Apply action + int pos = 0; boolean restart = false; - for (int pos = 0; pos < mAppAdapter.getCount(); pos++) { - publishProgress(pos, mAppAdapter.getCount()); - ApplicationInfoEx xAppInfo = mAppAdapter.getItem(pos); + List listAppInfo = mAppAdapter.getSelected(false); + for (ApplicationInfoEx xAppInfo : listAppInfo) { + publishProgress(pos++, listAppInfo.size()); if (mAppAdapter.getRestrictionName() == null && someRestricted) restart = PrivacyManager.deleteRestrictions(ActivityMain.this, xAppInfo.getUid()) || restart; else if (mAppAdapter.getRestrictionName() == null) { @@ -1065,7 +1065,7 @@ public SpinnerAdapter(Context context, int textViewResourceId) { @SuppressLint("DefaultLocale") private class AppListAdapter extends ArrayAdapter { private Context mContext; - private List mListApp; + private List mListAppAll; private List mListAppSelected = new ArrayList(); private String mRestrictionName; private LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); @@ -1076,8 +1076,8 @@ public AppListAdapter(Context context, int resource, List obj String initialRestrictionName) { super(context, resource, objects); mContext = context; - mListApp = new ArrayList(); - mListApp.addAll(objects); + mListAppAll = new ArrayList(); + mListAppAll.addAll(objects); mRestrictionName = initialRestrictionName; TypedArray ta1 = context.getTheme().obtainStyledAttributes( @@ -1094,6 +1094,13 @@ public String getRestrictionName() { return mRestrictionName; } + public List getSelected(boolean selectedOnly) { + if (mListAppSelected.size() == 0) + return (selectedOnly ? new ArrayList() : mListAppAll); + else + return mListAppSelected; + } + @Override public Filter getFilter() { return new AppFilter(); @@ -1121,9 +1128,9 @@ protected FilterResults performFiltering(CharSequence constraint) { // Match applications int current = 0; - int max = AppListAdapter.this.mListApp.size(); + int max = AppListAdapter.this.mListAppAll.size(); List lstApp = new ArrayList(); - for (ApplicationInfoEx xAppInfo : AppListAdapter.this.mListApp) { + for (ApplicationInfoEx xAppInfo : AppListAdapter.this.mListAppAll) { // Check if another filter has been started if (filtersRunning != mFiltersRunning.get()) return null; @@ -1207,7 +1214,7 @@ protected void publishResults(CharSequence constraint, FilterResults results) { ProgressBar pbFilter = (ProgressBar) findViewById(R.id.pbFilter); pbFilter.setVisibility(ProgressBar.GONE); tvStats.setVisibility(TextView.VISIBLE); - tvStats.setText(results.count + "/" + AppListAdapter.this.mListApp.size()); + tvStats.setText(results.count + "/" + AppListAdapter.this.mListAppAll.size()); Intent progressIntent = new Intent(ActivityShare.cProgressReport); progressIntent.putExtra(ActivityShare.cProgressMessage, getString(R.string.title_restrict));