From c4cae5d472711332e2d276b70edd83713ed64ad7 Mon Sep 17 00:00:00 2001 From: Naveen Kumar Kuppan Date: Sat, 20 May 2023 17:57:02 +0530 Subject: [PATCH] Updated compose screen with dark theme --- .../com/nkuppan/country/buildsrc/Versions.kt | 4 +- .../country/CountryListAndSearchView.kt | 8 ++-- .../country/CountrySelectionDialog.kt | 23 +++++----- .../country/CountrySelectionPage.kt | 15 ++++--- .../countrycompose/ui/theme/CountryTheme.kt | 45 +++++++++++++++++++ example/build.gradle | 8 ++-- 6 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 countrycompose/src/main/java/com/github/nkuppan/countrycompose/ui/theme/CountryTheme.kt diff --git a/buildSrc/src/main/java/com/nkuppan/country/buildsrc/Versions.kt b/buildSrc/src/main/java/com/nkuppan/country/buildsrc/Versions.kt index d555368..538e77e 100644 --- a/buildSrc/src/main/java/com/nkuppan/country/buildsrc/Versions.kt +++ b/buildSrc/src/main/java/com/nkuppan/country/buildsrc/Versions.kt @@ -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" diff --git a/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountryListAndSearchView.kt b/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountryListAndSearchView.kt index c47395f..d92498b 100644 --- a/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountryListAndSearchView.kt +++ b/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountryListAndSearchView.kt @@ -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 @@ -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 @@ -73,7 +75,7 @@ internal fun CountrySearchView( ) }, leadingIcon = { - Image( + Icon( modifier = Modifier .padding(8.dp) .size(24.dp) @@ -87,7 +89,7 @@ internal fun CountrySearchView( }, trailingIcon = { if (showClear) { - Image( + Icon( modifier = Modifier .padding(8.dp) .size(24.dp) @@ -197,7 +199,7 @@ internal fun CountryDetailsView( @Composable @Preview(showBackground = true) private fun CountryDetailsPreview() { - Column { + CountryAppTheme(isDarkTheme = true) { CountrySearchAndListView( countries = listOf( Country("India", "in", ""), diff --git a/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountrySelectionDialog.kt b/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountrySelectionDialog.kt index 92fa084..27b4758 100644 --- a/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountrySelectionDialog.kt +++ b/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountrySelectionDialog.kt @@ -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( @@ -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 - ) } } diff --git a/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountrySelectionPage.kt b/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountrySelectionPage.kt index 34a94e1..dad7c4e 100644 --- a/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountrySelectionPage.kt +++ b/countrycompose/src/main/java/com/github/nkuppan/countrycompose/presentation/country/CountrySelectionPage.kt @@ -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 @@ -17,11 +18,13 @@ fun CountrySelectionPage( ) { countryListViewModel.loadCountries() - CountrySearchAndListView( - modifier, - countryListViewModel, - onDismissRequest, - selection - ) + CountryAppTheme { + CountrySearchAndListView( + modifier, + countryListViewModel, + onDismissRequest, + selection + ) + } } diff --git a/countrycompose/src/main/java/com/github/nkuppan/countrycompose/ui/theme/CountryTheme.kt b/countrycompose/src/main/java/com/github/nkuppan/countrycompose/ui/theme/CountryTheme.kt new file mode 100644 index 0000000..a2c9579 --- /dev/null +++ b/countrycompose/src/main/java/com/github/nkuppan/countrycompose/ui/theme/CountryTheme.kt @@ -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 + ) +} \ No newline at end of file diff --git a/example/build.gradle b/example/build.gradle index ac1c293..31b627d 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -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))