Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
[CHORE] add example util method
Browse files Browse the repository at this point in the history
  • Loading branch information
kudanai committed Oct 14, 2020
1 parent 62e35ab commit cb8c8f7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/src/main/java/io/dotlottie/sample/utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.dotlottie.sample

import android.util.Log
import android.widget.Toast
import com.airbnb.lottie.LottieAnimationView
import io.dotlottie.loader.AbstractLoader
import io.dotlottie.loader.models.DotLottie
import io.dotlottie.loader.models.DotLottieResult
import java.io.ByteArrayInputStream
import java.io.InputStream

fun AbstractLoader.into(view: LottieAnimationView) {

load(object: DotLottieResult {
override fun onSuccess(result: DotLottie) {

//set image handler
view.setImageAssetDelegate(AppImageDelegate.getDelegate(view.context, result.images))

// set the animation
result.animations?.entries.first()?.let {
val input = ByteArrayInputStream(it.value)
view.setAnimation(input as InputStream, null)
view.playAnimation()

}
Log.d("DotLottie", "Parsed ${result}")
}

override fun onError(throwable: Throwable) {
Toast.makeText(view.context, "Error Loading Lottie", Toast.LENGTH_LONG)
.show()

throwable.printStackTrace()
}

})

}

0 comments on commit cb8c8f7

Please sign in to comment.