diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/activities/MainActivity.java b/app/src/main/java/io/github/muntashirakon/AppManager/activities/MainActivity.java index 0241d5be631..c5a6b563d61 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/activities/MainActivity.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/activities/MainActivity.java @@ -230,6 +230,9 @@ protected void onCreate(Bundle savedInstanceState) { }); mBottomAppBar.setOnMenuItemClickListener(item -> { switch (item.getItemId()) { + case R.id.action_select_all: + mAdapter.selectAll(); + return true; case R.id.action_block_trackers: handleBatchOp(BatchOpsManager.OP_BLOCK_TRACKERS, R.string.alert_failed_to_disable_trackers); return true; @@ -641,7 +644,7 @@ static class MainRecyclerAdapter extends RecyclerView.Adapter mAdapterList; + private final List mAdapterList = new ArrayList<>(); private static int mColorTransparent; private static int mColorSemiTransparent; @@ -669,21 +672,36 @@ static class MainRecyclerAdapter extends RecyclerView.Adapter list) { - mAdapterList = list; - mSearchQuery = mActivity.mModel.getSearchQuery(); - notifyDataSetChanged(); + synchronized (mAdapterList) { + mAdapterList.clear(); + mAdapterList.addAll(list); + mSearchQuery = mActivity.mModel.getSearchQuery(); + notifyDataSetChanged(); + } } void clearSelection() { - final AtomicInteger itemId = new AtomicInteger(); - for (ApplicationItem applicationItem: mActivity.mModel.getSelectedApplicationItems()) { - itemId.set(mAdapterList.indexOf(applicationItem)); - if (itemId.get() == -1) continue; - applicationItem.isSelected = false; - mAdapterList.set(itemId.get(), applicationItem); - mActivity.runOnUiThread(() -> notifyItemChanged(itemId.get())); + synchronized (mAdapterList) { + final AtomicInteger itemId = new AtomicInteger(); + for (ApplicationItem applicationItem : mActivity.mModel.getSelectedApplicationItems()) { + itemId.set(mAdapterList.indexOf(applicationItem)); + if (itemId.get() == -1) continue; + applicationItem.isSelected = false; + mAdapterList.set(itemId.get(), applicationItem); + mActivity.runOnUiThread(() -> notifyItemChanged(itemId.get())); + } + mActivity.mModel.clearSelection(); + } + } + + void selectAll() { + synchronized (mAdapterList) { + for (int i = 0; i < mAdapterList.size(); ++i) { + mAdapterList.set(i, mActivity.mModel.select(mAdapterList.get(i))); + notifyItemChanged(i); + } + mActivity.handleSelection(); } - mActivity.mModel.clearSelection(); } @NonNull @@ -836,7 +854,7 @@ public long getItemId(int i) { @Override public int getItemCount() { - return mAdapterList == null ? 0 : mAdapterList.size(); + return mAdapterList.size(); } @Override diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/viewmodels/MainViewModel.java b/app/src/main/java/io/github/muntashirakon/AppManager/viewmodels/MainViewModel.java index 35a39f02433..537f6de291e 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/viewmodels/MainViewModel.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/viewmodels/MainViewModel.java @@ -22,10 +22,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Objects; +import java.util.Set; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -48,7 +50,7 @@ public class MainViewModel extends AndroidViewModel { private @MainActivity.SortOrder int mSortBy; private @MainActivity.Filter int mFilterFlags; private String searchQuery; - private List selectedPackages = new LinkedList<>(); + private Set selectedPackages = new HashSet<>(); private List selectedApplicationItems = new LinkedList<>(); private int flagSigningInfo; public MainViewModel(@NonNull Application application) { @@ -107,7 +109,7 @@ public void clearSelection() { selectedApplicationItems.clear(); } - public List getSelectedPackages() { + public Set getSelectedPackages() { return selectedPackages; } diff --git a/app/src/main/res/drawable/ic_baseline_select_all_24.xml b/app/src/main/res/drawable/ic_baseline_select_all_24.xml new file mode 100644 index 00000000000..faf39160b85 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_select_all_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/menu/activity_main_selection_actions.xml b/app/src/main/res/menu/activity_main_selection_actions.xml index cd93df66add..6c1f5381451 100644 --- a/app/src/main/res/menu/activity_main_selection_actions.xml +++ b/app/src/main/res/menu/activity_main_selection_actions.xml @@ -1,7 +1,15 @@ - + + User apps System apps Apps with rules + Select All