Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ Update feature - Picker library Part 4 #42

Conversation

priyankj-simform
Copy link
Collaborator

@priyankj-simform priyankj-simform commented Aug 30, 2022

Update image picker library with configuration changes, picker config changes, and bucket name changes.

Part -4 contains the files related to the new image picker library's modification and changes.

Changes :

  • ⚡ Support for the device rotation configuration change.
  • ⚡ Picker config changes to limit max pick count, max size is in now float and a new way to register image picker.
  • ✨ Support for new photo picker up to Android 11. More details

Major File Changes:

Added

  • PickerConfigManager.kt - This class is the manager for the picker config. It extends SavedStateProvider to persist the picker config during activity configuration changes and process death.

🚧 Modified

  • ImagePicker.kt - Added a new way to register for the ImagePicker and it's listener. Now the user needs to create the library before on create.
  • ImagePickerViewModel.kt - Changed the MutableState flow to MutableSharedFlow. The state flow was causing issues in no data found as the same values cannot be emitted by state flow.
  • BaseFragment.kt - Modified base fragment to handle the configuration change. Rotation change will now display different grid span counts for recycler view.
  • DataModels.kt - Included support for floating max size. Also, limits the max pick count to 15.
  • attr.xml - Added an attribute ssPickerGridCountLandscape to represent grid count in landscape mode.
  • Extension.kt - Added some important extensions to easily check, get and register tasks.

📚 Usage:

  1. Add ImagePickerActivity into your AndroidManifest.xml. SSImagePicker is the default theme for image picker activity.
<activity
    android:name="com.app.imagepickerlibrary.ui.activity.ImagePickerActivity"
    android:configChanges="orientation|screenSize"
    android:theme="@style/SSImagePicker" />
  1. If you want to use Picker options Bottomsheet then implement SSPickerOptionsBottomSheet.ImagePickerClickListener in your fragment or activity. onImageProvider method will give the selected provider type.
    val pickerOptionBottomSheet = SSPickerOptionsBottomSheet.newInstance()
    pickerOptionBottomSheet.show(supportFragmentManager,"tag")
    ....
    override fun onImageProvider(provider: ImageProvider) {
        when (provider) {
            ImageProvider.GALLERY -> {
                //Open gallery
            }
            ImageProvider.CAMERA -> {
                //Open camera
            }
            ImageProvider.NONE -> {}
        }
    }
  1. Open Image Picker from activity or fragment via registering the image picker. It will give the object of ImagePicker class.
    private val imagePicker: ImagePicker = registerImagePicker(callback = this)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ...
    }
    
    //To Open the picker call the open method passing the picker type.
    imagePicker.open(PickerType.GALLERY)
  1. Add customization to the image picker via the image picker object. All the methods with descriptions are declared inside ImagePicker.kt file.
    imagePicker
            .title("My Picker")
            .multipleSelection(enable = true, maxCount = 5)
            .showCountInToolBar(false)
            .showFolder(true)
            .cameraIcon(true)
            .doneIcon(true)
            .allowCropping(true)
            .compressImage(false)
            .maxImageSize(2)
            .extension(PickExtension.JPEG)
    imagePicker.open(PickerType.GALLERY)
  1. To get results in activity or fragment implement ImagePickerResultListener.
    class MainActivity : AppCompatActivity(), ImagePickerResultListener {
        ...
    }
  1. Single Selection and The image captured from the camera will be received in
    onImagePick(uri: Uri?) callback.
    override fun onImagePick(uri: Uri?) {
        //Do something with uri
    }
  1. Multiple Selection uris will be received in onMultiImagePick(uris: List?) callback.
    override fun onMultiImagePick(uris: List<Uri>?) {
        //Do something with uris
    }

@priyankj-simform priyankj-simform changed the title ⚡ Update feature - Picker library ⚡ Update feature - Picker library Part 4 Aug 30, 2022
Update image picker library with configuration changes, picker config changes and bucket name changes.
@yashwantgowla-simform yashwantgowla-simform merged commit a147dbd into SimformSolutionsPvtLtd:develop Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants