Skip to content

Instantly share code, notes, and snippets.

@YuriDenison
Created April 14, 2018 20:21
Show Gist options
  • Save YuriDenison/2be7fa1e4a526b67c209dce659ba331b to your computer and use it in GitHub Desktop.
Save YuriDenison/2be7fa1e4a526b67c209dce659ba331b to your computer and use it in GitHub Desktop.
class FrescoSphericalPanoramaView(context: Context, attrs: AttributeSet) : SphericalPanoramaView(context: Context, attrs: AttributeSet) {
private val multiDraweeHolder: MultiDraweeHolder<GenericDraweeHierarchy> = MultiDraweeHolder()
fun bindTo(tileUris: List<Uri>) = post {
multiDraweeHolder.clear()
val imagesSetter = getImagesSetter(...)
tileUris.forEachIndexed { index, uri ->
val holder = DraweeHolder.create(GenericDraweeHierarchyBuilder(resources).build(), context)
val imageRequest = ImageRequestBuilder.newBuilderWithSource(uri)
.setPostprocessor(object : BasePostprocessor() {
override fun process(bitmap: Bitmap) {
imagesSetter.setImageToSector(index, bitmap)
}
})
.build()
holder.controller = Fresco.newDraweeControllerBuilder()
.setOldController(holder.controller)
.setImageRequest(imageRequest)
.build()
holder.topLevelDrawable.callback = this
multiDraweeHolder.add(holder)
}
}
@SuppressLint("MissingSuperCall")
override fun verifyDrawable(who: Drawable): Boolean = multiDraweeHolder.verifyDrawable(who)
public override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
multiDraweeHolder.onDetach()
}
override fun onStartTemporaryDetach() {
super.onStartTemporaryDetach()
multiDraweeHolder.onDetach()
}
public override fun onAttachedToWindow() {
super.onAttachedToWindow()
multiDraweeHolder.onAttach()
}
override fun onFinishTemporaryDetach() {
super.onFinishTemporaryDetach()
multiDraweeHolder.onAttach()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment