Imageviewer

Provides a seamless transition from thumbnail view to original view, and elegantly browse normal, long and GIF images.

The main function

  • Provides seamless animation when animating thumbnails to larger or larger images to thumbnails
  • When viewing a large picture, use a normal hand. Such as zooming pictures and so on.
  • Large image block loading. Avoid OOM (SubsamplingScaleImageView)
  • Video Support for Video loading (SimpleExoPlayer)
  • Drag close to exit browsing for up/down operation on large image.
  • Data paging loads millions of data asynchronously while viewing a large graph.
  • Custom UI Appends custom UI elements to preview pages

use

Implementation 'com. Making. Iielse: imageviewer: 2.1.2'Copy the code
Val Builder = ImageViewerBuilder(context = this, initKey = photo.id, // used to locate the initialization position after the thumbnail is clicked to change the large image. DataProvider = MyDataProvider(), // Browse the provider of the data source. ImageLoader = MyImageLoader(), // load the data source. Transformer = MyTransformer() // photoId as identifier, SetVHCustomizer (MyCustomViewHolderUI()) // Customize the UI on each page. For example, more information about images can be displayed. Provide storage sharing more functions such as builder. SetOverlayCustomizer (MyCustomIndicatorUI ()) / / custom 'cover (the) layer on the UI. Such as adding indicators such as builder. SetViewerCallback (MyViewerStateChangedListener ()) / / to monitor all kinds of state change in the viewer. Including page switching. And the execution state of the transition animation builder.show()Copy the code

The main interface

Class MyImageLoader: ImageLoader {/** * load images based on their own photo data. */ Override fun Load (view: ImageView, data: Photo, viewHolder: RecyclerView.ViewHolder) { val it = (data as? MyData?) ? .url ? : return Glide.with(view).load(it) .override(view.width, View.height).placeholder(view.drawable).into(view)} /** * The subsamplingView data source needs to download the full content locally. Need to pay attention to the life cycle of * / override fun load (subsamplingView: SubsamplingScaleImageView, data: Photo, viewHolder: RecyclerView.ViewHolder) { val it = (data as? MyData?) ? .url ? : return subsamplingDownloadRequest(it) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { findLoadingView(viewHolder)? .visibility = View.VISIBLE } .doFinally { findLoadingView(viewHolder)? .visibility = View.GONE } .doOnNext { subsamplingView.setImage(ImageSource.uri(Uri.fromFile(it))) } .doOnError { toast(it.message) } .subscribe().bindLifecycle(subsamplingView) } private fun subsamplingDownloadRequest(url: String): Observable<File> { return Observable.create { try { it.onNext(Glide.with(appContext()).downloadOnly().load(url).submit().get()) it.onComplete() } catch (e: java.lang.Exception) { if (! it.isDisposed) it.onError(e) } } } private fun findLoadingView(viewHolder: RecyclerView.ViewHolder): View? { return viewHolder.itemView.findViewById<ProgressBar>(R.id.loadingView) } }Copy the code

A little.

Other instructions

RTL layout adapted Video Loading See Demo Demo works. The Demo code has been reconstructed. Good readability. Rest assured to eat

Click to jump to source project address