1、修正部分性能问题代码
This commit is contained in:
shenzuqiang 2026-03-11 17:56:33 +08:00
parent 8ebaad0144
commit 7546fdfd53
1 changed files with 14 additions and 13 deletions

View File

@ -113,14 +113,15 @@ class MainActivity : ComponentActivity(), LoadingCallback {
val reportViewModel:ReportViewModel = viewModel() val reportViewModel:ReportViewModel = viewModel()
generalViewModel = ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(application))[GeneralViewModel::class.java] generalViewModel = ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(application))[GeneralViewModel::class.java]
val updateAppNotify by GlobalStateManager(context).globalUpdateNotifyFlow().collectAsState(initial = false) val globalStateManager = remember { GlobalStateManager(context) }
val updateUniDownloadNotify by GlobalStateManager(context).globalUniDownloadNotifyFlow().collectAsState(initial = false) val updateAppNotify by globalStateManager.globalUpdateNotifyFlow().collectAsState(initial = false)
val updateUserConfigNotify by GlobalStateManager(context).globalUserConfigNotifyFlow().collectAsState(initial = false) val updateUniDownloadNotify by globalStateManager.globalUniDownloadNotifyFlow().collectAsState(initial = false)
val updateUniUpdateNotify by GlobalStateManager(context).globalUniUpdateNotifyFlow().collectAsState(initial = false) val updateUserConfigNotify by globalStateManager.globalUserConfigNotifyFlow().collectAsState(initial = false)
val updateGlobalLoadingNotify by GlobalStateManager(context).isGlobalLoadingFlow().collectAsState(initial = false) val updateUniUpdateNotify by globalStateManager.globalUniUpdateNotifyFlow().collectAsState(initial = false)
val updateGlobalLoadingNotify by globalStateManager.isGlobalLoadingFlow().collectAsState(initial = false)
//重置状态信息(防止异常退出导致状态失效) //重置状态信息(防止异常退出导致状态失效)
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
GlobalStateManager(context).apply { globalStateManager.apply {
storeGlobalUpdateNotify(false) storeGlobalUpdateNotify(false)
storeGlobalUniDownloadNotify(false) storeGlobalUniDownloadNotify(false)
storeGlobalUserConfigNotify(false) storeGlobalUserConfigNotify(false)
@ -179,13 +180,13 @@ class MainActivity : ComponentActivity(), LoadingCallback {
delay(300) delay(300)
if(updateUserConfigNotify == true){ if(updateUserConfigNotify == true){
coroutineScope.launch { coroutineScope.launch {
GlobalStateManager(context).storeGlobalUserConfigNotify(false) globalStateManager.storeGlobalUserConfigNotify(false)
} }
} }
} }
//提示下载小程序资源(在跳转指定页面时,未下载资源需要提示) //提示下载小程序资源(在跳转指定页面时,未下载资源需要提示)
val progressWGTToPageState = mutableFloatStateOf(0f) val progressWGTToPageState = remember { mutableFloatStateOf(0f) }
LaunchedEffect(updateUniDownloadNotify) { LaunchedEffect(updateUniDownloadNotify) {
if(updateUniDownloadNotify == true) { if(updateUniDownloadNotify == true) {
UniAppUtils.currentDownloadUniMp?.let{ UniAppUtils.currentDownloadUniMp?.let{
@ -205,7 +206,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
progressWGTToPageState.floatValue = 1f progressWGTToPageState.floatValue = 1f
Log.i("HomeScreen", "DOWNLOAD_FINISH") Log.i("HomeScreen", "DOWNLOAD_FINISH")
coroutineScope.launch { coroutineScope.launch {
GlobalStateManager(context).storeGlobalUniDownloadNotify( globalStateManager.storeGlobalUniDownloadNotify(
false false
) )
} }
@ -216,7 +217,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
progressWGTToPageState.floatValue = -1f progressWGTToPageState.floatValue = -1f
Log.i("HomeScreen", "DOWNLOAD_FAIL") Log.i("HomeScreen", "DOWNLOAD_FAIL")
coroutineScope.launch { coroutineScope.launch {
GlobalStateManager(context).storeGlobalUniDownloadNotify( globalStateManager.storeGlobalUniDownloadNotify(
false false
) )
} }
@ -331,7 +332,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
if(!isUpdateFinish && !isCancel && data != null){ if(!isUpdateFinish && !isCancel && data != null){
isDownloadingWGT.value = true isDownloadingWGT.value = true
}else{ }else{
coroutineScope.launch { GlobalStateManager(context).storeGlobalUniUpdateNotify(false) } coroutineScope.launch { globalStateManager.storeGlobalUniUpdateNotify(false) }
} }
} }
) )
@ -354,7 +355,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
){ state, isCancel, url -> ){ state, isCancel, url ->
if(isCancel) { if(isCancel) {
coroutineScope.launch { coroutineScope.launch {
GlobalStateManager(context).storeGlobalUpdateNotify(state) globalStateManager.storeGlobalUpdateNotify(state)
} }
} }
if(!isCancel){ if(!isCancel){
@ -374,7 +375,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
} }
if(PreferenceUtil.getUserConfig()?.config?.versionEntity?.force == false) { if(PreferenceUtil.getUserConfig()?.config?.versionEntity?.force == false) {
coroutineScope.launch { coroutineScope.launch {
GlobalStateManager(context).storeGlobalUpdateNotify( globalStateManager.storeGlobalUpdateNotify(
state state
) )
} }