From 13fbf5ccf4b96dd26bf66b2d4a93517b64d109fc Mon Sep 17 00:00:00 2001 From: "Marlon D. Rocha" Date: Tue, 19 Mar 2024 00:51:37 -0300 Subject: [PATCH] Improvements from code review. --- .../local/LocalOperationDataSource.kt | 4 ++-- .../kotlin/domain/model/Category.kt | 6 ++++- .../kotlin/domain/model/Operation.kt | 5 ++-- .../kotlin/domain/model/OperationType.kt | 8 ++++++- .../screen/operation/NewOperationScreen.kt | 23 ++++--------------- .../presentation/designsystem/TabBarTest.kt | 2 +- 6 files changed, 22 insertions(+), 26 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/data/datasource/local/LocalOperationDataSource.kt b/composeApp/src/commonMain/kotlin/data/datasource/local/LocalOperationDataSource.kt index b85ef94..d2ec373 100644 --- a/composeApp/src/commonMain/kotlin/data/datasource/local/LocalOperationDataSource.kt +++ b/composeApp/src/commonMain/kotlin/data/datasource/local/LocalOperationDataSource.kt @@ -20,8 +20,8 @@ class LocalOperationDataSource: KoinComponent, OperationDataSource { id = -1, amount = 0.0, description = "Test", - type = OperationType.INCOME.operation, - category = Category.EDUCATION.name, + type = OperationType.INCOME, + category = Category.EDUCATION, date = LocalDateTime(2024, 3, 6, 1, 1 ,1, 1), isPeriodic = false, ) diff --git a/composeApp/src/commonMain/kotlin/domain/model/Category.kt b/composeApp/src/commonMain/kotlin/domain/model/Category.kt index 49e9984..d605602 100644 --- a/composeApp/src/commonMain/kotlin/domain/model/Category.kt +++ b/composeApp/src/commonMain/kotlin/domain/model/Category.kt @@ -51,5 +51,9 @@ enum class Category(val categoryName: String, val primaryColor: Color, TRAVEL("Travel", indigo500, indigo600, Res.drawable.ic_travel), TRANSPORT("Transport", purple600, purple500, Res.drawable.ic_transport), GIFTS_DONATIONS("Gifts & Donations", pink600, pink500, Res.drawable.ic_gifts), - MISCELLANEOUS("Miscellaneous", rose600, rose500, Res.drawable.ic_miscellaneous) + MISCELLANEOUS("Miscellaneous", rose600, rose500, Res.drawable.ic_miscellaneous); + + companion object { + fun all(): Array = enumValues() + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/domain/model/Operation.kt b/composeApp/src/commonMain/kotlin/domain/model/Operation.kt index 820cb9a..ea812b2 100644 --- a/composeApp/src/commonMain/kotlin/domain/model/Operation.kt +++ b/composeApp/src/commonMain/kotlin/domain/model/Operation.kt @@ -2,13 +2,12 @@ package domain.model import kotlinx.datetime.LocalDateTime - data class Operation( val id: Long, val amount: Double, val description: String, - val type: String, - val category: String, + val type: OperationType, + val category: Category, val date: LocalDateTime, val isPeriodic: Boolean, ) diff --git a/composeApp/src/commonMain/kotlin/domain/model/OperationType.kt b/composeApp/src/commonMain/kotlin/domain/model/OperationType.kt index d36dbee..443060a 100644 --- a/composeApp/src/commonMain/kotlin/domain/model/OperationType.kt +++ b/composeApp/src/commonMain/kotlin/domain/model/OperationType.kt @@ -6,5 +6,11 @@ import presentation.theme.income enum class OperationType(val operation: String, val color: Color) { EXPENSE("Expense", expense), - INCOME("Income", income) + INCOME("Income", income); + + companion object { + private fun all(): Array = enumValues() + + fun operationNames(): List = all().map { it.operation } + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/presentation/screen/operation/NewOperationScreen.kt b/composeApp/src/commonMain/kotlin/presentation/screen/operation/NewOperationScreen.kt index e75eb93..175fd26 100644 --- a/composeApp/src/commonMain/kotlin/presentation/screen/operation/NewOperationScreen.kt +++ b/composeApp/src/commonMain/kotlin/presentation/screen/operation/NewOperationScreen.kt @@ -31,7 +31,6 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.unit.dp import domain.model.Category import domain.model.OperationType import moe.tlaster.precompose.koin.koinViewModel @@ -92,22 +91,10 @@ internal fun NewOperationScreen( } val tabContentColors = listOf(expense, income) - val operations = listOf(OperationType.EXPENSE.operation, OperationType.INCOME.operation) + val operations = OperationType.operationNames().toList() //TODO: Remover esta lista ao implementar lógica de navegação para tela de categorias - val categories = listOf( - Category.TRAVEL, - Category.DINING_OUT, - Category.HEALTH_WELLNESS, - Category.EDUCATION, - Category.ENTERTAINMENT, - Category.GIFTS_DONATIONS, - Category.GROCERIES, - Category.INCOME, - Category.MISCELLANEOUS, - Category.TRANSPORT, - Category.SUBSCRIPTION - ) + val categories = Category.all() Scaffold( topBar = { @@ -216,10 +203,10 @@ fun Selector(modifier: Modifier = Modifier, icon: DrawableResource? = null, .height(INPUT_HEIGHT) .clip(MaterialTheme.shapes.small) .background(MaterialTheme.colors.surface) - .padding(SMALL_PADDING) - .clickable { onSelectorClick() }, + .clickable { onSelectorClick() } + .padding(SMALL_PADDING), verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp) + horizontalArrangement = Arrangement.spacedBy(EXTRA_SMALL_PADDING) ) { icon?.let { Icon( diff --git a/composeApp/src/commonTest/kotlin/presentation/designsystem/TabBarTest.kt b/composeApp/src/commonTest/kotlin/presentation/designsystem/TabBarTest.kt index 671678d..ec766ae 100644 --- a/composeApp/src/commonTest/kotlin/presentation/designsystem/TabBarTest.kt +++ b/composeApp/src/commonTest/kotlin/presentation/designsystem/TabBarTest.kt @@ -13,7 +13,7 @@ import kotlin.test.Test class TabBarTest { private val tabContentColors = listOf(expense, income) - private val tabItems = listOf(OperationType.EXPENSE.operation, OperationType.INCOME.operation) + private val tabItems = OperationType.operationNames() @OptIn(ExperimentalTestApi::class) @Test