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

Commit 41b2c8f

Browse files
committed
feat: Set ParseCompletion Nullable.
1 parent ae36dc3 commit 41b2c8f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

library/src/main/java/com/opensource/svgaplayer/SVGAParser.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SVGAParser(private val context: Context) {
9393
}
9494
}
9595

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

107-
fun decodeFromURL(url: URL, callback: ParseCompletion): (() -> Unit)? {
107+
fun decodeFromURL(url: URL, callback: ParseCompletion?): (() -> Unit)? {
108108
if (this.isCached(buildCacheKey(url))) {
109109
threadPoolExecutor.execute {
110110
this.decodeFromCacheKey(buildCacheKey(url), callback)
@@ -120,7 +120,7 @@ class SVGAParser(private val context: Context) {
120120
}
121121
}
122122

123-
fun decodeFromInputStream(inputStream: InputStream, cacheKey: String, callback: ParseCompletion, closeInputStream: Boolean = false) {
123+
fun decodeFromInputStream(inputStream: InputStream, cacheKey: String, callback: ParseCompletion?, closeInputStream: Boolean = false) {
124124
threadPoolExecutor.execute {
125125
try {
126126
readAsBytes(inputStream)?.let { bytes ->
@@ -155,44 +155,44 @@ class SVGAParser(private val context: Context) {
155155
* @deprecated from 2.4.0
156156
*/
157157
@Deprecated("This method has been deprecated from 2.4.0.", ReplaceWith("this.decodeFromAssets(assetsName, callback)"))
158-
fun parse(assetsName: String, callback: ParseCompletion) {
158+
fun parse(assetsName: String, callback: ParseCompletion?) {
159159
this.decodeFromAssets(assetsName, callback)
160160
}
161161

162162
/**
163163
* @deprecated from 2.4.0
164164
*/
165165
@Deprecated("This method has been deprecated from 2.4.0.", ReplaceWith("this.decodeFromURL(url, callback)"))
166-
fun parse(url: URL, callback: ParseCompletion) {
166+
fun parse(url: URL, callback: ParseCompletion?) {
167167
this.decodeFromURL(url, callback)
168168
}
169169

170170
/**
171171
* @deprecated from 2.4.0
172172
*/
173173
@Deprecated("This method has been deprecated from 2.4.0.", ReplaceWith("this.decodeFromInputStream(inputStream, cacheKey, callback, closeInputStream)"))
174-
fun parse(inputStream: InputStream, cacheKey: String, callback: ParseCompletion, closeInputStream: Boolean = false) {
174+
fun parse(inputStream: InputStream, cacheKey: String, callback: ParseCompletion?, closeInputStream: Boolean = false) {
175175
this.decodeFromInputStream(inputStream, cacheKey, callback, closeInputStream)
176176
}
177177

178-
private fun invokeCompleteCallback(videoItem: SVGAVideoEntity, callback: ParseCompletion) {
178+
private fun invokeCompleteCallback(videoItem: SVGAVideoEntity, callback: ParseCompletion?) {
179179
Handler(context.mainLooper).post {
180-
callback.onComplete(videoItem)
180+
callback?.onComplete(videoItem)
181181
}
182182
}
183183

184-
private fun invokeErrorCallback(e: java.lang.Exception, callback: ParseCompletion) {
184+
private fun invokeErrorCallback(e: java.lang.Exception, callback: ParseCompletion?) {
185185
e.printStackTrace()
186186
Handler(context.mainLooper).post {
187-
callback.onError()
187+
callback?.onError()
188188
}
189189
}
190190

191191
private fun isCached(cacheKey: String): Boolean {
192192
return buildCacheDir(cacheKey).exists()
193193
}
194194

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

0 commit comments

Comments
 (0)