This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
||
}) | ||
|
||
} |