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 5 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 @@ -53,4 +53,7 @@ enum class ApplicationWorkflow {

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

/** A workflow that copies text to keyboard */
COPY_TEXT,
}
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 @@ -37,13 +36,14 @@ import org.smartregister.fhircore.engine.configuration.view.ButtonProperties
import org.smartregister.fhircore.engine.configuration.workflow.ActionTrigger
import org.smartregister.fhircore.engine.configuration.workflow.ApplicationWorkflow
import org.smartregister.fhircore.engine.domain.model.ActionConfig
import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.engine.domain.model.ServiceStatus
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 Expand Up @@ -100,6 +100,17 @@ class ActionableButtonTest {
.performClick()
}

@Test
fun testActionableButtonRendersAndCopyText() {
setCopyButtonContent("false")

composeRule
.onNodeWithText("Copy Button Text", useUnmergedTree = true)
.assertExists()
.assertIsDisplayed()
.performClick()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a verification done for this perform click action?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update the test to test on click function instead

}

private fun setContent(
serviceStatus: String,
enabled: String = "true",
Expand Down Expand Up @@ -129,4 +140,41 @@ class ActionableButtonTest {
}
}
}

private fun setCopyButtonContent(
serviceStatus: String,
enabled: String = "true",
computedValuesMap: Map<String, Any> = emptyMap(),
) {
composeRule.setContent {
Column(modifier = Modifier.height(50.dp)) {
ActionableButton(
buttonProperties =
ButtonProperties(
status = serviceStatus,
text = "Copy Button Text",
actions =
listOf(
ActionConfig(
trigger = ActionTrigger.ON_CLICK,
workflow = ApplicationWorkflow.COPY_TEXT.name,
params =
listOf(
ActionParameter(
key = "copyText",
value = "https://my-url",
paramType = ActionParameterType.PARAMDATA,
),
),
),
),
enabled = enabled,
startIcon = ImageConfig("ic_copy", ICON_TYPE_LOCAL),
),
resourceData = ResourceData("id", ResourceType.Patient, computedValuesMap),
navController = TestNavHostController(LocalContext.current),
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.material.icons.filled.Check
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 @@ fun ActionableButton(
val clickable = buttonProperties.clickable.toBoolean()
val backgroundOpacity = buttonProperties.backgroundOpacity
val colorOpacity = buttonProperties.colorOpacity
val context = LocalContext.current
OutlinedButton(
onClick = {
if (
Expand All @@ -89,6 +91,7 @@ fun ActionableButton(
buttonProperties.actions.handleClickEvent(
navController = navController,
resourceData = resourceData,
context = context,
)
}
},
Expand Down Expand Up @@ -152,7 +155,11 @@ fun ActionableButton(
}
if (buttonProperties.startIcon != null) {
Image(
imageProperties = ImageProperties(imageConfig = buttonProperties.startIcon, size = 16),
imageProperties =
ImageProperties(
imageConfig = buttonProperties.startIcon,
size = 16,
),
tint = iconTintColor,
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ private fun RowScope.RenderActionButtons(
) {
ActionableButton(
buttonProperties = serviceCardProperties.serviceButton!!,
navController = navController,
resourceData = resourceData,
navController = navController,
)
}
}
Expand All @@ -276,8 +276,8 @@ private fun RowScope.RenderActionButtons(
serviceCardProperties.services?.forEach { buttonProperties ->
ActionableButton(
buttonProperties = buttonProperties,
navController = navController,
resourceData = resourceData,
navController = navController,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ fun GenerateView(
ActionableButton(
modifier = modifier,
buttonProperties = properties as ButtonProperties,
navController = navController,
resourceData = resourceData,
navController = navController,
)
ViewType.COLUMN -> {
val children = (properties as ColumnProperties).children
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.smartregister.fhircore.quest.util.extensions

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -45,9 +48,11 @@ fun List<ActionConfig>.handleClickEvent(
navController: NavController,
resourceData: ResourceData? = null,
navMenu: NavigationMenuConfig? = null,
context: Context? = null,
) {
val onClickAction =
this.find { it.trigger.isIn(ActionTrigger.ON_CLICK, ActionTrigger.ON_QUESTIONNAIRE_SUBMISSION) }

onClickAction?.let { theConfig ->
val computedValuesMap = resourceData?.computedValuesMap ?: emptyMap()
val actionConfig = theConfig.interpolate(computedValuesMap)
Expand Down Expand Up @@ -154,6 +159,13 @@ fun List<ActionConfig>.handleClickEvent(
intent.data = Uri.parse("tel:$patientPhoneNumber")
ContextCompat.startActivity(navController.context, intent, null)
}
ApplicationWorkflow.COPY_TEXT -> {
val copyTextActionParameter = interpolatedParams.first()
val clipboardManager =
context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(null, copyTextActionParameter.value)
clipboardManager.setPrimaryClip(clipData)
}
else -> return
}
}
Expand Down
22 changes: 22 additions & 0 deletions android/quest/src/main/res/drawable/ic_copy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="225dp"
android:height="225dp"
android:viewportWidth="225"
android:viewportHeight="225">
<path
android:pathData="M60.7,1.7c-7.6,2.6 -16,10.9 -18.2,18 -0.6,2.2 -0.5,2.3 7,2.3 7.1,-0 7.9,-0.2 11.7,-3.3l4,-3.2 56.4,-0.3c55,-0.2 56.5,-0.2 60.4,1.8 2.6,1.3 4.7,3.4 6,6 2,3.9 2,5.3 1.8,75.1l-0.3,71 -4.2,4c-2.3,2.1 -4.8,3.9 -5.6,3.9 -1.2,-0 -1.4,-7.6 -1.5,-46.5 0,-33.1 -0.4,-47.6 -1.3,-50.3 -0.8,-2.7 -6.3,-8.9 -20.8,-23.5 -10.8,-10.9 -21.4,-20.8 -23.6,-22 -3.9,-2.2 -4.8,-2.2 -47,-2.2l-43,-0 -5.7,2.8c-6.1,3 -10.5,7.4 -14,14l-2.3,4.2 0,75 0,75 2.9,5.3c3.3,6 7.6,10.1 13.9,13.4l4.2,2.3 57.5,-0 57.5,-0 5.1,-2.7c5.3,-2.8 11.2,-8.7 13.8,-13.6 1.4,-2.7 2,-5.2 3,-13.1 0.2,-2 1.2,-2.6 5,-3.6 9.2,-2.4 18.1,-11.2 20.6,-20.5 0.7,-2.6 1,-28.6 0.8,-76.7l-0.3,-72.8 -2.9,-5.3c-3.3,-6 -7.6,-10.1 -13.9,-13.4l-4.2,-2.3 -59,-0.2c-52,-0.2 -59.6,-0 -63.8,1.4zM123,56.2c0,14.7 2.6,20.9 11.2,26.5 3.7,2.5 5,2.8 16.4,3.1l12.4,0.4 0,56.8 0,56.7 -2.3,3.4c-4.7,7.1 -3.2,6.9 -61.5,6.9 -50.4,-0 -52.4,-0.1 -56.2,-2 -2.6,-1.3 -4.7,-3.4 -6,-6 -2,-3.9 -2,-5.3 -1.8,-74.9l0.3,-71 3,-3.2c5.5,-5.8 5.5,-5.8 46.8,-5.9l37.7,-0 0,9.2z"
android:fillColor="#000000"
android:strokeColor="#00000000"/>
<path
android:pathData="M53,90.5c-3.4,3.7 -3.3,9 0.4,12.1 2.7,2.4 2.8,2.4 29.2,2.4l26.5,-0 2.4,-2.5c3.4,-3.3 3.4,-8.7 0,-12l-2.4,-2.5 -26.9,-0 -26.9,-0 -2.3,2.5z"
android:fillColor="#000000"
android:strokeColor="#00000000"/>
<path
android:pathData="M54.9,127.5c-5.8,3.2 -5.8,12 0.1,15 4.3,2.2 83.7,2.2 88,-0 5.8,-3 6.7,-9 2.1,-13.6l-2.9,-2.9 -42.4,-0c-34.2,0.1 -42.8,0.3 -44.9,1.5z"
android:fillColor="#000000"
android:strokeColor="#00000000"/>
<path
android:pathData="M53,167.5c-3.4,3.7 -3.3,9 0.4,12.1l2.7,2.4 43,-0 43.1,-0 2.9,-2.9c1.6,-1.6 2.9,-3.9 2.9,-5.1 0,-2.9 -2.6,-7.6 -4.5,-8.4 -0.9,-0.3 -21.1,-0.6 -44.9,-0.6l-43.3,-0 -2.3,2.5z"
android:fillColor="#000000"
android:strokeColor="#00000000"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.core.content.ContextCompat.startActivity
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavOptions
Expand Down
Loading