diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.kt b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.kt index 296391c6d..29267452b 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.kt +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.kt @@ -253,13 +253,14 @@ class ContributionController @Inject constructor(@param:Named("default_preferenc */ fun initiateCustomGalleryPickWithPermission( activity: Activity, - resultLauncher: ActivityResultLauncher + resultLauncher: ActivityResultLauncher, + singleSelection: Boolean = false ) { setPickerConfiguration(activity, true) checkPermissionsAndPerformAction( activity, - { openCustomSelector(activity, resultLauncher, 0) }, + { FilePicker.openCustomSelector(activity, resultLauncher, 0, singleSelection) }, R.string.storage_permission_title, R.string.write_storage_permission_rationale, *PERMISSIONS_STORAGE diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/ui/adapter/ImageAdapter.kt b/app/src/main/java/fr/free/nrw/commons/customselector/ui/adapter/ImageAdapter.kt index 20a2fe70a..62a440ff4 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/ui/adapter/ImageAdapter.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/ui/adapter/ImageAdapter.kt @@ -327,12 +327,17 @@ class ImageAdapter( // Getting clicked index from all images index when show_already_actioned_images // switch is on + if (singleSelection) { + // If single selection mode, clear previous selection and select only the new one + if (selectedImages.isNotEmpty() && (selectedImages[0] != images[position])) { + val prevIndex = images.indexOf(selectedImages[0]) + selectedImages.clear() + notifyItemChanged(prevIndex, ImageUnselected()) + } + } val clickedIndex: Int = if (showAlreadyActionedImages) { ImageHelper.getIndex(selectedImages, images[position]) - - // Getting clicked index from actionable images when show_already_actioned_images - // switch is off } else { ImageHelper.getIndex(selectedImages, ArrayList(actionableImagesMap.values)[position]) } @@ -618,4 +623,13 @@ class ImageAdapter( * Returns the text for showing inside the bubble during bubble scroll. */ override fun getSectionName(position: Int): String = images[position].date + + private var singleSelection: Boolean = false + + /** + * Set single selection mode + */ + fun setSingleSelection(single: Boolean) { + singleSelection = single + } } diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt index f872d3044..7e7d7e4cd 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt @@ -104,7 +104,7 @@ class CustomSelectorActivity : /** * Maximum number of images that can be selected. */ - private val uploadLimit: Int = 20 + private var uploadLimit: Int = 20 /** * Flag that is marked true when the amount @@ -207,6 +207,9 @@ class CustomSelectorActivity : CustomSelectorViewModel::class.java, ) + // Check for single selection extra + uploadLimit = if (intent.getBooleanExtra(EXTRA_SINGLE_SELECTION, false)) 1 else 20 + setupViews() if (prefs.getBoolean("customSelectorFirstLaunch", true)) { @@ -728,6 +731,7 @@ class CustomSelectorActivity : const val FOLDER_ID: String = "FolderId" const val FOLDER_NAME: String = "FolderName" const val ITEM_ID: String = "ItemId" + const val EXTRA_SINGLE_SELECTION: String = "EXTRA_SINGLE_SELECTION" } } diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFragment.kt b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFragment.kt index 39d0d545a..6e08e30f1 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/ImageFragment.kt @@ -212,6 +212,9 @@ class ImageFragment : _binding = FragmentCustomSelectorBinding.inflate(inflater, container, false) imageAdapter = ImageAdapter(requireActivity(), activity as ImageSelectListener, imageLoader!!) + // Set single selection mode if needed + val singleSelection = (activity as? CustomSelectorActivity)?.intent?.getBooleanExtra(CustomSelectorActivity.EXTRA_SINGLE_SELECTION, false) == true + imageAdapter.setSingleSelection(singleSelection) gridLayoutManager = GridLayoutManager(context, getSpanCount()) with(binding?.selectorRv) { this?.layoutManager = gridLayoutManager diff --git a/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.kt b/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.kt index acf072f02..ccccfbd34 100644 --- a/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.kt +++ b/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.kt @@ -25,6 +25,9 @@ object FilePicker : Constants { private const val KEY_LAST_CAMERA_VIDEO = "last_video" private const val KEY_TYPE = "type" + // Add extra for single selection + private const val EXTRA_SINGLE_SELECTION = "EXTRA_SINGLE_SELECTION" + /** * Returns the uri of the clicked image so that it can be put in MediaStore */ @@ -73,12 +76,17 @@ object FilePicker : Constants { * CreateCustomSectorIntent, creates intent for custom selector activity. * @param context * @param type + * @param singleSelection If true, restricts to single image selection * @return Custom selector intent */ @JvmStatic - private fun createCustomSelectorIntent(context: Context, type: Int): Intent { + private fun createCustomSelectorIntent(context: Context, type: Int, singleSelection: Boolean = false): Intent { storeType(context, type) - return Intent(context, CustomSelectorActivity::class.java) + val intent = Intent(context, CustomSelectorActivity::class.java) + if (singleSelection) { + intent.putExtra(EXTRA_SINGLE_SELECTION, true) + } + return intent } @JvmStatic @@ -153,9 +161,10 @@ object FilePicker : Constants { fun openCustomSelector( activity: Activity, resultLauncher: ActivityResultLauncher, - type: Int + type: Int, + singleSelection: Boolean = false ) { - val intent = createCustomSelectorIntent(activity, type) + val intent = createCustomSelectorIntent(activity, type, singleSelection) resultLauncher.launch(intent) } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt index 56af614d7..5b52c0ce5 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.kt @@ -974,7 +974,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), } else if (bottomSheetDetailsBehavior!!.state == BottomSheetBehavior.STATE_EXPANDED ) { - bottomSheetDetailsBehavior!!.state = BottomSheetBehavior.STATE_COLLAPSED + bottomSheetDetailsBehavior!!.setState(BottomSheetBehavior.STATE_COLLAPSED) } } @@ -2457,9 +2457,11 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), Timber.d("Gallery button tapped. Place: %s", selectedPlace.toString()) storeSharedPrefs(selectedPlace!!) activity?.let { + // Pass singleSelection = true for Nearby flow controller!!.initiateCustomGalleryPickWithPermission( it, - customSelectorLauncherForResult + customSelectorLauncherForResult, + singleSelection = true ) } } diff --git a/app/src/main/res/values-x-invalidLanguageCode/error.xml b/app/src/main/res/values-x-invalidLanguageCode/error.xml deleted file mode 100644 index f4e2fe125..000000000 --- a/app/src/main/res/values-x-invalidLanguageCode/error.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - کامَنٕز گوو رُکِتھ - Oops. کیہہ تام گوو غلط! - ؤنِیوٚ اَسہِ توٚہہِ کیاہ ٲسِیوٚ کران، تہٕ کٕریٚو تہِ اَسہِ سٕتی شیر بذریعہِ برقی خط. یُس مَدَتھ کَرِ اَسہِ اَتھ شہَرنَس منٛز! - شُکریہ! -