mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 04:13:53 +01:00
Implement single selection logic in custom image picker (#6341)
Some checks are pending
Android CI / Run tests and generate APK (push) Waiting to run
Some checks are pending
Android CI / Run tests and generate APK (push) Waiting to run
* build failure cause * Fix image selector logic in custom picker
This commit is contained in:
parent
06a613e855
commit
f45f26e602
7 changed files with 45 additions and 22 deletions
|
|
@ -253,13 +253,14 @@ class ContributionController @Inject constructor(@param:Named("default_preferenc
|
|||
*/
|
||||
fun initiateCustomGalleryPickWithPermission(
|
||||
activity: Activity,
|
||||
resultLauncher: ActivityResultLauncher<Intent>
|
||||
resultLauncher: ActivityResultLauncher<Intent>,
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<Intent>,
|
||||
type: Int
|
||||
type: Int,
|
||||
singleSelection: Boolean = false
|
||||
) {
|
||||
val intent = createCustomSelectorIntent(activity, type)
|
||||
val intent = createCustomSelectorIntent(activity, type, singleSelection)
|
||||
resultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Authors:
|
||||
* Vlad5250
|
||||
-->
|
||||
<resources>
|
||||
<string name="crash_dialog_title">کامَنٕز گوو رُکِتھ</string>
|
||||
<string name="crash_dialog_text">Oops. کیہہ تام گوو غلط!</string>
|
||||
<string name="crash_dialog_comment_prompt">ؤنِیوٚ اَسہِ توٚہہِ کیاہ ٲسِیوٚ کران، تہٕ کٕریٚو تہِ اَسہِ سٕتی شیر بذریعہِ برقی خط. یُس مَدَتھ کَرِ اَسہِ اَتھ شہَرنَس منٛز!</string>
|
||||
<string name="crash_dialog_ok_toast">شُکریہ!</string>
|
||||
</resources>
|
||||
Loading…
Add table
Add a link
Reference in a new issue