1、修复一下bug
This commit is contained in:
shenzuqiang 2026-03-11 16:48:30 +08:00
parent fefe0ec8b7
commit decdad3de1
4 changed files with 45 additions and 50 deletions

View File

@ -4,7 +4,7 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-03-11T06:38:33.168759600Z">
<DropdownSelection timestamp="2026-03-11T08:00:19.371243300Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=Y5DELZR46DZTCI9D" />

View File

@ -109,7 +109,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
val reportViewModel:ReportViewModel = viewModel()
generalViewModel = ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(application))[GeneralViewModel::class.java]
var updateAppNotify by mutableStateOf(GlobalStateManager(context).globalUpdateNotifyFlow().collectAsState(initial = false))
val updateAppNotify by GlobalStateManager(context).globalUpdateNotifyFlow().collectAsState(initial = false)
val updateUniDownloadNotify by GlobalStateManager(context).globalUniDownloadNotifyFlow().collectAsState(initial = false)
val updateUserConfigNotify by GlobalStateManager(context).globalUserConfigNotifyFlow().collectAsState(initial = false)
val updateUniUpdateNotify by GlobalStateManager(context).globalUniUpdateNotifyFlow().collectAsState(initial = false)
@ -317,7 +317,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
//App更新提示
val isStartDownload = mutableStateOf(false)
val progressState = mutableFloatStateOf(0f)
if(updateAppNotify.value == true){
if(updateAppNotify == true){
UpdateDialog(
title = PreferenceUtil.getUserConfig()?.config?.versionEntity?.title?:"新版本,更新提示",
newVersion = "V${PreferenceUtil.getUserConfig()?.config?.versionEntity?.version}",
@ -397,7 +397,6 @@ class MainActivity : ComponentActivity(), LoadingCallback {
}
override fun showLoading() {
Log.i("HomeScreen","isStartOn--->${System.currentTimeMillis()}")
lifecycleScope.launch {
GlobalStateManager(this@MainActivity).storeGlobalLoading(true)
}
@ -405,7 +404,6 @@ class MainActivity : ComponentActivity(), LoadingCallback {
}
override fun hideLoading() {
Log.i("HomeScreen","isStartOff--->${System.currentTimeMillis()}")
lifecycleScope.launch {
delay(3000L)
GlobalStateManager(this@MainActivity).storeGlobalLoading(false)

View File

@ -72,13 +72,14 @@ import org.json.JSONObject
fun HomeScreen(
navController: NavHostController,
generalViewModel: GeneralViewModel,
reportViewModel: ReportViewModel = viewModel(),
loadingCallback: LoadingCallback?
) {
val TAG = "Rabbit_HomeScreen"
val context = LocalContext.current
val scope: CoroutineScope = rememberCoroutineScope()
val reportViewModel = viewModel<ReportViewModel>()
val progressPair = mutableStateMapOf<String, Float>()
// val progressPair = mutableStateMapOf<String, Float>()
val progressPair = remember { mutableStateMapOf<String, Float>() }
// 获取当前路由状态
val navBackStackEntry by navController.currentBackStackEntryAsState()
@ -1492,7 +1493,7 @@ fun HomeScreen(
@Preview(showBackground = true)
@Composable
private fun PreviewHomeScreen() {
HomeScreen(navController = rememberNavController(), generalViewModel = viewModel(), object: LoadingCallback{
HomeScreen(navController = rememberNavController(), generalViewModel = viewModel(), reportViewModel = viewModel(), object: LoadingCallback{
override fun showLoading() {
}

View File

@ -65,7 +65,7 @@ object UniAppUtils {
private fun getWgtFile(uniMpId: String): File{
val wgtName = getWgtName(uniMpId)
return File(FileUtils.instance?.cacheUniAppDir?.absolutePath?:"", wgtName)
return File(FileUtils.instance?.cacheUniAppDir?.absolutePath, wgtName)
}
/**
*获取当前前台运行的UniMp小程序实体
@ -123,12 +123,17 @@ object UniAppUtils {
if(originVersions.size != 3){
return false
}
for (i in 0..2) {
if (Integer.parseInt(newVersions[i]) > Integer.parseInt(originVersions[i])) {
return true
} else if (Integer.parseInt(newVersions[i]) < Integer.parseInt(originVersions[i])) {
return false
try {
for (i in 0..2) {
if (Integer.parseInt(newVersions[i]) > Integer.parseInt(originVersions[i])) {
return true
} else if (Integer.parseInt(newVersions[i]) < Integer.parseInt(originVersions[i])) {
return false
}
}
}catch (e: Exception){
e.printStackTrace()
Log.w(TAG, "checkUpdate: 解析版本号时,版本号格式错误 $version")
}
return false
}
@ -175,37 +180,25 @@ object UniAppUtils {
* 启动小程序并直达指定页面
*/
fun startUniMpPage(context: Context, uniMpId: String, uniMpType: String, pagePath: String, reportViewModel: ReportViewModel){
if(isRelease(uniMpId)){
if(!isRelease(uniMpId)){
releaseWgt(uniMpId,reportViewModel){
// 启动直达页面
startUniMpToPage(context, uniMpId, uniMpType, pagePath)
if(it){
// 启动直达页面
startUniMpToPage(context, uniMpId, uniMpType, pagePath)
}
}
}else if(DCUniMPSDK.getInstance().isExistsApp(uniMpId)){
}else {
val uniMp = _uniMpFlow.value[uniMpId]
if(uniMp?.isRuning == true){
uniMp.showUniMP()
}
// 启动直达页面
startUniMpToPage(context, uniMpId, uniMpType, pagePath)
}else{
CenterToast.show("加载失败,请重试或联系客服!")
//事件提交
reportViewModel.requestReport(
ReportRequest(
ReportType.ERROR,
ReportKey.EVENT_CLIENT_UNI_SPEC_PAGE_LOAD,
uniMpId,
"加载指定页面"
)
)
}
}
private fun startUniMpToPage(context: Context, uniMpId: String, uniMpType: String, pagePath: String){
// 启动直达页面
val configuration = getUniMPOpenConfiguration()
if(uniMpType == "wx"){
configuration.splashClass = UniMPWxSplashView::class.java
}
if(uniMpType == "wx"){
configuration.splashClass = UniMPWxSplashView::class.java
}else if("alipay" == uniMpType){
@ -413,35 +406,38 @@ object UniAppUtils {
api.sendReq(req)
}
suspend fun isFileDownloadable(url: String): Boolean = withContext(Dispatchers.IO) {
val client = OkHttpClient()
suspend fun isFileDownloadable(url: String): Boolean = withContext(Dispatchers.IO) {val client = OkHttpClient()
val request = Request.Builder().url(url).build()
try {
val response = client.newCall(request).execute()
val fileSize = response.body.contentLength()
//下载文件小于1KB需要判断Url是否可靠
if(fileSize < 1024){
if (!response.isSuccessful) {
val errorBody = response.body.string()
if (response.header("Content-Type")?.contains("application/json") == true) {
Log.i(TAG, "下载失败...$errorBody")
}else{
Log.i(TAG, "服务器错误...$errorBody")
client.newCall(request).execute().use { response ->
val body = response.body ?: return@withContext false
val fileSize = body.contentLength()
// 下载文件小于1KB需要判断Url是否可靠
if (fileSize < 1024) {
if (!response.isSuccessful) {
val errorBody = body.string() // string() 会内部读取并关闭 body但外层有 .use 更保险
if (response.header("Content-Type")?.contains("application/json") == true) {
Log.i(TAG, "下载失败...$errorBody")
} else {
Log.i(TAG, "服务器错误...$errorBody")
}
return@withContext false
} else {
Log.i(TAG, "文件正常,可以下载!")
return@withContext true
}
return@withContext false
}else{
Log.i(TAG, "文件正常,可以下载!${response.body.string()}")
} else {
return@withContext true
}
}else{
return@withContext true
}
}catch (e: Exception) {
} catch (e: Exception) {
Log.i(TAG, "异常:${e.message}")
}
return@withContext false
}
}
enum class UniMpUpdate{