Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: theming with config #196

Merged
merged 2 commits into from
Jan 29, 2024
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
13 changes: 13 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {

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

android {
compileSdk 34
Expand Down Expand Up @@ -39,6 +40,18 @@ android {
}
}

sourceSets {
prod {
res.srcDirs = ["src/$platformName/res"]
}
develop {
res.srcDirs = ["src/$platformName/res"]
}
stage {
res.srcDirs = ["src/$platformName/res"]
}
}

buildTypes {
release {
minifyEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import android.content.res.Configuration
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.MaterialTheme
Expand All @@ -27,12 +25,10 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
Expand All @@ -52,7 +48,7 @@ import org.openedx.core.ui.noRippleClickable
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.ui.theme.appColors
import org.openedx.core.ui.theme.appTypography
import org.openedx.core.R as coreR
import org.openedx.core.ui.theme.compose.LogistrationLogoView

class LogistrationFragment : Fragment() {

Expand Down Expand Up @@ -131,14 +127,7 @@ private fun LogistrationScreen(
vertical = 32.dp,
)
) {
Image(
painter = painterResource(id = coreR.drawable.core_ic_logo),
contentDescription = null,
modifier = Modifier
.padding(top = 64.dp, bottom = 20.dp)
.wrapContentWidth(),
colorFilter = ColorFilter.tint(MaterialTheme.appColors.primary)
)
LogistrationLogoView()
Text(
text = stringResource(id = R.string.pre_auth_title),
color = MaterialTheme.appColors.textPrimary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardActions
Expand Down Expand Up @@ -72,6 +71,7 @@ import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.ui.theme.appColors
import org.openedx.core.ui.theme.appShapes
import org.openedx.core.ui.theme.appTypography
import org.openedx.core.ui.theme.compose.SignInLogoView
import org.openedx.core.ui.windowSizeValue
import org.openedx.core.R as coreR

Expand Down Expand Up @@ -151,21 +151,7 @@ internal fun LoginScreen(
Modifier.padding(it),
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(0.2f),
contentAlignment = Alignment.Center
) {
Image(
painter = painterResource(id = coreR.drawable.core_ic_logo),
contentDescription = null,
modifier = Modifier
.padding(top = 20.dp)
.width(170.dp)
.height(48.dp)
)
}
SignInLogoView()
Surface(
color = MaterialTheme.appColors.background,
shape = MaterialTheme.appShapes.screenBackgroundShape,
Expand Down
13 changes: 12 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ plugins {
}

def currentFlavour = getCurrentFlavor()
def config = configHelper.fetchConfig()
def platformName = config.getOrDefault("PLATFORM_NAME", "OpenEdx").toLowerCase()

android {
compileSdk 34
Expand Down Expand Up @@ -47,8 +49,17 @@ android {
}

sourceSets {
prod {
java.srcDirs = ["src/$platformName"]
res.srcDirs = ["src/$platformName/res"]
}
develop {
res.srcDirs = ['src/openedx/res']
java.srcDirs = ["src/$platformName"]
res.srcDirs = ["src/$platformName/res"]
}
stage {
java.srcDirs = ["src/$platformName"]
res.srcDirs = ["src/$platformName/res"]
}
main {
assets {
Expand Down
22 changes: 0 additions & 22 deletions core/src/main/java/org/openedx/core/ui/theme/Shape.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.openedx.core.ui.theme

import androidx.compose.foundation.shape.CornerBasedShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Shapes
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.unit.dp

data class AppShapes(
val material: Shapes,
Expand All @@ -22,24 +18,6 @@ data class AppShapes(
val dialogShape: CornerBasedShape,
)

internal val LocalShapes = staticCompositionLocalOf {
AppShapes(
material = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(8.dp),
large = RoundedCornerShape(0.dp)
),
buttonShape = RoundedCornerShape(8.dp),
navigationButtonShape = RoundedCornerShape(8.dp),
textFieldShape = RoundedCornerShape(CornerSize(8.dp)),
screenBackgroundShape = RoundedCornerShape(topStart = 30.dp, topEnd = 30.dp),
cardShape = RoundedCornerShape(12.dp),
screenBackgroundShapeFull = RoundedCornerShape(24.dp),
courseImageShape = RoundedCornerShape(8.dp),
dialogShape = RoundedCornerShape(24.dp),
)
}

val MaterialTheme.appShapes: AppShapes
@Composable
@ReadOnlyComposable
Expand Down
25 changes: 25 additions & 0 deletions core/src/openedx/org/openedx/core/ui/theme/LocalShapes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.openedx.core.ui.theme

import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.unit.dp

internal val LocalShapes = staticCompositionLocalOf {
AppShapes(
material = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(8.dp),
large = RoundedCornerShape(0.dp)
),
buttonShape = RoundedCornerShape(8.dp),
navigationButtonShape = RoundedCornerShape(8.dp),
textFieldShape = RoundedCornerShape(CornerSize(8.dp)),
screenBackgroundShape = RoundedCornerShape(topStart = 30.dp, topEnd = 30.dp),
cardShape = RoundedCornerShape(12.dp),
screenBackgroundShapeFull = RoundedCornerShape(24.dp),
courseImageShape = RoundedCornerShape(8.dp),
dialogShape = RoundedCornerShape(24.dp)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.openedx.core.ui.theme.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.openedx.core.R
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.ui.theme.appColors

@Composable
fun LogistrationLogoView() {
Image(
modifier = Modifier
.padding(top = 64.dp, bottom = 20.dp)
.wrapContentWidth(),
painter = painterResource(id = R.drawable.core_ic_logo),
contentDescription = null,
colorFilter = ColorFilter.tint(MaterialTheme.appColors.primary)
)
}

@Preview(widthDp = 375)
@Composable
fun LogistrationLogoViewPreview() {
OpenEdXTheme {
LogistrationLogoView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.openedx.core.ui.theme.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.openedx.core.R
import org.openedx.core.ui.theme.OpenEdXTheme

@Composable
fun SignInLogoView() {
Box(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(0.2f),
contentAlignment = Alignment.Center
) {
Image(
painter = painterResource(id = R.drawable.core_ic_logo),
contentDescription = null,
modifier = Modifier.padding(top = 20.dp)
)
}
}

@Preview(widthDp = 375, heightDp = 400)
@Composable
fun SignInLogoViewPreview() {
OpenEdXTheme {
SignInLogoView()
}
}
Loading