@@ -2,6 +2,7 @@ package com.androidvip.sysctlgui.ui.params.edit
22
33import android.content.ClipData
44import android.widget.Toast
5+ import androidx.activity.compose.BackHandler
56import androidx.compose.animation.AnimatedContent
67import androidx.compose.animation.AnimatedVisibility
78import androidx.compose.animation.SizeTransform
@@ -12,6 +13,7 @@ import androidx.compose.animation.slideOutVertically
1213import androidx.compose.animation.togetherWith
1314import androidx.compose.foundation.background
1415import androidx.compose.foundation.combinedClickable
16+ import androidx.compose.foundation.interaction.MutableInteractionSource
1517import androidx.compose.foundation.layout.Arrangement
1618import androidx.compose.foundation.layout.Box
1719import androidx.compose.foundation.layout.Column
@@ -97,7 +99,7 @@ fun EditParamScreen(
9799 val context = LocalContext .current
98100 val state = viewModel.uiState.collectAsStateWithLifecycle()
99101 val taskerListOptions = listOf (" Primary" , " Secondary" )
100- var showSelectTaskerListDialog by rememberSaveable { mutableStateOf(true ) }
102+ var showSelectTaskerListDialog by rememberSaveable { mutableStateOf(false ) }
101103 var selectedOptionIndex by rememberSaveable {
102104 mutableIntStateOf(Consts .LIST_NUMBER_PRIMARY_TASKER )
103105 }
@@ -156,6 +158,7 @@ fun EditParamScreen(
156158 viewModel.onEvent(EditParamViewEvent .ApplyPressed (it))
157159 },
158160 onTaskerClicked = {
161+ showSelectTaskerListDialog = it
159162 viewModel.onEvent(EditParamViewEvent .TaskerTogglePressed (it, selectedOptionIndex))
160163 },
161164 onDocsReadMorePressed = {
@@ -229,6 +232,8 @@ private fun EditParamContent(
229232 modifier = Modifier
230233 .combinedClickable(
231234 enabled = true ,
235+ indication = null ,
236+ interactionSource = remember { MutableInteractionSource () },
232237 onClick = {
233238 Toast .makeText(context, " Long press to copy" , Toast .LENGTH_SHORT ).show()
234239 },
@@ -287,7 +292,7 @@ private fun EditParamContent(
287292 )
288293 }
289294
290- if ( param.isTaskerParam && state.taskerAvailable) {
295+ AnimatedVisibility (visible = param.isTaskerParam && state.taskerAvailable) {
291296 val listName = taskerListNameResolver(param.taskerList)
292297 AssistChip (
293298 onClick = { onTaskerClicked(true ) },
@@ -337,6 +342,11 @@ private fun ParamValueContent(
337342 var editedValue by remember(param.value) { mutableStateOf(param.value) }
338343 val view = LocalView .current
339344
345+ BackHandler (
346+ enabled = isEditing,
347+ onBack = { isEditing = false }
348+ )
349+
340350 HorizontalDivider ()
341351
342352 Row (
@@ -454,75 +464,90 @@ private fun ParamDocs(
454464 color = MaterialTheme .colorScheme.onBackground
455465 )
456466
457- if (documentation != null ) {
458- val documentationText = if (! documentation.documentationHtml.isNullOrEmpty()) {
459- AnnotatedString .fromHtml(
460- htmlString = documentation.documentationHtml.orEmpty(),
461- linkStyles = TextLinkStyles (
462- style = MaterialTheme .typography.bodyMedium.toSpanStyle().copy(
463- color = MaterialTheme .colorScheme.primary,
464- textDecoration = TextDecoration .Underline ,
465- fontWeight = FontWeight .Medium
466- ),
467- pressedStyle = MaterialTheme .typography.bodyMedium.toSpanStyle().copy(
468- color = MaterialTheme .colorScheme.tertiary,
469- textDecoration = TextDecoration .Underline ,
470- fontWeight = FontWeight .Medium
471- )
472- )
467+ AnimatedContent (targetState = documentation != null ) { documentationAvailable ->
468+ if (documentationAvailable && documentation != null ) {
469+ DocumentationContent (
470+ documentation = documentation,
471+ onReadMorePressed = onReadMorePressed
473472 )
474473 } else {
475- AnnotatedString (documentation.documentationText)
476- }
477-
478- SelectionContainer {
479- Text (
474+ Card (
480475 modifier = Modifier
481476 .fillMaxWidth()
482- .padding(vertical = 8 .dp),
483- text = documentationText,
484- style = MaterialTheme .typography.bodyMedium,
485- color = MaterialTheme .colorScheme.onSurfaceVariant
486- )
477+ .padding(24 .dp),
478+ colors = CardDefaults .cardColors(
479+ containerColor = MaterialTheme .colorScheme.errorContainer
480+ )
481+ ) {
482+ Row (
483+ modifier = Modifier .padding(24 .dp),
484+ horizontalArrangement = Arrangement .spacedBy(
485+ 16 .dp,
486+ Alignment .CenterHorizontally
487+ )
488+ ) {
489+ Icon (
490+ imageVector = Icons .Rounded .Warning ,
491+ contentDescription = stringResource(android.R .string.dialog_alert_title),
492+ tint = MaterialTheme .colorScheme.onErrorContainer
493+ )
494+ Text (
495+ text = " No documentation available" ,
496+ style = MaterialTheme .typography.bodyLarge.copy(),
497+ fontWeight = FontWeight .Medium ,
498+ color = MaterialTheme .colorScheme.onErrorContainer
499+ )
500+ }
501+ }
487502 }
503+ }
504+ }
505+ }
488506
489- TextButton (
490- onClick = onReadMorePressed,
491- modifier = Modifier
492- .padding(vertical = 8 .dp)
493- .align(Alignment .End )
494- ) {
495- Text (text = " Read more" )
496- }
507+ @Composable
508+ private fun DocumentationContent (
509+ documentation : ParamDocumentation ,
510+ onReadMorePressed : () -> Unit
511+ ) {
512+ Column {
513+ val documentationText = if (! documentation.documentationHtml.isNullOrEmpty()) {
514+ AnnotatedString .fromHtml(
515+ htmlString = documentation.documentationHtml.orEmpty(),
516+ linkStyles = TextLinkStyles (
517+ style = MaterialTheme .typography.bodyMedium.toSpanStyle().copy(
518+ color = MaterialTheme .colorScheme.primary,
519+ textDecoration = TextDecoration .Underline ,
520+ fontWeight = FontWeight .Medium
521+ ),
522+ pressedStyle = MaterialTheme .typography.bodyMedium.toSpanStyle().copy(
523+ color = MaterialTheme .colorScheme.tertiary,
524+ textDecoration = TextDecoration .Underline ,
525+ fontWeight = FontWeight .Medium
526+ )
527+ )
528+ )
497529 } else {
498- Card (
530+ AnnotatedString (documentation.documentationText)
531+ }
532+
533+ SelectionContainer {
534+ Text (
499535 modifier = Modifier
500536 .fillMaxWidth()
501- .padding(24 .dp),
502- colors = CardDefaults .cardColors(
503- containerColor = MaterialTheme .colorScheme.errorContainer
504- )
505- ) {
506- Row (
507- modifier = Modifier .padding(24 .dp),
508- horizontalArrangement = Arrangement .spacedBy(
509- 16 .dp,
510- Alignment .CenterHorizontally
511- )
512- ) {
513- Icon (
514- imageVector = Icons .Rounded .Warning ,
515- contentDescription = stringResource(android.R .string.dialog_alert_title),
516- tint = MaterialTheme .colorScheme.onErrorContainer
517- )
518- Text (
519- text = " No documentation available" ,
520- style = MaterialTheme .typography.bodyLarge.copy(),
521- fontWeight = FontWeight .Medium ,
522- color = MaterialTheme .colorScheme.onErrorContainer
523- )
524- }
525- }
537+ .padding(vertical = 8 .dp),
538+ text = documentationText,
539+ style = MaterialTheme .typography.bodyMedium,
540+ color = MaterialTheme .colorScheme.onSurfaceVariant
541+ )
542+ }
543+
544+ TextButton (
545+ onClick = onReadMorePressed,
546+ modifier = Modifier
547+ .padding(vertical = 8 .dp)
548+ .align(Alignment .End )
549+ ) {
550+ Text (text = " Read more" )
526551 }
527552 }
528553}
0 commit comments