Skip to content

Commit

Permalink
[#540] Display OdsBanner XML code implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea authored and florentmaitre committed Jan 29, 2024
1 parent 221b656 commit 3ee0430
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ import com.orange.ods.app.ui.components.utilities.ComponentCountRow
import com.orange.ods.app.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.app.ui.components.utilities.clickOnElement
import com.orange.ods.app.ui.utilities.DrawableManager
import com.orange.ods.app.ui.utilities.code.CodeBackgroundColumn
import com.orange.ods.app.ui.utilities.code.CodeImplementationColumn
import com.orange.ods.app.ui.utilities.code.FunctionCallCode
import com.orange.ods.app.ui.utilities.code.XmlViewTag
import com.orange.ods.app.ui.utilities.composable.Subtitle
import com.orange.ods.app.ui.utilities.extension.buildImageRequest
import com.orange.ods.compose.OdsComposable
Expand Down Expand Up @@ -148,34 +150,58 @@ fun ComponentBanners() {

CodeImplementationColumn(
modifier = Modifier.padding(horizontal = dimensionResource(id = com.orange.ods.R.dimen.screen_horizontal_margin)),
) {
FunctionCallCode(
name = OdsComposable.OdsBanner.name,
exhaustiveParameters = false,
parameters = {
string("message", if (hasShortMessage) recipe.title else recipe.description)
if (hasFirstButton) {
classInstance<OdsBanner.Button>("firstButton") {
text(context.getString(R.string.component_banner_dismiss))
onClick()
xmlContent = {
CodeBackgroundColumn {
XmlViewTag(
clazz = com.orange.ods.xml.component.banner.OdsBanner::class.java,
xmlAttributes = {
id("ods_banner")
layoutWidth(true)
layoutHeight()
appAttr("message", message)
firstButtonText?.let {
appAttr("firstButtonText", it)
}
secondButtonText?.let {
appAttr("secondButtonText", it)
}
if (hasImage) {
drawableAppAttr("image", "image")
appAttr("imageContentDescription", "Banner image")
}
}
}
if (hasImage) {
classInstance<OdsBanner.Image>("image") {
painter()
contentDescription("")
)
}
},
composeContent = {
FunctionCallCode(
name = OdsComposable.OdsBanner.name,
exhaustiveParameters = false,
parameters = {
string("message", message)
firstButtonText?.let {
classInstance<OdsBanner.Button>("firstButton") {
text(it)
onClick()
}
}
}
if (hasSecondButton) {
classInstance<OdsBanner.Button>("secondButton") {
text(context.getString(R.string.component_banner_detail))
onClick()
if (hasImage) {
classInstance<OdsBanner.Image>("image") {
painter()
contentDescription("")
}
}
secondButtonText?.let {
classInstance<OdsBanner.Button>("secondButton") {
text(it)
onClick()
}
}
}
}
)
}
)
}
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ open class XmlAttribute(val key: String, val value: String) {
fun XmlViewTag(clazz: Class<out View>, xmlAttributes: (XmlAttributesBuilder.() -> Unit)? = null) {
val viewName = clazz.name
if (xmlAttributes != null) {

TechnicalText(text = "<$viewName")
IndentCodeColumn {
XmlAttributesBuilder().apply(xmlAttributes).Build()
Expand All @@ -42,6 +41,9 @@ object PredefinedXmlAttribute {
class Id(value: String) : XmlAttribute("android:id", "@+id/$value")
class LayoutHeight(matchParent: Boolean = false) : XmlAttribute("android:layout_height", getLayoutParamValue(matchParent))
class LayoutWidth(matchParent: Boolean = false) : XmlAttribute("android:layout_width", getLayoutParamValue(matchParent))

open class AppAttr(name: String, value: String) : XmlAttribute("app:$name", value)
class DrawableAppAttr(name: String, drawableName: String) : AppAttr(name, "@drawable/$drawableName")
}

@DslMarker
Expand All @@ -57,6 +59,8 @@ class XmlAttributesBuilder {
fun id(value: String) = add(PredefinedXmlAttribute.Id(value))
fun layoutHeight(matchParent: Boolean = false) = add(PredefinedXmlAttribute.LayoutHeight(matchParent))
fun layoutWidth(matchParent: Boolean = false) = add(PredefinedXmlAttribute.LayoutWidth(matchParent))
fun appAttr(name: String, value: String) = add(PredefinedXmlAttribute.AppAttr(name, value))
fun drawableAppAttr(name: String, drawableName: String) = add(PredefinedXmlAttribute.DrawableAppAttr(name, drawableName))

@Composable
fun Build() = xmlAttributes.forEach { it.code() }
Expand Down

0 comments on commit 3ee0430

Please sign in to comment.