From 132d3f9e539647c7b0101e4a77189825b8ead934 Mon Sep 17 00:00:00 2001 From: Vivian Li <112584985+strawberrybread@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:02:45 -0400 Subject: [PATCH] mylibrary: context-based activated remove button (fixes #3574) (#3587) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../myplanet/ui/resources/ResourcesFragment.kt | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7a64a235ed..756a5ad13a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1575 - versionName "0.15.75" + versionCode 1576 + versionName "0.15.76" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/resources/ResourcesFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/resources/ResourcesFragment.kt index 79b535c17d..ce94d8315c 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/resources/ResourcesFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/resources/ResourcesFragment.kt @@ -81,6 +81,8 @@ class ResourcesFragment : BaseRecyclerFragment(), OnLibraryItem tvDelete = requireView().findViewById(R.id.tv_delete) filter = requireView().findViewById(R.id.filter) initArrays() + updateTvDelete() + tvAddToLib?.setOnClickListener { if ((selectedItems?.size ?: 0) > 0) { confirmation = createAlertDialog() @@ -91,6 +93,7 @@ class ResourcesFragment : BaseRecyclerFragment(), OnLibraryItem checkList() } } + tvDelete?.setOnClickListener { AlertDialog.Builder(this.context) .setMessage(R.string.confirm_removal) @@ -124,6 +127,7 @@ class ResourcesFragment : BaseRecyclerFragment(), OnLibraryItem if (isMyCourseLib) tvFragmentInfo.setText(R.string.txt_myLibrary) checkList() selectAll?.setOnClickListener { + updateTvDelete() val allSelected = selectedItems?.size == adapterLibrary?.getLibraryList()?.size adapterLibrary?.selectAllItems(!allSelected) if (allSelected) { @@ -136,6 +140,14 @@ class ResourcesFragment : BaseRecyclerFragment(), OnLibraryItem } } + private fun updateTvDelete(){ + if (selectedItems?.size!! == 0) { + tvDelete?.isEnabled = false + } else{ + tvDelete?.isEnabled = true + } + } + private fun checkList() { if (adapterLibrary?.getLibraryList()?.isEmpty() == true) { selectAll?.visibility = View.GONE @@ -198,6 +210,7 @@ class ResourcesFragment : BaseRecyclerFragment(), OnLibraryItem override fun onSelectedListChange(list: MutableList) { selectedItems = list changeButtonStatus() + updateTvDelete() } override fun onTagClicked(realmTag: RealmTag) {