From d0b8144b96aec887c30e19348d2f547a311ae3fa Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 31 Jul 2023 16:15:27 +0800 Subject: [PATCH] manager: refresh module screen if it comes from install screen. fix #758 --- .../src/main/java/me/weishu/kernelsu/ui/screen/Module.kt | 4 +++- .../me/weishu/kernelsu/ui/viewmodel/ModuleViewModel.kt | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt index 2f689f65d068..0911885bf568 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt @@ -52,7 +52,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) { val viewModel = viewModel() LaunchedEffect(Unit) { - if (viewModel.moduleList.isEmpty()) { + if (viewModel.moduleList.isEmpty() || viewModel.isNeedRefresh) { viewModel.fetchModuleList() } } @@ -80,6 +80,8 @@ fun ModuleScreen(navigator: DestinationsNavigator) { navigator.navigate(InstallScreenDestination(uri)) + viewModel.markNeedRefresh() + Log.i("ModuleScreen", "select zip result: ${it.data}") } diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/viewmodel/ModuleViewModel.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/viewmodel/ModuleViewModel.kt index ca3331719d46..9be914977dad 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/viewmodel/ModuleViewModel.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/viewmodel/ModuleViewModel.kt @@ -58,6 +58,13 @@ class ModuleViewModel : ViewModel() { } } + var isNeedRefresh by mutableStateOf(false) + private set + + fun markNeedRefresh() { + isNeedRefresh = true + } + fun fetchModuleList() { viewModelScope.launch(Dispatchers.IO) { isRefreshing = true @@ -91,6 +98,7 @@ class ModuleViewModel : ViewModel() { obj.optString("updateJson", "") ) }.toList() + isNeedRefresh = false }.onFailure { e -> Log.e(TAG, "fetchModuleList: ", e) isRefreshing = false