bingoogolapple / BGAPhotoPicker-Android

Android 图片选择、预览、九宫格图片控件、拖拽排序九宫格图片控件
2.24k stars 413 forks source link

新版本Glide兼容问题 #165

Open aicareles opened 5 years ago

aicareles commented 5 years ago

java.lang.NoSuchMethodError: No virtual method placeholder(I)Lcom/bumptech/glide/request/RequestOptions; in class Lcom/bumptech/glide/request/RequestOptions; or its super classes (declaration of 'com.bumptech.glide.request.RequestOptions' appears in /data/app/com.example.keli-h0Lm38NUdlZHvovbP2fMmQ==/base.apk) at cn.bingoogolapple.photopicker.imageloader.BGAGlideImageLoader.display(BGAGlideImageLoader.java:47) at cn.bingoogolapple.photopicker.imageloader.BGAImage.display(BGAImage.java:76) at cn.bingoogolapple.photopicker.imageloader.BGAImage.display(BGAImage.java:83) at cn.bingoogolapple.photopicker.imageloader.BGAImage.display(BGAImage.java:87) at cn.bingoogolapple.photopicker.imageloader.BGAImage.display(BGAImage.java:91) at cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout$PhotoAdapter.fillData(BGANinePhotoLayout.java:238) at cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout$PhotoAdapter.fillData(BGANinePhotoLayout.java:223)

作者您好,最近在使用您的图片选择库时,由于项目中用了新版本的glide4.9.0,导致了这个问题,请问可否升级您的开源库兼容新版本glide

iOrchid commented 5 years ago

java.lang.NoSuchMethodError: No virtual method placeholder(I)Lcom/bumptech/glide/request/RequestOptions; in class Lcom/bumptech/glide/request/RequestOptions; or its super classes (declaration of 'com.bumptech.glide.request.RequestOptions' appears in /data/app/com.example.keli-h0Lm38NUdlZHvovbP2fMmQ==/base.apk) at cn.bingoogolapple.photopicker.imageloader.BGAGlideImageLoader.display(BGAGlideImageLoader.java:47) at cn.bingoogolapple.photopicker.imageloader.BGAImage.display(BGAImage.java:76) at cn.bingoogolapple.photopicker.imageloader.BGAImage.display(BGAImage.java:83) at cn.bingoogolapple.photopicker.imageloader.BGAImage.display(BGAImage.java:87) at cn.bingoogolapple.photopicker.imageloader.BGAImage.display(BGAImage.java:91) at cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout$PhotoAdapter.fillData(BGANinePhotoLayout.java:238) at cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout$PhotoAdapter.fillData(BGANinePhotoLayout.java:223)

作者您好,最近在使用您的图片选择库时,由于项目中用了新版本的glide4.9.0,导致了这个问题,请问可否升级您的开源库兼容新版本glide

作者已经在Readme中已经写了兼容Glide3的方式,其实一样的,你只需要继承BGAImageLoader然后自己实现对应函数,再在初始化的地方设置BGAImage.setImageLoader即可

/**
 * 选择照片的bga图片库需要的imageLoader,因为它的glide版本为4.5,而4.9新版会不兼容
 */
class FixedGlideImageLoader : BGAImageLoader() {

    override fun display(imageView: ImageView?, path: String?, loadingResId: Int, failResId: Int, width: Int, height: Int, delegate: BGAImageLoader.DisplayDelegate?) {
        if (imageView == null) return
        val finalPath = getPath(path)
        val activity = getActivity(imageView)
        val options = RequestOptions().placeholder(loadingResId).error(failResId).override(width, height).dontAnimate()
        Glide.with(activity)
                .load(finalPath)
                .apply(options)
                .listener(object : RequestListener<Drawable> {
                    override fun onLoadFailed(@Nullable e: GlideException?
                                              , model: Any
                                              , target: Target<Drawable>
                                              , isFirstResource: Boolean): Boolean {
                        return false
                    }

                    override fun onResourceReady(resource: Drawable, model: Any
                                                 , target: Target<Drawable>
                                                 , dataSource: DataSource
                                                 , isFirstResource: Boolean): Boolean {
                        delegate?.onSuccess(imageView, finalPath)
                        return false
                    }
                })
                .into(imageView)
    }

    override fun download(path: String?, delegate: DownloadDelegate?) {
        val finalPath = getPath(path)
        Glide.with(BGABaseAdapterUtil.getApp())
                .asBitmap()
                .load(finalPath)
                .into(object : CustomTarget<Bitmap>() {
                    override fun onLoadCleared(placeholder: Drawable?) {
                        //do nothing
                    }

                    override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                        delegate?.onSuccess(finalPath, resource)
                    }

                    override fun onLoadFailed(@Nullable errorDrawable: Drawable?) {
                        delegate?.onFailed(finalPath)
                    }
                })
    }

    override fun pause(activity: Activity?) {
        if (activity != null) {
            Glide.with(activity).pauseRequests()
        }
    }

    override fun resume(activity: Activity?) {
        if (activity != null) {
            Glide.with(activity).resumeRequestsRecursive()
        }
    }
}
aicareles commented 5 years ago

是的,当时就是看了那个 解决的,多谢