Skip to content

Commit

Permalink
fix: checkbox cannot click
Browse files Browse the repository at this point in the history
  • Loading branch information
RugerMcCarthy committed Mar 18, 2021
1 parent 550e6fc commit 1a9008d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 84 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
implementation "androidx.navigation:navigation-compose:1.0.0-alpha09"

implementation "dev.chrisbanes.accompanist:accompanist-insets:0.6.2"
testImplementation 'junit:junit:4.13.2'

androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ package com.example.androiddevchallenge
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.example.androiddevchallenge.ui.NavGraph
import com.example.androiddevchallenge.ui.theme.BloomTheme

class MainActivity : AppCompatActivity() {

var theme: BloomTheme by mutableStateOf(BloomTheme.DARK)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BloomTheme(true) {
BloomTheme(theme) {
NavGraph(window)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
*/
package com.example.androiddevchallenge.data

data class Item(val name: String, val resId: Int)
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue

data class Item(val name: String, val resId: Int) {
var enable: Boolean by mutableStateOf(false)
}
32 changes: 19 additions & 13 deletions app/src/main/java/com/example/androiddevchallenge/ui/HomePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ val designList = listOf(
Item("Monstera", R.drawable.monstera),
Item("Aglaonema", R.drawable.aglaonema),
Item("Peace lily", R.drawable.peace_lily),
Item("Fiddle leaf tree", R.drawable.fiddle_leaf)
Item("Fiddle leaf tree", R.drawable.fiddle_leaf),
Item("Desert chic", R.drawable.desert_chic),
Item("Tiny terrariums", R.drawable.tiny_terrariums),
Item("Jungle Vibes", R.drawable.jungle_vibes)
)

val navList = listOf(
Expand Down Expand Up @@ -162,7 +165,8 @@ fun HomePage() {
LazyColumn(
modifier = Modifier
.padding(top = 16.dp)
.fillMaxWidth()
.fillMaxWidth(),
contentPadding = PaddingValues(bottom = 56.dp)
) {
items(designList.size) {
if (it != 0) {
Expand Down Expand Up @@ -209,14 +213,16 @@ fun DesignCard(plant: Item) {
)
}
Checkbox(
checked = plant.name == "Monstera",
onCheckedChange = {},
colors = CheckboxDefaults.colors(
checkmarkColor = MaterialTheme.colors.background
),
modifier = Modifier
.size(24.dp)
.padding(top = 24.dp)
.size(24.dp),
checked = plant.enable,
onCheckedChange = {
plant.enable = it
},
colors = CheckboxDefaults.colors(
checkmarkColor = MaterialTheme.colors.background
)
)
}
Divider(color = MaterialTheme.colors.onPrimary, modifier = Modifier.padding(top = 16.dp), thickness = 0.5.dp)
Expand Down Expand Up @@ -293,39 +299,39 @@ fun BottomBar() {
@Preview
@Composable
fun BottomBarPreview() {
BloomTheme(false) {
BloomTheme() {
BottomBar()
}
}

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

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

@Preview
@Composable
fun HomePageLightPreview() {
BloomTheme(false) {
BloomTheme() {
HomePage()
}
}

@Preview
@Composable
fun HomePageDarkPreview() {
BloomTheme(true) {
BloomTheme() {
HomePage()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ fun LoginPage() {
@Composable
@Preview
fun LoginPageLightPreview() {
BloomTheme(false) {
BloomTheme() {
LoginPage()
}
}

@Composable
@Preview
fun LoginPageDarkPreview() {
BloomTheme(true) {
BloomTheme() {
LoginPage()
}
}
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.getWelcomeAssets
import com.example.androiddevchallenge.ui.theme.welcomeAssets

@Composable
fun WelcomePage() {
Expand All @@ -51,13 +51,13 @@ fun WelcomePage() {
.background(MaterialTheme.colors.primary)
) {
Image(
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.getWelcomeAssets().background)),
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.welcomeAssets.background)),
contentDescription = "weclome_bg",
modifier = Modifier.fillMaxSize()
)
Column(modifier = Modifier.fillMaxSize()) {
Image(
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.getWelcomeAssets().illos)),
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.welcomeAssets.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.getWelcomeAssets().logo)),
painter = rememberVectorPainter(image = ImageVector.vectorResource(id = MaterialTheme.welcomeAssets.logo)),
contentDescription = "weclome_logo",
modifier = Modifier.wrapContentSize()
)
Expand Down Expand Up @@ -123,15 +123,15 @@ fun WelcomePage() {
@Preview
@Composable
fun WelcomePageLightPreview() {
BloomTheme(false) {
BloomTheme() {
WelcomePage()
}
}

@Preview
@Composable
fun WelcomePageDarkPreview() {
BloomTheme(true) {
BloomTheme() {
WelcomePage()
}
}
83 changes: 23 additions & 60 deletions app/src/main/java/com/example/androiddevchallenge/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/
package com.example.androiddevchallenge.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.Colors
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.ReadOnlyComposable
import androidx.compose.runtime.staticCompositionLocalOf
import com.example.androiddevchallenge.R

Expand All @@ -47,75 +46,39 @@ private val BloomDarkColorPaltte = darkColors(
onSurface = white850
)

private val DarkColorPalette = darkColors(
primary = purple200,
primaryVariant = purple700,
secondary = teal200
)

private val LightColorPalette = lightColors(
primary = purple500,
primaryVariant = purple700,
secondary = teal200
open class WelcomeAssets(var background: Int, var illos: Int, var logo: Int)

/* Other default colors to override
background = Color.White,
surface = Color.White,
onPrimary = Color.White,
onSecondary = Color.Black,
onBackground = Color.Black,
onSurface = Color.Black,
*/
object LightWelcomeAssets : WelcomeAssets(
background = R.drawable.ic_light_welcome_bg,
illos = R.drawable.ic_light_welcome_illos,
logo = R.drawable.ic_light_logo
)

@Composable
fun MyTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}

MaterialTheme(
colors = colors,
typography = typography,
shapes = shapes,
content = content
)
}

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
object DarkWelcomeAssets : WelcomeAssets(
background = R.drawable.ic_dark_welcome_bg,
illos = R.drawable.ic_dark_welcome_illos,
logo = R.drawable.ic_dark_logo
)

internal var LocalWelcomeAssets = staticCompositionLocalOf { WelcomeAssets() }
internal var LocalWelcomeAssets = staticCompositionLocalOf { LightWelcomeAssets as WelcomeAssets }

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

@Composable
fun BloomTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
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 {
WelcomeAssets(
background = R.drawable.ic_light_welcome_bg,
illos = R.drawable.ic_light_welcome_illos,
logo = R.drawable.ic_light_logo
)
}
enum class BloomTheme {
LIGHT, DARK
}

@Composable
fun BloomTheme(theme: BloomTheme = BloomTheme.LIGHT, content: @Composable() () -> Unit) {
val welcomeAssets = if (theme == BloomTheme.DARK) DarkWelcomeAssets else LightWelcomeAssets
CompositionLocalProvider(
LocalWelcomeAssets provides welcomeAssets
LocalWelcomeAssets provides welcomeAssets,
) {
MaterialTheme(
colors = if (darkTheme) BloomDarkColorPaltte else BloomLightColorPaltte,
colors = if (theme == BloomTheme.DARK) BloomDarkColorPaltte else BloomLightColorPaltte,
typography = bloomTypoGraphy,
shapes = shapes,
content = content
Expand Down

0 comments on commit 1a9008d

Please sign in to comment.