iielse / imageviewer

A simple and customizable Android full-screen image viewer 一个简单且可自定义的Android全屏图像浏览器
MIT License
2.23k stars 310 forks source link

Could you add generalize support ? #53

Closed gyqsophila closed 4 years ago

gyqsophila commented 6 years ago

usually we load network image, and only has url ,we customize a local type named Image with some additional attributes like rotation and so on, In loader completion class, I need to also load rotated image. so in such case, How can i use this library ? I had try to add generalization to this library, bug failed .

一般我们加载的都是网络图片,然后会自定义本地的 Image 数据类型,会包含一些额外的属性比如 旋转角度 等; 在 Loader 的实现中,需要加载旋转后的图片; 在这种情况下,我应该如何使用这个库呢? 我尝试给这个库加入泛型支持,但是失败了。

iielse commented 4 years ago
public interface Loader {
    void load(Context context, Uri uri, LoadCallback lc);
}

修改为
interface Photo {
    fun id(): Long
    fun subsampling(): Boolean = false
}
interface ImageLoader {
    fun load(view: ImageView, data: Photo, viewHolder: RecyclerView.ViewHolder)
    fun load(subsamplingView: SubsamplingScaleImageView, data: Photo, viewHolder: RecyclerView.ViewHolder)
}

对于你的这种情况.我将Loader的接口进行了调整. 现在框架不关心数据源是什么,也不关心加载过程.全权交给开发者. 你仅仅需要“自定义本地的 Image 数据类型”来实现Photo接口 告诉框架是否使用 SubsamplingScaleImageView 加载超大图. 以及每条数据的唯一标示.(用于分页拉数据)