@@ -56,7 +56,10 @@ class SVGAParser(context: Context?) {
56
56
}
57
57
threadPoolExecutor.execute {
58
58
try {
59
- LogUtils .info(TAG , " ================ svga file download start ================" )
59
+ LogUtils .info(
60
+ TAG ,
61
+ " ================ svga file: $url download start ================"
62
+ )
60
63
if (HttpResponseCache .getInstalled() == null && ! noCache) {
61
64
LogUtils .error(
62
65
TAG ,
@@ -80,7 +83,7 @@ class SVGAParser(context: Context?) {
80
83
if (cancelled) {
81
84
LogUtils .warn(
82
85
TAG ,
83
- " ================ svga file download canceled ================"
86
+ " ================ svga file: $url download canceled ================"
84
87
)
85
88
break
86
89
}
@@ -93,24 +96,21 @@ class SVGAParser(context: Context?) {
93
96
if (cancelled) {
94
97
LogUtils .warn(
95
98
TAG ,
96
- " ================ svga file download canceled ================"
99
+ " ================ svga file: $url download canceled ================"
97
100
)
98
101
return @execute
99
102
}
100
103
ByteArrayInputStream (outputStream.toByteArray()).use {
101
104
LogUtils .info(
102
105
TAG ,
103
- " ================ svga file download complete ================"
106
+ " ================ svga file: $url download complete ================"
104
107
)
105
108
complete(it)
106
109
}
107
110
}
108
111
}
109
112
}
110
113
} catch (e: Exception ) {
111
- LogUtils .error(TAG , " ================ svga file download fail ================" )
112
- LogUtils .error(TAG , " error: ${e.message} " )
113
- e.printStackTrace()
114
114
failure(e)
115
115
}
116
116
}
@@ -154,19 +154,20 @@ class SVGAParser(context: Context?) {
154
154
LogUtils .error(TAG , " 在配置 SVGAParser context 前, 无法解析 SVGA 文件。" )
155
155
return
156
156
}
157
- LogUtils .info(TAG , " ================ decode from assets ================" )
157
+ LogUtils .info(TAG , " ================ decode $name from assets ================" )
158
158
threadPoolExecutor.execute {
159
159
try {
160
160
mContext?.assets?.open(name)?.let {
161
161
this .decodeFromInputStream(
162
162
it,
163
163
SVGACache .buildCacheKey(" file:///assets/$name " ),
164
164
callback,
165
- true
165
+ true ,
166
+ alias = name
166
167
)
167
168
}
168
169
} catch (e: java.lang.Exception ) {
169
- this .invokeErrorCallback(e, callback)
170
+ this .invokeErrorCallback(e, callback, name )
170
171
}
171
172
}
172
173
}
@@ -176,39 +177,44 @@ class SVGAParser(context: Context?) {
176
177
LogUtils .error(TAG , " 在配置 SVGAParser context 前, 无法解析 SVGA 文件。" )
177
178
return null
178
179
}
179
- LogUtils .info(TAG , " ================ decode from url ================" )
180
+ val urlPath = url.toString()
181
+ LogUtils .info(TAG , " ================ decode $urlPath from url ================" )
180
182
val cacheKey = SVGACache .buildCacheKey(url);
181
183
return if (SVGACache .isCached(cacheKey)) {
182
184
LogUtils .info(TAG , " this url cached" )
183
185
threadPoolExecutor.execute {
184
186
if (SVGACache .isDefaultCache()) {
185
- this .decodeFromCacheKey(cacheKey, callback)
187
+ this .decodeFromCacheKey(cacheKey, callback, alias = urlPath )
186
188
} else {
187
- this ._decodeFromCacheKey (cacheKey, callback)
189
+ this ._decodeFromCacheKey (cacheKey, callback, alias = urlPath )
188
190
}
189
191
}
190
192
return null
191
193
} else {
192
194
LogUtils .info(TAG , " no cached, prepare to download" )
193
195
fileDownloader.resume(url, {
194
196
if (SVGACache .isDefaultCache()) {
195
- this .decodeFromInputStream(it, cacheKey, callback)
197
+ this .decodeFromInputStream(it, cacheKey, callback, alias = urlPath )
196
198
} else {
197
- this ._decodeFromInputStream (it, cacheKey, callback)
199
+ this ._decodeFromInputStream (it, cacheKey, callback, alias = urlPath )
198
200
}
199
201
}, {
200
- this .invokeErrorCallback(it, callback)
202
+ LogUtils .error(
203
+ TAG ,
204
+ " ================ svga file: $url download fail ================"
205
+ )
206
+ this .invokeErrorCallback(it, callback, alias = urlPath)
201
207
})
202
208
}
203
209
}
204
210
205
211
/* *
206
212
* 读取解析本地缓存的svga文件.
207
213
*/
208
- fun _decodeFromCacheKey (cacheKey : String , callback : ParseCompletion ? ) {
214
+ fun _decodeFromCacheKey (cacheKey : String , callback : ParseCompletion ? , alias : String ) {
209
215
val svga = SVGACache .buildSvgaFile(cacheKey)
210
216
try {
211
- LogUtils .info(TAG , " cache.binary change to entity" )
217
+ LogUtils .info(TAG , " $alias cache.binary change to entity" )
212
218
FileInputStream (svga).use { inputStream ->
213
219
try {
214
220
readAsBytes(inputStream)?.let { bytes ->
@@ -223,28 +229,29 @@ class SVGAParser(context: Context?) {
223
229
)
224
230
videoItem.prepare {
225
231
LogUtils .info(TAG , " cache.prepare success" )
226
- this .invokeCompleteCallback(videoItem, callback)
232
+ this .invokeCompleteCallback(videoItem, callback, alias )
227
233
}
228
- } ? : doError(" cache.inflate(bytes) cause exception" , callback)
229
- } ? : doError(" cache.readAsBytes(inputStream) cause exception" , callback)
234
+ } ? : doError(" cache.inflate(bytes) cause exception" , callback, alias )
235
+ } ? : doError(" cache.readAsBytes(inputStream) cause exception" , callback, alias )
230
236
} catch (e: Exception ) {
231
- this .invokeErrorCallback(e, callback)
237
+ this .invokeErrorCallback(e, callback, alias )
232
238
} finally {
233
239
inputStream.close()
234
240
}
235
241
}
236
242
} catch (e: Exception ) {
237
- LogUtils .error(TAG , " cache.binary change to entity fail" , e)
243
+ LogUtils .error(TAG , " $alias cache.binary change to entity fail" , e)
238
244
svga.takeIf { it.exists() }?.delete()
239
- this .invokeErrorCallback(e, callback)
245
+ this .invokeErrorCallback(e, callback, alias )
240
246
}
241
247
}
242
248
243
- fun doError (error : String , callback : ParseCompletion ? ) {
244
- LogUtils .info (TAG , error)
249
+ fun doError (error : String , callback : ParseCompletion ? , alias : String ) {
250
+ LogUtils .error (TAG , error)
245
251
this .invokeErrorCallback(
246
252
Exception (error),
247
- callback
253
+ callback,
254
+ alias
248
255
)
249
256
}
250
257
@@ -254,11 +261,12 @@ class SVGAParser(context: Context?) {
254
261
fun _decodeFromInputStream (
255
262
inputStream : InputStream ,
256
263
cacheKey : String ,
257
- callback : ParseCompletion ?
264
+ callback : ParseCompletion ? ,
265
+ alias : String
258
266
) {
259
267
threadPoolExecutor.execute {
260
268
try {
261
- LogUtils .info(TAG , " Input .binary change to entity" )
269
+ LogUtils .info(TAG , " $alias input .binary change to entity" )
262
270
readAsBytes(inputStream)?.let { bytes ->
263
271
threadPoolExecutor.execute {
264
272
SVGACache .buildSvgaFile(cacheKey).let { cacheFile ->
@@ -271,7 +279,7 @@ class SVGAParser(context: Context?) {
271
279
}
272
280
}
273
281
}
274
- LogUtils .info(TAG , " Input .inflate start" )
282
+ LogUtils .info(TAG , " input .inflate start" )
275
283
inflate(bytes)?.let { inflateBytes ->
276
284
LogUtils .info(TAG , " Input.inflate success" )
277
285
val videoItem = SVGAVideoEntity (
@@ -286,13 +294,13 @@ class SVGAParser(context: Context?) {
286
294
// 在ImageView添加clearsAfterDetached,用于控制imageview在onDetach的时候是否要自动调用clear.
287
295
// 以暂时缓解需要为RecyclerView缓存drawable或者entity的人士.用完记得调用clear()
288
296
videoItem.prepare {
289
- LogUtils .info(TAG , " Input .prepare success" )
290
- this .invokeCompleteCallback(videoItem, callback)
297
+ LogUtils .info(TAG , " input .prepare success" )
298
+ this .invokeCompleteCallback(videoItem, callback, alias )
291
299
}
292
- } ? : doError(" Input .inflate(bytes) cause exception" , callback)
293
- } ? : doError(" Input .readAsBytes(inputStream) cause exception" , callback)
300
+ } ? : doError(" input .inflate(bytes) cause exception" , callback, alias )
301
+ } ? : doError(" input .readAsBytes(inputStream) cause exception" , callback, alias )
294
302
} catch (e: Exception ) {
295
- this .invokeErrorCallback(e, callback)
303
+ this .invokeErrorCallback(e, callback, alias )
296
304
} finally {
297
305
inputStream.close()
298
306
}
@@ -303,13 +311,14 @@ class SVGAParser(context: Context?) {
303
311
inputStream : InputStream ,
304
312
cacheKey : String ,
305
313
callback : ParseCompletion ? ,
306
- closeInputStream : Boolean = false
314
+ closeInputStream : Boolean = false,
315
+ alias : String
307
316
) {
308
317
if (mContext == null ) {
309
318
LogUtils .error(TAG , " 在配置 SVGAParser context 前, 无法解析 SVGA 文件。" )
310
319
return
311
320
}
312
- LogUtils .info(TAG , " ================ decode from input stream ================" )
321
+ LogUtils .info(TAG , " ================ decode $alias from input stream ================" )
313
322
threadPoolExecutor.execute {
314
323
try {
315
324
readAsBytes(inputStream)?.let { bytes ->
@@ -328,7 +337,7 @@ class SVGAParser(context: Context?) {
328
337
}
329
338
}
330
339
}
331
- this .decodeFromCacheKey(cacheKey, callback)
340
+ this .decodeFromCacheKey(cacheKey, callback, alias )
332
341
} else {
333
342
LogUtils .info(TAG , " decode from input stream, inflate start" )
334
343
inflate(bytes)?.let {
@@ -340,20 +349,22 @@ class SVGAParser(context: Context?) {
340
349
)
341
350
videoItem.prepare {
342
351
LogUtils .info(TAG , " decode from input stream, inflate end" )
343
- this .invokeCompleteCallback(videoItem, callback)
352
+ this .invokeCompleteCallback(videoItem, callback, alias )
344
353
}
345
354
346
355
} ? : this .invokeErrorCallback(
347
356
Exception (" inflate(bytes) cause exception" ),
348
- callback
357
+ callback,
358
+ alias
349
359
)
350
360
}
351
361
} ? : this .invokeErrorCallback(
352
362
Exception (" readAsBytes(inputStream) cause exception" ),
353
- callback
363
+ callback,
364
+ alias
354
365
)
355
366
} catch (e: java.lang.Exception ) {
356
- this .invokeErrorCallback(e, callback)
367
+ this .invokeErrorCallback(e, callback, alias )
357
368
} finally {
358
369
if (closeInputStream) {
359
370
inputStream.close()
@@ -397,27 +408,35 @@ class SVGAParser(context: Context?) {
397
408
callback : ParseCompletion ? ,
398
409
closeInputStream : Boolean = false
399
410
) {
400
- this .decodeFromInputStream(inputStream, cacheKey, callback, closeInputStream)
411
+ this .decodeFromInputStream(inputStream, cacheKey, callback, closeInputStream, " " )
401
412
}
402
413
403
- private fun invokeCompleteCallback (videoItem : SVGAVideoEntity , callback : ParseCompletion ? ) {
414
+ private fun invokeCompleteCallback (
415
+ videoItem : SVGAVideoEntity ,
416
+ callback : ParseCompletion ? ,
417
+ alias : String
418
+ ) {
404
419
Handler (Looper .getMainLooper()).post {
405
- LogUtils .info(TAG , " ================ parser complete ================" )
420
+ LogUtils .info(TAG , " ================ $alias parser complete ================" )
406
421
callback?.onComplete(videoItem)
407
422
}
408
423
}
409
424
410
- private fun invokeErrorCallback (e : java.lang.Exception , callback : ParseCompletion ? ) {
425
+ private fun invokeErrorCallback (
426
+ e : java.lang.Exception ,
427
+ callback : ParseCompletion ? ,
428
+ alias : String
429
+ ) {
411
430
e.printStackTrace()
412
- LogUtils .error(TAG , " ================ parser error ================" )
413
- LogUtils .error(TAG , " error" , e)
431
+ LogUtils .error(TAG , " ================ $alias parser error ================" )
432
+ LogUtils .error(TAG , " $alias parser error" , e)
414
433
Handler (Looper .getMainLooper()).post {
415
434
callback?.onError()
416
435
}
417
436
}
418
437
419
- private fun decodeFromCacheKey (cacheKey : String , callback : ParseCompletion ? ) {
420
- LogUtils .info(TAG , " ================ decode from cache ================" )
438
+ private fun decodeFromCacheKey (cacheKey : String , callback : ParseCompletion ? , alias : String ) {
439
+ LogUtils .info(TAG , " ================ decode $alias from cache ================" )
421
440
LogUtils .debug(TAG , " decodeFromCacheKey called with cacheKey : $cacheKey " )
422
441
if (mContext == null ) {
423
442
LogUtils .error(TAG , " 在配置 SVGAParser context 前, 无法解析 SVGA 文件。" )
@@ -436,7 +455,9 @@ class SVGAParser(context: Context?) {
436
455
cacheDir,
437
456
mFrameWidth,
438
457
mFrameHeight
439
- ), callback
458
+ ),
459
+ callback,
460
+ alias
440
461
)
441
462
}
442
463
} catch (e: Exception ) {
@@ -468,7 +489,9 @@ class SVGAParser(context: Context?) {
468
489
cacheDir,
469
490
mFrameWidth,
470
491
mFrameHeight
471
- ), callback
492
+ ),
493
+ callback,
494
+ alias
472
495
)
473
496
}
474
497
}
@@ -482,7 +505,7 @@ class SVGAParser(context: Context?) {
482
505
}
483
506
}
484
507
} catch (e: Exception ) {
485
- this .invokeErrorCallback(e, callback)
508
+ this .invokeErrorCallback(e, callback, alias )
486
509
}
487
510
}
488
511
0 commit comments