From 76decba8d9543d5e9707e0de114c9a576d01eaae Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 31 Jul 2023 15:06:00 +0800 Subject: [PATCH 1/3] manager: auto scroll for module installation. #815 --- .../src/main/java/me/weishu/kernelsu/ui/screen/Install.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt index 89c8d24f4968..b385b82b0702 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt @@ -46,6 +46,7 @@ fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) { val snackBarHost = LocalSnackbarHost.current val scope = rememberCoroutineScope() + val scrollState = rememberScrollState() LaunchedEffect(Unit) { if (text.isNotEmpty()) { @@ -58,6 +59,9 @@ fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) { } }, onStdout = { text += "$it\n" + scope.launch { + scrollState.animateScrollTo(scrollState.maxValue) + } logContent.append(it).append("\n") }, onStderr = { logContent.append(it).append("\n") @@ -107,7 +111,7 @@ fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) { modifier = Modifier .fillMaxSize(1f) .padding(innerPadding) - .verticalScroll(rememberScrollState()), + .verticalScroll(scrollState), ) { Text( modifier = Modifier.padding(8.dp), From d16d3f87a6fcd32878630f5e3c1c1c4ece3a1510 Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 31 Jul 2023 15:27:53 +0800 Subject: [PATCH 2/3] manager: block vol up & down for module installation. fix #815 --- .../kernelsu/ui/component/KeyEventBlocker.kt | 28 +++++++++++++++++++ .../me/weishu/kernelsu/ui/screen/Install.kt | 9 +++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 manager/app/src/main/java/me/weishu/kernelsu/ui/component/KeyEventBlocker.kt diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/component/KeyEventBlocker.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/component/KeyEventBlocker.kt new file mode 100644 index 000000000000..b3268131268a --- /dev/null +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/component/KeyEventBlocker.kt @@ -0,0 +1,28 @@ +package me.weishu.kernelsu.ui.component + +import androidx.compose.foundation.focusable +import androidx.compose.foundation.layout.Box +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.input.key.KeyEvent +import androidx.compose.ui.input.key.onKeyEvent + +@Composable +fun KeyEventBlocker(predicate: (KeyEvent) -> Boolean) { + val requester = remember { FocusRequester() } + Box( + Modifier + .onKeyEvent { + predicate(it) + } + .focusRequester(requester) + .focusable() + ) + LaunchedEffect(Unit) { + requester.requestFocus() + } +} \ No newline at end of file diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt index b385b82b0702..2299f4050a6b 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt @@ -14,7 +14,10 @@ import androidx.compose.material.icons.filled.Save import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier +import androidx.compose.ui.input.key.Key +import androidx.compose.ui.input.key.key import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -24,11 +27,11 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import me.weishu.kernelsu.R +import me.weishu.kernelsu.ui.component.KeyEventBlocker import me.weishu.kernelsu.ui.util.LocalSnackbarHost import me.weishu.kernelsu.ui.util.installModule import me.weishu.kernelsu.ui.util.reboot import java.io.File -import java.lang.StringBuilder import java.text.SimpleDateFormat import java.util.* @@ -36,6 +39,7 @@ import java.util.* * @author weishu * @date 2023/1/1. */ +@OptIn(ExperimentalComposeUiApi::class) @Composable @Destination fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) { @@ -107,6 +111,9 @@ fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) { } ) { innerPadding -> + KeyEventBlocker { + it.key == Key.VolumeDown || it.key == Key.VolumeUp + } Column( modifier = Modifier .fillMaxSize(1f) From d0b8144b96aec887c30e19348d2f547a311ae3fa Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 31 Jul 2023 16:15:27 +0800 Subject: [PATCH 3/3] 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