Skip to content

Commit

Permalink
ADST-35 (#316)
Browse files Browse the repository at this point in the history
* added hostname check to redirect the URL

* code refactor

* added validation and disbaled buttons state
  • Loading branch information
aman-alfresco authored Mar 12, 2024
1 parent ce31d09 commit 84ed440
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 35 deletions.
2 changes: 1 addition & 1 deletion capture/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
<string name="format_video_duration_minute" translatable="false">%02d:%02d</string>
<string name="error_file_size_exceed">Die ausgewählte Dateigröße darf beim Hochladen 100 MB nicht überschreiten.</string>

</resources>
</resources>
2 changes: 1 addition & 1 deletion capture/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
<string name="format_video_duration_minute" translatable="false">%02d:%02d</string>
<string name="error_file_size_exceed">El tamaño del fichero seleccionado no puede superar los 100 MB para cargarlo.</string>

</resources>
</resources>
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
package com.alfresco.content.common

import com.alfresco.content.session.Session
import com.alfresco.content.session.SessionManager
import com.alfresco.content.session.SessionNotFoundException
import java.net.URL
import java.net.URLDecoder

class SharedURLParser {

lateinit var session: Session

init {
try {
session = SessionManager.requireSession
} catch (e: SessionNotFoundException) {
e.printStackTrace()
}
}

/**
* isPreview (Boolean)
* String
Expand All @@ -12,6 +26,16 @@ class SharedURLParser {
fun getEntryIdFromShareURL(url: String, isHyperLink: Boolean = false): Triple<Boolean, String, Boolean> {
val extData = URLDecoder.decode(url, "UTF-8")

val hostname = URL(session.baseUrl).host

if (!url.contains(hostname)) {
return Triple(
true,
"",
false,
)
}

if (!isHyperLink && !extData.contains(SCHEME)) return Triple(false, "", false)

if (extData.contains(IDENTIFIER_PREVIEW)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class ComponentSheet : BottomSheetDialogFragment(), MavericksView {

when {
(state.parent?.selector == ComponentType.DROPDOWN_RADIO.value) ||
(state.parent?.selector == ComponentType.PROCESS_ACTION.value) -> {
(state.parent?.selector == ComponentType.PROCESS_ACTION.value) -> {
}

else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data class FormViewState(
val requestProcessDefinition: Async<ResponseListProcessDefinition> = Uninitialized,
val formFields: List<FieldsData> = emptyList(),
val processOutcomes: List<OptionsModel> = emptyList(),
val enabledOutcomes: Boolean = false,
) : MavericksState {
constructor(target: ProcessEntry) : this(parent = target)

Expand Down Expand Up @@ -98,7 +99,7 @@ class FormViewModel(
}

fun updateFieldValue(fieldId: String, newValue: Any?, state: FormViewState) {
val updatedFields = state.copy(
val updatedState = state.copy(
formFields = state.formFields.map { field ->
if (field.id == fieldId) {
field.copy(value = newValue)
Expand All @@ -107,7 +108,10 @@ class FormViewModel(
}
},
)
setState { updatedFields }

val hasAllRequiredData = updatedState.formFields.filter { it.required }.all { it.value != null }

setState { updatedState.copy(enabledOutcomes = hasAllRequiredData) }
}

companion object : MavericksViewModelFactory<FormViewModel, FormViewState> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,27 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel, outcomes: L
}

Column(
modifier = Modifier.fillMaxWidth(),
modifier = Modifier
.fillMaxWidth()
.clickable {
// Hide the keyboard on click outside of input fields
// keyboardController?.hide()
// focusManager.clearFocus()
},
) {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.weight(1f, false)
.clickable {
// Hide the keyboard on click outside of input fields
keyboardController?.hide()
focusManager.clearFocus()
},
.weight(1f, false),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally,
) {
items(key = {
it.id
}, items = formList) { field ->
items(
key = {
it.id
},
items = formList,
) { field ->
FormScrollContent(field, viewModel, state)
}
}
Expand All @@ -63,7 +67,7 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel, outcomes: L
.fillMaxWidth()
.align(alignment = Alignment.CenterHorizontally),
) {
Outcomes(outcomes = outcomes)
Outcomes(outcomes = outcomes, state.enabledOutcomes)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,31 @@ import com.alfresco.content.data.OptionsModel
import com.alfresco.content.process.R

@Composable
fun FloatingActionButton(outcomes: List<OptionsModel>) {
fun FloatingActionButton(outcomes: List<OptionsModel>, enabledOutcomes: Boolean) {
val context = LocalContext.current

ExtendedFloatingActionButton(
onClick = {
val componentData = ComponentData.with(
outcomes,
"",
"",
)
ComponentBuilder(context, componentData)
.onApply { name, query, _ ->
}
.onReset { name, query, _ ->
}
.onCancel {
}
.show()
if (enabledOutcomes) {
val componentData = ComponentData.with(
outcomes,
"",
"",
)
ComponentBuilder(context, componentData)
.onApply { name, query, _ ->
}
.onReset { name, query, _ ->
}
.onCancel {
}
.show()
}
},
containerColor = MaterialTheme.colorScheme.primary,
icon = { Icon(Icons.Filled.PlaylistAdd, stringResource(id = R.string.accessibility_process_actions)) },
text = { Text(text = stringResource(id = R.string.title_actions)) },
modifier = Modifier.navigationBarsPadding(),
modifier = Modifier
.navigationBarsPadding(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fun FormScreen(navController: NavController) {
else -> {
Scaffold(
topBar = { ComposeTopBar() },
floatingActionButton = { FloatingActionButton(customOutcomes) },
floatingActionButton = { FloatingActionButton(customOutcomes, state.enabledOutcomes) },
floatingActionButtonPosition = FabPosition.End,
) { padding ->
val colorScheme = MaterialTheme.colorScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview
import com.alfresco.content.data.payloads.FieldsData
Expand All @@ -17,7 +16,6 @@ fun MultiLineInputField(
fieldsData: FieldsData = FieldsData(),
) {
val keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.None,
keyboardType = KeyboardType.Text,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import com.alfresco.content.data.OptionsModel
import com.alfresco.content.process.ui.theme.AlfrescoGray900

@Composable
fun Outcomes(outcomes: List<OptionsModel>) {
fun Outcomes(outcomes: List<OptionsModel>, enabledOutcomes: Boolean) {
outcomes.forEach {
Button(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 4.dp),
onClick = { },
shape = RoundedCornerShape(4.dp),
enabled = enabledOutcomes,
colors = ButtonDefaults.buttonColors(
contentColor = AlfrescoGray900,
),
Expand Down

0 comments on commit 84ed440

Please sign in to comment.