From e0bfa8f2da1bcec64870b1afb0b35c6997b06139 Mon Sep 17 00:00:00 2001 From: Avneet Singh Date: Tue, 6 Feb 2024 23:43:12 +0530 Subject: [PATCH] refactor #2503: migrated home screen to compose --- .../org/mifos/mobile/ui/home/HomeContent.kt | 19 ++++++------------- .../mobile/core/ui/component/EmptyDataView.kt | 5 +++-- .../core/ui/component/MifosTitleSearchCard.kt | 5 +++-- .../org/mifos/mobile/core/ui/theme/Theme.kt | 5 ++++- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/mifos/mobile/ui/home/HomeContent.kt b/app/src/main/java/org/mifos/mobile/ui/home/HomeContent.kt index 4e6dd0af0..3c68999ef 100644 --- a/app/src/main/java/org/mifos/mobile/ui/home/HomeContent.kt +++ b/app/src/main/java/org/mifos/mobile/ui/home/HomeContent.kt @@ -3,7 +3,6 @@ package org.mifos.mobile.ui.home import android.graphics.Bitmap import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ExperimentalLayoutApi @@ -28,7 +27,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.painterResource @@ -124,7 +122,6 @@ fun UserDetailsRow( .padding(20.dp), verticalAlignment = Alignment.CenterVertically ) { - MifosUserImage( modifier = Modifier .size(84.dp) @@ -135,14 +132,10 @@ fun UserDetailsRow( bitmap = userBitmap, username = username ) - Text( - text = stringResource( - R.string.hello_client, - username - ), + text = stringResource(R.string.hello_client, username), style = MaterialTheme.typography.headlineSmall, - color = if (isSystemInDarkTheme()) Color.White else Color.Black, + color = MaterialTheme.colorScheme.onSurface, modifier = Modifier .padding(horizontal = 20.dp) .fillMaxWidth(1f) @@ -179,7 +172,7 @@ private fun HomeCard( text = stringResource(id = titleId), textAlign = TextAlign.Center, style = MaterialTheme.typography.bodyMedium, - color = if (isSystemInDarkTheme()) Color.White else Color.Black + color = MaterialTheme.colorScheme.onSurface ) } } @@ -208,7 +201,7 @@ private fun AccountOverviewCard( Text( text = stringResource(id = R.string.accounts_overview), style = MaterialTheme.typography.bodyMedium, - color = if (isSystemInDarkTheme()) Color.White else Color.Black + color = MaterialTheme.colorScheme.onSurface ) Divider(modifier = Modifier.padding(top = 8.dp, bottom = 4.dp)) @@ -253,7 +246,7 @@ private fun ContactUsRow( Text( text = stringResource(id = R.string.need_help), modifier = Modifier.weight(1f), - color = if (isSystemInDarkTheme()) Color.White else Color.Black, + color = MaterialTheme.colorScheme.onSurface, style = MaterialTheme.typography.bodyMedium ) @@ -279,7 +272,7 @@ private fun ContactUsRow( fun PreviewHomeContent() { MifosMobileTheme { HomeContent( - username = "Mifos", + username = stringResource(id = R.string.app_name), totalLoanAmount = 32.32, totalSavingsAmount = 34.43, userBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888), diff --git a/ui/src/main/java/org/mifos/mobile/core/ui/component/EmptyDataView.kt b/ui/src/main/java/org/mifos/mobile/core/ui/component/EmptyDataView.kt index 1225da9cd..9c89c407b 100644 --- a/ui/src/main/java/org/mifos/mobile/core/ui/component/EmptyDataView.kt +++ b/ui/src/main/java/org/mifos/mobile/core/ui/component/EmptyDataView.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -34,13 +35,13 @@ fun EmptyDataView( .padding(bottom = 12.dp), painter = painterResource(id = icon), contentDescription = null, - tint = if (isSystemInDarkTheme()) Color.White else Color.Gray + tint = MaterialTheme.colorScheme.onSecondary ) Text( text = stringResource(id = error), style = TextStyle(fontSize = 20.sp), - color = if (isSystemInDarkTheme()) Color.White else Color.Gray + color = MaterialTheme.colorScheme.onSecondary ) } } \ No newline at end of file diff --git a/ui/src/main/java/org/mifos/mobile/core/ui/component/MifosTitleSearchCard.kt b/ui/src/main/java/org/mifos/mobile/core/ui/component/MifosTitleSearchCard.kt index 30b0cc2d1..9ba942569 100644 --- a/ui/src/main/java/org/mifos/mobile/core/ui/component/MifosTitleSearchCard.kt +++ b/ui/src/main/java/org/mifos/mobile/core/ui/component/MifosTitleSearchCard.kt @@ -8,6 +8,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Search import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -42,7 +43,7 @@ fun MifosTitleSearchCard( ) { Text( text = stringResource(id = titleResourceId), - color = if (isSystemInDarkTheme()) Color.White else Color.Black, + color = MaterialTheme.colorScheme.onSurface, style = TextStyle(fontSize = 24.sp), modifier = Modifier.weight(1f), maxLines = 1 @@ -52,7 +53,7 @@ fun MifosTitleSearchCard( Icon( imageVector = Icons.Default.Search, contentDescription = "Search Icon", - tint = if (isSystemInDarkTheme()) Color.White else Color.Black, + tint = MaterialTheme.colorScheme.onSurface, ) } } diff --git a/ui/src/main/java/org/mifos/mobile/core/ui/theme/Theme.kt b/ui/src/main/java/org/mifos/mobile/core/ui/theme/Theme.kt index aca22cc38..ac12da2a4 100644 --- a/ui/src/main/java/org/mifos/mobile/core/ui/theme/Theme.kt +++ b/ui/src/main/java/org/mifos/mobile/core/ui/theme/Theme.kt @@ -14,7 +14,8 @@ private val LightThemeColors = lightColorScheme( error = RedErrorDark, background = BackgroundLight, onSurface = Black2, - outlineVariant = Color.Gray + onSecondary = Color.Gray, + outlineVariant = Color.Gray, ) private val DarkThemeColors = darkColorScheme( @@ -24,6 +25,8 @@ private val DarkThemeColors = darkColorScheme( error = RedErrorDark, background = BackgroundDark, surface = Black1, + onSurface = Color.White, + onSecondary = Color.White, outlineVariant = Color.White )