@@ -14,6 +14,7 @@ import androidx.activity.result.ActivityResultLauncher
1414import androidx.activity.result.contract.ActivityResultContracts
1515import androidx.fragment.app.Fragment
1616import androidx.lifecycle.lifecycleScope
17+ import com.bn.easypicker.EasyPicker.Companion.IMAGE_CHOSE_TYPE
1718import com.bn.easypicker.MediaStoreUtils.deleteUriFile
1819import com.bn.easypicker.listeners.OnAttachmentTypeSelected
1920import com.bn.easypicker.listeners.OnCaptureMedia
@@ -43,12 +44,27 @@ class FragmentEasyPicker(
4344 private val backgroundColor: Int = builder.sheetBackgroundColor
4445 private val btnBackground: Int = builder.btnBackground
4546 private val maximumSelectionLimit: Int = builder.maximumSelectionLimit
47+ private var currentChoseType: Int = 1
4648
4749
4850 private val resultLauncher =
4951 fragment.registerForActivityResult(ActivityResultContracts .StartActivityForResult ()) { result ->
5052 if (result.resultCode == - 1 ) {
51- chooseImage()
53+ when (currentChoseType){
54+ EasyPicker .IMAGE_CHOSE_TYPE -> {
55+ chooseImage()
56+ }
57+ EasyPicker .MULTI_IMAGES_TYPE -> {
58+ chooseMultipleImages()
59+ }
60+ EasyPicker .VIDEO_TYPE -> {
61+ chooseVideo()
62+ }
63+ EasyPicker .FILE_TYPE -> {
64+ chooseFile()
65+ }
66+
67+ }
5268 }
5369 }
5470
@@ -407,6 +423,8 @@ class FragmentEasyPicker(
407423 }
408424
409425 fun chooseImage () {
426+ currentChoseType = EasyPicker .IMAGE_CHOSE_TYPE
427+
410428 if (checkPermission()) {
411429 mSelectImageSheet.show()
412430 } else {
@@ -415,6 +433,8 @@ class FragmentEasyPicker(
415433 }
416434
417435 fun chooseMultipleImages () {
436+ currentChoseType = EasyPicker .MULTI_IMAGES_TYPE
437+
418438 if (checkPermission()) {
419439 if (Build .VERSION .SDK_INT > 30 ) {
420440 val intent = Intent (
@@ -437,6 +457,7 @@ class FragmentEasyPicker(
437457 }
438458
439459 fun chooseAndCompressImage () {
460+ currentChoseType = IMAGE_CHOSE_TYPE
440461 if (checkPermission()) {
441462 val intent = Intent (
442463 Intent .ACTION_PICK ,
@@ -455,6 +476,7 @@ class FragmentEasyPicker(
455476 }
456477
457478 fun chooseVideo () {
479+ currentChoseType = EasyPicker .VIDEO_TYPE
458480 if (checkPermission()) {
459481 val intent = Intent (
460482 Intent .ACTION_GET_CONTENT ,
@@ -471,6 +493,7 @@ class FragmentEasyPicker(
471493 }
472494
473495 fun chooseFile () {
496+ currentChoseType = EasyPicker .FILE_TYPE
474497 if (checkPermission()) {
475498 val mRequestFileIntent = Intent (Intent .ACTION_GET_CONTENT )
476499 mRequestFileIntent.type = " */*"
@@ -496,6 +519,7 @@ class FragmentEasyPicker(
496519
497520 fun captureHighQualityImage () {
498521 CoroutineScope (Main ).launch {
522+ currentChoseType = IMAGE_CHOSE_TYPE
499523
500524 mPath = async { MediaStoreUtils .createImageUri(fragment.requireActivity())!! }.await()
501525 if (checkPermission()) {
@@ -516,6 +540,7 @@ class FragmentEasyPicker(
516540 }
517541
518542 override fun onAttachSelected (selectedAttatchType : Int ) {
543+ currentChoseType = IMAGE_CHOSE_TYPE
519544 // 0 mean open Camera , 1 mean select image
520545 fragment.lifecycleScope.launchWhenStarted {
521546 imageLauncher
0 commit comments