Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Small UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-TSNG committed May 6, 2022
1 parent 9106fc4 commit 6794d3a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun SearchAppBar(
val focusRequester = remember { FocusRequester() }
var onSearch by remember { mutableStateOf(false) }

LaunchedEffect(onSearch) {
LaunchedEffect(Unit) {
if (onSearch) focusRequester.requestFocus()
}

Expand Down
5 changes: 2 additions & 3 deletions manager/src/main/java/org/lsposed/lspatch/ui/page/HomePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ private val listener: (Int, Int) -> Unit = { _, grantResult ->
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun ShizukuCard() {
val key = remember { true }
LaunchedEffect(key) {
LaunchedEffect(Unit) {
Shizuku.addRequestPermissionResultListener(listener)
}
DisposableEffect(key) {
DisposableEffect(Unit) {
onDispose {
Shizuku.removeRequestPermissionResultListener(listener)
}
Expand Down
80 changes: 45 additions & 35 deletions manager/src/main/java/org/lsposed/lspatch/ui/page/NewPatchPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.ClipboardManager
import android.content.Context
import android.content.pm.PackageInstaller
import android.util.Log
import androidx.activity.compose.BackHandler
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
Expand Down Expand Up @@ -36,7 +37,6 @@ import androidx.navigation.NavBackStackEntry
import kotlinx.coroutines.launch
import org.lsposed.lspatch.Patcher
import org.lsposed.lspatch.R
import org.lsposed.lspatch.TAG
import org.lsposed.lspatch.lspApp
import org.lsposed.lspatch.ui.component.SelectionColumn
import org.lsposed.lspatch.ui.component.ShimmerAnimation
Expand All @@ -50,43 +50,49 @@ import org.lsposed.lspatch.util.LSPPackageInstaller
import org.lsposed.lspatch.util.ShizukuApi
import org.lsposed.patch.util.Logger

private const val TAG = "NewPatchPage"

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NewPatchPage(entry: NavBackStackEntry) {
val viewModel = viewModel<NewPatchViewModel>()
val navController = LocalNavController.current
val lifecycleOwner = LocalLifecycleOwner.current
val isCancelled by entry.observeState<Boolean>("isCancelled")
entry.savedStateHandle.getLiveData<AppInfo>("appInfo").observe(lifecycleOwner) {
viewModel.patchApp = it
LaunchedEffect(Unit) {
entry.savedStateHandle.getLiveData<AppInfo>("appInfo").observe(lifecycleOwner) {
viewModel.configurePatch(it)
}
}

Log.d(TAG, "NewPatchPage: ${viewModel.patchState}")
Log.d(TAG, "PatchState: ${viewModel.patchState}")
if (viewModel.patchState == PatchState.SELECTING) {
when {
isCancelled == true -> {
LaunchedEffect(viewModel) { navController.popBackStack() }
return
}
viewModel.patchApp != null -> {
LaunchedEffect(viewModel) { viewModel.configurePatch() }
}
else -> {
LaunchedEffect(viewModel) { navController.navigate(PageList.SelectApps.name + "/false") }
}
LaunchedEffect(Unit) {
if (isCancelled == true) navController.popBackStack()
else navController.navigate(PageList.SelectApps.name + "/false")
}
} else {
Scaffold(
topBar = { TopBar(viewModel.patchApp!!) },
topBar = {
when (viewModel.patchState) {
PatchState.CONFIGURING -> ConfiguringTopBar { navController.popBackStack() }
PatchState.PATCHING,
PatchState.FINISHED,
PatchState.ERROR -> CenterAlignedTopAppBar(title = { Text(viewModel.patchApp.app.packageName) })
else -> Unit
}
},
floatingActionButton = {
if (viewModel.patchState == PatchState.CONFIGURING) {
ConfiguringFab()
}
}
) { innerPadding ->
if (viewModel.patchState == PatchState.CONFIGURING) {
entry.savedStateHandle.getLiveData<SnapshotStateList<AppInfo>>("selected", SnapshotStateList()).observe(lifecycleOwner) {
viewModel.embeddedModules = it
LaunchedEffect(Unit) {
entry.savedStateHandle.getLiveData<SnapshotStateList<AppInfo>>("selected", SnapshotStateList()).observe(lifecycleOwner) {
viewModel.embeddedModules = it
}
}
PatchOptionsBody(Modifier.padding(innerPadding))
} else {
Expand All @@ -97,21 +103,14 @@ fun NewPatchPage(entry: NavBackStackEntry) {
}

@Composable
private fun TopBar(patchApp: AppInfo) {
private fun ConfiguringTopBar(onBackClick: () -> Unit) {
SmallTopAppBar(
title = {
Column {
Text(
text = patchApp.label,
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(horizontal = 24.dp)
)
Text(
text = patchApp.app.packageName,
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(horizontal = 24.dp)
)
}
title = { Text(stringResource(R.string.page_new_patch)) },
navigationIcon = {
IconButton(
onClick = onBackClick,
content = { Icon(Icons.Outlined.ArrowBack, null) }
)
}
)
}
Expand Down Expand Up @@ -141,6 +140,16 @@ private fun PatchOptionsBody(modifier: Modifier) {
val navController = LocalNavController.current

Column(modifier.verticalScroll(rememberScrollState())) {
Text(
text = viewModel.patchApp.label,
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(horizontal = 24.dp)
)
Text(
text = viewModel.patchApp.app.packageName,
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(horizontal = 24.dp)
)
Text(
text = stringResource(R.string.patch_mode),
style = MaterialTheme.typography.titleLarge,
Expand Down Expand Up @@ -263,7 +272,7 @@ private fun DoPatchBody(modifier: Modifier) {
val logs = remember { mutableStateListOf<Pair<Int, String>>() }
val logger = remember { PatchLogger(logs) }

LaunchedEffect(viewModel) {
LaunchedEffect(Unit) {
try {
Patcher.patch(context, logger, viewModel.patchOptions)
viewModel.finishPatch()
Expand All @@ -276,7 +285,7 @@ private fun DoPatchBody(modifier: Modifier) {
}
}

BoxWithConstraints(modifier.padding(24.dp)) {
BoxWithConstraints(modifier.padding(start = 24.dp, end = 24.dp, bottom = 24.dp)) {
val shellBoxMaxHeight =
if (viewModel.patchState == PatchState.PATCHING) maxHeight
else maxHeight - ButtonDefaults.MinHeight - 12.dp
Expand Down Expand Up @@ -318,13 +327,14 @@ private fun DoPatchBody(modifier: Modifier) {
}

when (viewModel.patchState) {
PatchState.PATCHING -> BackHandler {}
PatchState.FINISHED -> {
val shizukuUnavailable = stringResource(R.string.shizuku_unavailable)
val installSuccessfully = stringResource(R.string.patch_install_successfully)
val installFailed = stringResource(R.string.patch_install_failed)
val copyError = stringResource(R.string.patch_copy_error)
var installing by rememberSaveable { mutableStateOf(false) }
if (installing) InstallDialog(viewModel.patchApp!!) { status, message ->
if (installing) InstallDialog(viewModel.patchApp) { status, message ->
scope.launch {
installing = false
if (status == PackageInstaller.STATUS_SUCCESS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@ class NewPatchViewModel : ViewModel() {

var patchState by mutableStateOf(PatchState.SELECTING)
private set
var patchApp by mutableStateOf<AppInfo?>(null)

var useManager by mutableStateOf(true)
var debuggable by mutableStateOf(false)
var overrideVersionCode by mutableStateOf(false)
var sign = mutableStateListOf(false, true)
var sigBypassLevel by mutableStateOf(2)

lateinit var patchApp: AppInfo
private set
lateinit var embeddedModules: SnapshotStateList<AppInfo>
lateinit var patchOptions: Patcher.Options

fun configurePatch() {
fun configurePatch(app: AppInfo) {
patchApp = app
patchState = PatchState.CONFIGURING
}

fun submitPatch() {
if (useManager) embeddedModules.clear()
patchOptions = Patcher.Options(
apkPaths = listOf(patchApp!!.app.sourceDir) + (patchApp!!.app.splitSourceDirs ?: emptyArray()),
apkPaths = listOf(patchApp.app.sourceDir) + (patchApp.app.splitSourceDirs ?: emptyArray()),
debuggable = debuggable,
sigbypassLevel = sigBypassLevel,
v1 = sign[0], v2 = sign[1],
Expand Down

0 comments on commit 6794d3a

Please sign in to comment.