Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AzukiPaste authored Jul 31, 2023
2 parents e9e235c + d0b8144 commit da93f8a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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()
}
}
15 changes: 13 additions & 2 deletions manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Install.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,18 +27,19 @@ 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.*

/**
* @author weishu
* @date 2023/1/1.
*/
@OptIn(ExperimentalComposeUiApi::class)
@Composable
@Destination
fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) {
Expand All @@ -46,6 +50,7 @@ fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) {

val snackBarHost = LocalSnackbarHost.current
val scope = rememberCoroutineScope()
val scrollState = rememberScrollState()

LaunchedEffect(Unit) {
if (text.isNotEmpty()) {
Expand All @@ -58,6 +63,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")
Expand Down Expand Up @@ -103,11 +111,14 @@ fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) {

}
) { innerPadding ->
KeyEventBlocker {
it.key == Key.VolumeDown || it.key == Key.VolumeUp
}
Column(
modifier = Modifier
.fillMaxSize(1f)
.padding(innerPadding)
.verticalScroll(rememberScrollState()),
.verticalScroll(scrollState),
) {
Text(
modifier = Modifier.padding(8.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
val viewModel = viewModel<ModuleViewModel>()

LaunchedEffect(Unit) {
if (viewModel.moduleList.isEmpty()) {
if (viewModel.moduleList.isEmpty() || viewModel.isNeedRefresh) {
viewModel.fetchModuleList()
}
}
Expand Down Expand Up @@ -80,6 +80,8 @@ fun ModuleScreen(navigator: DestinationsNavigator) {

navigator.navigate(InstallScreenDestination(uri))

viewModel.markNeedRefresh()

Log.i("ModuleScreen", "select zip result: ${it.data}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,6 +98,7 @@ class ModuleViewModel : ViewModel() {
obj.optString("updateJson", "")
)
}.toList()
isNeedRefresh = false
}.onFailure { e ->
Log.e(TAG, "fetchModuleList: ", e)
isRefreshing = false
Expand Down

0 comments on commit da93f8a

Please sign in to comment.