From 202cf320d54ff4216330b4f27b9052a2e45862b9 Mon Sep 17 00:00:00 2001 From: CraZyLegenD <25645122+CraZyLegenD@users.noreply.github.com> Date: Sun, 24 May 2020 17:37:03 +0200 Subject: [PATCH] Update README.md --- imagepicker/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/imagepicker/README.md b/imagepicker/README.md index 5f3ccaf..ad3810a 100644 --- a/imagepicker/README.md +++ b/imagepicker/README.md @@ -87,9 +87,30 @@ dependencies { doSomethingWithImageList(list) } ``` + +If you're using Fragments to call the pickers you can leverage [set fragment result listener](https://developer.android.com/reference/androidx/fragment/app/FragmentManager#setfragmentresultlistener) to get back the result and you don't have to restore the listener nor provide a lambda for the listener, it can be as simple as +```kotlin +SingleImagePicker.showPicker(requireContext()) +``` +```kotlin + +setFragmentResultListener(SingleImagePicker.SINGLE_IMAGE_REQUEST_KEY) { _, bundle -> + val loadedModel = bundle.getParcelable(SingleImagePicker.ON_SINGLE_IMAGE_PICK_KEY) + loadedModel?.let { loadImage(it) } + } + +setFragmentResultListener(MultiImagePicker.MULTI_IMAGE_REQUEST_KEY) { _, bundle -> + val loadedModel = bundle.getParcelableArrayList(MultiImagePicker.ON_MULTI_IMAGE_PICK_KEY) + loadedModel?.let { doSomethingWithImageList(it) } + } +``` + ## If you're still not sure how to use, take a look at the [Sample app](https://github.com/CraZyLegenD/MediaPicker/blob/master/app/src/main/java/com/crazylegend/mediapicker/MainActivity.kt) +## +If you're still not sure how to use fragment listener, take a look at the [Sample app](https://github.com/CraZyLegenD/MediaPicker/blob/master/app/src/main/java/com/crazylegend/mediapicker/FragmentResult.kt#L310) + ## Screens Single picker