Fallery is a solution for creating custom online/offline galley that is written with kotlin. I’m an Android developer and I have not seen a gallery and media picker with high customizability for android. There are a few libraries that are interesting but that not highly customizable. This is the main reason of creating Fallery.
Key features
- Select media(photo, video) from android media store with custom offline gallery or custom online gallery.
- Compatible with android API Level 14 to 30.
- Content Observer.
- Filter media based on types(Photos, videos, both).
- Modern user interface with the capability to add new themes and languages.
- Select media with a caption.
- Taking photos from the camera with the intent.
- Showing bucket list in two different UI(grid and linear) which user can switches between them in runtime.
- Support setting max selectable media by user.
- Support orientation.
- Support custom edit text layout for caption(for emoji compatibility, etc).
- Enable or disable media counts in fallery toolbar.
- Support Vertical, Horizontal scrolling in showing media view-pager.
- Support any view-pager transformer in media view-pager.
- Support custom onClick for video toggle in the video preview screen.
- Automatic grant external storage permissions.
- Automatic grant shared storage permissions(only for android +10).
- Easy to use.
Usage
How to add Fallery to android app ?
Gradle. Step 1. Add it in your root build.gradle
at the end of repositories:
allprojects {
repositories {
maven { url https://jitpack.io }
}
}
Step 2. Add the dependency
dependencies {
implementation com.github.mehdiyari:Fallery:{latest_version}
}
Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.mehdiyari</groupId>
<artifactId>Fallery</artifactId>
<version>{latest_version}</version>
</dependency>
How to use Fallery for pick medias on device ?
Fallery designed to be used in java and kotlin. but before starting fallery you must set an image loader. reason for doing that is fallery is not using image loader libraries(Glide, Picasso) by default for decrease library size. for creating fallery image loader you must create ImageLoader and implement the FalleryImageLoader
interface like this
class GlideImageLoader : FalleryImageLoader {
override fun loadPhoto(
context: Context,
imageView: ImageView,
resizeDiminution: PhotoDiminution,
placeHolderColor: Int,
path: String
) {
Glide.with(imageView)
.asBitmap()
.placeholder(ColorDrawable(placeHolderColor))
.load(path)
.override(resizeDiminution.width, resizeDiminution.height)
.into(imageView)
}
override fun loadGif(
context: Context,
imageView: ImageView,
resizeDiminution: PhotoDiminution,
placeHolderColor: Int,
path: String
) {
Glide.with(imageView)
.asGif()
.placeholder(ColorDrawable(placeHolderColor))
.load(path)
.override(resizeDiminution.width, resizeDiminution.height)
.into(imageView)
}
}
And simply passing the new object of this class to FalleryBuilder
. below you can see kotlin and java examples.
Kotlin
class MainActivity : AppCompatActivity(R.layout.activity_main) { private val glideImageLoader by lazy { GlideImageLoader() } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val falleryOptions = FalleryBuilder() .setImageLoader(glideImageLoader) .build() falleryButton.setOnClickListener { startFalleryWithOptions(requestCode = 1, falleryOptions = falleryOptions) } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == 1 && resultCode == RESULT_OK && data != null) { handleResultWithCaption( result = data?.getFalleryResultMediasFromIntent(), caption = data?.getFalleryCaptionFromIntent() ) } } private fun handleResultWithCaption(result: Array<String>?, caption: String?) { TODO("handle result and caption") } }
Java
public class MainActivity extends AppCompatActivity { private Button button; private GlideImageLoader glideImageLoader = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); glideImageLoader = New GlideImageLoader(); final FalleryOptions falleryOptions = new FalleryBuilder() .setImageLoader(glideImageLoader) .build(); this.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fallery.startFalleryFromActivityWithOptions( MainActivity.this, 1, falleryOptions ); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1 && resultCode == RESULT_OK && data != null) { String[] result = Fallery.getResultMediasFromIntent(data); String caption = Fallery.getCaptionFromIntent(data); handleResultWithCaption(result, caption); } } private void handleResultWithCaption(String[] result, String caption) { // todo: handle result and caption } }
These examples show how to start fallery in java/kotlin activity. for fragments, in kotlin, you can start fallery with startFalleryWithOptions
but for java, you must start fallery with Fallery.startFalleryFromFragmentWithOptions
and override onActivityResult
method for fragment and extract the result from input intent.
Be First to Comment