Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

BugFix : Broken IvyImport to Db #790

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Account> = emptyList(),
val budgets: List<Budget> = emptyList(),
val categories: List<Category> = emptyList(),
val loanRecords: List<LoanRecord> = emptyList(),
val loans: List<Loan> = emptyList(),
val plannedPaymentRules: List<PlannedPaymentRule> = emptyList(),
val settings: List<Settings> = emptyList(),
val transactions: List<Transaction> = emptyList(),
val accounts: List<AccountEntity> = emptyList(),
val budgets: List<BudgetEntity> = emptyList(),
val categories: List<CategoryEntity> = emptyList(),
val loanRecords: List<LoanRecordEntity> = emptyList(),
val loans: List<LoanEntity> = emptyList(),
val plannedPaymentRules: List<PlannedPaymentRuleEntity> = emptyList(),
val settings: List<SettingsEntity> = emptyList(),
val transactions: List<TransactionEntity> = emptyList(),
val sharedPrefs: HashMap<String, String> = HashMap()
)
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -217,33 +217,33 @@ 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()

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(
Expand Down Expand Up @@ -277,8 +277,8 @@ class ExportZipLogic(
completeData: IvyWalletCompleteData
): List<Pair<UUID, UUID>> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,15 @@ class OnboardingViewModel @Inject constructor(
}
}

private suspend fun accountsWithBalance(): List<AccountBalance> = accountsAct(Unit)
.map {
AccountBalance(
account = it,
balance = accountLogic.calculateAccountBalance(it)
)
}
private suspend fun accountsWithBalance(): List<AccountBalance> = ioThread {
accountsAct(Unit)
.map {
AccountBalance(
account = it,
balance = accountLogic.calculateAccountBalance(it)
)
}
}

fun onAddAccountsDone() {
viewModelScope.launch {
Expand Down