Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 25 additions & 8 deletions android_kmp/app-sample/src/main/assets/dynamic.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"key": "CraftDTextView",
"value": {
"text": "Knife",
"backgroundHex" : "#9A71F6",
"backgroundHex": "#9A71F6",
"textSize": "30",
"textColorHex": "#000000"
}
Expand All @@ -16,7 +16,6 @@
"textColorHex": "#D977EB"
}
},

{
"key": "CraftDTextView",
"value": {
Expand Down Expand Up @@ -48,6 +47,27 @@
}
}
},
{
"key": "CraftDCheckBox",
"value": {
"text": "Mark here ",
"align": "RIGHT",
"textAlign": "CENTER",
"hasItRightText": false,
"enable": true,
"style": {
"checkedColorHex": "#FF0000",
"uncheckedColorHex": " #808080"
},
"actionProperties": {
"analytics": {
"category": "hello",
"action": "world",
"label": "everywhere"
}
}
}
},
{
"key": "MySampleButton",
"value": {
Expand All @@ -72,7 +92,7 @@
"key": "CraftDTextView",
"value": {
"text": "Knife",
"backgroundHex" : "#9A71F6",
"backgroundHex": "#9A71F6",
"textSize": "30",
"textColorHex": "#000000"
}
Expand Down Expand Up @@ -133,7 +153,6 @@
"textColorHex": "#D977EB"
}
},

{
"key": "CraftDTextView",
"value": {
Expand Down Expand Up @@ -169,7 +188,7 @@
"key": "CraftDTextView",
"value": {
"text": "Knife",
"backgroundHex" : "#9A71F6",
"backgroundHex": "#9A71F6",
"textSize": "30",
"textColorHex": "#000000"
}
Expand Down Expand Up @@ -230,7 +249,6 @@
"textColorHex": "#D977EB"
}
},

{
"key": "CraftDTextView",
"value": {
Expand Down Expand Up @@ -267,7 +285,7 @@
"key": "CraftDTextView",
"value": {
"text": "Knife",
"backgroundHex" : "#9A71F6",
"backgroundHex": "#9A71F6",
"textSize": "30",
"textColorHex": "#000000"
}
Expand Down Expand Up @@ -328,7 +346,6 @@
"textColorHex": "#D977EB"
}
},

{
"key": "CraftDTextView",
"value": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import com.github.codandotv.craftd.app_sample.presentation.compose.customview.MySampleButtonComposeBuilder
import com.github.codandotv.craftd.compose.ui.checkbox.CraftDCheckBoxComposeBuilder
import com.github.codandotv.craftd.compose.builder.CraftDComposeBuilders
import com.github.codandotv.craftd.compose.ui.CraftDComposeController

Expand All @@ -17,6 +18,8 @@ fun InitialScreen(
val dynamicBuilder = remember {
CraftDComposeBuilders().addBuilderRender(
MySampleButtonComposeBuilder()
).addBuilderRender(
CraftDCheckBoxComposeBuilder()
)
}
LaunchedEffect(Unit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.codandotv.craftd.compose.extensions

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
Expand Down Expand Up @@ -28,6 +29,12 @@ fun CraftDAlign?.toArrangementCompose() : Arrangement.Horizontal = when (this) {
else -> Arrangement.Start
}

fun CraftDAlign?.toAlignmentCompose() : Alignment.Vertical = when (this) {
CraftDAlign.CENTER -> Alignment.CenterVertically
CraftDAlign.BOTTOM -> Alignment.Bottom
else -> Alignment.Top
}

fun String?.parseColorCompose(): Color {
return try {
Color(android.graphics.Color.parseColor(this))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.github.codandotv.craftd.compose.ui.checkbox

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CheckboxDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.github.codandotv.craftd.androidcore.data.model.checkbox.CheckBoxProperties
import com.github.codandotv.craftd.androidcore.data.model.text.TextProperties
import com.github.codandotv.craftd.compose.extensions.parseColorCompose
import com.github.codandotv.craftd.compose.extensions.toAlignmentCompose
import com.github.codandotv.craftd.compose.extensions.toArrangementCompose
import com.github.codandotv.craftd.compose.ui.text.CraftDText

@Composable
fun CraftDCheckBox(
checkboxProperties: CheckBoxProperties,
modifier: Modifier = Modifier,
onChecked: (Boolean) -> Unit
) {
Row(
horizontalArrangement = checkboxProperties.align.toArrangementCompose(),
verticalAlignment = checkboxProperties.textAlign.toAlignmentCompose(),
modifier = Modifier.fillMaxWidth(0.4f)
) {
if (checkboxProperties.hasItRightText == true)
Box(
modifier = Modifier
.padding(start = 4.dp)
.fillMaxWidth(0.65f)
) {
CraftDText(
textProperties = TextProperties(
text = checkboxProperties.text,
)
)
}

Checkbox(
checked = checkboxProperties.enable ?: false,
onCheckedChange = onChecked,
modifier = modifier,
colors = CheckboxDefaults.colors(
checkedColor = checkboxProperties.styleProperties?.checkedColor.parseColorCompose(),
uncheckedColor = checkboxProperties.styleProperties?.uncheckedColor.parseColorCompose()
)
)

if (checkboxProperties.hasItRightText == false)
CraftDText(
textProperties = TextProperties(
text = checkboxProperties.text,
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.codandotv.craftd.compose.ui.checkbox

import androidx.compose.runtime.Composable
import com.github.codandotv.craftd.androidcore.data.convertToVO
import com.github.codandotv.craftd.androidcore.data.model.base.SimpleProperties
import com.github.codandotv.craftd.androidcore.data.model.checkbox.CheckBoxProperties
import com.github.codandotv.craftd.androidcore.presentation.CraftDComponent
import com.github.codandotv.craftd.androidcore.presentation.CraftDViewListener
import com.github.codandotv.craftd.compose.builder.CraftDComposeBuilder

class CraftDCheckBoxComposeBuilder : CraftDComposeBuilder(
key = CraftDComponent.CHECK_BOX_COMPONENT.key
) {
@Composable
override fun craft(model: SimpleProperties, listener: CraftDViewListener) {
val checkBoxProperties = model.value.convertToVO<CheckBoxProperties>()
CraftDCheckBox(checkBoxProperties) {
checkBoxProperties.actionProperties?.let { listener.invoke(it) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.codandotv.craftd.androidcore.data.model.checkbox

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.github.codandotv.craftd.androidcore.data.model.action.ActionProperties
import com.github.codandotv.craftd.androidcore.domain.CraftDAlign

@JsonIgnoreProperties(ignoreUnknown = true)
@Immutable
@Stable
data class CheckBoxProperties(
@JsonProperty("text") val text: String? = null,
@JsonProperty("align") val align: CraftDAlign? = null,
@JsonProperty("textAlign") val textAlign: CraftDAlign? = null,
@JsonProperty("enable") val enable: Boolean? = false,
@JsonProperty("hasItRightText") val hasItRightText: Boolean? = false,
@JsonProperty("actionProperties") var actionProperties: ActionProperties? = null,
@JsonProperty("style") var styleProperties: StyleProperties? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.codandotv.craftd.androidcore.data.model.checkbox

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty

@JsonIgnoreProperties(ignoreUnknown = true)
data class StyleProperties(
@JsonProperty("checkedColorHex")
val checkedColor: String?,
@JsonProperty("uncheckedColorHex")
val uncheckedColor: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ package com.github.codandotv.craftd.androidcore.domain
enum class CraftDAlign {
CENTER,
LEFT,
RIGHT
RIGHT,
TOP,
BOTTOM
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package com.github.codandotv.craftd.androidcore.presentation
enum class CraftDComponent(val key: String) {
TEXT_VIEW_COMPONENT("${CRAFT_D}TextView"),
BUTTON_COMPONENT("${CRAFT_D}Button"),
CHECK_BOX_COMPONENT("${CRAFT_D}CheckBox"),
}

internal const val CRAFT_D = "CraftD"
Binary file added android_kmp/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions android_kmp/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading