feat ; 预加载 麦位资源

This commit is contained in:
eggmanQQQ
2024-12-27 14:31:03 +08:00
parent e5147ba8b1
commit 2f9263f3c9
2 changed files with 54 additions and 11 deletions

View File

@@ -1,11 +1,21 @@
package com.chwl.app.utils
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.chwl.core.gift.bean.RoomMicDress
import com.chwl.core.home.bean.ClientResource
import com.chwl.core.initial.InitialModel
import com.chwl.core.manager.AvRoomDataManager
import com.chwl.library.common.glide.GlideUtils
import com.chwl.library.common.util.doLog
import com.chwl.library.common.util.isVerify
import com.example.lib_utils.AppUtils
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.File
object ResourceManager {
@@ -15,6 +25,7 @@ object ResourceManager {
InitialModel.get().clientResource().doOnSuccess {
"data = $it".doLog()
mClientResource = it
preLoad(it)
}.subscribe()
}
@@ -47,4 +58,44 @@ object ResourceManager {
}
return data
}
private fun preLoad(clientResource: ClientResource) {
GlobalScope.launch {
clientResource?.roomMicDressList?.forEach {
delay(500)
doLoad(it.normalMicLockUrl)
doLoad(it.normalMicLockUrl)
doLoad(it.bossMicUrl)
doLoad(it.bossMicLockUrl)
}
}
}
private fun doLoad(url: String) {
if (url.isVerify()) {
"预加载 -> ResourceManager doLoad url = $url".doLog()
GlideUtils.instance().downloadFromUrl2(AppUtils.getApp(),url,object : RequestListener<File?> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<File?>?,
isFirstResource: Boolean
): Boolean {
"预加载 -> ResourceManager onLoadFailed error = ${e?.message} url = $url".doLog()
return true
}
override fun onResourceReady(
resource: File?,
model: Any?,
target: Target<File?>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
"预加载 -> ResourceManager onResourceReady Success url = $url".doLog()
return true
}
})
}
}
}

View File

@@ -2,13 +2,7 @@
"code": 200,
"message": "success",
"data": {
"roomVal": 60936.5,
"currentLevelIcon": "https://image.pekolive.com/3room_lv.png",
"currentLevel": 3,
"currentLevelExp": 52500,
"nextLevel": 4,
"nextLevelExp": 78750,
"micEffects": [
"roomMicDressList": [
{
"id": 4,
"dressType": 2,
@@ -35,9 +29,7 @@
"normalMicLockUrl": "",
"bossMicUrl": "",
"bossMicLockUrl": ""
}
],
"micSkins": [
},
{
"id": 1,
"dressType": 1,
@@ -67,5 +59,5 @@
}
]
},
"timestamp": 1735200527891
"timestamp": 1735280964981
}