An Android library to pick single or multiple photos from Unsplash. Supports API 23+
Features:
- Material 3
- Adaptive layout
- Search
- Single and multiple selection
Add it in your root build.gradle
at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add dependency to your module:
dependencies {
// ... other dependencies
implementation "com.github.savvasenok:unsplash-picker:1.0"
}
You can initialize the library from any place in your app, but it is recommended to do it in your Application
class in onCreate
like this:
class App : Application() {
override fun onCreate() {
super.onCreate()
UnsplashPickerConfig.init("YOUR_UNSPLASH_API_KEY")
}
}
The library returns the result as a List<UnsplashPhoto>
of all selected images, even if selection mode is set to single. The data model looks like:
data class UnsplashPhoto(
val id: String,
val thumb: String,
val full: String
)
- id ... identifier of this photo by Unsplash
- thumb ... thumbnail url
- full ... url for the photo in the best possible resolution
Paste this contract in your Activity/Fragment/DialogFragment like any other contract you would do:
val contract = registerForActivityResult(PickingImageFlowFromUnsplashContract()) { unsplashPhotos ->
/* your code here */
}
To actually start the selection flow, launch this contract and specify whether you want user to select single image or an arbitrary amount of them:
// for single image
contract.launch( /* isSingleSelect = */ true)
// for multiple images
contract.launch(/* isSingleSelect = */ false)