From 6564a9d33dc0d870d5890c3c8e09b203b3fe607f Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 19 Sep 2024 18:52:55 +0200 Subject: [PATCH] Moved now all Sqldelight related classes and settings over to BankingPersistence - and finally it compiles on iOS! --- BankingPersistence/build.gradle.kts | 25 ++++---- .../banking/persistence}/BankingRepository.kt | 16 ++--- .../persistence/BankingRepositoryNewStart.kt | 16 ----- .../persistence}/InMemoryBankingRepository.kt | 21 ++++--- .../persistence}/SqliteBankingRepository.kt | 58 +++++++++++++------ .../entities/AccountTransactionEntity.kt | 2 +- .../persistence}/entities/BankAccessEntity.kt | 3 +- .../entities/BankAccountEntity.kt | 2 +- .../persistence}/entities/HoldingEntity.kt | 2 +- .../persistence}/entities/TanMediumEntity.kt | 2 +- .../persistence}/entities/TanMethodEntity.kt | 2 +- .../persistence/entities/UiSettingsEntity.kt | 17 ++++++ .../ui/model/AccountTransactionViewModel.kt | 2 +- .../model/settings/AppAuthenticationMethod.kt | 0 .../banking/ui/model/settings/AppSettings.kt | 0 .../model/settings}/TransactionsGrouping.kt | 2 +- .../persistence}/AccountTransaction.sq | 0 .../net/codinux/banking/persistence}/Bank.sq | 0 .../codinux/banking/persistence}/Settings.sq | 0 .../dataaccess/SqliteBankingRepositoryTest.kt | 13 ++--- composeApp/build.gradle.kts | 35 ++++------- .../net/codinux/banking/ui/MainActivity.kt | 9 +-- .../banking/ui/appskeleton/FilterBar.kt | 2 +- .../banking/ui/composables/BanksList.kt | 4 +- .../ui/composables/NavigationMenuItem.kt | 4 +- .../ui/composables/settings/UiSettings.kt | 2 +- .../GroupedTransactionsListItems.kt | 4 +- .../transactions/TransactionsList.kt | 2 +- .../net/codinux/banking/ui/config/DI.kt | 8 +-- .../banking/ui/config/Internationalization.kt | 2 +- .../ui/model/AccountTransactionsFilter.kt | 4 +- .../banking/ui/model/BankAccountFilter.kt | 4 +- .../ui/model/ShowTransferMoneyDialogData.kt | 2 +- .../AccountTransactionDetailsScreen.kt | 2 +- .../ui/screens/BankAccountSettingsScreen.kt | 2 +- .../banking/ui/screens/BankSettingsScreen.kt | 2 +- .../banking/ui/screens/ExportScreen.kt | 2 +- .../AccountTransactionsFilterService.kt | 8 +-- .../banking/ui/service/BankingService.kt | 20 +++++-- .../banking/ui/service/CalculatorService.kt | 2 +- .../codinux/banking/ui/service/FormatUtil.kt | 2 +- .../ui/service/TransactionsGroupingService.kt | 2 +- .../codinux/banking/ui/settings/UiSettings.kt | 2 +- .../net/codinux/banking/ui/state/UiState.kt | 6 +- .../kotlin/net/codinux/banking/ui/main.kt | 30 +++------- .../codinux/banking/ui/MainViewController.kt | 6 +- gradle/libs.versions.toml | 2 + settings.gradle.kts | 3 + 48 files changed, 180 insertions(+), 176 deletions(-) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/BankingRepository.kt (72%) delete mode 100644 BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepositoryNewStart.kt rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/InMemoryBankingRepository.kt (83%) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/SqliteBankingRepository.kt (90%) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/entities/AccountTransactionEntity.kt (98%) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/entities/BankAccessEntity.kt (95%) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/entities/BankAccountEntity.kt (98%) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/entities/HoldingEntity.kt (96%) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/entities/TanMediumEntity.kt (92%) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence}/entities/TanMethodEntity.kt (94%) create mode 100644 BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/UiSettingsEntity.kt rename {composeApp => BankingPersistence}/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionViewModel.kt (93%) rename {composeApp => BankingPersistence}/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppAuthenticationMethod.kt (100%) rename {composeApp => BankingPersistence}/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppSettings.kt (100%) rename {composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model => BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/settings}/TransactionsGrouping.kt (64%) rename {composeApp/src/commonMain/sqldelight/net/codinux/banking/ui => BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence}/AccountTransaction.sq (100%) rename {composeApp/src/commonMain/sqldelight/net/codinux/banking/ui => BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence}/Bank.sq (100%) rename {composeApp/src/commonMain/sqldelight/net/codinux/banking/ui => BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence}/Settings.sq (100%) rename {composeApp/src/desktopTest => BankingPersistence/src/jvmTest}/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepositoryTest.kt (90%) diff --git a/BankingPersistence/build.gradle.kts b/BankingPersistence/build.gradle.kts index 0f13d0d..4d3cfb4 100644 --- a/BankingPersistence/build.gradle.kts +++ b/BankingPersistence/build.gradle.kts @@ -30,8 +30,8 @@ kotlin { iosSimulatorArm64() ).forEach { iosTarget -> iosTarget.binaries.framework { - baseName = "ComposeApp" - isStatic = false + baseName = "BankingPersistence" + isStatic = true } } @@ -40,9 +40,14 @@ kotlin { sourceSets { commonMain.dependencies { + implementation(libs.banking.client.model) + implementation(libs.kotlinx.datetime) + implementation(libs.sqldelight.runtime) implementation(libs.sqldelight.coroutines.extensions) implementation(libs.sqldelight.paging.extensions) + + implementation(libs.klf) } commonTest.dependencies { @@ -51,20 +56,20 @@ kotlin { implementation(libs.coroutines.test) } - androidMain.dependencies { - implementation(libs.sqldelight.android.driver) - } - - iosMain.dependencies { - implementation(libs.sqldelight.native.driver) + jvmMain.dependencies { + implementation(libs.sqldelight.sqlite.driver) } jvmTest.dependencies { implementation(libs.kotlin.test.junit) } - jvmMain.dependencies { - implementation(libs.sqldelight.sqlite.driver) + androidMain.dependencies { + implementation(libs.sqldelight.android.driver) + } + + iosMain.dependencies { + implementation(libs.sqldelight.native.driver) } } } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/BankingRepository.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt similarity index 72% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/BankingRepository.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt index 4e4ddc3..eb33f97 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/BankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepository.kt @@ -1,15 +1,15 @@ -package net.codinux.banking.dataaccess +package net.codinux.banking.persistence import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.BankAccess import net.codinux.banking.client.model.securitiesaccount.Holding -import net.codinux.banking.dataaccess.entities.AccountTransactionEntity -import net.codinux.banking.dataaccess.entities.BankAccountEntity -import net.codinux.banking.dataaccess.entities.HoldingEntity -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.AccountTransactionEntity +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.HoldingEntity +import net.codinux.banking.persistence.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.UiSettingsEntity import net.codinux.banking.ui.model.AccountTransactionViewModel import net.codinux.banking.ui.model.settings.AppSettings -import net.codinux.banking.ui.settings.UiSettings interface BankingRepository { @@ -17,9 +17,9 @@ interface BankingRepository { suspend fun saveAppSettings(settings: AppSettings) - fun getUiSettings(settings: UiSettings) + fun getUiSettings(): UiSettingsEntity? - suspend fun saveUiSettings(settings: UiSettings) + suspend fun saveUiSettings(settings: UiSettingsEntity) fun getAllBanks(): List diff --git a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepositoryNewStart.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepositoryNewStart.kt deleted file mode 100644 index b4b5d3a..0000000 --- a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/BankingRepositoryNewStart.kt +++ /dev/null @@ -1,16 +0,0 @@ -package net.codinux.banking.persistence - -import app.cash.sqldelight.db.QueryResult -import app.cash.sqldelight.db.SqlDriver -import app.cash.sqldelight.db.SqlSchema - -expect fun createSqlDriverDriver(dbName: String, schema: SqlSchema>, version: Long): SqlDriver - - -class BankingRepositoryNewStart { - - private val schema = BankmeisterDb.Schema - - private val sqlDriver = createSqlDriverDriver("Bankmeister.db", schema, 1L) - -} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt similarity index 83% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt index 955f4a3..4bc7016 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/InMemoryBankingRepository.kt @@ -1,15 +1,16 @@ -package net.codinux.banking.dataaccess +package net.codinux.banking.persistence import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.BankAccess import net.codinux.banking.client.model.securitiesaccount.Holding -import net.codinux.banking.dataaccess.entities.AccountTransactionEntity -import net.codinux.banking.dataaccess.entities.BankAccountEntity -import net.codinux.banking.dataaccess.entities.HoldingEntity -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.AccountTransactionEntity +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.HoldingEntity +import net.codinux.banking.persistence.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.UiSettingsEntity import net.codinux.banking.ui.model.AccountTransactionViewModel import net.codinux.banking.ui.model.settings.AppSettings -import net.codinux.banking.ui.settings.UiSettings +import net.codinux.banking.ui.model.settings.TransactionsGrouping class InMemoryBankingRepository( banks: Collection = emptyList(), @@ -23,7 +24,7 @@ class InMemoryBankingRepository( private val transactions = transactions.map { map(it) }.toMutableList() - private lateinit var uiSettings: UiSettings + private var uiSettings: UiSettingsEntity = UiSettingsEntity(true, TransactionsGrouping.Month, true, true, true) override fun getAppSettings(): AppSettings? = appSettings @@ -32,11 +33,9 @@ class InMemoryBankingRepository( this.appSettings = settings } - override fun getUiSettings(settings: UiSettings) { - this.uiSettings = settings - } + override fun getUiSettings() = this.uiSettings - override suspend fun saveUiSettings(settings: UiSettings) { + override suspend fun saveUiSettings(settings: UiSettingsEntity) { this.uiSettings = settings } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt similarity index 90% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt index 91de99f..9eb760b 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/SqliteBankingRepository.kt @@ -1,25 +1,45 @@ -package net.codinux.banking.dataaccess +package net.codinux.banking.persistence +import app.cash.sqldelight.db.QueryResult import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.db.SqlSchema import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate -import net.codinux.banking.client.model.* +import net.codinux.banking.client.model.AccountTransaction +import net.codinux.banking.client.model.Amount +import net.codinux.banking.client.model.BankAccess +import net.codinux.banking.client.model.BankAccount +import net.codinux.banking.client.model.BankAccountFeatures +import net.codinux.banking.client.model.BankAccountType +import net.codinux.banking.client.model.BankingGroup import net.codinux.banking.client.model.securitiesaccount.Holding -import net.codinux.banking.client.model.tan.* -import net.codinux.banking.dataaccess.entities.* +import net.codinux.banking.client.model.tan.AllowedTanFormat +import net.codinux.banking.client.model.tan.MobilePhoneTanMedium +import net.codinux.banking.client.model.tan.TanGeneratorTanMedium +import net.codinux.banking.client.model.tan.TanMedium +import net.codinux.banking.client.model.tan.TanMediumStatus +import net.codinux.banking.client.model.tan.TanMediumType +import net.codinux.banking.client.model.tan.TanMethod +import net.codinux.banking.client.model.tan.TanMethodType +import net.codinux.banking.persistence.entities.* import net.codinux.banking.ui.model.AccountTransactionViewModel -import net.codinux.banking.ui.model.TransactionsGrouping import net.codinux.banking.ui.model.settings.AppAuthenticationMethod import net.codinux.banking.ui.model.settings.AppSettings -import net.codinux.banking.ui.settings.UiSettings +import net.codinux.banking.ui.model.settings.TransactionsGrouping import net.codinux.log.logger import kotlin.enums.EnumEntries import kotlin.js.JsName import kotlin.jvm.JvmName -open class SqliteBankingRepository( - sqlDriver: SqlDriver -) : BankingRepository { + +expect fun createSqlDriverDriver(dbName: String, schema: SqlSchema>, version: Long): SqlDriver + + +open class SqliteBankingRepository : BankingRepository { + + private val schema = BankmeisterDb.Schema + + private val sqlDriver = createSqlDriverDriver("Bankmeister.db", schema, 1L) private val database = BankmeisterDb(sqlDriver) @@ -52,18 +72,20 @@ open class SqliteBankingRepository( } - override fun getUiSettings(settings: UiSettings) { - settingsQueries.getUiSettings { _, transactionsGrouping, showBalance, showBankIcons, showColoredAmounts, showTransactionsInAlternatingColors -> - settings.transactionsGrouping.value = mapToEnum(transactionsGrouping, TransactionsGrouping.entries) - settings.showBalance.value = showBalance - settings.showBankIcons.value = showBankIcons - settings.showColoredAmounts.value = showColoredAmounts - settings.showTransactionsInAlternatingColors.value = showTransactionsInAlternatingColors + override fun getUiSettings(): UiSettingsEntity? { + return settingsQueries.getUiSettings { _, transactionsGrouping, showBalance, showBankIcons, showColoredAmounts, showTransactionsInAlternatingColors -> + UiSettingsEntity( + showBalance, + mapToEnum(transactionsGrouping, TransactionsGrouping.entries), + showTransactionsInAlternatingColors, + showBankIcons, + showColoredAmounts + ) }.executeAsOneOrNull() } - override suspend fun saveUiSettings(settings: UiSettings) { - settingsQueries.upsertUiSettings(mapEnum(settings.transactionsGrouping.value), settings.showBalance.value, settings.showBankIcons.value, settings.showColoredAmounts.value, settings.showTransactionsInAlternatingColors.value) + override suspend fun saveUiSettings(settings: UiSettingsEntity) { + settingsQueries.upsertUiSettings(mapEnum(settings.transactionsGrouping), settings.showBalance, settings.showBankIcons, settings.showColoredAmounts, settings.showTransactionsInAlternatingColors) } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/AccountTransactionEntity.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/AccountTransactionEntity.kt similarity index 98% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/AccountTransactionEntity.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/AccountTransactionEntity.kt index 1b14ad5..b23920e 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/AccountTransactionEntity.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/AccountTransactionEntity.kt @@ -1,4 +1,4 @@ -package net.codinux.banking.dataaccess.entities +package net.codinux.banking.persistence.entities import kotlinx.datetime.LocalDate import net.codinux.banking.client.model.AccountTransaction diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccessEntity.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccessEntity.kt similarity index 95% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccessEntity.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccessEntity.kt index a74af83..819eb70 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccessEntity.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccessEntity.kt @@ -1,8 +1,7 @@ -package net.codinux.banking.dataaccess.entities +package net.codinux.banking.persistence.entities import net.codinux.banking.client.model.BankAccess import net.codinux.banking.client.model.BankingGroup -import net.codinux.banking.client.model.tan.TanMedium class BankAccessEntity( val id: Long, diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccountEntity.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccountEntity.kt similarity index 98% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccountEntity.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccountEntity.kt index 3d5158c..4ea4b93 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccountEntity.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/BankAccountEntity.kt @@ -1,4 +1,4 @@ -package net.codinux.banking.dataaccess.entities +package net.codinux.banking.persistence.entities import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/HoldingEntity.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/HoldingEntity.kt similarity index 96% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/HoldingEntity.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/HoldingEntity.kt index fe2aebd..0ed608b 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/HoldingEntity.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/HoldingEntity.kt @@ -1,4 +1,4 @@ -package net.codinux.banking.dataaccess.entities +package net.codinux.banking.persistence.entities import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/TanMediumEntity.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/TanMediumEntity.kt similarity index 92% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/TanMediumEntity.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/TanMediumEntity.kt index 67b8e45..19075af 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/TanMediumEntity.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/TanMediumEntity.kt @@ -1,4 +1,4 @@ -package net.codinux.banking.dataaccess.entities +package net.codinux.banking.persistence.entities import net.codinux.banking.client.model.tan.* diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/TanMethodEntity.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/TanMethodEntity.kt similarity index 94% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/TanMethodEntity.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/TanMethodEntity.kt index 72a37c3..f943bd6 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/TanMethodEntity.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/TanMethodEntity.kt @@ -1,4 +1,4 @@ -package net.codinux.banking.dataaccess.entities +package net.codinux.banking.persistence.entities import net.codinux.banking.client.model.tan.AllowedTanFormat import net.codinux.banking.client.model.tan.TanMethod diff --git a/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/UiSettingsEntity.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/UiSettingsEntity.kt new file mode 100644 index 0000000..e4908d9 --- /dev/null +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/persistence/entities/UiSettingsEntity.kt @@ -0,0 +1,17 @@ +package net.codinux.banking.persistence.entities + +import net.codinux.banking.ui.model.settings.TransactionsGrouping + +class UiSettingsEntity( + + val showBalance: Boolean, + + val transactionsGrouping: TransactionsGrouping, + + val showTransactionsInAlternatingColors: Boolean, + + val showBankIcons: Boolean, + + val showColoredAmounts: Boolean + +) \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionViewModel.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionViewModel.kt similarity index 93% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionViewModel.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionViewModel.kt index 50ec664..942191f 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionViewModel.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionViewModel.kt @@ -3,7 +3,7 @@ package net.codinux.banking.ui.model import kotlinx.datetime.LocalDate import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.Amount -import net.codinux.banking.dataaccess.entities.AccountTransactionEntity +import net.codinux.banking.persistence.entities.AccountTransactionEntity data class AccountTransactionViewModel( val id: Long, diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppAuthenticationMethod.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppAuthenticationMethod.kt similarity index 100% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppAuthenticationMethod.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppAuthenticationMethod.kt diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppSettings.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppSettings.kt similarity index 100% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppSettings.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/AppSettings.kt diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/TransactionsGrouping.kt b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/TransactionsGrouping.kt similarity index 64% rename from composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/TransactionsGrouping.kt rename to BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/TransactionsGrouping.kt index 3a19578..543be21 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/TransactionsGrouping.kt +++ b/BankingPersistence/src/commonMain/kotlin/net/codinux/banking/ui/model/settings/TransactionsGrouping.kt @@ -1,4 +1,4 @@ -package net.codinux.banking.ui.model +package net.codinux.banking.ui.model.settings enum class TransactionsGrouping { None, diff --git a/composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/AccountTransaction.sq b/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/AccountTransaction.sq similarity index 100% rename from composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/AccountTransaction.sq rename to BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/AccountTransaction.sq diff --git a/composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/Bank.sq b/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Bank.sq similarity index 100% rename from composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/Bank.sq rename to BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Bank.sq diff --git a/composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/Settings.sq b/BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Settings.sq similarity index 100% rename from composeApp/src/commonMain/sqldelight/net/codinux/banking/ui/Settings.sq rename to BankingPersistence/src/commonMain/sqldelight/net/codinux/banking/persistence/Settings.sq diff --git a/composeApp/src/desktopTest/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepositoryTest.kt b/BankingPersistence/src/jvmTest/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepositoryTest.kt similarity index 90% rename from composeApp/src/desktopTest/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepositoryTest.kt rename to BankingPersistence/src/jvmTest/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepositoryTest.kt index e94987b..748be0d 100644 --- a/composeApp/src/desktopTest/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepositoryTest.kt +++ b/BankingPersistence/src/jvmTest/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepositoryTest.kt @@ -1,23 +1,18 @@ package net.codinux.banking.dataaccess -import app.cash.sqldelight.async.coroutines.synchronous -import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver import kotlinx.coroutines.test.runTest import kotlinx.datetime.LocalDate import net.codinux.banking.client.model.* -import net.codinux.banking.dataaccess.entities.AccountTransactionEntity +import net.codinux.banking.persistence.SqliteBankingRepository +import net.codinux.banking.persistence.entities.AccountTransactionEntity import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull class SqliteBankingRepositoryTest { - private val sqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY).apply { - BankmeisterDb.Schema.synchronous().create(this) - } - - private val underTest = object : SqliteBankingRepository(sqlDriver) { - override public suspend fun persistTransaction(bankId: Long, accountId: Long, transaction: AccountTransaction): AccountTransactionEntity = + private val underTest = object : SqliteBankingRepository() { + public override suspend fun persistTransaction(bankId: Long, accountId: Long, transaction: AccountTransaction): AccountTransactionEntity = super.persistTransaction(bankId, accountId, transaction) } diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 6d5684b..51dc087 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -10,8 +10,6 @@ plugins { alias(libs.plugins.compose.compiler) alias(libs.plugins.kotlinxSerialization) - - alias(libs.plugins.sqldelight) } @@ -50,7 +48,14 @@ kotlin { ).forEach { iosTarget -> iosTarget.binaries.framework { baseName = "ComposeApp" - isStatic = true + isStatic = false + } + + // don't know why but this has to be added here, adding it in BankingPersistence.build.gradle.kt does not work + iosTarget.binaries.forEach { binary -> + if (binary is org.jetbrains.kotlin.gradle.plugin.mpp.Framework) { + binary.linkerOpts.add("-lsqlite3") // without this we get a lot of "Undefined symbol _co_touchlab_sqliter..." errors in Xcode + } } } @@ -58,6 +63,8 @@ kotlin { val desktopMain by getting commonMain.dependencies { + implementation(project(":BankingPersistence")) + implementation(libs.banking.client.model) implementation(libs.fints4k.banking.client) @@ -65,10 +72,6 @@ kotlin { implementation(libs.klf) implementation(libs.kotlinx.serializable) - implementation(libs.sqldelight.runtime) - implementation(libs.sqldelight.coroutines.extensions) - implementation(libs.sqldelight.paging.extensions) - // UI implementation(compose.runtime) implementation(compose.foundation) @@ -93,13 +96,11 @@ kotlin { implementation(libs.androidx.activity.compose) implementation(libs.androidx.biometric) - implementation(libs.sqldelight.android.driver) - implementation(libs.favre.bcrypt) } iosMain.dependencies { - implementation(libs.sqldelight.native.driver) + } jvmTest.dependencies { @@ -110,8 +111,6 @@ kotlin { implementation(compose.desktop.currentOs) implementation(libs.kotlinx.coroutines.swing) - implementation(libs.sqldelight.sqlite.driver) - implementation(libs.favre.bcrypt) implementation(libs.logback) @@ -120,18 +119,6 @@ kotlin { } -sqldelight { - databases { - create("BankmeisterDb") { - packageName.set("net.codinux.banking.dataaccess") - generateAsync = true - - schemaOutputDirectory = file("src/commonMain/sqldelight/databases") - } - } -} - - android { namespace = "net.codinux.banking.ui" compileSdk = libs.versions.android.compileSdk.get().toInt() diff --git a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/MainActivity.kt b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/MainActivity.kt index b55449f..06c90af 100644 --- a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/MainActivity.kt @@ -5,9 +5,8 @@ import androidx.activity.compose.setContent import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import androidx.fragment.app.FragmentActivity -import app.cash.sqldelight.async.coroutines.synchronous -import app.cash.sqldelight.driver.android.AndroidSqliteDriver -import net.codinux.banking.dataaccess.BankmeisterDb +import net.codinux.banking.persistence.AndroidContext +import net.codinux.banking.persistence.SqliteBankingRepository import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.service.AuthenticationService import net.codinux.banking.ui.service.BiometricAuthenticationService @@ -17,10 +16,12 @@ class MainActivity : FragmentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + AndroidContext.applicationContext = this.applicationContext + ImageService.context = this.applicationContext AuthenticationService.biometricAuthenticationService = BiometricAuthenticationService(this) - DI.setRepository(AndroidSqliteDriver(BankmeisterDb.Schema.synchronous(), this, "Bankmeister.db")) + DI.setRepository(SqliteBankingRepository()) setContent { App() diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/FilterBar.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/FilterBar.kt index 27b6113..2bf49d3 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/FilterBar.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/appskeleton/FilterBar.kt @@ -13,7 +13,7 @@ import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.config.Internationalization import net.codinux.banking.ui.forms.RoundedCornersCard import net.codinux.banking.ui.forms.Select -import net.codinux.banking.ui.model.TransactionsGrouping +import net.codinux.banking.ui.model.settings.TransactionsGrouping private val uiState = DI.uiState diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/BanksList.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/BanksList.kt index aed18b3..43addab 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/BanksList.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/BanksList.kt @@ -10,8 +10,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import net.codinux.banking.dataaccess.entities.BankAccountEntity -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.BankAccessEntity import net.codinux.banking.ui.config.DI private val uiState = DI.uiState diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/NavigationMenuItem.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/NavigationMenuItem.kt index bf3daaf..36ba8aa 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/NavigationMenuItem.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/NavigationMenuItem.kt @@ -19,8 +19,8 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import net.codinux.banking.dataaccess.entities.BankAccountEntity -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.BankAccessEntity import net.codinux.banking.ui.config.Colors import net.codinux.banking.ui.config.DI diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/settings/UiSettings.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/settings/UiSettings.kt index dcb87a5..b531324 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/settings/UiSettings.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/settings/UiSettings.kt @@ -13,7 +13,7 @@ import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.config.Internationalization import net.codinux.banking.ui.forms.BooleanOption import net.codinux.banking.ui.forms.Select -import net.codinux.banking.ui.model.TransactionsGrouping +import net.codinux.banking.ui.model.settings.TransactionsGrouping @Composable fun UiSettings(modifier: Modifier, textColor: Color = Color.Unspecified) { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/GroupedTransactionsListItems.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/GroupedTransactionsListItems.kt index fc7cfad..1558e78 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/GroupedTransactionsListItems.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/GroupedTransactionsListItems.kt @@ -14,13 +14,13 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import net.codinux.banking.client.model.Amount import net.codinux.banking.client.model.securitiesaccount.Holding -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccessEntity import net.codinux.banking.ui.config.Colors import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.config.Style import net.codinux.banking.ui.forms.RoundedCornersCard import net.codinux.banking.ui.model.AccountTransactionViewModel -import net.codinux.banking.ui.model.TransactionsGrouping +import net.codinux.banking.ui.model.settings.TransactionsGrouping import net.codinux.banking.ui.service.TransactionsGroupingService private val calculator = DI.calculator diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionsList.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionsList.kt index a70213b..916b717 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionsList.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/transactions/TransactionsList.kt @@ -12,7 +12,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import net.codinux.banking.ui.config.Colors import net.codinux.banking.ui.config.DI -import net.codinux.banking.ui.model.TransactionsGrouping +import net.codinux.banking.ui.model.settings.TransactionsGrouping import net.codinux.banking.ui.settings.UiSettings import net.codinux.banking.ui.state.UiState import org.jetbrains.compose.ui.tooling.preview.Preview diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/DI.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/DI.kt index 2f2641e..666559f 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/DI.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/DI.kt @@ -1,9 +1,7 @@ package net.codinux.banking.ui.config -import app.cash.sqldelight.db.SqlDriver -import net.codinux.banking.dataaccess.BankingRepository -import net.codinux.banking.dataaccess.InMemoryBankingRepository -import net.codinux.banking.dataaccess.SqliteBankingRepository +import net.codinux.banking.persistence.BankingRepository +import net.codinux.banking.persistence.InMemoryBankingRepository import net.codinux.banking.ui.Platform import net.codinux.banking.ui.getPlatform import net.codinux.banking.ui.service.* @@ -39,8 +37,6 @@ object DI { val bankingService by lazy { BankingService(uiState, uiSettings, bankingRepository, bankFinder) } - fun setRepository(sqlDriver: SqlDriver) = setRepository(SqliteBankingRepository(sqlDriver)) - fun setRepository(repository: BankingRepository) { this.bankingRepository = repository diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt index 1348fba..f4566f7 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt @@ -2,7 +2,7 @@ package net.codinux.banking.ui.config import net.codinux.banking.client.model.BankAccountType import net.codinux.banking.client.model.tan.ActionRequiringTan -import net.codinux.banking.ui.model.TransactionsGrouping +import net.codinux.banking.ui.model.settings.TransactionsGrouping import net.codinux.banking.ui.model.settings.AppAuthenticationMethod object Internationalization { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionsFilter.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionsFilter.kt index 78b7005..09cf315 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionsFilter.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/AccountTransactionsFilter.kt @@ -1,8 +1,8 @@ package net.codinux.banking.ui.model import androidx.compose.runtime.* -import net.codinux.banking.dataaccess.entities.BankAccountEntity -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.BankAccessEntity class AccountTransactionsFilter { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/BankAccountFilter.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/BankAccountFilter.kt index 2f940f8..11eba5b 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/BankAccountFilter.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/BankAccountFilter.kt @@ -1,7 +1,7 @@ package net.codinux.banking.ui.model -import net.codinux.banking.dataaccess.entities.BankAccountEntity -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.BankAccessEntity data class BankAccountFilter( val bank: BankAccessEntity, diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/ShowTransferMoneyDialogData.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/ShowTransferMoneyDialogData.kt index 4da1afc..d36489d 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/ShowTransferMoneyDialogData.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/ShowTransferMoneyDialogData.kt @@ -1,7 +1,7 @@ package net.codinux.banking.ui.model import net.codinux.banking.client.model.Amount -import net.codinux.banking.dataaccess.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.BankAccountEntity data class ShowTransferMoneyDialogData( val senderAccount: BankAccountEntity? = null, diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/AccountTransactionDetailsScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/AccountTransactionDetailsScreen.kt index 534e80b..0ef7a5e 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/AccountTransactionDetailsScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/AccountTransactionDetailsScreen.kt @@ -7,7 +7,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import net.codinux.banking.client.model.isNegative -import net.codinux.banking.dataaccess.entities.AccountTransactionEntity +import net.codinux.banking.persistence.entities.AccountTransactionEntity import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.extensions.verticalScroll import net.codinux.banking.ui.forms.LabelledValue diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankAccountSettingsScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankAccountSettingsScreen.kt index 29df1b7..8906746 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankAccountSettingsScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankAccountSettingsScreen.kt @@ -6,7 +6,7 @@ import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import net.codinux.banking.dataaccess.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.BankAccountEntity import net.codinux.banking.ui.config.Internationalization import net.codinux.banking.ui.extensions.verticalScroll import net.codinux.banking.ui.forms.* diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt index d2b0a6c..ec6bc1e 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/BankSettingsScreen.kt @@ -5,7 +5,7 @@ import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccessEntity import net.codinux.banking.ui.config.DI import net.codinux.banking.ui.extensions.verticalScroll import net.codinux.banking.ui.forms.* diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/ExportScreen.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/ExportScreen.kt index 9dcb840..b3b75b1 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/ExportScreen.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/screens/ExportScreen.kt @@ -13,7 +13,7 @@ import androidx.compose.ui.text.style.TextAlign import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import net.codinux.banking.dataaccess.entities.AccountTransactionEntity +import net.codinux.banking.persistence.entities.AccountTransactionEntity import net.codinux.banking.ui.IOorDefault import net.codinux.banking.ui.config.Colors import net.codinux.banking.ui.config.DI diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt index e1fa5e1..febdfae 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt @@ -1,8 +1,8 @@ package net.codinux.banking.ui.service -import net.codinux.banking.dataaccess.entities.BankAccountEntity -import net.codinux.banking.dataaccess.entities.HoldingEntity -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.HoldingEntity +import net.codinux.banking.persistence.entities.BankAccessEntity import net.codinux.banking.ui.model.AccountTransactionViewModel import net.codinux.banking.ui.model.AccountTransactionsFilter import net.codinux.banking.ui.model.BankAccountFilter @@ -46,7 +46,7 @@ class AccountTransactionsFilterService { private fun matchesSearchTerm(transaction: AccountTransactionViewModel, searchTerm: String): Boolean = transaction.reference?.contains(searchTerm, true) == true - || (transaction.otherPartyName != null && transaction.otherPartyName.contains(searchTerm, true)) + || transaction.otherPartyName?.contains(searchTerm, true) == true fun filterHoldings(holdings: List, filter: AccountTransactionsFilter): List { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt index 3227679..4c1d565 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt @@ -16,8 +16,12 @@ import net.codinux.banking.client.model.request.TransferMoneyRequestForUser import net.codinux.banking.client.model.response.* import net.codinux.banking.client.model.securitiesaccount.Holding import net.codinux.banking.client.service.BankingModelService -import net.codinux.banking.dataaccess.BankingRepository -import net.codinux.banking.dataaccess.entities.* +import net.codinux.banking.persistence.BankingRepository +import net.codinux.banking.persistence.entities.AccountTransactionEntity +import net.codinux.banking.persistence.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.HoldingEntity +import net.codinux.banking.persistence.entities.UiSettingsEntity import net.codinux.banking.ui.IOorDefault import net.codinux.banking.ui.model.AccountTransactionViewModel import net.codinux.banking.ui.model.BankInfo @@ -57,7 +61,13 @@ class BankingService( } uiState.appSettings.value = appSettings - bankingRepository.getUiSettings(uiSettings) + bankingRepository.getUiSettings()?.let { + uiSettings.showBalance.value = it.showBalance + uiSettings.transactionsGrouping.value = it.transactionsGrouping + uiSettings.showTransactionsInAlternatingColors.value = it.showTransactionsInAlternatingColors + uiSettings.showBankIcons.value = it.showBankIcons + uiSettings.showColoredAmounts.value = it.showColoredAmounts + } updateOnChanges(uiSettings) @@ -76,7 +86,9 @@ class BankingService( suspend fun saveAppSettings(settings: AppSettings) = bankingRepository.saveAppSettings(settings) - suspend fun saveUiSettings(settings: UiSettings) = bankingRepository.saveUiSettings(settings) + suspend fun saveUiSettings(settings: UiSettings) = bankingRepository.saveUiSettings(UiSettingsEntity( + settings.showBalance.value, settings.transactionsGrouping.value, settings.showTransactionsInAlternatingColors.value, settings.showBankIcons.value, settings.showColoredAmounts.value + )) fun getAllBanks() = bankingRepository.getAllBanks() diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/CalculatorService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/CalculatorService.kt index f10133f..f9fb39c 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/CalculatorService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/CalculatorService.kt @@ -1,7 +1,7 @@ package net.codinux.banking.ui.service import net.codinux.banking.client.model.* -import net.codinux.banking.dataaccess.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccessEntity import net.codinux.banking.ui.model.AccountTransactionViewModel import net.codinux.banking.ui.model.AccountTransactionsFilter diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt index 265a80e..80d8d00 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/FormatUtil.kt @@ -5,7 +5,7 @@ import kotlinx.datetime.* import net.codinux.banking.client.model.Amount import net.codinux.banking.client.model.isNegative import net.codinux.banking.ui.config.Colors -import net.codinux.banking.ui.model.TransactionsGrouping +import net.codinux.banking.ui.model.settings.TransactionsGrouping class FormatUtil { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/TransactionsGroupingService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/TransactionsGroupingService.kt index 196c95a..c3928d6 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/TransactionsGroupingService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/TransactionsGroupingService.kt @@ -5,7 +5,7 @@ import kotlinx.datetime.LocalDate import kotlinx.datetime.Month import net.codinux.banking.client.model.extensions.minusDays import net.codinux.banking.ui.model.AccountTransactionViewModel -import net.codinux.banking.ui.model.TransactionsGrouping +import net.codinux.banking.ui.model.settings.TransactionsGrouping class TransactionsGroupingService { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/settings/UiSettings.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/settings/UiSettings.kt index 7fed82f..5f6c2e8 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/settings/UiSettings.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/settings/UiSettings.kt @@ -2,7 +2,7 @@ package net.codinux.banking.ui.settings import androidx.lifecycle.ViewModel import kotlinx.coroutines.flow.MutableStateFlow -import net.codinux.banking.ui.model.TransactionsGrouping +import net.codinux.banking.ui.model.settings.TransactionsGrouping class UiSettings : ViewModel() { diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt index 24b11a5..01970cd 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/state/UiState.kt @@ -7,9 +7,9 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import net.codinux.banking.client.model.tan.EnterTanResult import net.codinux.banking.client.model.tan.TanChallenge -import net.codinux.banking.dataaccess.entities.HoldingEntity -import net.codinux.banking.dataaccess.entities.BankAccessEntity -import net.codinux.banking.dataaccess.entities.BankAccountEntity +import net.codinux.banking.persistence.entities.HoldingEntity +import net.codinux.banking.persistence.entities.BankAccessEntity +import net.codinux.banking.persistence.entities.BankAccountEntity import net.codinux.banking.ui.model.* import net.codinux.banking.ui.model.error.ApplicationError import net.codinux.banking.ui.model.error.BankingClientError diff --git a/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/main.kt b/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/main.kt index 2eaca16..608dedd 100644 --- a/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/main.kt +++ b/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/main.kt @@ -6,19 +6,15 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import androidx.compose.ui.window.* -import app.cash.sqldelight.async.coroutines.synchronous -import app.cash.sqldelight.db.SqlDriver -import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver import bankmeister.composeapp.generated.resources.AppIcon_svg import bankmeister.composeapp.generated.resources.Res import kotlinx.datetime.LocalDate import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.Amount -import net.codinux.banking.dataaccess.BankmeisterDb -import net.codinux.banking.dataaccess.InMemoryBankingRepository +import net.codinux.banking.persistence.InMemoryBankingRepository +import net.codinux.banking.persistence.SqliteBankingRepository import net.codinux.banking.ui.config.DI import org.jetbrains.compose.resources.painterResource -import java.io.File fun main() = application { Window( @@ -27,34 +23,22 @@ fun main() = application { icon = painterResource(Res.drawable.AppIcon_svg), state = WindowState(position = WindowPosition(Alignment.Center), size = DpSize(1000.dp, 800.dp)), ) { - DI.setRepository(createSqlDriverDriver()) + DI.setRepository(SqliteBankingRepository()) App() } } -private fun createSqlDriverDriver(): SqlDriver { - File("data/db").mkdirs() - - return JdbcSqliteDriver("jdbc:sqlite:data/db/Bankmeister.db").also { driver -> - BankmeisterDb.Schema.synchronous().also { schema -> - if (File("data/db/Bankmeister.db").exists() == false) { - schema.create(driver) - } - - schema.migrate(driver, schema.version, 1) - } - } -} - @Preview @Composable fun AppPreview() { - DI.setRepository(InMemoryBankingRepository( + DI.setRepository( + InMemoryBankingRepository( emptyList(), listOf(AccountTransaction(Amount("12.34"), "EUR", "Lohn", LocalDate(2024, 7, 5), LocalDate(2024, 6, 15), "Dein Boss")) - )) + ) + ) App() } \ No newline at end of file diff --git a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/MainViewController.kt b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/MainViewController.kt index a6031a6..42015bb 100644 --- a/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/MainViewController.kt +++ b/composeApp/src/iosMain/kotlin/net/codinux/banking/ui/MainViewController.kt @@ -1,13 +1,11 @@ package net.codinux.banking.ui import androidx.compose.ui.window.ComposeUIViewController -import app.cash.sqldelight.async.coroutines.synchronous -import app.cash.sqldelight.driver.native.NativeSqliteDriver -import net.codinux.banking.dataaccess.BankmeisterDb +import net.codinux.banking.persistence.SqliteBankingRepository import net.codinux.banking.ui.config.DI fun MainViewController() = ComposeUIViewController { - DI.setRepository(NativeSqliteDriver(BankmeisterDb.Schema.synchronous(), "Bankmeister.db")) + DI.setRepository(SqliteBankingRepository()) App() } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d0d1ee4..c03b9c1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,6 +6,7 @@ banking-client = "0.6.1-SNAPSHOT" kcsv = "2.2.0" kotlinx-serializable = "1.7.1" +kotlinx-datetime = "0.5.0" favre-bcrypt = "0.10.2" @@ -38,6 +39,7 @@ fints4k-banking-client = { group = "net.codinux.banking.client", name = "fints4k kcsv = { group = "net.codinux.csv", name = "kcsv", version.ref = "kcsv" } coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } kotlinx-serializable = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serializable" } +kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" } favre-bcrypt = { group = "at.favre.lib", name = "bcrypt", version.ref = "favre-bcrypt" } diff --git a/settings.gradle.kts b/settings.gradle.kts index a10d6cc..b6ee11e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -33,4 +33,7 @@ dependencyResolutionManagement { } +// had to extract Sql'delight' dependencies to an extra project as they conflict with Compose dependencies on iOS +include(":BankingPersistence") + include(":composeApp") \ No newline at end of file