Skip to content

Commit a22654f

Browse files
authored
Merge pull request #2 from ServerDriven/dev/actual_import
SD Project imported
2 parents 4b1a051 + 90a6762 commit a22654f

File tree

13 files changed

+460
-29
lines changed

13 files changed

+460
-29
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ android {
4141

4242
dependencies {
4343

44+
implementation project(':screendataui')
45+
4446
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4547
implementation 'androidx.core:core-ktx:1.3.2'
4648
implementation 'androidx.appcompat:appcompat:1.2.0'

app/src/main/java/com/pv/screendataandroid/MainActivity.kt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,13 @@ import androidx.compose.runtime.Composable
99
import androidx.compose.ui.platform.setContent
1010
import androidx.ui.tooling.preview.Preview
1111
import com.pv.screendataandroid.ui.ScreenDataAndroidTheme
12+
import com.pv.screendataui.SDScreenDemo
1213

1314
class MainActivity : AppCompatActivity() {
1415
override fun onCreate(savedInstanceState: Bundle?) {
1516
super.onCreate(savedInstanceState)
1617
setContent {
17-
ScreenDataAndroidTheme {
18-
// A surface container using the 'background' color from the theme
19-
Surface(color = MaterialTheme.colors.background) {
20-
Greeting("Android")
21-
}
22-
}
18+
SDScreenDemo.mock()
2319
}
2420
}
2521
}
26-
27-
@Composable
28-
fun Greeting(name: String) {
29-
Text(text = "Hello $name!")
30-
}
31-
32-
@Preview(showBackground = true)
33-
@Composable
34-
fun DefaultPreview() {
35-
ScreenDataAndroidTheme {
36-
Greeting("Android")
37-
}
38-
}

screendataui/src/main/java/com/pv/screendataui/Entry.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.pv.screendataui
2+
3+
import androidx.compose.foundation.Text
4+
import androidx.compose.foundation.layout.fillMaxSize
5+
import androidx.compose.material.Scaffold
6+
import androidx.compose.material.TopAppBar
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.Modifier
9+
import androidx.compose.ui.graphics.Color
10+
import androidx.ui.tooling.preview.Preview
11+
import com.pv.screendata.extensions.SomeStyleHelper.paddingStyle
12+
import com.pv.screendata.extensions.toSomeLabel
13+
import com.pv.screendata.extensions.toSomeView
14+
import com.pv.screendata.objects.SomeStyle
15+
import com.pv.screendata.objects.SomeColor as SomeColor
16+
import com.pv.screendata.screens.SomeScreen
17+
import com.pv.screendata.types.ViewDirectionAxis
18+
import com.pv.screendata.views.SomeContainerView
19+
import com.pv.screendata.views.SomeSpacer
20+
import com.pv.screendataui.viewsamples.SDButton
21+
import com.pv.screendataui.viewsamples.SDImage
22+
23+
@Composable
24+
fun SDSCreen(screen: SomeScreen) {
25+
Scaffold(
26+
Modifier.fillMaxSize(),
27+
backgroundColor = Color(
28+
screen.backgroundColor.red,
29+
screen.backgroundColor.green,
30+
screen.backgroundColor.blue
31+
),
32+
topBar = {
33+
TopAppBar(title = {
34+
Text(screen.title)
35+
})
36+
},
37+
) {
38+
SDSomeView(someView = screen.someView)
39+
}
40+
}
41+
42+
@Preview(showBackground = true)
43+
@Composable
44+
fun sdScreenPreview() {
45+
SDScreenDemo.mock()
46+
}
47+
48+
object SDScreenDemo {
49+
@Composable
50+
fun mock() = SDSCreen(
51+
screen = SomeScreen(
52+
id = "yoloId",
53+
title = "YoloTitile",
54+
subtitle = null,
55+
backgroundColor = SomeColor(
56+
102f / 255f,
57+
187f / 255f,
58+
106f / 255f,
59+
.1f
60+
),
61+
headerView = null,
62+
someView = SomeContainerView(
63+
id = null,
64+
axis = ViewDirectionAxis.vertical,
65+
someViews = arrayOf(
66+
SDImage.mock.toSomeView(),
67+
SomeSpacer(8).toSomeView(),
68+
"what".toSomeLabel()
69+
.copy(someStyle = paddingStyle(8, 0))
70+
.toSomeView(),
71+
"yea".toSomeLabel()
72+
.copy(someStyle = paddingStyle(8, 0))
73+
.toSomeView(),
74+
SomeSpacer(8).toSomeView(),
75+
Pair("Something", "Worse")
76+
.toSomeLabel()
77+
.copy(someStyle = paddingStyle(8, 0))
78+
.toSomeView(),
79+
SomeSpacer(8).toSomeView(),
80+
"what".toSomeLabel()
81+
.copy(someStyle = paddingStyle(8, 0))
82+
.toSomeView(),
83+
SomeSpacer(8).toSomeView(),
84+
Pair(
85+
"Something important", """
86+
Is this an important piece of informtation or just another bunch of fake news if you read this far then you are a fool lul
87+
""".trimIndent()
88+
).toSomeLabel()
89+
.copy(someStyle = paddingStyle(8, 8))
90+
.toSomeView(),
91+
SomeSpacer(32).toSomeView(),
92+
SDButton.mock
93+
.copy(
94+
someStyle = SomeStyle(
95+
isHidden = false,
96+
cornerRadius = 4,
97+
paddingStart = 8,
98+
paddingEnd = 8
99+
)
100+
)
101+
.toSomeView()
102+
),
103+
someStyle = null
104+
).toSomeView(),
105+
footerView = null
106+
)
107+
)
108+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.pv.screendataui
2+
3+
import androidx.compose.foundation.Text
4+
import androidx.compose.runtime.Composable
5+
import androidx.ui.tooling.preview.Preview
6+
import com.pv.screendata.objects.SomeView
7+
import com.pv.screendata.types.ViewDirectionAxis
8+
import com.pv.screendata.types.ViewType
9+
import com.pv.screendataui.viewsamples.*
10+
11+
// Todo : find safe fallback on those labels
12+
@Composable
13+
fun SDSomeView(someView: SomeView) = when (someView.type) {
14+
ViewType.label -> {
15+
SDLabel(label = someView.someLabel!!)
16+
}
17+
ViewType.image -> {
18+
SDImage(image = someView.someImage!!)
19+
}
20+
ViewType.labeledImage -> {
21+
SDLabeledImage(labeledImage = someView.someLabeledImage!!)
22+
}
23+
ViewType.container -> {
24+
SDContainerView(containerView = someView.someContainer!!)
25+
}
26+
ViewType.custom -> {
27+
Text(text = "Will link to a custom")
28+
}
29+
ViewType.text -> {
30+
Text(text = someView.someText!!.title)
31+
}
32+
ViewType.button -> {
33+
SDButton(someButton = someView.someButton!!)
34+
}
35+
ViewType.spacer -> {
36+
SDSpacer(someSpacer = someView.someSpacer!!)
37+
}
38+
}
39+
40+
@Preview(showBackground = true)
41+
@Composable
42+
fun sdSomeViewPreview() {
43+
SDSomeView(someView = SDSomeViewDemo.mock)
44+
}
45+
46+
object SDSomeViewDemo {
47+
48+
val mock = SomeView(
49+
type = ViewType.container,
50+
someContainer = SDContainerViewDemo.containerMock(ViewDirectionAxis.vertical),
51+
someText = null,
52+
someButton = null,
53+
someImage = null,
54+
someLabel = null,
55+
someLabeledImage = null,
56+
someCustomView = null
57+
)
58+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.pv.screendataui
2+
3+
import androidx.compose.ui.graphics.Color
4+
import com.pv.screendata.objects.SomeColor
5+
6+
fun SomeColor.toComposeColor(): Color = Color(red, green, blue)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.pv.screendataui.viewsamples
2+
3+
import androidx.compose.foundation.Text
4+
import androidx.compose.foundation.layout.fillMaxWidth
5+
import androidx.compose.foundation.layout.padding
6+
import androidx.compose.foundation.shape.RoundedCornerShape
7+
import androidx.compose.material.TextButton
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.graphics.Color
11+
import androidx.compose.ui.text.style.TextAlign
12+
import androidx.compose.ui.unit.dp
13+
import androidx.ui.tooling.preview.Preview
14+
import com.pv.screendata.objects.SomeColor
15+
import com.pv.screendata.objects.SomeStyle
16+
import com.pv.screendataui.toComposeColor
17+
import com.pv.screendata.views.SomeButton
18+
19+
@Composable
20+
fun SDButton(someButton: SomeButton) {
21+
22+
val cbModifier = Modifier.fillMaxWidth() +
23+
Modifier.padding(
24+
start = someButton.someStyle?.paddingStart?.dp ?: 0.dp,
25+
end = someButton.someStyle?.paddingEnd?.dp ?: 0.dp
26+
)
27+
28+
TextButton(
29+
onClick = {},
30+
cbModifier,
31+
shape = RoundedCornerShape(someButton.someStyle?.cornerRadius?.dp ?: 2.dp),
32+
backgroundColor = someButton.someStyle?.backgroundColor?.toComposeColor() ?: Color.White
33+
) {
34+
Text(
35+
text = someButton.title,
36+
textAlign = TextAlign.Center,
37+
color = someButton.someStyle?.foregroundColor?.toComposeColor() ?: Color.Black
38+
)
39+
}
40+
41+
42+
}
43+
44+
@Preview
45+
@Composable
46+
fun sdButtonPreview() {
47+
SDButton(someButton = SDButton.mock)
48+
}
49+
50+
object SDButton {
51+
52+
val mock = SomeButton(
53+
id = null,
54+
actionId = null,
55+
title = "clieck meh mmooo",
56+
destination = null,
57+
someStyle = SomeStyle(
58+
backgroundColor = SomeColor(
59+
1f,
60+
152f / 255f,
61+
0f,
62+
1f
63+
),
64+
foregroundColor = SomeColor(
65+
81f / 255f,
66+
45f / 255f,
67+
168f / 255f,
68+
1f
69+
),
70+
isHidden = false,
71+
cornerRadius = 4
72+
)
73+
)
74+
}
75+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.pv.screendataui.viewsamples
2+
3+
import androidx.compose.foundation.ScrollableColumn
4+
import androidx.compose.foundation.ScrollableRow
5+
import androidx.compose.foundation.layout.fillMaxWidth
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.Modifier
9+
import androidx.compose.ui.unit.dp
10+
import androidx.ui.tooling.preview.Preview
11+
import com.pv.screendataui.SDSomeView
12+
import com.pv.screendata.extensions.SomeStyleHelper.paddingStyle
13+
import com.pv.screendata.extensions.toSomeView
14+
import com.pv.screendata.types.ViewDirectionAxis
15+
import com.pv.screendata.views.SomeContainerView
16+
17+
@Composable
18+
fun SDContainerView(containerView: SomeContainerView) {
19+
val content = @Composable {
20+
containerView.someViews.forEach {
21+
SDSomeView(someView = it)
22+
}
23+
}
24+
25+
val cvModifier = Modifier.fillMaxWidth() +
26+
Modifier.padding(
27+
start = containerView.someStyle?.paddingStart?.dp ?: 0.dp,
28+
end = containerView.someStyle?.paddingEnd?.dp ?: 0.dp
29+
)
30+
31+
when (containerView.axis) {
32+
ViewDirectionAxis.horizontal -> ScrollableRow(
33+
modifier = cvModifier,
34+
) {
35+
content()
36+
}
37+
ViewDirectionAxis.vertical -> ScrollableColumn(
38+
modifier = cvModifier,
39+
) {
40+
content()
41+
}
42+
}
43+
}
44+
45+
@Preview(showBackground = true)
46+
@Composable
47+
fun sdContainerViewPreview() {
48+
SDContainerView(
49+
containerView = SDContainerViewDemo.containerMock(ViewDirectionAxis.vertical)
50+
)
51+
}
52+
53+
object SDContainerViewDemo {
54+
55+
val containerMock = { axis: ViewDirectionAxis ->
56+
SomeContainerView(
57+
id = "someContainerId",
58+
axis = axis,
59+
someViews = arrayOf(
60+
SDLabel.mock.toSomeView(),
61+
SDLabel.mock.toSomeView(),
62+
SDLabel.mock.toSomeView()
63+
),
64+
someStyle = paddingStyle(start = 4, end = 4)
65+
)
66+
}
67+
}

0 commit comments

Comments
 (0)