esafirm / android-image-picker

Image Picker for Android 🤖

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I am using 1.8.0 but i dont need glide is it possible with this library

amankumarjain opened this issue · comments

I am using fresco for image loading, and with this library glide gets added in my external libraries how to remove it?

in your dependencies:
final glideVersion = '4.5.0'
implementation "com.github.bumptech.glide:glide:$glideVersion"

is it possible to use it without glide?

@amankumarjain i think if you set a custom ImageLoader and then exclude Glide in the build.gradle

But i haven't tried it yet.

ok i will try that, just want to know if glide is being used in this library or not? otherwise it will break something else.
is their any readme to know how to set custom image loader?

@amankumarjain If you try this and get it working, please let me know. I'm already using Picasso and would prefer not to include Glide as well if it's not necessary.

You can remove glide by using a custom image loader and then excluding glide with gradle.

Custom image loader:

class PicassoImageLoader : ImageLoader {
    
    companion object {
        const val WIDTH = 300
        const val HEIGHT = 300
    }

    override fun loadImage(path: String, imageView: ImageView, imageType: ImageType) {
        val placeholderResId = when(imageType) {
            ImageType.FOLDER -> R.drawable.ef_folder_placeholder
            else -> R.drawable.ef_image_placeholder
        }

        Picasso.with(imageView.context)
                .load(File(path))
                .resize(WIDTH, HEIGHT)
                .centerCrop()
                .placeholder(placeholderResId)
                .error(placeholderResId)
                .into(imageView)
    }
}

Starting image picker with custom image loader:

ImagePicker
    .create(activity)
    .single()
    .imageLoader(PicassoImageLoader())
    .start()

Excluding Glide with gradle:

implementation("com.github.esafirm.android-image-picker:imagepicker:1.12.0", {
    exclude group: 'com.github.bumptech.glide', module: 'glide'
})

Thanks @Galaxer for confirming this. I think i should add this somewhere 😄

Included in README. Closing this. Thanks all 🙏

Great job @Galaxer!

@esafirm Perhaps this should be incorporated within the library somehow?

  • Either include the above snippet directly
  • Provide a base library dependency along with multiple optional sub-dependencies hooking up image picker with the user's choice of library?

@amankumarjain how did you managed to add fresco as a custom image Loader

commented

Java example for Picasso

import android.widget.ImageView;
import com.esafirm.imagepicker.features.imageloader.ImageLoader;
import com.esafirm.imagepicker.features.imageloader.ImageType;
import com.squareup.picasso.Picasso;

public class PicassoImageLoader implements ImageLoader {

  @Override
  public void loadImage(String path, ImageView imageView, ImageType imageType) {
    Picasso.get()
            .load("file://"+path)
            .resize(500, 500).centerCrop()
            .into(imageView);
  }
}

I have managed to add Fresco like this

`

public class FrescoImageLoader implements ImageLoader {


@Override
public void loadImage(String path, ImageView imageView, ImageType imageType) {
    Drawable defaultDrawable = imageView.getDrawable();
    Resources resources = imageView.getContext().getResources();
    GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(resources)
            .build();
    final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, imageView.getContext());
    draweeHolder.getHierarchy().setProgressBarImage(new ProgressBarDrawable());
    Drawable drawable = draweeHolder.getHierarchy().getTopLevelDrawable();
    if (drawable == null) {
        imageView.setImageDrawable(defaultDrawable);
    } else {
        imageView.setImageDrawable(drawable);
    }

    Uri uri = new Uri.Builder()
            .scheme(UriUtil.LOCAL_FILE_SCHEME)
            .path(path)
            .build();
    ImageRequest imageRequest = ImageRequestBuilder
            .newBuilderWithSource(uri)
            .setResizeOptions(new ResizeOptions(200, 200))
            .build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setOldController(draweeHolder.getController())
            .setImageRequest(imageRequest)
            .build();
    draweeHolder.setController(controller);

}

}`

I use it with picasso like this

Image image = ImagePicker.getFirstImageOrNull();

Picasso.get()
.load("file://".concat(image.getPath()))
.resize(100, 100)
.centerCrop()
.into(imageView);

but I am not sure this is the best way.

Hi All! I have a question!
It is possible to allow only images in landscape?