Custom Gallery For Android
--
Hey Guys !! This is my 2nd story here on medium. After writing up on Camera2 Android API I realized another common problem that android developers face, which is a need for a customized gallery inside their android applications. So I came up with a generic solution which has a lot of pros as compared to other 3rd-party libraries and solutions online which implicated limitations when compiled as dependencies in your app. You can find the complete code on Github.
Content:
The purpose of this article is to show you the pros and the magic behind the custom gallery working as well as how the image selection algorithm works with a great run-time complexity. I will also be explaining about the custom pagination I developed to fetch all images from the device storage using Android’s Cursor API asynchronously through reactive programming while following a clean code architecture.
Pre-Requisites:
We will be using Kotlin and AndroidX artifacts so you must have them configured and RxJava for the purpose of fetching images in background and posting result to main thread. So I assume you are familiar with basics of reactive programming.
Why to use ?
- Shows all images smoothly from device storage.
- Multiple Image Selection.
- Open to Support for Image Deletion.
- Uses Pagination.
- Its not a fixed dependency to be included in your project to increase redundancy.
- Its flexible to be converted in any library/SDK or modular form as per your requirement.
- Modifications/Enhancements can be made as required.
- Highly decoupled,optimized and clean code.
- No Obfuscation Required (Proguard/Dexguard).
- It would be a part of your project while not implying any 3rd-party involvement.
Let’s get Started
1st of all you will need to add read storage permission in your Android Manifest and also ask it at run time before allowing the user to open your gallery activity. This permission is required for reading data from device storage.
<uses-permission…