Skip to content

Commit

Permalink
refact: adjust code architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
RugerMcCarthy committed Mar 18, 2021
1 parent 7d1ad87 commit 550e6fc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BloomTheme(false) {
BloomTheme(true) {
NavGraph(window)
}
}
Expand Down
47 changes: 24 additions & 23 deletions app/src/main/java/com/example/androiddevchallenge/ui/HomePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ fun DesignCard(plant: Item) {
modifier = Modifier
.padding(end = 16.dp)
.size(64.dp)
.clip(RoundedCornerShape(4.dp))
)
Column {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Expand Down Expand Up @@ -289,29 +290,29 @@ fun BottomBar() {
}
}

// @Preview
// @Composable
// fun BottomBarPreview() {
// BloomTheme(false) {
// BottomBar()
// }
// }
//
// @Preview
// @Composable
// fun DesignCardPreview() {
// BloomTheme(false) {
// DesignCard(designList[0])
// }
// }
//
// @Preview
// @Composable
// fun PlantCardPreview() {
// BloomTheme(false) {
// PlantCard(plantList[0])
// }
// }
@Preview
@Composable
fun BottomBarPreview() {
BloomTheme(false) {
BottomBar()
}
}

@Preview
@Composable
fun DesignCardPreview() {
BloomTheme(false) {
DesignCard(designList[0])
}
}

@Preview
@Composable
fun PlantCardPreview() {
BloomTheme(false) {
PlantCard(plantList[0])
}
}

@Preview
@Composable
Expand Down
18 changes: 12 additions & 6 deletions app/src/main/java/com/example/androiddevchallenge/ui/NavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,30 @@ object TouristGuide {
fun toWelcome() {
navController?.navigate(RouterPath.WELCOME) {
anim {
enter = R.anim.slide_in_right
exit = R.anim.slide_out_left
this.enter = R.anim.slide_in_right
this.exit = R.anim.slide_out_left
this.popEnter = R.anim.slide_in_left
this.popExit = R.anim.slide_out_right
}
}
}
fun toLogin() {
navController?.navigate(RouterPath.LOGIN) {
anim {
enter = R.anim.slide_in_right
exit = R.anim.slide_out_left
this.enter = R.anim.slide_in_right
this.exit = R.anim.slide_out_left
this.popEnter = R.anim.slide_in_left
this.popExit = R.anim.slide_out_right
}
}
}
fun toHome() {
navController?.navigate(RouterPath.HOME) {
anim {
enter = R.anim.slide_in_right
exit = R.anim.slide_out_left
this.enter = R.anim.slide_in_right
this.exit = R.anim.slide_out_left
this.popEnter = R.anim.slide_in_left
this.popExit = R.anim.slide_out_right
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.androiddevchallenge.ui.theme.BloomTheme
import com.example.androiddevchallenge.ui.theme.welcomeAssets
import com.example.androiddevchallenge.ui.theme.getWelcomeAssets

@Composable
fun WelcomePage() {
Expand All @@ -51,13 +51,13 @@ fun WelcomePage() {
.background(MaterialTheme.colors.primary)
) {
Image(
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.welcomeAssets.background)),
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.getWelcomeAssets().background)),
contentDescription = "weclome_bg",
modifier = Modifier.fillMaxSize()
)
Column(modifier = Modifier.fillMaxSize()) {
Image(
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.welcomeAssets.illos)),
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.getWelcomeAssets().illos)),
contentDescription = "weclome_illos",
modifier = Modifier
.wrapContentSize()
Expand All @@ -70,7 +70,7 @@ fun WelcomePage() {
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.welcomeAssets.logo)),
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.getWelcomeAssets().logo)),
contentDescription = "weclome_logo",
modifier = Modifier.wrapContentSize()
)
Expand Down
45 changes: 22 additions & 23 deletions app/src/main/java/com/example/androiddevchallenge/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.staticCompositionLocalOf
import com.example.androiddevchallenge.R

private val BloomLightColorPaltte = lightColors(
Expand Down Expand Up @@ -82,44 +84,41 @@ fun MyTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() (
)
}

object WelcomeAssets {
var background: Int = R.drawable.ic_light_welcome_bg
var illos: Int = R.drawable.ic_light_welcome_illos
data class WelcomeAssets(
var background: Int = R.drawable.ic_light_welcome_bg,
var illos: Int = R.drawable.ic_light_welcome_illos,
var logo: Int = R.drawable.ic_light_logo
)

fun set(background: Int, illos: Int, logo: Int) {
this.background = background
this.illos = illos
this.logo = logo
}
}
internal var LocalWelcomeAssets = staticCompositionLocalOf { WelcomeAssets() }

val MaterialTheme.welcomeAssets: WelcomeAssets
get() = WelcomeAssets
@Composable
fun MaterialTheme.getWelcomeAssets() = LocalWelcomeAssets.current

@Composable
fun BloomTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
var colors: Colors
if (darkTheme) {
colors = BloomDarkColorPaltte
WelcomeAssets.set(
val welcomeAssets = if (darkTheme) {
WelcomeAssets(
background = R.drawable.ic_dark_welcome_bg,
illos = R.drawable.ic_dark_welcome_illos,
logo = R.drawable.ic_dark_logo
)
} else {
colors = BloomLightColorPaltte
WelcomeAssets.set(
WelcomeAssets(
background = R.drawable.ic_light_welcome_bg,
illos = R.drawable.ic_light_welcome_illos,
logo = R.drawable.ic_light_logo
)
}

MaterialTheme(
colors = colors,
typography = bloomTypoGraphy,
shapes = shapes,
content = content
)
CompositionLocalProvider(
LocalWelcomeAssets provides welcomeAssets
) {
MaterialTheme(
colors = if (darkTheme) BloomDarkColorPaltte else BloomLightColorPaltte,
typography = bloomTypoGraphy,
shapes = shapes,
content = content
)
}
}

0 comments on commit 550e6fc

Please sign in to comment.