Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Image and ActionableButton Widget to add ability to copy text #3040

Merged
merged 25 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8dd2984
Enhance Actionable Button to add ability to copy text
SebaMutuku Feb 6, 2024
b653da5
Remove unnecessary icon
SebaMutuku Feb 6, 2024
37f8b56
Run spotlessApply
SebaMutuku Feb 6, 2024
ffdad0f
Remove context as param from Composable function
SebaMutuku Feb 6, 2024
bae78d8
Merge branch 'main' into fix_issue_3033_add_copy_text_widget
SebaMutuku Feb 6, 2024
889926a
Merge branch 'main' into fix_issue_3033_add_copy_text_widget
pld Feb 6, 2024
23e2cab
Merge branch 'main' into fix_issue_3033_add_copy_text_widget
SebaMutuku Feb 8, 2024
4028f40
Refactor Image Widget to enable on click
SebaMutuku Feb 8, 2024
0d9565f
Merge branch 'fix_issue_3033_add_copy_text_widget' of github.com:open…
SebaMutuku Feb 8, 2024
0e97195
Remove unnecessary ActionableButton previews
SebaMutuku Feb 8, 2024
84182ef
Add text property
SebaMutuku Feb 8, 2024
5723b56
Run spotlessApply
SebaMutuku Feb 8, 2024
43fcd0f
Fix failing tests and add test to confirm toast is shown
SebaMutuku Feb 9, 2024
e70a605
Run spotlessApply
SebaMutuku Feb 9, 2024
870e97a
Add text color
SebaMutuku Feb 12, 2024
a6ac600
Merge branch 'main' into fix_issue_3033_add_copy_text_widget
pld Feb 12, 2024
fc5091d
Update button as per design requirements
SebaMutuku Feb 13, 2024
e0d88fa
Merge branch 'fix_issue_3033_add_copy_text_widget' of github.com:open…
SebaMutuku Feb 13, 2024
e2b9fb6
Add condition when clicking an image
SebaMutuku Feb 13, 2024
90e5857
Run spotlessApply on Image.kt
SebaMutuku Feb 13, 2024
2d956e9
Add docs for Copy data on actionable button
SebaMutuku Feb 14, 2024
ec0c421
Merge branch 'main' into fix_issue_3033_add_copy_text_widget
SebaMutuku Feb 16, 2024
815aab9
Merge branch 'main' into fix_issue_3033_add_copy_text_widget
SebaMutuku Feb 19, 2024
1658100
Add tests for ConfigurationRegistry.writeFile()
SebaMutuku Feb 20, 2024
eb48629
Merge branch 'main' into fix_issue_3033_add_copy_text_widget
SebaMutuku Feb 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ constructor(
} // is focus.identifier a necessary check
.groupBy { section ->
section.focus.reference.substringBefore(
ConfigurationRegistry.TYPE_REFERENCE_DELIMITER,
TYPE_REFERENCE_DELIMITER,
missingDelimiterValue = "",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ data class NavigationMenuConfig(
data class ImageConfig(
val type: String = ICON_TYPE_LOCAL,
val reference: String? = null,
val color: String? = null,
@Contextual var decodedBitmap: Bitmap? = null,
) : Parcelable, java.io.Serializable {
fun interpolate(computedValuesMap: Map<String, Any>): ImageConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.graphics.Shape
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
import org.smartregister.fhircore.engine.configuration.navigation.ImageConfig
import org.smartregister.fhircore.engine.domain.model.ActionConfig
import org.smartregister.fhircore.engine.domain.model.ViewType
import org.smartregister.fhircore.engine.util.extension.interpolate

Expand All @@ -40,9 +41,12 @@ data class ImageProperties(
override val clickable: String = "false",
override val visible: String = "true",
val tint: String? = null,
val text: String? = null,
val imageConfig: ImageConfig? = null,
val size: Int? = null,
val shape: ImageShape? = null,
val textColor: String? = null,
val actions: List<ActionConfig> = emptyList(),
) : ViewProperties(), Parcelable {
override fun interpolate(computedValuesMap: Map<String, Any>): ViewProperties {
return this.copy(
Expand All @@ -53,6 +57,7 @@ data class ImageProperties(
),
tint = this.tint?.interpolate(computedValuesMap),
backgroundColor = this.backgroundColor?.interpolate(computedValuesMap),
text = this.text?.interpolate(computedValuesMap),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@

/** A workflow that launches user insight screen */
LAUNCH_INSIGHT_SCREEN,

/** A workflow that copies text to keyboard */
COPY_TEXT,

Check warning on line 58 in android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/workflow/ApplicationWorkflow.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/workflow/ApplicationWorkflow.kt#L58

Added line #L58 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.unit.dp
import androidx.navigation.testing.TestNavHostController
import androidx.test.core.app.ApplicationProvider
import org.hl7.fhir.r4.model.ResourceType
import org.junit.Rule
import org.junit.Test
Expand All @@ -43,7 +42,6 @@ import org.smartregister.fhircore.quest.ui.shared.components.ActionableButton

class ActionableButtonTest {
@get:Rule val composeRule = createComposeRule()
private val navController = TestNavHostController(ApplicationProvider.getApplicationContext())

@Test
fun testActionableButtonRendersAncClickWorksCorrectlyWithStatusDue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,19 @@ class ViewGeneratorTest {
fun testImageIsRenderedFromLocalAsset() {
composeRule.setContent {
GenerateView(
properties = ImageProperties(imageConfig = ImageConfig(ICON_TYPE_LOCAL, "ic_walk")),
properties =
ImageProperties(
imageConfig = ImageConfig(ICON_TYPE_LOCAL, "ic_walk", color = "#FFF000"),
text = "Copy text",
),
resourceData = resourceData,
navController = TestNavHostController(LocalContext.current),
)
}
composeRule.onNodeWithTag(SIDE_MENU_ITEM_LOCAL_ICON_TEST_TAG).assertExists().assertIsDisplayed()
composeRule
.onNodeWithTag(SIDE_MENU_ITEM_LOCAL_ICON_TEST_TAG, useUnmergedTree = true)
.assertExists()
.assertIsDisplayed()
}

@Test
Expand All @@ -375,7 +382,7 @@ class ViewGeneratorTest {
)
}
composeRule
.onNodeWithTag(SIDE_MENU_ITEM_REMOTE_ICON_TEST_TAG)
.onNodeWithTag(SIDE_MENU_ITEM_REMOTE_ICON_TEST_TAG, useUnmergedTree = true)
.assertExists()
.assertIsDisplayed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ constructor(
val workManager: WorkManager,
val fhirCarePlanGenerator: FhirCarePlanGenerator,
) : ViewModel() {

val appMainUiState: MutableState<AppMainUiState> =
mutableStateOf(
appMainUiStateOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@
paddingEnd = 10,
imageProperties = ImageProperties(imageConfig = imageConfig, size = 32),
tint = MenuItemColor,
navController = rememberNavController(),

Check warning on line 359 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/components/AppDrawer.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/components/AppDrawer.kt#L359

Added line #L359 was not covered by tests
)
SideMenuItemText(title = title, textColor = Color.White)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@
Image(
imageProperties = ImageProperties(imageConfig = overflowMenuItemConfig.icon),
tint = contentColor,
navController = navController,
resourceData = profileUiState.resourceData!!,

Check warning on line 359 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/profile/ProfileScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/profile/ProfileScreen.kt#L358-L359

Added lines #L358 - L359 were not covered by tests
)
if (overflowMenuItemConfig.icon != null) Spacer(modifier = Modifier.width(4.dp))
Text(text = overflowMenuItemConfig.title, color = contentColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class RegisterFragment : Fragment(), OnSyncListener {
.collectAsState(emptyFlow())
.value
.collectAsLazyPagingItems()

// Register screen provides access to the side navigation
Scaffold(
drawerGesturesEnabled = scaffoldState.drawerState.isOpen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -80,6 +81,7 @@
val clickable = buttonProperties.clickable.toBoolean()
val backgroundOpacity = buttonProperties.backgroundOpacity
val colorOpacity = buttonProperties.colorOpacity
val context = LocalContext.current

Check warning on line 84 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt#L84

Added line #L84 was not covered by tests
OutlinedButton(
onClick = {
if (
Expand All @@ -89,6 +91,7 @@
buttonProperties.actions.handleClickEvent(
navController = navController,
resourceData = resourceData,
context = context,

Check warning on line 94 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt#L94

Added line #L94 was not covered by tests
)
}
},
Expand Down Expand Up @@ -154,6 +157,8 @@
Image(
imageProperties = ImageProperties(imageConfig = buttonProperties.startIcon, size = 16),
tint = iconTintColor,
resourceData = resourceData,
navController = navController,

Check warning on line 161 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ActionableButton.kt#L160-L161

Added lines #L160 - L161 were not covered by tests
)
} else {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,55 +51,58 @@
resourceData: ResourceData,
navController: NavController,
) {
val headerActionVisible = viewProperties.headerAction?.visible.toBoolean()
Column(modifier = modifier.background(viewProperties.headerBackgroundColor.parseColor())) {
// Header section
Row(
modifier =
modifier
.fillMaxWidth()
.conditional(viewProperties.header != null, { padding(top = 24.dp, bottom = 8.dp) }),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween,
) {
if (viewProperties.header != null) {
CompoundText(
modifier =
modifier
.conditional(headerActionVisible, { weight(if (headerActionVisible) 0.6f else 1f) })
.wrapContentWidth(Alignment.Start),
compoundTextProperties = viewProperties.header!!.copy(textCase = TextCase.UPPER_CASE),
resourceData = resourceData,
navController = navController,
)
if (viewProperties.headerAction != null && headerActionVisible) {
// Check if card is visible
if (viewProperties.visible.toBoolean()) {
val headerActionVisible = viewProperties.headerAction?.visible.toBoolean()
Column(modifier = modifier.background(viewProperties.headerBackgroundColor.parseColor())) {

Check warning on line 57 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L57

Added line #L57 was not covered by tests
// Header section
Row(

Check warning on line 59 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L59

Added line #L59 was not covered by tests
modifier =
modifier
.fillMaxWidth()

Check warning on line 62 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L61-L62

Added lines #L61 - L62 were not covered by tests
.conditional(viewProperties.header != null, { padding(top = 24.dp, bottom = 8.dp) }),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween,

Check warning on line 65 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L64-L65

Added lines #L64 - L65 were not covered by tests
) {
if (viewProperties.header != null) {
CompoundText(
modifier = modifier.wrapContentWidth(Alignment.End).weight(0.4f),
compoundTextProperties = viewProperties.headerAction!!,
modifier =
modifier

Check warning on line 70 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L70

Added line #L70 was not covered by tests
.conditional(headerActionVisible, { weight(if (headerActionVisible) 0.6f else 1f) })
.wrapContentWidth(Alignment.Start),
compoundTextProperties = viewProperties.header!!.copy(textCase = TextCase.UPPER_CASE),

Check warning on line 73 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L72-L73

Added lines #L72 - L73 were not covered by tests
resourceData = resourceData,
navController = navController,
)
if (viewProperties.headerAction != null && headerActionVisible) {
CompoundText(
modifier = modifier.wrapContentWidth(Alignment.End).weight(0.4f),
compoundTextProperties = viewProperties.headerAction!!,
resourceData = resourceData,
navController = navController,

Check warning on line 82 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L78-L82

Added lines #L78 - L82 were not covered by tests
)
}
}
}
}
// Card section
Card(
elevation = viewProperties.elevation.dp,
modifier =
modifier
.padding(
start = viewProperties.padding.dp,
end = viewProperties.padding.dp,
// Card section
Card(
elevation = viewProperties.elevation.dp,

Check warning on line 89 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L88-L89

Added lines #L88 - L89 were not covered by tests
modifier =
modifier
.padding(
start = viewProperties.padding.dp,
end = viewProperties.padding.dp,

Check warning on line 94 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L91-L94

Added lines #L91 - L94 were not covered by tests
)
.fillMaxWidth()
.clip(RoundedCornerShape(viewProperties.cornerSize.dp)),
) {

Check warning on line 98 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L96-L98

Added lines #L96 - L98 were not covered by tests
Column(modifier = modifier.padding(viewProperties.contentPadding.dp)) {
ViewRenderer(
viewProperties = viewProperties.content,
resourceData = resourceData,
navController = navController,

Check warning on line 103 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/CardView.kt#L100-L103

Added lines #L100 - L103 were not covered by tests
)
.fillMaxWidth()
.clip(RoundedCornerShape(viewProperties.cornerSize.dp)),
) {
Column(modifier = modifier.padding(viewProperties.contentPadding.dp)) {
ViewRenderer(
viewProperties = viewProperties.content,
resourceData = resourceData,
navController = navController,
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
modifier = modifier.testTag(FAB_BUTTON_ROW_ICON_TEST_TAG),
imageProperties = ImageProperties(imageConfig = firstMenuIconConfig),
tint = if (firstFabEnabled) Color.White else DefaultColor,
navController = navController,
resourceData = resourceData!!,

Check warning on line 92 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ExtendedFab.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/ExtendedFab.kt#L91-L92

Added lines #L91 - L92 were not covered by tests
)
}
if (text.isNotEmpty()) {
Expand Down
Loading
Loading