Skip to content

Commit

Permalink
Updated compose screen with dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuppan committed May 20, 2023
1 parent d0136cf commit c4cae5d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ object Versions {
const val minSdk = 21
const val targetSdk = 33

const val versionCode = 17
const val versionName = "1.0.17"
const val versionCode = 18
const val versionName = "1.0.18"

const val groupId = "com.github.nkuppan"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Icon
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
Expand All @@ -35,6 +36,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.github.nkuppan.country.core.R
import com.github.nkuppan.country.domain.model.Country
import com.github.nkuppan.countrycompose.ui.theme.CountryAppTheme
import com.github.nkuppan.countrycompose.utils.getCountryImage

@Composable
Expand Down Expand Up @@ -73,7 +75,7 @@ internal fun CountrySearchView(
)
},
leadingIcon = {
Image(
Icon(
modifier = Modifier
.padding(8.dp)
.size(24.dp)
Expand All @@ -87,7 +89,7 @@ internal fun CountrySearchView(
},
trailingIcon = {
if (showClear) {
Image(
Icon(
modifier = Modifier
.padding(8.dp)
.size(24.dp)
Expand Down Expand Up @@ -197,7 +199,7 @@ internal fun CountryDetailsView(
@Composable
@Preview(showBackground = true)
private fun CountryDetailsPreview() {
Column {
CountryAppTheme(isDarkTheme = true) {
CountrySearchAndListView(
countries = listOf(
Country("India", "in", ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.window.Dialog
import androidx.lifecycle.viewmodel.compose.viewModel
import com.github.nkuppan.country.domain.model.Country
import com.github.nkuppan.countrycompose.ui.theme.CountryAppTheme

@Composable
fun CountrySelectionDialog(
Expand All @@ -16,17 +17,19 @@ fun CountrySelectionDialog(

countryListViewModel.loadCountries()

Dialog(
onDismissRequest = {
onDismissRequest?.invoke()
CountryAppTheme {
Dialog(
onDismissRequest = {
onDismissRequest?.invoke()
}
) {
CountrySearchAndListView(
modifier,
countryListViewModel,
onDismissRequest,
selection
)
}
) {
CountrySearchAndListView(
modifier,
countryListViewModel,
onDismissRequest,
selection
)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.viewmodel.compose.viewModel
import com.github.nkuppan.country.domain.model.Country
import com.github.nkuppan.countrycompose.ui.theme.CountryAppTheme


@Preview
Expand All @@ -17,11 +18,13 @@ fun CountrySelectionPage(
) {
countryListViewModel.loadCountries()

CountrySearchAndListView(
modifier,
countryListViewModel,
onDismissRequest,
selection
)
CountryAppTheme {
CountrySearchAndListView(
modifier,
countryListViewModel,
onDismissRequest,
selection
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.nkuppan.countrycompose.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import com.github.nkuppan.country.core.R

private val DarkColors = darkColors(
primary = Color(R.color.weather_green_300),
primaryVariant = Color(R.color.weather_green_700),
onPrimary = Color(R.color.black),
secondary = Color(R.color.weather_blue_300),
secondaryVariant = Color(R.color.weather_blue_300),
onSecondary = Color(R.color.black),
error = Color(R.color.weather_red_300),
onError = Color(R.color.black),
)

private val LightColors = lightColors(
primary = Color(R.color.weather_green_700),
primaryVariant = Color(R.color.weather_green_900),
onPrimary = Color(R.color.white),
secondary = Color(R.color.weather_blue_900),
secondaryVariant = Color(R.color.weather_blue_900),
onSecondary = Color(R.color.white),
error = Color(R.color.weather_red_600),
onError = Color(R.color.white),
)

@Composable
fun CountryAppTheme(
isDarkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {

val colors = if (isDarkTheme) DarkColors else LightColors

MaterialTheme(
colors = colors,
content = content
)
}
8 changes: 4 additions & 4 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ dependencies {

implementation(Libs.Google.material)

implementation("com.github.nkuppan.country:country:1.0.17")
implementation("com.github.nkuppan.country:countrycompose:1.0.17")
// implementation("com.github.nkuppan.country:country:1.0.17")
// implementation("com.github.nkuppan.country:countrycompose:1.0.17")

// implementation project(":country")
// implementation project(":countrycompose")
implementation project(":country")
implementation project(":countrycompose")

implementation(platform(Libs.AndroidX.Compose.bom))
androidTestImplementation(platform(Libs.AndroidX.Compose.bom))
Expand Down

0 comments on commit c4cae5d

Please sign in to comment.