From aefbba603e00d3bcfd83098ca6806eb6ae59a7e5 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Wed, 16 Oct 2024 11:06:01 -0600 Subject: [PATCH 1/4] rename the `parent` object in ButtonTest to avoid a conflict with Base.parent when it is made visible --- .../shared/tool/parser/model/ButtonTest.kt | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/ButtonTest.kt b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/ButtonTest.kt index 378aa0e89..ca05f31e1 100644 --- a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/ButtonTest.kt +++ b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/ButtonTest.kt @@ -22,7 +22,7 @@ import org.cru.godtools.shared.tool.state.State @RunOnAndroidWith(AndroidJUnit4::class) class ButtonTest : UsesResources() { - private val parent = object : BaseModel(), Styles { + private val parentObj = object : BaseModel(), Styles { override lateinit var buttonStyle: Button.Style override var primaryColor = TestColors.BLACK override var primaryTextColor = TestColors.BLACK @@ -151,16 +151,16 @@ class ButtonTest : UsesResources() { // region Property - style @Test fun testButtonStyleUtilizesStylesDefault() { - with(Button(parent)) { - parent.buttonStyle = Button.Style.CONTAINED + with(Button(parentObj)) { + parentObj.buttonStyle = Button.Style.CONTAINED assertEquals(Button.Style.CONTAINED, style) - parent.buttonStyle = Button.Style.OUTLINED + parentObj.buttonStyle = Button.Style.OUTLINED assertEquals(Button.Style.OUTLINED, style) } - parent.buttonStyle = Button.Style.CONTAINED - with(Button(parent, style = Button.Style.OUTLINED)) { - assertNotEquals(parent.buttonStyle, style) + parentObj.buttonStyle = Button.Style.CONTAINED + with(Button(parentObj, style = Button.Style.OUTLINED)) { + assertNotEquals(parentObj.buttonStyle, style) assertEquals(Button.Style.OUTLINED, style) } } @@ -194,17 +194,17 @@ class ButtonTest : UsesResources() { // region Property - text - textAlign @Test fun testButtonTextTextAlignFallbackBehavior() { - parent.textAlign = Text.Align.START + parentObj.textAlign = Text.Align.START // Buttons default to center aligned text - with(Button(parent, text = { Text(it) })) { - assertNotEquals(parent.textAlign, text.textAlign) + with(Button(parentObj, text = { Text(it) })) { + assertNotEquals(parentObj.textAlign, text.textAlign) assertEquals(Text.Align.CENTER, text.textAlign) } // Text Align can still be overridden on the text element - with(Button(parent, text = { Text(it, textAlign = Text.Align.END) })) { - assertNotEquals(parent.textAlign, text.textAlign) + with(Button(parentObj, text = { Text(it, textAlign = Text.Align.END) })) { + assertNotEquals(parentObj.textAlign, text.textAlign) assertEquals(Text.Align.END, text.textAlign) } } @@ -213,39 +213,39 @@ class ButtonTest : UsesResources() { // region Property - text - textColor @Test fun testButtonTextColorFallbackBehaviorContained() { - parent.primaryColor = TestColors.RED - parent.primaryTextColor = TestColors.GREEN + parentObj.primaryColor = TestColors.RED + parentObj.primaryTextColor = TestColors.GREEN - with(Button(parent, style = Button.Style.CONTAINED, text = { Text(it) })) { - assertNotEquals(parent.primaryColor, text.textColor) - assertNotEquals(parent.textColor, text.textColor) + with(Button(parentObj, style = Button.Style.CONTAINED, text = { Text(it) })) { + assertNotEquals(parentObj.primaryColor, text.textColor) + assertNotEquals(parentObj.textColor, text.textColor) assertNotEquals(buttonColor, text.textColor) - assertEquals(parent.primaryTextColor, text.textColor) + assertEquals(parentObj.primaryTextColor, text.textColor) assertEquals(TestColors.GREEN, text.textColor) } - with(Button(parent, style = Button.Style.CONTAINED, text = { Text(it, textColor = TestColors.BLUE) })) { - assertNotEquals(parent.primaryTextColor, text.textColor) + with(Button(parentObj, style = Button.Style.CONTAINED, text = { Text(it, textColor = TestColors.BLUE) })) { + assertNotEquals(parentObj.primaryTextColor, text.textColor) assertEquals(TestColors.BLUE, text.textColor) } } @Test fun testButtonTextColorFallbackBehaviorOutlined() { - parent.primaryColor = TestColors.RED - parent.primaryTextColor = TestColors.RED + parentObj.primaryColor = TestColors.RED + parentObj.primaryTextColor = TestColors.RED - with(Button(parent, style = Button.Style.OUTLINED, color = TestColors.GREEN, text = { Text(it) })) { - assertNotEquals(parent.primaryColor, text.textColor) - assertNotEquals(parent.primaryTextColor, text.textColor) - assertNotEquals(parent.textColor, text.textColor) + with(Button(parentObj, style = Button.Style.OUTLINED, color = TestColors.GREEN, text = { Text(it) })) { + assertNotEquals(parentObj.primaryColor, text.textColor) + assertNotEquals(parentObj.primaryTextColor, text.textColor) + assertNotEquals(parentObj.textColor, text.textColor) assertEquals(buttonColor, text.textColor) assertEquals(TestColors.GREEN, text.textColor) } with( Button( - parent, + parentObj, style = Button.Style.OUTLINED, color = TestColors.RED, text = { Text(it, textColor = TestColors.GREEN) } From 3623897acc9809f41e4834f62feb4ee2258fce38 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Wed, 16 Oct 2024 11:11:56 -0600 Subject: [PATCH 2/4] make Base.parent visible for use in the godtools-shared library --- .../cru/godtools/shared/tool/parser/model/Base.kt | 12 ++++++++++++ .../godtools/shared/tool/parser/model/BaseModel.kt | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt index 8926f0b5f..757388ce0 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt @@ -1,6 +1,18 @@ package org.cru.godtools.shared.tool.parser.model +import kotlin.experimental.ExperimentalObjCRefinement +import kotlin.js.ExperimentalJsExport +import kotlin.js.JsExport +import kotlin.native.HiddenFromObjC +import org.ccci.gto.support.androidx.annotation.RestrictTo +import org.ccci.gto.support.androidx.annotation.RestrictToScope + +@OptIn(ExperimentalJsExport::class, ExperimentalObjCRefinement::class) interface Base { + @HiddenFromObjC + @JsExport.Ignore + @get:RestrictTo(RestrictToScope.LIBRARY) + val parent: Base? get() = null val manifest: Manifest val stylesParent: Styles? } diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt index a1a3e8fb1..90fc87a90 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt @@ -1,6 +1,6 @@ package org.cru.godtools.shared.tool.parser.model -abstract class BaseModel internal constructor(private val parent: Base? = null) : Base { +abstract class BaseModel internal constructor(override val parent: Base? = null) : Base { override val stylesParent get() = parent as? Styles ?: parent?.stylesParent override val manifest get() = checkNotNull(parent?.manifest) { "No manifest found in model ancestors" } } From ccca187f62429d6138e36121f44effe7599bc3c2 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Wed, 16 Oct 2024 11:20:59 -0600 Subject: [PATCH 3/4] make stylesParent an extension property only --- .../kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt | 3 +-- .../org/cru/godtools/shared/tool/parser/model/BaseModel.kt | 1 - .../org/cru/godtools/shared/tool/parser/model/page/Page.kt | 1 + .../org/cru/godtools/shared/tool/parser/model/tract/Hero.kt | 1 + .../org/cru/godtools/shared/tool/parser/model/StylesTest.kt | 1 - .../cru/godtools/shared/tool/parser/model/tract/HeroTest.kt | 1 + 6 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt index 757388ce0..2d8066e02 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt @@ -14,10 +14,9 @@ interface Base { @get:RestrictTo(RestrictToScope.LIBRARY) val parent: Base? get() = null val manifest: Manifest - val stylesParent: Styles? } val Base?.manifest get() = this?.manifest -val Base?.stylesParent get() = this?.stylesParent +val Base?.stylesParent: Styles? get() = this?.parent?.let { it as? Styles ?: it.stylesParent } internal fun Base.getResource(name: String?) = manifest.getResource(name) diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt index 90fc87a90..7b5faa868 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt @@ -1,6 +1,5 @@ package org.cru.godtools.shared.tool.parser.model abstract class BaseModel internal constructor(override val parent: Base? = null) : Base { - override val stylesParent get() = parent as? Styles ?: parent?.stylesParent override val manifest get() = checkNotNull(parent?.manifest) { "No manifest found in model ancestors" } } diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/page/Page.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/page/Page.kt index a32173a84..0642d42fd 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/page/Page.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/page/Page.kt @@ -49,6 +49,7 @@ import org.cru.godtools.shared.tool.parser.model.page.Page.Companion.DEFAULT_BAC import org.cru.godtools.shared.tool.parser.model.page.Page.Companion.DEFAULT_BACKGROUND_IMAGE_SCALE_TYPE import org.cru.godtools.shared.tool.parser.model.primaryColor import org.cru.godtools.shared.tool.parser.model.primaryTextColor +import org.cru.godtools.shared.tool.parser.model.stylesParent import org.cru.godtools.shared.tool.parser.model.textColor import org.cru.godtools.shared.tool.parser.model.textScale import org.cru.godtools.shared.tool.parser.model.toColorOrNull diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/Hero.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/Hero.kt index 804aa2a4c..dce027506 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/Hero.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/Hero.kt @@ -20,6 +20,7 @@ import org.cru.godtools.shared.tool.parser.model.parseContent import org.cru.godtools.shared.tool.parser.model.parseTextChild import org.cru.godtools.shared.tool.parser.model.primaryColor import org.cru.godtools.shared.tool.parser.model.stylesOverride +import org.cru.godtools.shared.tool.parser.model.stylesParent import org.cru.godtools.shared.tool.parser.xml.XmlPullParser private const val XML_HEADING = "heading" diff --git a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt index e05bd5779..06801c287 100644 --- a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt +++ b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt @@ -7,7 +7,6 @@ import kotlin.test.assertNull class StylesTest { private val parent by lazy { object : Styles { - override val stylesParent: Styles? = null override val manifest get() = TODO() override var primaryColor = TestColors.RED diff --git a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/tract/HeroTest.kt b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/tract/HeroTest.kt index 84543df48..d954ae987 100644 --- a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/tract/HeroTest.kt +++ b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/tract/HeroTest.kt @@ -20,6 +20,7 @@ import org.cru.godtools.shared.tool.parser.model.Paragraph import org.cru.godtools.shared.tool.parser.model.Tabs import org.cru.godtools.shared.tool.parser.model.TestColors import org.cru.godtools.shared.tool.parser.model.Text +import org.cru.godtools.shared.tool.parser.model.stylesParent import org.cru.godtools.shared.tool.parser.withDeviceType @RunOnAndroidWith(AndroidJUnit4::class) From 3c99bebb833888c78044c98d966f0ac8d591b599 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Wed, 16 Oct 2024 14:56:42 -0600 Subject: [PATCH 4/4] provide a default implementation of Base.manifest --- .../kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt | 3 +-- .../org/cru/godtools/shared/tool/parser/model/BaseModel.kt | 4 +--- .../org/cru/godtools/shared/tool/parser/model/Styles.kt | 2 +- .../cru/godtools/shared/tool/parser/model/tract/TractPage.kt | 3 +-- .../org/cru/godtools/shared/tool/parser/model/StylesTest.kt | 2 -- 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt index 2d8066e02..7376866de 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt @@ -13,10 +13,9 @@ interface Base { @JsExport.Ignore @get:RestrictTo(RestrictToScope.LIBRARY) val parent: Base? get() = null - val manifest: Manifest + val manifest: Manifest get() = checkNotNull(parent?.manifest) { "No manifest found in model ancestors" } } -val Base?.manifest get() = this?.manifest val Base?.stylesParent: Styles? get() = this?.parent?.let { it as? Styles ?: it.stylesParent } internal fun Base.getResource(name: String?) = manifest.getResource(name) diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt index 7b5faa868..c5858c434 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt @@ -1,5 +1,3 @@ package org.cru.godtools.shared.tool.parser.model -abstract class BaseModel internal constructor(override val parent: Base? = null) : Base { - override val manifest get() = checkNotNull(parent?.manifest) { "No manifest found in model ancestors" } -} +abstract class BaseModel internal constructor(override val parent: Base? = null) : Base diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Styles.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Styles.kt index 14859b8c5..bf6be72d9 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Styles.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Styles.kt @@ -53,7 +53,7 @@ internal val Styles?.cardBackgroundColor get() = this?.cardBackgroundColor ?: Ma // region Multiselect styles internal val Styles?.multiselectOptionBackgroundColor - get() = this?.multiselectOptionBackgroundColor ?: manifest.backgroundColor + get() = this?.multiselectOptionBackgroundColor ?: this?.manifest.backgroundColor // endregion Multiselect styles // region Text styles diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/TractPage.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/TractPage.kt index 4ab608d1b..e2caf6c51 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/TractPage.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/TractPage.kt @@ -38,7 +38,6 @@ import org.cru.godtools.shared.tool.parser.model.XML_TEXT_COLOR import org.cru.godtools.shared.tool.parser.model.backgroundColor import org.cru.godtools.shared.tool.parser.model.contentTips import org.cru.godtools.shared.tool.parser.model.getResource -import org.cru.godtools.shared.tool.parser.model.manifest import org.cru.godtools.shared.tool.parser.model.page.Page import org.cru.godtools.shared.tool.parser.model.parseContent import org.cru.godtools.shared.tool.parser.model.parseTextChild @@ -317,6 +316,6 @@ class TractPage : Page { } @get:AndroidColorInt -val Card?.backgroundColor get() = this?.backgroundColor ?: manifest.backgroundColor +val Card?.backgroundColor get() = this?.backgroundColor ?: this?.manifest.backgroundColor val Card?.backgroundImageGravity get() = this?.backgroundImageGravity ?: Card.DEFAULT_BACKGROUND_IMAGE_GRAVITY val Card?.backgroundImageScaleType get() = this?.backgroundImageScaleType ?: Card.DEFAULT_BACKGROUND_IMAGE_SCALE_TYPE diff --git a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt index 06801c287..9be701389 100644 --- a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt +++ b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt @@ -7,8 +7,6 @@ import kotlin.test.assertNull class StylesTest { private val parent by lazy { object : Styles { - override val manifest get() = TODO() - override var primaryColor = TestColors.RED override var primaryTextColor = TestColors.RED