Skip to content

Commit

Permalink
added hyperlink field
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Feb 15, 2024
1 parent 72af17e commit 3f3ced0
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ data class FieldsData(
var fields: List<FieldsData> = emptyList(),
var params: Params? = null,
var options: List<OptionsModel> = emptyList(),
var dateDisplayFormat: String? = null,
var hyperlinkUrl: String? = null,
var displayText: String? = null,
) : Parcelable {

companion object {
Expand Down Expand Up @@ -62,6 +65,9 @@ data class FieldsData(
enablePeriodSeparator = raw.enablePeriodSeparator ?: false,
options = raw.options?.map { OptionsModel.with(it) } ?: emptyList(),
fields = raw.getFieldMapAsList()?.map { with(it) } ?: emptyList(),
dateDisplayFormat = raw.dateDisplayFormat,
hyperlinkUrl = raw.hyperlinkUrl,
displayText = raw.displayText,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.ResponseListForm
import com.alfresco.content.data.ResponseListProcessDefinition
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.data.UserGroupDetails
import com.alfresco.content.data.payloads.FieldsData
import com.alfresco.coroutines.asFlow
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.alfresco.content.process.ui.components.AmountInputField
import com.alfresco.content.process.ui.components.CheckBoxField
import com.alfresco.content.process.ui.components.DateTimeField
import com.alfresco.content.process.ui.components.DropdownField
import com.alfresco.content.process.ui.components.HyperLinkField
import com.alfresco.content.process.ui.components.IntegerInputField
import com.alfresco.content.process.ui.components.MultiLineInputField
import com.alfresco.content.process.ui.components.PeopleField
Expand Down Expand Up @@ -57,7 +58,7 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally,

) {
) {
LazyColumn(
modifier = Modifier
.fillMaxSize(),
Expand Down Expand Up @@ -174,7 +175,7 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
}

FieldType.HYPERLINK.value() -> {

HyperLinkField(field)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ private fun customLabel(visibleText: String, showReadMoreButtonState: Boolean, f
val startIndexReadMore = labelReadMore.indexOf(readMore)
val endIndexReadMore = startIndexReadMore + readMore.length

println("startIndexReadMore == $startIndexReadMore")

val startIndexAsteric = labelReadMore.indexOf(spaceAsteric)
val endIndexAsteric = startIndexAsteric + spaceAsteric.length

Expand All @@ -152,7 +150,6 @@ private fun customLabel(visibleText: String, showReadMoreButtonState: Boolean, f
end = endIndexAsteric,
)
}

addStyle(
style = SpanStyle(color = MaterialTheme.colorScheme.primary),
start = startIndexReadMore + 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.alfresco.content.process.ui.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.ClickableText
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.UrlAnnotation
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.alfresco.content.data.payloads.FieldsData

@OptIn(ExperimentalTextApi::class)
@Composable
fun HyperLinkField(
fieldsData: FieldsData = FieldsData(),
) {
val uriHandler = LocalUriHandler.current

val hyperlinkData = buildAnnotatedString {
append(fieldsData.displayText)
addStyle(
style = SpanStyle(
fontSize = 16.sp,
color = MaterialTheme.colorScheme.primary,
),
start = 0,
end = fieldsData.displayText?.length ?: 0,
)
addUrlAnnotation(
UrlAnnotation(fieldsData.hyperlinkUrl ?: ""),
start = 0,
end = fieldsData.displayText?.length ?: 0,
)
}

Column(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 0.dp),
horizontalAlignment = Alignment.Start,
) {
Text(
text = fieldsData.name,
style = TextStyle(
fontSize = 16.sp,
color = MaterialTheme.colorScheme.onSurface,
),
)
ClickableText(
text = hyperlinkData,
style = TextStyle(
color = MaterialTheme.colorScheme.onSurface,
),
onClick = {
hyperlinkData
.getUrlAnnotations(it, it)
.firstOrNull()?.let { annotation ->
uriHandler.openUri(annotation.item.url)
}
},
)
}
}

0 comments on commit 3f3ced0

Please sign in to comment.