diff --git a/app/build.gradle b/app/build.gradle index 7a566c1f37..ddad3ebe3f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1052 - versionName "0.10.52" + versionCode 1053 + versionName "0.10.53" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/course/AdapterCourses.java b/app/src/main/java/org/ole/planet/myplanet/ui/course/AdapterCourses.java index 550631c4c0..ac0d27b4dd 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/course/AdapterCourses.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/course/AdapterCourses.java @@ -56,6 +56,8 @@ public class AdapterCourses extends RecyclerView.Adapter courseList, HashMap map) { this.map = map; this.context = context; @@ -178,6 +180,29 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int } } + public boolean areAllSelected(){ + if (selectedItems.size() != courseList.size()) { + areAllSelected = false; + } + return areAllSelected; + } + + public void selectAllItems(boolean selectAll) { + if (selectAll) { + selectedItems.clear(); + selectedItems.addAll(courseList); + } else { + selectedItems.clear(); + } + + notifyDataSetChanged(); + + if (listener != null) { + listener.onSelectedListChange(selectedItems); + } + } + + private void displayTagCloud(FlexboxLayout flexboxDrawable, int position) { flexboxDrawable.removeAllViews(); final ChipCloud chipCloud = new ChipCloud(context, flexboxDrawable, config); diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseFragment.java index 2ed0e5f7da..197f2ff38a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseFragment.java @@ -7,6 +7,7 @@ import android.view.View; import android.widget.AdapterView; import android.widget.Button; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; import android.widget.Spinner; @@ -47,10 +48,12 @@ public class CourseFragment extends BaseRecyclerFragment implemen ImageView imgSearch; AdapterCourses adapterCourses; Button btnRemove, orderByDate, orderByTitle; + CheckBox selectAll; Spinner spnGrade, spnSubject; List searchTags; Spinner spn; AlertDialog confirmation; + private boolean allItemsSelected = false; public CourseFragment() { } @@ -88,9 +91,22 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { KeyboardUtils.hideSoftKeyboard(getActivity()); }); - btnRemove.setOnClickListener(V -> new AlertDialog.Builder(this.getContext()).setMessage(R.string.are_you_sure_you_want_to_delete_these_courses).setPositiveButton(R.string.yes, (dialogInterface, i) -> { - deleteSelected(true); - }).setNegativeButton(R.string.no, null).show()); + btnRemove.setOnClickListener(V -> new AlertDialog.Builder(this.getContext()) + .setMessage(R.string.are_you_sure_you_want_to_delete_these_courses) + .setPositiveButton(R.string.yes, (dialogInterface, i) -> { + deleteSelected(true); + if (adapterCourses.getCourseList().size() == 0) { + selectAll.setVisibility(View.GONE); + etSearch.setVisibility(View.GONE); + imgSearch.setVisibility(View.GONE); + tvAddToLib.setVisibility(View.GONE); + getView().findViewById(R.id.filter).setVisibility(View.GONE); + spn.setVisibility(View.GONE); + btnRemove.setVisibility(View.GONE); + tvSelected.setVisibility(View.GONE); + } + }) + .setNegativeButton(R.string.no, null).show()); getView().findViewById(R.id.btn_collections).setOnClickListener(view -> { CollectionsFragment f = CollectionsFragment.getInstance(searchTags, "courses"); f.setListener(this); @@ -140,6 +156,16 @@ private void initializeView() { addToMyList(); selectedItems.clear(); tvAddToLib.setEnabled(false); // selectedItems will always have a size of 0 + if (adapterCourses.getCourseList().size() == 0) { + selectAll.setVisibility(View.GONE); + etSearch.setVisibility(View.GONE); + imgSearch.setVisibility(View.GONE); + tvAddToLib.setVisibility(View.GONE); + getView().findViewById(R.id.filter).setVisibility(View.GONE); + spn.setVisibility(View.GONE); + btnRemove.setVisibility(View.GONE); + tvSelected.setVisibility(View.GONE); + } } }); etSearch = getView().findViewById(R.id.et_search); @@ -153,6 +179,22 @@ private void initializeView() { tvFragmentInfo = getView().findViewById(R.id.tv_fragment_info); spnGrade.setOnItemSelectedListener(itemSelectedListener); spnSubject.setOnItemSelectedListener(itemSelectedListener); + selectAll = getView().findViewById(R.id.selectAll); + if (adapterCourses.getCourseList().size() == 0) { + selectAll.setVisibility(View.GONE); + etSearch.setVisibility(View.GONE); + imgSearch.setVisibility(View.GONE); + tvAddToLib.setVisibility(View.GONE); + getView().findViewById(R.id.filter).setVisibility(View.GONE); + spn.setVisibility(View.GONE); + btnRemove.setVisibility(View.GONE); + tvSelected.setVisibility(View.GONE); + } + selectAll.setOnClickListener(view -> { + boolean allSelected = selectedItems.size() == adapterCourses.getCourseList().size(); + adapterCourses.selectAllItems(!allSelected); + selectAll.setText(allSelected ? getString(R.string.select_all) : getString(R.string.unselect_all)); + }); } private AdapterView.OnItemSelectedListener itemSelectedListener = new AdapterView.OnItemSelectedListener() { @@ -218,6 +260,7 @@ public void onTagClicked(RealmTag tag) { private void changeButtonStatus() { tvAddToLib.setEnabled(selectedItems.size() > 0); + selectAll.setText(adapterCourses.areAllSelected() ? getString(R.string.unselect_all) : getString(R.string.select_all)); } @Override diff --git a/app/src/main/res/layout/fragment_my_course.xml b/app/src/main/res/layout/fragment_my_course.xml index 8cf47f1f3a..770dc0d73b 100644 --- a/app/src/main/res/layout/fragment_my_course.xml +++ b/app/src/main/res/layout/fragment_my_course.xml @@ -1,3 +1,4 @@ + - - - - -