Jelajahi Sumber

fix: 兼容表情包解压失败或者文件缺失可以重新下载

wutiaorong 5 bulan lalu
induk
melakukan
09ddcbce40

+ 10 - 28
module/emotion/src/main/java/com/adealink/weparty/emotion/manager/EmotionManager.kt

@@ -546,20 +546,7 @@ class EmotionManager : BaseFrame<IEmotionListener>(), IEmotionManager {
     }
 
     override fun getEmotionAnimationResPath(emotionNotify: SendEmotionNotify): String? {
-        val emotionInfo = emotionNotify.emotionInfo
-        val emotionResPath = getEmotionResourcePath(emotionInfo)
-        val emotionResFile = storageService.file.createWeFile(emotionResPath)
-        if (emotionResFile.use().isNullOrEmpty()) {
-            Log.e(TAG_EMOTION, "getEmotionAnimationResultPath, no exist, emotionResFile:$emotionResPath")
-            return null
-        }
-        val resPath = "${emotionResPath}${File.separator}${getEmotionAnimationResName(emotionInfo.type)}"
-        if (isFileExists(resPath)) {
-            Log.d(TAG_EMOTION, "getEmotionAnimationResPath, exist, resPath: $resPath")
-            return resPath
-        }
-        Log.e(TAG_EMOTION, "getEmotionAnimationResPath, no exist, resPath:$resPath")
-        return null
+        return getEmotionAnimationResPath(emotionNotify.emotionInfo)
     }
 
     override fun getEmotionAnimationResPath(emotionInfo: EmotionInfo): String? {
@@ -574,25 +561,16 @@ class EmotionManager : BaseFrame<IEmotionListener>(), IEmotionManager {
             Log.d(TAG_EMOTION, "getEmotionAnimationResPath, exist, resPath: $resPath")
             return resPath
         }
+        //文件不存在,删除原目录
+        launch(Dispatcher.WENEXT_THREAD_POOL) {
+            emotionResFile.delete()
+        }
         Log.e(TAG_EMOTION, "getEmotionAnimationResPath, no exist, resPath:$resPath")
         return null
     }
 
     override fun getEmotionAnimationResultPath(emotionNotify: SendEmotionNotify): String? {
-        val emotionInfo = emotionNotify.emotionInfo
-        val emotionResPath = getEmotionResourcePath(emotionInfo)
-        val emotionResFile = storageService.file.createWeFile(emotionResPath)
-        if (emotionResFile.use().isNullOrEmpty()) {
-            Log.e(TAG_EMOTION, "getEmotionAnimationResultPath, no exist, emotionResFile:$emotionResPath")
-            return null
-        }
-        val resultPath = "${emotionResPath}${File.separator}${EMOTION_ANIMATION_RESULT_NAME}${emotionNotify.resultIndex}.png"
-        if (isFileExists(resultPath)) {
-            Log.d(TAG_EMOTION, "getEmotionAnimationResultPath, exist, resultPath: $resultPath")
-            return resultPath
-        }
-        Log.e(TAG_EMOTION, "getEmotionAnimationResultPath, no exist, resultPath:$resultPath")
-        return null
+        return getEmotionAnimationResultPath(emotionNotify.emotionInfo, emotionNotify.resultIndex)
     }
 
     override fun getEmotionAnimationResultPath(emotionInfo: EmotionInfo, resultIndex: Int): String? {
@@ -607,6 +585,10 @@ class EmotionManager : BaseFrame<IEmotionListener>(), IEmotionManager {
             Log.d(TAG_EMOTION, "getEmotionAnimationResultPath, exist, resultPath: $resultPath")
             return resultPath
         }
+        //文件不存在,删除原目录
+        launch(Dispatcher.WENEXT_THREAD_POOL) {
+            emotionResFile.delete()
+        }
         Log.e(TAG_EMOTION, "getEmotionAnimationResultPath, no exist, resultPath:$resultPath")
         return null
     }