Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
feat: Set ParseCompletion Nullable.
Browse files Browse the repository at this point in the history
  • Loading branch information
errnull committed Sep 10, 2019
1 parent ae36dc3 commit 41b2c8f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions library/src/main/java/com/opensource/svgaplayer/SVGAParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SVGAParser(private val context: Context) {
}
}

fun decodeFromAssets(name: String, callback: ParseCompletion) {
fun decodeFromAssets(name: String, callback: ParseCompletion?) {
try {
context.assets.open(name)?.let {
this.decodeFromInputStream(it, buildCacheKey("file:///assets/$name"), callback, true)
Expand All @@ -104,7 +104,7 @@ class SVGAParser(private val context: Context) {
}
}

fun decodeFromURL(url: URL, callback: ParseCompletion): (() -> Unit)? {
fun decodeFromURL(url: URL, callback: ParseCompletion?): (() -> Unit)? {
if (this.isCached(buildCacheKey(url))) {
threadPoolExecutor.execute {
this.decodeFromCacheKey(buildCacheKey(url), callback)
Expand All @@ -120,7 +120,7 @@ class SVGAParser(private val context: Context) {
}
}

fun decodeFromInputStream(inputStream: InputStream, cacheKey: String, callback: ParseCompletion, closeInputStream: Boolean = false) {
fun decodeFromInputStream(inputStream: InputStream, cacheKey: String, callback: ParseCompletion?, closeInputStream: Boolean = false) {
threadPoolExecutor.execute {
try {
readAsBytes(inputStream)?.let { bytes ->
Expand Down Expand Up @@ -155,44 +155,44 @@ class SVGAParser(private val context: Context) {
* @deprecated from 2.4.0
*/
@Deprecated("This method has been deprecated from 2.4.0.", ReplaceWith("this.decodeFromAssets(assetsName, callback)"))
fun parse(assetsName: String, callback: ParseCompletion) {
fun parse(assetsName: String, callback: ParseCompletion?) {
this.decodeFromAssets(assetsName, callback)
}

/**
* @deprecated from 2.4.0
*/
@Deprecated("This method has been deprecated from 2.4.0.", ReplaceWith("this.decodeFromURL(url, callback)"))
fun parse(url: URL, callback: ParseCompletion) {
fun parse(url: URL, callback: ParseCompletion?) {
this.decodeFromURL(url, callback)
}

/**
* @deprecated from 2.4.0
*/
@Deprecated("This method has been deprecated from 2.4.0.", ReplaceWith("this.decodeFromInputStream(inputStream, cacheKey, callback, closeInputStream)"))
fun parse(inputStream: InputStream, cacheKey: String, callback: ParseCompletion, closeInputStream: Boolean = false) {
fun parse(inputStream: InputStream, cacheKey: String, callback: ParseCompletion?, closeInputStream: Boolean = false) {
this.decodeFromInputStream(inputStream, cacheKey, callback, closeInputStream)
}

private fun invokeCompleteCallback(videoItem: SVGAVideoEntity, callback: ParseCompletion) {
private fun invokeCompleteCallback(videoItem: SVGAVideoEntity, callback: ParseCompletion?) {
Handler(context.mainLooper).post {
callback.onComplete(videoItem)
callback?.onComplete(videoItem)
}
}

private fun invokeErrorCallback(e: java.lang.Exception, callback: ParseCompletion) {
private fun invokeErrorCallback(e: java.lang.Exception, callback: ParseCompletion?) {
e.printStackTrace()
Handler(context.mainLooper).post {
callback.onError()
callback?.onError()
}
}

private fun isCached(cacheKey: String): Boolean {
return buildCacheDir(cacheKey).exists()
}

private fun decodeFromCacheKey(cacheKey: String, callback: ParseCompletion) {
private fun decodeFromCacheKey(cacheKey: String, callback: ParseCompletion?) {
try {
val cacheDir = File(context.cacheDir.absolutePath + "/" + cacheKey + "/")
File(cacheDir, "movie.binary").takeIf { it.isFile }?.let { binaryFile ->
Expand Down

0 comments on commit 41b2c8f

Please sign in to comment.