Skip to content

Commit

Permalink
added people field
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Feb 1, 2024
1 parent 2a29534 commit f391e30
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enum class FieldType {
RADIO_BUTTONS,
READONLY_TEXT,
READONLY,
PEOPLE,
;

fun value() = name.lowercase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ class ProcessFormActivity : AppCompatActivity() {

fragmentManager
.beginTransaction()
.replace(fragmentContainer.id, ProcessFormFragment(), "firstFragment")
.replace(
fragmentContainer.id,
ProcessFormFragment().apply {
// Set your data using intent extras
arguments = intent.extras
},
"firstFragment",
)
.commit()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.tooling.preview.Preview
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.data.UserGroupDetails
import com.alfresco.content.data.payloads.FieldType
import com.alfresco.content.process.FormViewModel
import com.alfresco.content.process.FormViewState
Expand All @@ -26,6 +27,7 @@ import com.alfresco.content.process.ui.components.DateTimeField
import com.alfresco.content.process.ui.components.DropdownField
import com.alfresco.content.process.ui.components.IntegerInputField
import com.alfresco.content.process.ui.components.MultiLineInputField
import com.alfresco.content.process.ui.components.PeopleField
import com.alfresco.content.process.ui.components.RadioButtonField
import com.alfresco.content.process.ui.components.ReadOnlyField
import com.alfresco.content.process.ui.components.SingleLineInputField
Expand Down Expand Up @@ -155,6 +157,18 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
fieldsData = field,
)
}

FieldType.PEOPLE.value() -> {
var userDetailValue by remember { mutableStateOf<UserGroupDetails?>(null) }
PeopleField(
userDetail = userDetailValue,
onAssigneeSelected = { userDetails ->
userDetailValue = userDetails
},
fieldsData = field,
processEntry = state.parent,
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.alfresco.content.process.ui.components

import android.content.Context
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.InputChip
import androidx.compose.material3.InputChipDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.alfresco.content.data.UserGroupDetails
import com.alfresco.content.getLocalizedName
import com.alfresco.content.process.ui.theme.SeparateColorGray
import com.alfresco.content.process.ui.theme.chipBackgroundColorGray
import com.alfresco.content.process.ui.theme.chipColorGray

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun InputChip(
context: Context,
userDetail: UserGroupDetails,
) {
InputChip(
modifier = Modifier.padding(vertical = 8.dp),
onClick = {
},
label = { Text(context.getLocalizedName(userDetail.name)) },
selected = true,
shape = RoundedCornerShape(24.dp),
border = InputChipDefaults.inputChipBorder(
selectedBorderWidth = 0.dp,

),
colors = InputChipDefaults.inputChipColors(
labelColor = SeparateColorGray,
selectedLabelColor = SeparateColorGray,
selectedLeadingIconColor = SeparateColorGray,
selectedContainerColor = chipBackgroundColorGray,
),
leadingIcon = {
Text(
color = SeparateColorGray,
modifier = Modifier
.padding(16.dp)
.drawBehind {
drawCircle(
color = chipColorGray,
radius = this.size.maxDimension,
)
},
text = context.getLocalizedName(userDetail.nameInitial),
fontSize = 12.sp,
)
},
)
}

@Preview
@Composable
fun InputChipPreview() {
InputChip(LocalContext.current, UserGroupDetails())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.alfresco.content.process.ui.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.alfresco.content.component.searchusergroup.SearchUserGroupComponentBuilder
import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.UserGroupDetails
import com.alfresco.content.data.payloads.FieldsData
import com.alfresco.content.process.ui.theme.AlfrescoError

@Composable
fun PeopleField(
userDetail: UserGroupDetails? = null,
onAssigneeSelected: (UserGroupDetails?) -> Unit = { },
fieldsData: FieldsData = FieldsData(),
processEntry: ProcessEntry = ProcessEntry(),
) {
val labelWithAsterisk = buildAnnotatedString {
append(fieldsData.name)
if (fieldsData.required) {
withStyle(style = SpanStyle(color = AlfrescoError)) {
append(" *") // Adding a red asterisk for mandatory fields
}
}
}

val context = LocalContext.current
Column(
modifier = Modifier
.fillMaxSize()
.padding(all = 16.dp),
) {
Text(
text = labelWithAsterisk,
modifier = Modifier
.padding(end = 4.dp)
.clickable {
SearchUserGroupComponentBuilder(context, processEntry)
.onApply { userDetails ->
onAssigneeSelected(userDetails)
}
.onCancel {
onAssigneeSelected(null)
}
.show()
},
)
if (userDetail != null) {
InputChip(context, userDetail)
}
}
}

@Preview
@Composable
fun PeopleFieldPreview() {
PeopleField()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ val White15 = Color(0x26FFFFFF)
val White60 = Color(0x99FFFFFF)
val ActionModeColor = AlfrescoBlue700 // Using AlfrescoBlue700 as action mode color
val SeparateColorGray = Color(0xFF212121)
val chipColorGray = Color(0x1F212121)
val chipBackgroundColorGray = Color(0x0D212121)

0 comments on commit f391e30

Please sign in to comment.