Ensuring BankingRepository / SqliteDriver gets created only once and catching errors
This commit is contained in:
parent
b384f6bc00
commit
d549b96e7b
|
@ -14,6 +14,7 @@ import net.codinux.banking.ui.config.DI
|
||||||
import net.codinux.banking.ui.model.settings.AppAuthenticationMethod
|
import net.codinux.banking.ui.model.settings.AppAuthenticationMethod
|
||||||
import net.codinux.banking.ui.screens.LoginScreen
|
import net.codinux.banking.ui.screens.LoginScreen
|
||||||
import net.codinux.banking.ui.screens.MainScreen
|
import net.codinux.banking.ui.screens.MainScreen
|
||||||
|
import net.codinux.log.Log
|
||||||
import net.codinux.log.LoggerFactory
|
import net.codinux.log.LoggerFactory
|
||||||
import org.jetbrains.compose.ui.tooling.preview.Preview
|
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||||
|
|
||||||
|
@ -26,8 +27,6 @@ private val typography = Typography(
|
||||||
fun App(repository: BankingRepository? = null) {
|
fun App(repository: BankingRepository? = null) {
|
||||||
LoggerFactory.defaultLoggerName = "net.codinux.banking.ui.Bankmeister"
|
LoggerFactory.defaultLoggerName = "net.codinux.banking.ui.Bankmeister"
|
||||||
|
|
||||||
DI.setRepository(repository ?: SqliteBankingRepository())
|
|
||||||
|
|
||||||
|
|
||||||
val colors = MaterialTheme.colors.copy(primary = Colors.Primary, primaryVariant = Colors.PrimaryDark, onPrimary = Color.White,
|
val colors = MaterialTheme.colors.copy(primary = Colors.Primary, primaryVariant = Colors.PrimaryDark, onPrimary = Color.White,
|
||||||
secondary = Colors.Accent, secondaryVariant = Colors.Accent, onSecondary = Color.White)
|
secondary = Colors.Accent, secondaryVariant = Colors.Accent, onSecondary = Color.White)
|
||||||
|
@ -40,6 +39,14 @@ fun App(repository: BankingRepository? = null) {
|
||||||
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isInitialized == false) {
|
||||||
|
DI.setRepository(repository ?: SqliteBankingRepository())
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Log.error(e) { "Could not set repository" }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MaterialTheme(colors = colors, typography = typography) {
|
MaterialTheme(colors = colors, typography = typography) {
|
||||||
if (isLoggedIn == false) {
|
if (isLoggedIn == false) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import net.codinux.banking.ui.config.DI
|
||||||
import net.codinux.banking.ui.forms.*
|
import net.codinux.banking.ui.forms.*
|
||||||
import net.codinux.banking.ui.forms.OutlinedTextField
|
import net.codinux.banking.ui.forms.OutlinedTextField
|
||||||
import net.codinux.banking.ui.model.BankInfo
|
import net.codinux.banking.ui.model.BankInfo
|
||||||
|
import net.codinux.log.Log
|
||||||
|
|
||||||
|
|
||||||
private val bankingService = DI.bankingService
|
private val bankingService = DI.bankingService
|
||||||
|
@ -69,7 +70,12 @@ fun AddAccountDialog(
|
||||||
isAddingAccount = true
|
isAddingAccount = true
|
||||||
|
|
||||||
addAccountJob = coroutineScope.launch(Dispatchers.IOorDefault) {
|
addAccountJob = coroutineScope.launch(Dispatchers.IOorDefault) {
|
||||||
val successful = DI.bankingService.addAccount(bank, loginName, password, retrieveAllTransactions)
|
val successful = try {
|
||||||
|
DI.bankingService.addAccount(bank, loginName, password, retrieveAllTransactions)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Log.error(e) { "Could not add account for $bank" }
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
addAccountJob = null
|
addAccountJob = null
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue