Moved now all Sqldelight related classes and settings over to BankingPersistence - and finally it compiles on iOS!

This commit is contained in:
dankito 2024-09-19 18:52:55 +02:00
parent 0f89314ba3
commit 6564a9d33d
48 changed files with 180 additions and 176 deletions

View File

@ -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)
}
}
}

View File

@ -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<BankAccessEntity>

View File

@ -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<QueryResult.AsyncValue<Unit>>, version: Long): SqlDriver
class BankingRepositoryNewStart {
private val schema = BankmeisterDb.Schema
private val sqlDriver = createSqlDriverDriver("Bankmeister.db", schema, 1L)
}

View File

@ -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<BankAccess> = 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
}

View File

@ -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<QueryResult.AsyncValue<Unit>>, 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)
}

View File

@ -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

View File

@ -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,

View File

@ -1,4 +1,4 @@
package net.codinux.banking.dataaccess.entities
package net.codinux.banking.persistence.entities
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate

View File

@ -1,4 +1,4 @@
package net.codinux.banking.dataaccess.entities
package net.codinux.banking.persistence.entities
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate

View File

@ -1,4 +1,4 @@
package net.codinux.banking.dataaccess.entities
package net.codinux.banking.persistence.entities
import net.codinux.banking.client.model.tan.*

View File

@ -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

View File

@ -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
)

View File

@ -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,

View File

@ -1,4 +1,4 @@
package net.codinux.banking.ui.model
package net.codinux.banking.ui.model.settings
enum class TransactionsGrouping {
None,

View File

@ -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)
}

View File

@ -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()

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -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.*

View File

@ -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.*

View File

@ -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

View File

@ -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<HoldingEntity>, filter: AccountTransactionsFilter): List<HoldingEntity> {

View File

@ -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()

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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() {

View File

@ -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

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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" }

View File

@ -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")