Skip to content

Commit 17400df

Browse files
authored
feat: theming with config (#196)
* feat: theming with config * chore: added preview to composables
1 parent aa832e2 commit 17400df

File tree

9 files changed

+128
-52
lines changed

9 files changed

+128
-52
lines changed

app/build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88

99
def config = configHelper.fetchConfig()
1010
def appId = config.getOrDefault("APPLICATION_ID", "org.openedx.app")
11+
def platformName = config.getOrDefault("PLATFORM_NAME", "OpenEdx").toLowerCase()
1112

1213
android {
1314
compileSdk 34
@@ -39,6 +40,18 @@ android {
3940
}
4041
}
4142

43+
sourceSets {
44+
prod {
45+
res.srcDirs = ["src/$platformName/res"]
46+
}
47+
develop {
48+
res.srcDirs = ["src/$platformName/res"]
49+
}
50+
stage {
51+
res.srcDirs = ["src/$platformName/res"]
52+
}
53+
}
54+
4255
buildTypes {
4356
release {
4457
minifyEnabled true

auth/src/main/java/org/openedx/auth/presentation/logistration/LogistrationFragment.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import android.content.res.Configuration
44
import android.os.Bundle
55
import android.view.LayoutInflater
66
import android.view.ViewGroup
7-
import androidx.compose.foundation.Image
87
import androidx.compose.foundation.layout.Column
98
import androidx.compose.foundation.layout.Spacer
109
import androidx.compose.foundation.layout.fillMaxSize
1110
import androidx.compose.foundation.layout.fillMaxWidth
1211
import androidx.compose.foundation.layout.height
1312
import androidx.compose.foundation.layout.navigationBarsPadding
1413
import androidx.compose.foundation.layout.padding
15-
import androidx.compose.foundation.layout.wrapContentWidth
1614
import androidx.compose.foundation.rememberScrollState
1715
import androidx.compose.foundation.verticalScroll
1816
import androidx.compose.material.MaterialTheme
@@ -27,12 +25,10 @@ import androidx.compose.runtime.saveable.rememberSaveable
2725
import androidx.compose.runtime.setValue
2826
import androidx.compose.ui.ExperimentalComposeUiApi
2927
import androidx.compose.ui.Modifier
30-
import androidx.compose.ui.graphics.ColorFilter
3128
import androidx.compose.ui.platform.ComposeView
3229
import androidx.compose.ui.platform.LocalFocusManager
3330
import androidx.compose.ui.platform.ViewCompositionStrategy
3431
import androidx.compose.ui.platform.testTag
35-
import androidx.compose.ui.res.painterResource
3632
import androidx.compose.ui.res.stringResource
3733
import androidx.compose.ui.semantics.semantics
3834
import androidx.compose.ui.semantics.testTagsAsResourceId
@@ -52,7 +48,7 @@ import org.openedx.core.ui.noRippleClickable
5248
import org.openedx.core.ui.theme.OpenEdXTheme
5349
import org.openedx.core.ui.theme.appColors
5450
import org.openedx.core.ui.theme.appTypography
55-
import org.openedx.core.R as coreR
51+
import org.openedx.core.ui.theme.compose.LogistrationLogoView
5652

5753
class LogistrationFragment : Fragment() {
5854

@@ -131,14 +127,7 @@ private fun LogistrationScreen(
131127
vertical = 32.dp,
132128
)
133129
) {
134-
Image(
135-
painter = painterResource(id = coreR.drawable.core_ic_logo),
136-
contentDescription = null,
137-
modifier = Modifier
138-
.padding(top = 64.dp, bottom = 20.dp)
139-
.wrapContentWidth(),
140-
colorFilter = ColorFilter.tint(MaterialTheme.appColors.primary)
141-
)
130+
LogistrationLogoView()
142131
Text(
143132
text = stringResource(id = R.string.pre_auth_title),
144133
color = MaterialTheme.appColors.textPrimary,

auth/src/main/java/org/openedx/auth/presentation/signin/compose/SignInView.kt

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.height
1515
import androidx.compose.foundation.layout.navigationBarsPadding
1616
import androidx.compose.foundation.layout.padding
1717
import androidx.compose.foundation.layout.statusBarsPadding
18-
import androidx.compose.foundation.layout.width
1918
import androidx.compose.foundation.layout.widthIn
2019
import androidx.compose.foundation.rememberScrollState
2120
import androidx.compose.foundation.text.KeyboardActions
@@ -72,6 +71,7 @@ import org.openedx.core.ui.theme.OpenEdXTheme
7271
import org.openedx.core.ui.theme.appColors
7372
import org.openedx.core.ui.theme.appShapes
7473
import org.openedx.core.ui.theme.appTypography
74+
import org.openedx.core.ui.theme.compose.SignInLogoView
7575
import org.openedx.core.ui.windowSizeValue
7676
import org.openedx.core.R as coreR
7777

@@ -151,21 +151,7 @@ internal fun LoginScreen(
151151
Modifier.padding(it),
152152
horizontalAlignment = Alignment.CenterHorizontally
153153
) {
154-
Box(
155-
modifier = Modifier
156-
.fillMaxWidth()
157-
.fillMaxHeight(0.2f),
158-
contentAlignment = Alignment.Center
159-
) {
160-
Image(
161-
painter = painterResource(id = coreR.drawable.core_ic_logo),
162-
contentDescription = null,
163-
modifier = Modifier
164-
.padding(top = 20.dp)
165-
.width(170.dp)
166-
.height(48.dp)
167-
)
168-
}
154+
SignInLogoView()
169155
Surface(
170156
color = MaterialTheme.appColors.background,
171157
shape = MaterialTheme.appShapes.screenBackgroundShape,

core/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ plugins {
1616
}
1717

1818
def currentFlavour = getCurrentFlavor()
19+
def config = configHelper.fetchConfig()
20+
def platformName = config.getOrDefault("PLATFORM_NAME", "OpenEdx").toLowerCase()
1921

2022
android {
2123
compileSdk 34
@@ -47,8 +49,17 @@ android {
4749
}
4850

4951
sourceSets {
52+
prod {
53+
java.srcDirs = ["src/$platformName"]
54+
res.srcDirs = ["src/$platformName/res"]
55+
}
5056
develop {
51-
res.srcDirs = ['src/openedx/res']
57+
java.srcDirs = ["src/$platformName"]
58+
res.srcDirs = ["src/$platformName/res"]
59+
}
60+
stage {
61+
java.srcDirs = ["src/$platformName"]
62+
res.srcDirs = ["src/$platformName/res"]
5263
}
5364
main {
5465
assets {

core/src/main/java/org/openedx/core/ui/theme/Shape.kt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package org.openedx.core.ui.theme
22

33
import androidx.compose.foundation.shape.CornerBasedShape
4-
import androidx.compose.foundation.shape.CornerSize
5-
import androidx.compose.foundation.shape.RoundedCornerShape
64
import androidx.compose.material.MaterialTheme
75
import androidx.compose.material.Shapes
86
import androidx.compose.runtime.Composable
97
import androidx.compose.runtime.ReadOnlyComposable
10-
import androidx.compose.runtime.staticCompositionLocalOf
11-
import androidx.compose.ui.unit.dp
128

139
data class AppShapes(
1410
val material: Shapes,
@@ -22,24 +18,6 @@ data class AppShapes(
2218
val dialogShape: CornerBasedShape,
2319
)
2420

25-
internal val LocalShapes = staticCompositionLocalOf {
26-
AppShapes(
27-
material = Shapes(
28-
small = RoundedCornerShape(4.dp),
29-
medium = RoundedCornerShape(8.dp),
30-
large = RoundedCornerShape(0.dp)
31-
),
32-
buttonShape = RoundedCornerShape(8.dp),
33-
navigationButtonShape = RoundedCornerShape(8.dp),
34-
textFieldShape = RoundedCornerShape(CornerSize(8.dp)),
35-
screenBackgroundShape = RoundedCornerShape(topStart = 30.dp, topEnd = 30.dp),
36-
cardShape = RoundedCornerShape(12.dp),
37-
screenBackgroundShapeFull = RoundedCornerShape(24.dp),
38-
courseImageShape = RoundedCornerShape(8.dp),
39-
dialogShape = RoundedCornerShape(24.dp),
40-
)
41-
}
42-
4321
val MaterialTheme.appShapes: AppShapes
4422
@Composable
4523
@ReadOnlyComposable
File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.openedx.core.ui.theme
2+
3+
import androidx.compose.foundation.shape.CornerSize
4+
import androidx.compose.foundation.shape.RoundedCornerShape
5+
import androidx.compose.material.Shapes
6+
import androidx.compose.runtime.staticCompositionLocalOf
7+
import androidx.compose.ui.unit.dp
8+
9+
internal val LocalShapes = staticCompositionLocalOf {
10+
AppShapes(
11+
material = Shapes(
12+
small = RoundedCornerShape(4.dp),
13+
medium = RoundedCornerShape(8.dp),
14+
large = RoundedCornerShape(0.dp)
15+
),
16+
buttonShape = RoundedCornerShape(8.dp),
17+
navigationButtonShape = RoundedCornerShape(8.dp),
18+
textFieldShape = RoundedCornerShape(CornerSize(8.dp)),
19+
screenBackgroundShape = RoundedCornerShape(topStart = 30.dp, topEnd = 30.dp),
20+
cardShape = RoundedCornerShape(12.dp),
21+
screenBackgroundShapeFull = RoundedCornerShape(24.dp),
22+
courseImageShape = RoundedCornerShape(8.dp),
23+
dialogShape = RoundedCornerShape(24.dp)
24+
)
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.openedx.core.ui.theme.compose
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.layout.padding
5+
import androidx.compose.foundation.layout.wrapContentWidth
6+
import androidx.compose.material.MaterialTheme
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.Modifier
9+
import androidx.compose.ui.graphics.ColorFilter
10+
import androidx.compose.ui.res.painterResource
11+
import androidx.compose.ui.tooling.preview.Preview
12+
import androidx.compose.ui.unit.dp
13+
import org.openedx.core.R
14+
import org.openedx.core.ui.theme.OpenEdXTheme
15+
import org.openedx.core.ui.theme.appColors
16+
17+
@Composable
18+
fun LogistrationLogoView() {
19+
Image(
20+
modifier = Modifier
21+
.padding(top = 64.dp, bottom = 20.dp)
22+
.wrapContentWidth(),
23+
painter = painterResource(id = R.drawable.core_ic_logo),
24+
contentDescription = null,
25+
colorFilter = ColorFilter.tint(MaterialTheme.appColors.primary)
26+
)
27+
}
28+
29+
@Preview(widthDp = 375)
30+
@Composable
31+
fun LogistrationLogoViewPreview() {
32+
OpenEdXTheme {
33+
LogistrationLogoView()
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.openedx.core.ui.theme.compose
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.fillMaxHeight
6+
import androidx.compose.foundation.layout.fillMaxWidth
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.Alignment
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.res.painterResource
12+
import androidx.compose.ui.tooling.preview.Preview
13+
import androidx.compose.ui.unit.dp
14+
import org.openedx.core.R
15+
import org.openedx.core.ui.theme.OpenEdXTheme
16+
17+
@Composable
18+
fun SignInLogoView() {
19+
Box(
20+
modifier = Modifier
21+
.fillMaxWidth()
22+
.fillMaxHeight(0.2f),
23+
contentAlignment = Alignment.Center
24+
) {
25+
Image(
26+
painter = painterResource(id = R.drawable.core_ic_logo),
27+
contentDescription = null,
28+
modifier = Modifier.padding(top = 20.dp)
29+
)
30+
}
31+
}
32+
33+
@Preview(widthDp = 375, heightDp = 400)
34+
@Composable
35+
fun SignInLogoViewPreview() {
36+
OpenEdXTheme {
37+
SignInLogoView()
38+
}
39+
}

0 commit comments

Comments
 (0)