From 4f1eae18d044ea19a90da584612c17a95535552a Mon Sep 17 00:00:00 2001 From: Vishwa Raghavendra K S Date: Tue, 26 Apr 2022 00:33:44 +0530 Subject: [PATCH] BugFix : Broken IvyImport to Db --- .../domain/data/IvyWalletCompleteData.kt | 18 +++++----- .../deprecated/logic/zip/ExportZipLogic.kt | 36 +++++++++---------- .../viewmodel/OnboardingViewModel.kt | 16 +++++---- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/domain/data/IvyWalletCompleteData.kt b/app/src/main/java/com/ivy/wallet/domain/data/IvyWalletCompleteData.kt index 143680c392..efe0b95e52 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/IvyWalletCompleteData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/IvyWalletCompleteData.kt @@ -1,15 +1,15 @@ package com.ivy.wallet.domain.data -import com.ivy.wallet.domain.data.core.* +import com.ivy.wallet.io.persistence.data.* data class IvyWalletCompleteData( - val accounts: List = emptyList(), - val budgets: List = emptyList(), - val categories: List = emptyList(), - val loanRecords: List = emptyList(), - val loans: List = emptyList(), - val plannedPaymentRules: List = emptyList(), - val settings: List = emptyList(), - val transactions: List = emptyList(), + val accounts: List = emptyList(), + val budgets: List = emptyList(), + val categories: List = emptyList(), + val loanRecords: List = emptyList(), + val loans: List = emptyList(), + val plannedPaymentRules: List = emptyList(), + val settings: List = emptyList(), + val transactions: List = emptyList(), val sharedPrefs: HashMap = HashMap() ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt index a692259b5e..bb59cdf50a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt @@ -56,15 +56,15 @@ class ExportZipLogic( private suspend fun generateJsonString(): String { return scopedIOThread { - val accounts = it.async { accountDao.findAll().map { it.toDomain() } } - val budgets = it.async { budgetDao.findAll().map { it.toDomain() } } - val categories = it.async { categoryDao.findAll().map { it.toDomain() } } - val loanRecords = it.async { loanRecordDao.findAll().map { it.toDomain() } } - val loans = it.async { loanDao.findAll().map { it.toDomain() } } + val accounts = it.async { accountDao.findAll() } + val budgets = it.async { budgetDao.findAll() } + val categories = it.async { categoryDao.findAll() } + val loanRecords = it.async { loanRecordDao.findAll() } + val loans = it.async { loanDao.findAll() } val plannedPaymentRules = - it.async { plannedPaymentRuleDao.findAll().map { it.toDomain() } } - val settings = it.async { settingsDao.findAll().map { it.toDomain() } } - val transactions = it.async { transactionDao.findAll().map { it.toDomain() } } + it.async { plannedPaymentRuleDao.findAll() } + val settings = it.async { settingsDao.findAll() } + val transactions = it.async { transactionDao.findAll() } val sharedPrefs = it.async { getSharedPrefsData() } val gson = GsonBuilder().registerTypeAdapter( @@ -217,22 +217,22 @@ class ExportZipLogic( onProgress: suspend (progressPercent: Double) -> Unit = {} ) { scopedIOThread { - transactionDao.save(completeData.transactions.map { it.toEntity() }) + transactionDao.save(completeData.transactions) onProgress(0.6) - val accounts = it.async { accountDao.save(completeData.accounts.map { it.toEntity() }) } - val budgets = it.async { budgetDao.save(completeData.budgets.map { it.toEntity() }) } + val accounts = it.async { accountDao.save(completeData.accounts) } + val budgets = it.async { budgetDao.save(completeData.budgets) } val categories = - it.async { categoryDao.save(completeData.categories.map { it.toEntity() }) } + it.async { categoryDao.save(completeData.categories) } accounts.await() budgets.await() categories.await() onProgress(0.7) - val loans = it.async { loanDao.save(completeData.loans.map { it.toEntity() }) } + val loans = it.async { loanDao.save(completeData.loans) } val loanRecords = - it.async { loanRecordDao.save(completeData.loanRecords.map { it.toEntity() }) } + it.async { loanRecordDao.save(completeData.loanRecords) } loans.await() loanRecords.await() @@ -240,10 +240,10 @@ class ExportZipLogic( onProgress(0.8) val plannedPayments = - it.async { plannedPaymentRuleDao.save(completeData.plannedPaymentRules.map { it.toEntity() }) } + it.async { plannedPaymentRuleDao.save(completeData.plannedPaymentRules) } val settings = it.async { settingsDao.deleteAll() - settingsDao.save(completeData.settings.map { it.toEntity() }) + settingsDao.save(completeData.settings) } sharedPrefs.putBoolean( @@ -277,8 +277,8 @@ class ExportZipLogic( completeData: IvyWalletCompleteData ): List> { return scopedIOThread { scope -> - val existingAccountsList = accountDao.findAll().map { it.toDomain() } - val existingCategoryList = categoryDao.findAll().map { it.toDomain() } + val existingAccountsList = accountDao.findAll() + val existingCategoryList = categoryDao.findAll() val backupAccountsList = completeData.accounts val backupCategoryList = completeData.categories diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingViewModel.kt index 4d8c66f9aa..2a4d1e590b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingViewModel.kt @@ -288,13 +288,15 @@ class OnboardingViewModel @Inject constructor( } } - private suspend fun accountsWithBalance(): List = accountsAct(Unit) - .map { - AccountBalance( - account = it, - balance = accountLogic.calculateAccountBalance(it) - ) - } + private suspend fun accountsWithBalance(): List = ioThread { + accountsAct(Unit) + .map { + AccountBalance( + account = it, + balance = accountLogic.calculateAccountBalance(it) + ) + } + } fun onAddAccountsDone() { viewModelScope.launch {