From 78bee3deebe2478fcffcfeae87c6aa2c14d16dc9 Mon Sep 17 00:00:00 2001 From: StarHamster <91747573+StarHamster@users.noreply.github.com> Date: Sun, 24 Apr 2022 07:55:05 +0700 Subject: [PATCH 01/40] Apply calculator pattern to number order --- .../ivy/wallet/ui/theme/modal/edit/AmountModal.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AmountModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AmountModal.kt index f459e84fe3..04707cb542 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AmountModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AmountModal.kt @@ -270,21 +270,21 @@ fun AmountKeyboard( horizontalArrangement = Arrangement.Center ) { CircleNumberButton( - value = "1", + value = "7", onNumberPressed = onNumberPressed ) Spacer(Modifier.width(16.dp)) CircleNumberButton( - value = "2", + value = "8", onNumberPressed = onNumberPressed ) Spacer(Modifier.width(16.dp)) CircleNumberButton( - value = "3", + value = "9", onNumberPressed = onNumberPressed ) @@ -336,21 +336,21 @@ fun AmountKeyboard( horizontalArrangement = Arrangement.Center ) { CircleNumberButton( - value = "7", + value = "1", onNumberPressed = onNumberPressed ) Spacer(Modifier.width(16.dp)) CircleNumberButton( - value = "8", + value = "2", onNumberPressed = onNumberPressed ) Spacer(Modifier.width(16.dp)) CircleNumberButton( - value = "9", + value = "3", onNumberPressed = onNumberPressed ) From a277075560e7fae96818a466e66dbf5cddddbf27 Mon Sep 17 00:00:00 2001 From: code-a1 <68858676+code-a1@users.noreply.github.com> Date: Sun, 24 Apr 2022 18:14:26 +0200 Subject: [PATCH 02/40] Added Italian translation, added strings to strings.xml and optimized a date for localization --- .../ivy/wallet/domain/data/entity/Budget.kt | 8 +- .../com/ivy/wallet/domain/data/entity/Loan.kt | 5 +- .../ivy/wallet/ui/theme/modal/model/Month.kt | 26 +- .../main/java/com/ivy/wallet/utils/DateExt.kt | 4 +- app/src/main/res/values-it/strings.xml | 418 ++++++++++++++++++ app/src/main/res/values/strings.xml | 19 +- 6 files changed, 461 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/values-it/strings.xml diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt b/app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt index 86693c0d1a..48969cebd7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt @@ -2,6 +2,8 @@ package com.ivy.wallet.domain.data.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.ivy.wallet.R +import com.ivy.wallet.stringRes import java.util.* @Entity(tableName = "budgets") @@ -26,9 +28,9 @@ data class Budget( fun type(categoriesCount: Int): String { return when (categoriesCount) { - 0 -> "Total Budget" - 1 -> "Category Budget" - else -> "Multi-Category ($categoriesCount) Budget" + 0 -> stringRes(R.string.total_budget) + 1 -> stringRes(R.string.category_budget) + else -> stringRes(R.string.multi_category_budget, categoriesCount.toString()) } } } diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt b/app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt index 849c6d6767..9acd2d6c84 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt @@ -2,7 +2,9 @@ package com.ivy.wallet.domain.data.entity import androidx.room.Entity import androidx.room.PrimaryKey +import com.ivy.wallet.R import com.ivy.wallet.domain.data.LoanType +import com.ivy.wallet.stringRes import java.util.* @Entity(tableName = "loans") @@ -22,6 +24,7 @@ data class Loan( val id: UUID = UUID.randomUUID() ) { fun humanReadableType(): String { - return if (type == LoanType.BORROW) "BORROWED" else "LENT" + return if (type == LoanType.BORROW) stringRes(R.string.borrowed_uppercase) else stringRes( + R.string.lent_uppercase) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt index 2317160261..ec5400d688 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/model/Month.kt @@ -1,5 +1,7 @@ package com.ivy.wallet.ui.theme.modal.model +import com.ivy.wallet.R +import com.ivy.wallet.stringRes import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod import com.ivy.wallet.utils.dateNowUTC @@ -11,18 +13,18 @@ data class Month( ) { companion object { fun monthsList(): MutableList = mutableListOf( - Month(1, "January"), - Month(2, "February"), - Month(3, "March"), - Month(4, "April"), - Month(5, "May"), - Month(6, "June"), - Month(7, "July"), - Month(8, "August"), - Month(9, "September"), - Month(10, "October"), - Month(11, "November"), - Month(12, "December"), + Month(1, stringRes(R.string.january)), + Month(2, stringRes(R.string.february)), + Month(3, stringRes(R.string.march)), + Month(4, stringRes(R.string.april)), + Month(5, stringRes(R.string.may)), + Month(6, stringRes(R.string.june)), + Month(7, stringRes(R.string.july)), + Month(8, stringRes(R.string.august)), + Month(9, stringRes(R.string.september)), + Month(10, stringRes(R.string.october)), + Month(11, stringRes(R.string.november)), + Month(12, stringRes(R.string.december)), ) fun fromMonthValue(code: Int): Month = diff --git a/app/src/main/java/com/ivy/wallet/utils/DateExt.kt b/app/src/main/java/com/ivy/wallet/utils/DateExt.kt index 92b9d386e6..52195e84cb 100644 --- a/app/src/main/java/com/ivy/wallet/utils/DateExt.kt +++ b/app/src/main/java/com/ivy/wallet/utils/DateExt.kt @@ -99,9 +99,9 @@ fun LocalDateTime.formatNicelyWithTime( } else -> { if (isThisYear) { - this.formatLocal("EEE, dd MMM 'at' HH:mm", zone) + this.formatLocal("EEE, dd MMM HH:mm", zone) } else { - this.formatLocal("dd MMM, yyyy 'at' HH:mm", zone) + this.formatLocal("dd MMM, yyyy HH:mm", zone) } } } diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml new file mode 100644 index 0000000000..f4d946dcdf --- /dev/null +++ b/app/src/main/res/values-it/strings.xml @@ -0,0 +1,418 @@ + + + Conti + Totale: %1$s %2$s + ENTRATE DEL MESE + USCITE DEL MESE + (escluso) + ENTRATE + USCITE + APP BLOCCATA + Autenticati per entrare nell\'app + Sblocca + SALDO ATTUALE + SALDO DOPO I PAGAMENTI PIANIFICATI + Connetti + Sincronizza transazioni + Sincronizzazione transazioni… + Sincronizzazione della banca attiva: + Rimuovi client + Aggiungi budget + Nessun budget + Non hai nessun budget impostato.\nTocca \"+ Aggiungi budget\" per aggiungerne uno. + Budgets + %1$s %2$s per categorie + %1$s %2$s budget dell\'app + Informazioni sul budget: %1$s / %2$s + Info sul budget %1$s%2$s + Aggiungi categoria + Uscite + Numero uscite + Entrate + Numero entrate + Grafico del saldo + SALDO %1$s + Grafici + Periodo: + Categorie + Esporta file CSV + Esporta il file CSV con le opzioni standard + Si prega di utilizzare le opzioni standard e assicurarsi di includere le intestazioni. + Come importare + apri + Passaggi + Come fare + Video + Articolo + Carica il file CSV + Esporta i dati + Carica il file CSV/ZIP + Esporta su file + Character set: UTF-8\nDecimal separator: Decimal point \'.\'\nDelimiter character: Comma \',\' + Esporta il file Excel + Converti XLS in CSV + !NOTA: Se il file esportato non ha l\'estensione \".xls\", aggiungila rinominando manualmente il file. + Convertitore online di CSV GRATIS + Controlla le cartelle \"Promozioni\" e \"Spam\" della tua email + Scarica il file \"transactions_export…\" allegato all\'email. + Se hai più di una valuta dovrai scaricare ogni file \"transactions_export…\" e importarlo in Ivy. + Importa da + Attendere prego + Importazione del file CSV + Completato + Errore + Importato + %1$d transazioni + %1$d conti + %1$d categorie + Non riuscito + %1$d righe dal file CSV non riconosciute + Fine + Aggiungi descrizione + Descrizione + Pianificato per + Aggiungi denaro a + Paga con + Da + Conto + A + Aggiungi conto + Titolo entrata + Titolo spesa + Titolo del trasferimento + Uscite + Aggiungi la data prevista del pagamento + Paga + Ricevi + Conferma l\'eliminazione + L\'eliminazione di questa transazione la rimuoverà dalla cronologia delle transazioni e aggiornerà di conseguenza il saldo. + Conferma cambio contro + Nota: Stai cercando di modificare il conto associato al prestito con un conto di valuta diversa, \nTutti i record del prestito saranno ricalcolati in base ai tassi di cambio di oggi + Conferma + Attendi, tutti i prestiti stanno venendo ricalcolati + Creato il + Ciao + Ciao %1$s + Flusso di cassa: %1$s%2$s %3$s + Cerca transazioni + Ivy Wallet è open-source + Obiettivo di risparmio + Accesso rapido + Impostazioni + Modalità chiara + Modalità scura + Modalità\nautomatica + Pagamenti\nPianificati + Condividi Ivy + Resoconti + Prestiti + Imposta la valuta + Nessuna transazione + Non hai nessuna transazione per %1$s.\nPuoi aggiungerne una toccando il tasto \"+\". + Aggiungi prestito + Nessun prestito + Non hai alcun prestito.\nTocca il tasto \"+ Aggiungi prestito\" per aggiungerne uno. + Nota: L\'eliminazione di questo prestito lo rimuoverà definitivamente ed eliminerà tutte le registrazioni associate. + Attendi, tutte le registrazioni dei prestiti stanno venendo ricalcolate + Pagato + %1$s %2$s rimasti + Interessi del prestito + %1$s %2$s pagati + Aggiungi registrazione + Interessi + Nessuna registrazione + Non hai ancora nessuna registrazione per questo prestito. Tocca \"Aggiungi registrazione\" per crearne uno. + Aggiungi entrata + Aggiungi uscita + Non specificato + %1$s\%% + Trasferimenti Conti + Non hai nessuna transazione per %1$s.\nÈ possibile aggiungerne una scorrendo verso il basso e toccando il pulsante \"Aggiungi entrata\" o \"Aggiungi uscita\" in alto. + Nota: L\'eliminazione di questo conto lo rimuoverà definitivamente ed eliminerà tutte le registrazioni associate. + Nota: L\'eliminazione di questa categoria la rimuoverà permanentemente. + Modifica + transazioni + Home + Aggiungi pagamento pianificato + AGGIUNGI ENTRATA + AGGIUNGI SPESA + TRASFERIM. CONTO + Salta + Aggiungi nuovo + Da %1$s + A %1$s + Range + Privacy e\nraccolta di dati + Scorri per accettare i nostri Termini e condizioni + In accordo con i nostri Termini e condizioni + Scorri per accettare la nostra informativa sulla privacy + In accordo con la nostra Informativa sulla privacy + Termini e condizioni + Informativa sulla privacy + Traccia le tue entrate, le uscite e i budget con Ivy.\n\nIU intuitiva, pagamenti ricorrenti e pianificati, gestione di più conti, organizzazione delle transazioni in categorie, statistiche eloquenti, esportazione in CSV e molto altro. + Inserisci il tuo nome\nper personalizzare il tuo\nportafoglio + Come ti chiami? + Invia + Aggiungi i conti + Suggerimenti + Prossimo + Aggiungi le categorie + Suggerimenti + Imposta + Il tuo gestore di denaro personale + #opensource + Errore. Prova di nuovo: %1$s + Accesso in corso… + Completato! + Accedi con Google + Account offline + SINCRONIZZA I TUOI DATI SU IVY CLOUD + L\'integrità e la protezione dei dati non sono garantite! + O PROCEDI CON UN ACCOUNT OFFLINE + I tuoi dati verranno salvati localmente (solo sul tuo telefono) e non verranno sincronizzati nel cloud. Rischi di perdete i dati se disinstalli l\'applicazione o se cambi il tuo dispositivo. È sempre possibile attivare la sincronizzazione in seguito se decidi di farlo. + + Accedendo accetti i nostri %1$s e la nostra %2$s. + Importa un file CSV + da Ivy o da un\'altra app + Importare un file di backup da un\'altra app può richiedere fino a 5 minuti. È sempre possibile importare i dati in un secondo momento, se lo desideri. + Importa un file di backup + Inizia da zero + L\'eliminazione di questo pagamento pianificato eliminerà anche tutte le transazioni associate non pagate in arrivo o in ritardo. + Imposta il tipo di pagamento + Inizio pianificato il + SI RIPETE OGNI %1$d %2$s + eliminato + "PIANIFICATO PER " + n.d. + "INIZIA %1$s " + Aggiungi pagamento + Pagamenti una tantum + Pagamenti ricorrenti + Nessun pagamento pianificato + Non hai nessun pagamento pianificato.\nPremi il tasto \'⚡\' in basso per aggiungerne uno. + Pagamenti pianificati + Oggi + Ieri + Domani + Scade %1$s + In arrivo + Scaduti + uscite + entrate + Modifica conto + Nuovo conto + Nome del conto + Includi conto + Inserisci il saldo del conto + Scegli una valuta + Calcolatrice + Calcolo (+-/*=) + Modifica categoria + Crea una categoria + Nome della categoria + Scegli la categoria + Inserisci qui ogni dettaglio (supporta il Markdown) + Cancella filtro + Filtro + Applica il filtro + Per Tipo + Entrate + Periodo di Tempo + Seleziona l\'intervallo di tempo + Conti (%1$d) + Categorie (%1$d) + Cancella tutto + Seleziona tutto + Importo (facoltativo) + Parole chiave (opzionale) + INCLUDI + Aggiungi una parola chiave + ESCLUDI + Non hai transazioni per il tuo filtro. + Nessun Filtro + Per generare un resoconto devi prima impostare un filtro valido. + Imposta Filtro + Esporta + Non hai nessuna transazione corrispondente alla ricerca di \"%1$s\". + + Backup dei dati + Importa i dati + Impostazioni dell\'App + Blocca l\'app + Mostra le notifiche + Nascondi saldo + Fai clic sul saldo nascosto per visualizzarlo per 5s + Altro + Valutaci su Google Play + Condividi Ivy Wallet + Prodotto + Zona pericolosa + Elimina tutti i dati utente + Eliminare tutti i dati utente? + ATTENZIONE! Questa azione eliminerà tutti i dati per %1$s PERMANENTEMENTE e non sarai in grado di recuperarli. + il tuo account + Conferma l\'eliminazione permanente per \'%1$s\' + tutti i tuoi dati + AVVISO FINALE! Dopo aver cliccato su \"Elimina\" i tuoi dati saranno persi per sempre. + Esportando i dati + Attendi, esportazione dei dati in corso + Data di inizio del mese + Ivy Telegram + Centro assistenza + Roadmap + Richiedi una funzionalità + Contatta il supporto + Contributori del progetto + ACCOUNT + Esci + Accedi + Sincronizzazione… + Dati sincronizzati nel cloud + Tocca per sincronizzare + Sincronizzazione non riuscita. Tocca per sincronizzare + Anonimo + Esporta in CSV + Rimangono da spendere + Budget superato di + Margine superato di + Imposta il tipo di transazione + Trasferimento + Selezionato + Cerca (USD, EUR, GBP, BTC, ecc) + Pre-selezionato + Crypto + Tasso Di Cambio + Scegli il colore + Riordina + Parola chiave + Modifica il budget + Crea un budget + Nome del budget + IMPORTO DEL BUDGET + Sei sicuro di voler eliminare il budget \"%1$s\"? + Modifica l\'obiettivo di risparmio + Scegli l\'icona + Scegli il mese + o un intervallo personalizzato + Aggiungi una data + o nell’ultimo + o tutto il tempo + Deseleziona tutto il tempo + Seleziona tutto il tempo + Scegli la data di inizio del mese + supporta criptovalute + Elimina + Salva + Aggiungi + Crea + Modifica prestito + Nuovo prestito + Nome del prestito + Account Associato + Crea una transazione principale + INSERISCI L\'IMPORTO DEL PRESTITO + "Nota: Stai cercando di modificare il conto associato al prestito con un conto di valuta diversa, \nTutti i record del prestito saranno ricalcolati in base ai tassi di cambio di oggi " + Tipo di prestito + Ricevi in prestito + Dai in prestito + Modifica registrazione + Nuovo record + Note + Segna come interessi + Ricalcola l\'ammontare con i tassi di cambio di oggi + INSERISCI L\'IMPORTO DELLA REGISTRAZIONE + Sei sicuro di voler eliminare la registrazione \"%1$s\"? + "Nota: Stai cercando di modificare il conto associato alla registrazione del prestito con un conto di valuta diversa, \nL'importo sarà ricalcolato in base ai tassi di cambio di oggi " + Modifica il nome + Pianifica per + Una volta + Più volte + Inizia + Ripeti ogni + Invia + Di cosa hai bisogno? + Spiegalo in una frase in inglese. (è supportato il markdown) + Ultimi 12 mesi + Ultimi 6 mesi + Ultime 4 settimane + Ultimi 7 giorni + Oggi, %1$s + Ieri, %1$s + Domani, %1$s + Scaduto + Autenticazione riuscita! + Autenticazione non riuscita. + Hai effettuato delle transazioni oggi? 🏁 + Hai tenuto traccia delle tue spese oggi? 💸 + Hai registrato le tue transazioni oggi? 🏁 + Contanti + Banca + Revolut + + + Trasporti + Alimentari + Intrattenimento + Shopping + Regali + Salute + Investimenti + Auto + Lavoro + Ristorante + Famiglia + Vita Sociale + Cibo a domicilio + Viaggi + Fitness + Self-development + Vestiti + Bellezza + Istruzione + Animali + Sport + Sistema il tuo saldo iniziale + Visualizza i conti + Seleziona un conto -> Seleziona il suo saldo -> Digita il saldo attuale. Ecco fatto!]]> + Crea il tuo primo pagamento pianificato + Automatizza il monitoraggio delle transazioni ricorrenti come i tuoi abbonamenti, l\'affitto, lo stipendio, ecc. Stai al passo con le tue finanze sapendo già quanto devi pagare/ricevere in anticipo. + Lo sapevi? + Ivy Wallet ha un fantastico widget che consente di aggiungere ENTRATE/USCITE/TRASFERIMENTI con un clic dalla tua home\n\nNota: se il pulsante \"Aggiungi widget\" non funziona, aggiungilo manualmente dal menu dei widget del tuo launcher. + Aggiungi widget + Imposta un budget + Ivy Wallet non solo ti aiuta a monitorare passivamente le tue spese, ma crea anche pro-attivamente il tuo futuro finanziario impostando budget e seguendoli. + Puoi vedere lo schema delle tue spese diviso per categorie! Provalo, tocca il pulsante grigio e nero appena sotto il tuo saldo. + Grafico a torta delle uscite + Recensisci Ivy Wallet + Dacci il tuo feedback! Aiuta Ivy Wallet a migliorare e crescere scrivendoci una recensione. Complimenti, idee e critiche sono benvenuti! Facciamo del nostro meglio.\n\nA presto,\nIvy Team + Aiutaci a crescere in modo da poter investire di più nello sviluppo e rendere l\'applicazione migliore per te. Condividendo Ivy Wallet potrai rendere felici due sviluppatori e aiutare un amico a tenere sotto controllo le sue finanze. + Condividi con gli amici + Puoi generare dei resoconti per ottenere un\'analisi approfondita delle tue entrate e delle tue uscite. Filtra le tue transazioni per tipo, periodo di tempo, categoria, conto, parole chiave e non solo per ottenere una vista migliore sulle tue finanze. + Crea un report + Vuoi rendere migliore Ivy Wallet? Scrivici una recensione. Questo, per noi, è l\'unico modo di sviluppare quello che vuoi e che ti serve. Inoltre ci aiuta a ottenere una posizione migliore nel PlayStore così da poter investire sul prodotto pittosto che sul marketing.\n\nFacciamo del nostro meglio.\nIvy Team + Abbiamo bisogno del tuo aiuto! + Siamo solo un designer e uno sviluppatore che lavorano sull\'app dopo i nostri 9–5 lavori. Attualmente, investiamo molto tempo e denaro per generare solo perdite e sfinimento. Se vuoi che continuiamo a sviluppare Ivy Wallet per favore condividilo con amici e familiari.\n\nP.S. Le recensioni sul Google PlayStore aiutano molto! + Ivy Wallet è open-source! + Il codice di Ivy Wallet è aperto e tutti possono vederlo. Crediamo che la trasparenza e l\'etica siano fondamentali per ogni prodotto software. Se ti piace il nostro lavoro e vuoi migliorare l\'app, puoi contribuire nel nostro repository pubblico su Github. + Contribuisci + Sistema il saldo + Autenticazione richiesta + Dimostra di avere accesso a questo dispositivo per sbloccare l\'app. + Budget generale + Budget di categoria + Budget multi-categoria (%1$s) + RICEVUTO + PRESTATO + Gennaio + Febbraio + Marzo + Aprile + Maggio + Giugno + Luglio + Agosto + Settembre + Ottobre + Novembre + Dicembre + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b87a5a63b3..90aa42b106 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -125,7 +125,7 @@ Add income Add expense Unspecified - %1$s% + %1$s\%% Account Transfers You don\'t have any transactions for %1$s.\nYou can add one by scrolling down and tapping "Add income" or "Add expense" button at the top. Note: Deleting this account will remove it permanently and delete all associated transactions with it. @@ -398,4 +398,21 @@ Adjust balance Authentication required Prove that you have access to this device to unlock the app. + Total Budget + Category Budget + Multi-Category (%1$s) Budget + BORROWED + LENT + January + February + March + April + May + June + July + August + September + October + November + December From 1815146377f739e614719b095e84f554b27ff3e9 Mon Sep 17 00:00:00 2001 From: StarHamster <91747573+StarHamster@users.noreply.github.com> Date: Sun, 24 Apr 2022 23:27:02 +0700 Subject: [PATCH 03/40] Update BudgetScreen.kt --- app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt index 08916b5347..ecb5b0e35b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt @@ -133,7 +133,7 @@ private fun BoxWithConstraintsScope.UI( NoBudgetsEmptyState( emptyStateTitle = stringResource(R.string.no_budgets), - emptyStateText = stringResource(R.string.no_budgets) + emptyStateText = stringResource(R.string.no_budgets_text) ) Spacer(Modifier.weight(1f)) From 2cf9c52df1080070f1452ccff575dfc7467e5a26 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Thu, 21 Apr 2022 01:05:35 +0300 Subject: [PATCH 04/40] WIP: Composition refactor (not building) --- .../com/ivy/wallet/domain/action/Action.kt | 27 +++++++++++ .../domain/action/account/AccTrnsAct.kt | 29 ++++++++++++ .../domain/action/wallet/CalcAccBalanceAct.kt | 47 +++++++++++++++++++ .../action/wallet/CalcAccountsBalanceAct.kt | 33 +++++++++++++ .../action/wallet/CalcWalletBalanceAct.kt | 19 -------- .../wallet/domain/fp/account/AccountCore.kt | 23 +++++++-- .../domain/fp/account/AccountFunctions.kt | 6 +-- .../ivy/wallet/domain/fp/wallet/WalletCore.kt | 34 ++++++++++++-- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 6 +-- 9 files changed, 193 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccountsBalanceAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt b/app/src/main/java/com/ivy/wallet/domain/action/Action.kt index 4c46662198..50c8a4d206 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/Action.kt @@ -34,6 +34,33 @@ infix fun Action.then(act2: Action): Action = object } } +suspend infix fun Action.after(lambda: suspend (A) -> B): suspend (A) -> C = { a -> + val b = lambda(a) + this@after(b) +} + +suspend infix fun Action.then(lambda: suspend (B) -> C): suspend (A) -> C = { a -> + val b = this@then(a) + lambda(b) +} + +suspend infix fun (suspend (B) -> C).after(lambda: suspend (A) -> B): suspend (A) -> C = + { a -> + val b = lambda(a) + this@after(b) + } + +suspend infix fun (suspend (A) -> B).then(lambda: suspend (B) -> C): suspend (A) -> C = + { a -> + val b = this@then(a) + lambda(b) + } + +fun Action.lambda(): suspend (A) -> B = { a -> + this(a) +} + + ///** // * Action composition example // */ diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt new file mode 100644 index 0000000000..f438350cc4 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -0,0 +1,29 @@ +package com.ivy.wallet.domain.action.account + +import com.ivy.wallet.domain.action.Action +import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.fp.data.ClosedTimeRange +import com.ivy.wallet.io.persistence.dao.TransactionDao +import java.util.* +import javax.inject.Inject + +class AccTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : Action>() { + override suspend fun Input.willDo(): List = io { + transactionDao.findAllByAccountAndBetween( + accountId = accountId, + startDate = range.from, + endDate = range.to + ) + transactionDao.findAllToAccountAndBetween( + toAccountId = accountId, + startDate = range.from, + endDate = range.to + ) + } + + data class Input( + val accountId: UUID, + val range: ClosedTimeRange + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt new file mode 100644 index 0000000000..564deb170b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt @@ -0,0 +1,47 @@ +package com.ivy.wallet.domain.action.wallet + +import arrow.core.nonEmptyListOf +import com.ivy.wallet.domain.action.Action +import com.ivy.wallet.domain.action.account.AccTrnsAct +import com.ivy.wallet.domain.action.then +import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.fp.account.AccountValueFunctions +import com.ivy.wallet.domain.fp.account.calcAccValues +import com.ivy.wallet.domain.fp.data.ClosedTimeRange +import java.math.BigDecimal +import javax.inject.Inject + +class CalcAccBalanceAct @Inject constructor( + private val accTrnsAct: AccTrnsAct +) : Action() { + + override suspend fun Input.willDo(): Output = io { + val composition = accTrnsAct then { accTrns -> + Output( + account = account, + balance = calcAccValues( + accountId = account.id, + accountsTrns = accTrns, + valueFunctions = nonEmptyListOf(AccountValueFunctions::balance) + ).head + ) + } + + composition( + AccTrnsAct.Input( + accountId = account.id, + range = ClosedTimeRange.allTimeIvy() + ) + ) + + } + + data class Input( + val account: Account + ) + + data class Output( + val account: Account, + val balance: BigDecimal + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccountsBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccountsBalanceAct.kt new file mode 100644 index 0000000000..66709560e0 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccountsBalanceAct.kt @@ -0,0 +1,33 @@ +package com.ivy.wallet.domain.action.wallet + +import com.ivy.wallet.domain.action.Action +import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.fp.data.WalletDAOs +import com.ivy.wallet.io.persistence.dao.ExchangeRateDao +import java.math.BigDecimal +import javax.inject.Inject + +class CalcAccountsBalanceAct @Inject constructor( + private val walletDAOs: WalletDAOs, + private val exchangeRateDao: ExchangeRateDao +) : Action() { + override suspend fun Input.willDo(): BigDecimal = io { + +// sumAccountValuesInCurrency( +// accountTrns = , +// baseCurrencyCode = currency, +// exchangeRateDao = exchangeRateDao, +// valueFunctions = nonEmptyListOf(AccountValueFunctions::balance) +// ).value +// calculateWalletBalance( +// walletDAOs = walletDAOs, +// baseCurrencyCode = currency +// ).value + TODO() + } + + data class Input( + val accounts: List, + val currency: String + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt deleted file mode 100644 index 1b35c54806..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.ivy.wallet.domain.action.wallet - -import com.ivy.wallet.domain.action.Action -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletBalance -import java.math.BigDecimal -import javax.inject.Inject - -class CalcWalletBalanceAct @Inject constructor( - private val walletDAOs: WalletDAOs, -) : Action() { - override suspend fun String.willDo(): BigDecimal = io { - val baseCurrency = this - calculateWalletBalance( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrency - ).value - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt b/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt index 493efeb1b4..5e9a347071 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt @@ -2,6 +2,7 @@ package com.ivy.wallet.domain.fp.account import arrow.core.NonEmptyList import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.fp.core.Pure import com.ivy.wallet.domain.fp.core.Total import com.ivy.wallet.domain.fp.core.calculateValueFunctionsSum import com.ivy.wallet.domain.fp.data.ClosedTimeRange @@ -11,13 +12,13 @@ import java.math.BigDecimal import java.util.* @Total -suspend fun calculateAccountValues( +suspend fun calcAccValues( transactionDao: TransactionDao, accountId: UUID, range: ClosedTimeRange, valueFunctions: NonEmptyList ): NonEmptyList { - return calculateAccountValues( + return calcAccValues( accountId = accountId, retrieveAccountTransactions = { transactionDao.findAllByAccountAndBetween( @@ -38,7 +39,7 @@ suspend fun calculateAccountValues( } @Total -suspend fun calculateAccountValues( +suspend fun calcAccValues( accountId: UUID, retrieveAccountTransactions: suspend (UUID) -> List, retrieveToAccountTransfers: suspend (UUID) -> List, @@ -48,6 +49,22 @@ suspend fun calculateAccountValues( .plus(retrieveToAccountTransfers(accountId)) .map { it.toFPTransaction() } + return calculateValueFunctionsSum( + valueFunctionArgument = accountId, + transactions = accountTrns, + valueFunctions = valueFunctions + ) +} + +@Pure +fun calcAccValues( + accountId: UUID, + accountsTrns: List, + valueFunctions: NonEmptyList +): NonEmptyList { + val accountTrns = accountsTrns + .map { it.toFPTransaction() } + return calculateValueFunctionsSum( valueFunctionArgument = accountId, transactions = accountTrns, diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt index 20e99c8902..e9031cf274 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt @@ -13,7 +13,7 @@ suspend fun calculateAccountBalance( accountId: UUID, range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() ): BigDecimal { - return calculateAccountValues( + return calcAccValues( transactionDao = transactionDao, accountId = accountId, range = range, @@ -36,7 +36,7 @@ suspend fun calculateAccountStats( accountId: UUID, range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() ): AccountStats { - val values = calculateAccountValues( + val values = calcAccValues( transactionDao = transactionDao, accountId = accountId, range = range, @@ -63,7 +63,7 @@ suspend fun calculateAccountIncomeExpense( accountId: UUID, range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() ): IncomeExpensePair { - val values = calculateAccountValues( + val values = calcAccValues( transactionDao = transactionDao, accountId = accountId, range = range, diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt index 7f4b431dbe..0006f1199f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt @@ -2,8 +2,10 @@ package com.ivy.wallet.domain.fp.wallet import arrow.core.NonEmptyList import arrow.core.Some +import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.fp.account.AccountValueFunction -import com.ivy.wallet.domain.fp.account.calculateAccountValues +import com.ivy.wallet.domain.fp.account.calcAccValues import com.ivy.wallet.domain.fp.core.Uncertain import com.ivy.wallet.domain.fp.core.mapIndexedNel import com.ivy.wallet.domain.fp.core.nonEmptyListOfZeros @@ -31,7 +33,7 @@ suspend fun calculateWalletValues( .map { account -> Pair( first = account.toFPAccount(baseCurrencyCode), - second = calculateAccountValues( + second = calcAccValues( transactionDao = walletDAOs.transactionDao, accountId = account.id, range = range, @@ -50,6 +52,32 @@ suspend fun calculateWalletValues( ) } +suspend fun sumAccountValuesInCurrency( + accountTrns: List>>, + baseCurrencyCode: String, + exchangeRateDao: ExchangeRateDao, + valueFunctions: NonEmptyList +): UncertainWalletValues { + val uncertainWalletValues = accountTrns.map { (account, trns) -> + Pair( + first = account.toFPAccount(baseCurrencyCode), + second = calcAccValues( + accountId = account.id, + accountsTrns = trns, + valueFunctions = valueFunctions + ) + ) + }.convertValuesInBaseCurrency( + exchangeRateDao = exchangeRateDao, + baseCurrencyCode = baseCurrencyCode + ) + + return sumUncertainWalletValues( + valueN = valueFunctions.size, + uncertainWalletValues = uncertainWalletValues + ) +} + suspend fun calculateWalletValuesWithAccountFilters( walletDAOs: WalletDAOs, baseCurrencyCode: String, @@ -76,7 +104,7 @@ suspend fun calculateWalletValuesWithAccountFilters( .map { account -> Pair( first = account.toFPAccount(baseCurrencyCode), - second = calculateAccountValues( + second = calcAccValues( transactionDao = walletDAOs.transactionDao, accountId = account.id, range = range, diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 4cb87fdefb..49e8b33d3e 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -4,9 +4,9 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation import com.ivy.design.viewmodel.IvyViewModel +import com.ivy.wallet.domain.action.wallet.CalcAccountsBalanceAct import com.ivy.wallet.domain.action.wallet.CalcOverdueAct import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct -import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.action.wallet.HistoryWithDateDivAct import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.fp.data.WalletDAOs @@ -46,7 +46,7 @@ class HomeViewModel @Inject constructor( private val plannedPaymentsLogic: PlannedPaymentsLogic, private val customerJourneyLogic: CustomerJourneyLogic, private val sharedPrefs: SharedPrefs, - private val calcWalletBalanceAct: CalcWalletBalanceAct, + private val calcAccountBalanceAct: CalcAccountsBalanceAct, private val calcUpcomingAct: CalcUpcomingAct, private val calcOverdueAct: CalcOverdueAct, private val historyWithDateDivAct: HistoryWithDateDivAct, @@ -102,7 +102,7 @@ class HomeViewModel @Inject constructor( updateState { it.copy( - balance = calcWalletBalanceAct(settings.currency) + balance = calcAccountBalanceAct(settings.currency) ) } From 8b22a511dc8981a4e55dd373b301d1d34173206c Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Thu, 21 Apr 2022 18:45:22 +0300 Subject: [PATCH 05/40] WIP: Action composition (not building) --- .../com/ivy/wallet/domain/action/Action.kt | 65 ++++++++++++++----- .../com/ivy/wallet/domain/action/FPAction.kt | 9 +++ .../domain/action/account/AccTrnsAct.kt | 28 ++++---- .../domain/action/account/AccountsAct.kt | 14 ++++ .../domain/action/settings/BaseCurrencyAct.kt | 16 +++++ .../action/settings/GetBaseCurrencyAct.kt | 14 ---- .../domain/action/wallet/CalcAccBalanceAct.kt | 37 +++++------ .../action/wallet/CalcAccountsBalanceAct.kt | 33 ---------- .../action/wallet/CalcWalletBalanceAct.kt | 39 +++++++++++ .../domain/action/wallet/ExchangeAct.kt | 33 ++++++++++ .../wallet/ui/accounts/AccountsViewModel.kt | 63 +++++++++--------- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 15 +++-- 12 files changed, 232 insertions(+), 134 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/settings/GetBaseCurrencyAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccountsBalanceAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt b/app/src/main/java/com/ivy/wallet/domain/action/Action.kt index 50c8a4d206..b920f51ad6 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/Action.kt @@ -15,6 +15,11 @@ abstract class Action { } protected suspend fun computation(action: suspend () -> T): T = + withContext(Dispatchers.Default) { + return@withContext action() + } + + protected suspend fun ui(action: suspend () -> T): T = withContext(Dispatchers.Main) { return@withContext action() } @@ -39,11 +44,6 @@ suspend infix fun Action.after(lambda: suspend (A) -> B): suspen this@after(b) } -suspend infix fun Action.then(lambda: suspend (B) -> C): suspend (A) -> C = { a -> - val b = this@then(a) - lambda(b) -} - suspend infix fun (suspend (B) -> C).after(lambda: suspend (A) -> B): suspend (A) -> C = { a -> val b = lambda(a) @@ -56,17 +56,48 @@ suspend infix fun (suspend (A) -> B).then(lambda: suspend (B) -> C): s lambda(b) } -fun Action.lambda(): suspend (A) -> B = { a -> - this(a) -} +suspend infix fun (suspend () -> B).then(lambda: suspend (B) -> C): suspend () -> C = + { + val b = this@then() + lambda(b) + } + +suspend infix fun (suspend () -> B).then(act: Action): suspend () -> C = + { + val b = this@then() + act(b) + } + +suspend infix fun (suspend (A) -> B).then(act: Action): suspend (A) -> C = + { a -> + val b = this@then(a) + act(b) + } + +suspend infix fun (Action).then(f: suspend (B) -> C): suspend (A) -> C = + { a -> + val b = this@then(a) + f(b) + } -///** -// * Action composition example -// */ -//suspend fun example( -// calcWalletBalance: CalcWalletBalanceAct, -// getBaseCurrency: GetBaseCurrencyAct -//): BigDecimal { -// return (calcWalletBalance after getBaseCurrency)(Unit) -//} \ No newline at end of file +suspend infix fun (() -> B).then(f: suspend (B) -> C): suspend () -> C = + { + val b = this@then() + f(b) + } + +fun (() -> C).fixUnit(): suspend (Unit) -> C = + { + this() + } + +fun (suspend () -> C).fixUnit(): suspend (Unit) -> C = + { + this() + } + +fun (suspend (Unit) -> C).fixUnit(): suspend () -> C = + { + this(Unit) + } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt b/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt new file mode 100644 index 0000000000..f0b370473b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt @@ -0,0 +1,9 @@ +package com.ivy.wallet.domain.action + +abstract class FPAction : Action() { + protected abstract suspend fun I.recipe(): (suspend () -> O) + + override suspend fun I.willDo(): O { + return recipe().invoke() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt index f438350cc4..364fcb044e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.account -import com.ivy.wallet.domain.action.Action +import com.ivy.wallet.domain.action.FPAction import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.fp.data.ClosedTimeRange import com.ivy.wallet.io.persistence.dao.TransactionDao @@ -9,20 +9,22 @@ import javax.inject.Inject class AccTrnsAct @Inject constructor( private val transactionDao: TransactionDao -) : Action>() { - override suspend fun Input.willDo(): List = io { - transactionDao.findAllByAccountAndBetween( - accountId = accountId, - startDate = range.from, - endDate = range.to - ) + transactionDao.findAllToAccountAndBetween( - toAccountId = accountId, - startDate = range.from, - endDate = range.to - ) +) : FPAction>() { + override suspend fun Input.recipe(): suspend () -> List = suspend { + io { + transactionDao.findAllByAccountAndBetween( + accountId = accountId, + startDate = range.from, + endDate = range.to + ) + transactionDao.findAllToAccountAndBetween( + toAccountId = accountId, + startDate = range.from, + endDate = range.to + ) + } } - data class Input( + class Input( val accountId: UUID, val range: ClosedTimeRange ) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt new file mode 100644 index 0000000000..c76212dd16 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt @@ -0,0 +1,14 @@ +package com.ivy.wallet.domain.action.account + +import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.io.persistence.dao.AccountDao +import javax.inject.Inject + +class AccountsAct @Inject constructor( + private val accountDao: AccountDao +) : FPAction>() { + override suspend fun Unit.recipe(): suspend () -> List = suspend { + io { accountDao.findAll() } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt new file mode 100644 index 0000000000..b3bc6f668a --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt @@ -0,0 +1,16 @@ +package com.ivy.wallet.domain.action.settings + +import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode +import com.ivy.wallet.io.persistence.dao.SettingsDao +import javax.inject.Inject + +class BaseCurrencyAct @Inject constructor( + private val settingsDao: SettingsDao +) : FPAction() { + override suspend fun Unit.recipe(): suspend () -> String { + return suspend { + io { baseCurrencyCode(settingsDao) } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/GetBaseCurrencyAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/GetBaseCurrencyAct.kt deleted file mode 100644 index f3cfe73457..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/settings/GetBaseCurrencyAct.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.ivy.wallet.domain.action.settings - -import com.ivy.wallet.domain.action.Action -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.io.persistence.dao.SettingsDao -import javax.inject.Inject - -class GetBaseCurrencyAct @Inject constructor( - private val settingsDao: SettingsDao -) : Action() { - override suspend fun Unit.willDo(): String = io { - baseCurrencyCode(settingsDao) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt index 564deb170b..eb6387a76c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.action.wallet import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.action.Action +import com.ivy.wallet.domain.action.FPAction import com.ivy.wallet.domain.action.account.AccTrnsAct import com.ivy.wallet.domain.action.then import com.ivy.wallet.domain.data.entity.Account @@ -13,27 +13,24 @@ import javax.inject.Inject class CalcAccBalanceAct @Inject constructor( private val accTrnsAct: AccTrnsAct -) : Action() { +) : FPAction() { - override suspend fun Input.willDo(): Output = io { - val composition = accTrnsAct then { accTrns -> - Output( - account = account, - balance = calcAccValues( - accountId = account.id, - accountsTrns = accTrns, - valueFunctions = nonEmptyListOf(AccountValueFunctions::balance) - ).head - ) - } - - composition( - AccTrnsAct.Input( - accountId = account.id, - range = ClosedTimeRange.allTimeIvy() - ) + override suspend fun Input.recipe(): suspend () -> Output = suspend { + AccTrnsAct.Input( + accountId = account.id, + range = ClosedTimeRange.allTimeIvy() + ) + } then accTrnsAct then { accTrns -> + calcAccValues( + accountId = account.id, + accountsTrns = accTrns, + valueFunctions = nonEmptyListOf(AccountValueFunctions::balance) + ).head + } then { balance -> + Output( + account = account, + balance = balance ) - } data class Input( diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccountsBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccountsBalanceAct.kt deleted file mode 100644 index 66709560e0..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccountsBalanceAct.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.ivy.wallet.domain.action.wallet - -import com.ivy.wallet.domain.action.Action -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao -import java.math.BigDecimal -import javax.inject.Inject - -class CalcAccountsBalanceAct @Inject constructor( - private val walletDAOs: WalletDAOs, - private val exchangeRateDao: ExchangeRateDao -) : Action() { - override suspend fun Input.willDo(): BigDecimal = io { - -// sumAccountValuesInCurrency( -// accountTrns = , -// baseCurrencyCode = currency, -// exchangeRateDao = exchangeRateDao, -// valueFunctions = nonEmptyListOf(AccountValueFunctions::balance) -// ).value -// calculateWalletBalance( -// walletDAOs = walletDAOs, -// baseCurrencyCode = currency -// ).value - TODO() - } - - data class Input( - val accounts: List, - val currency: String - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt new file mode 100644 index 0000000000..818cc00b59 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -0,0 +1,39 @@ +package com.ivy.wallet.domain.action.wallet + +import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.then +import java.math.BigDecimal +import javax.inject.Inject + +class CalcWalletBalanceAct @Inject constructor( + private val accountsAct: AccountsAct, + private val calcAccBalanceAct: CalcAccBalanceAct, + private val exchangeAct: ExchangeAct, + private val baseCurrencyAct: BaseCurrencyAct +) : FPAction() { + + override suspend fun Input.recipe(): suspend () -> BigDecimal = (accountsAct then { + it.filter { acc -> acc.includeInBalance } + } then { + it.map { acc -> calcAccBalanceAct(CalcAccBalanceAct.Input(acc)) } + } then baseCurrencyAct then { + it.map { balanceOutput -> + exchangeAct( + ExchangeAct.Input( + baseCurrency =, + fromCurrency = balanceOutput.account.currency.toOption(), + toCurrency =, + amount = balanceOutput.balance + ) + ) + } + } then { balances -> + balances.sumOf { it.orNull() ?: BigDecimal.ZERO } + }).fixUnit() + + data class Input( + val currency: String + ) +} diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt new file mode 100644 index 0000000000..d00ae3e75d --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt @@ -0,0 +1,33 @@ +package com.ivy.wallet.domain.action.wallet + +import arrow.core.Option +import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.fp.exchange +import com.ivy.wallet.io.persistence.dao.ExchangeRateDao +import java.math.BigDecimal +import javax.inject.Inject + +class ExchangeAct @Inject constructor( + private val exchangeRateDao: ExchangeRateDao, +) : FPAction>() { + + override suspend fun Input.recipe(): suspend () -> Option = suspend { + io { + exchange( + baseCurrencyCode = baseCurrency, + exchangeRateDao = exchangeRateDao, + fromAmount = amount, + fromCurrencyCode = fromCurrency, + toCurrencyCode = toCurrency + ) + } + } + + + data class Input( + val baseCurrency: String, + val fromCurrency: Option, + val toCurrency: String, + val amount: BigDecimal + ) +} diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt index b074d3f52f..a0601924e6 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt @@ -2,6 +2,7 @@ package com.ivy.wallet.ui.accounts import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.event.AccountsUpdatedEvent import com.ivy.wallet.domain.fp.account.calculateAccountBalance @@ -35,6 +36,7 @@ class AccountsViewModel @Inject constructor( private val accountSync: AccountSync, private val accountCreator: AccountCreator, private val ivyContext: IvyWalletCtx, + private val accountsAct: AccountsAct ) : ViewModel() { @Subscribe @@ -67,38 +69,39 @@ class AccountsViewModel @Inject constructor( val baseCurrencyCode = ioThread { baseCurrencyCode(settingsDao) } _baseCurrencyCode.value = baseCurrencyCode - _accounts.value = ioThread { - accountDao.findAll() - .map { - val balance = calculateAccountBalance( - transactionDao = walletDAOs.transactionDao, - accountId = it.id - ) - val balanceBaseCurrency = if (it.currency != baseCurrencyCode) { - exchangeToBaseCurrency( - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = it.currency ?: baseCurrencyCode, - fromAmount = balance - ).orNull()?.toDouble() - } else { - null - } - - val incomeExpensePair = calculateAccountIncomeExpense( - transactionDao = walletDAOs.transactionDao, - accountId = it.id, - range = range.toCloseTimeRange() - ) + val accs = accountsAct(Unit) - AccountData( - account = it, - balance = balance.toDouble(), - balanceBaseCurrency = balanceBaseCurrency, - monthlyIncome = incomeExpensePair.income.toDouble(), - monthlyExpenses = incomeExpensePair.expense.toDouble(), - ) + _accounts.value = ioThread { + accs.map { + val balance = calculateAccountBalance( + transactionDao = walletDAOs.transactionDao, + accountId = it.id + ) + val balanceBaseCurrency = if (it.currency != baseCurrencyCode) { + exchangeToBaseCurrency( + exchangeRateDao = walletDAOs.exchangeRateDao, + baseCurrencyCode = baseCurrencyCode, + fromCurrencyCode = it.currency ?: baseCurrencyCode, + fromAmount = balance + ).orNull()?.toDouble() + } else { + null } + + val incomeExpensePair = calculateAccountIncomeExpense( + transactionDao = walletDAOs.transactionDao, + accountId = it.id, + range = range.toCloseTimeRange() + ) + + AccountData( + account = it, + balance = balance.toDouble(), + balanceBaseCurrency = balanceBaseCurrency, + monthlyIncome = incomeExpensePair.income.toDouble(), + monthlyExpenses = incomeExpensePair.expense.toDouble(), + ) + } } _totalBalanceWithExcluded.value = ioThread { diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 49e8b33d3e..1aef9faa04 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -4,9 +4,9 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation import com.ivy.design.viewmodel.IvyViewModel -import com.ivy.wallet.domain.action.wallet.CalcAccountsBalanceAct import com.ivy.wallet.domain.action.wallet.CalcOverdueAct import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct +import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.action.wallet.HistoryWithDateDivAct import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.fp.data.WalletDAOs @@ -46,7 +46,7 @@ class HomeViewModel @Inject constructor( private val plannedPaymentsLogic: PlannedPaymentsLogic, private val customerJourneyLogic: CustomerJourneyLogic, private val sharedPrefs: SharedPrefs, - private val calcAccountBalanceAct: CalcAccountsBalanceAct, + private val calcAccountBalanceAct: CalcWalletBalanceAct, private val calcUpcomingAct: CalcUpcomingAct, private val calcOverdueAct: CalcOverdueAct, private val historyWithDateDivAct: HistoryWithDateDivAct, @@ -100,11 +100,12 @@ class HomeViewModel @Inject constructor( val timeRange = period.toRange(ivyContext.startDayOfMonth) - updateState { - it.copy( - balance = calcAccountBalanceAct(settings.currency) - ) - } + //TODO: Fix that! +// updateState { +// it.copy( +// balance = calcAccountBalanceAct(settings.currency) +// ) +// } updateState { it.copy( From 9ad7b53d2f588dea819ac180f2683ff0f45f7c9e Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Thu, 21 Apr 2022 20:52:40 +0300 Subject: [PATCH 06/40] WIP: Composition --- .../com/ivy/wallet/domain/action/Action.kt | 79 +------------------ .../ivy/wallet/domain/action/Composition.kt | 54 +++++++++++++ .../wallet/domain/action/CompositionUtils.kt | 9 +++ .../com/ivy/wallet/domain/action/FPAction.kt | 4 +- .../domain/action/account/AccTrnsAct.kt | 2 +- .../domain/action/account/AccountsAct.kt | 2 +- .../domain/action/settings/BaseCurrencyAct.kt | 2 +- .../domain/action/wallet/CalcAccBalanceAct.kt | 2 +- .../action/wallet/CalcWalletBalanceAct.kt | 42 +++++----- .../domain/action/wallet/ExchangeAct.kt | 2 +- 10 files changed, 94 insertions(+), 104 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/Composition.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt b/app/src/main/java/com/ivy/wallet/domain/action/Action.kt index b920f51ad6..5de7d11243 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/Action.kt @@ -23,81 +23,4 @@ abstract class Action { withContext(Dispatchers.Main) { return@withContext action() } -} - -infix fun Action.after(act1: Action): Action = object : Action() { - override suspend fun A.willDo(): C { - val b = act1(this@willDo) //A -> B - return this@after(b) //B -> C - } -} - -infix fun Action.then(act2: Action): Action = object : Action() { - override suspend fun A.willDo(): C { - val b = this@then(this) - return act2(b) - } -} - -suspend infix fun Action.after(lambda: suspend (A) -> B): suspend (A) -> C = { a -> - val b = lambda(a) - this@after(b) -} - -suspend infix fun (suspend (B) -> C).after(lambda: suspend (A) -> B): suspend (A) -> C = - { a -> - val b = lambda(a) - this@after(b) - } - -suspend infix fun (suspend (A) -> B).then(lambda: suspend (B) -> C): suspend (A) -> C = - { a -> - val b = this@then(a) - lambda(b) - } - -suspend infix fun (suspend () -> B).then(lambda: suspend (B) -> C): suspend () -> C = - { - val b = this@then() - lambda(b) - } - -suspend infix fun (suspend () -> B).then(act: Action): suspend () -> C = - { - val b = this@then() - act(b) - } - -suspend infix fun (suspend (A) -> B).then(act: Action): suspend (A) -> C = - { a -> - val b = this@then(a) - act(b) - } - -suspend infix fun (Action).then(f: suspend (B) -> C): suspend (A) -> C = - { a -> - val b = this@then(a) - f(b) - } - - -suspend infix fun (() -> B).then(f: suspend (B) -> C): suspend () -> C = - { - val b = this@then() - f(b) - } - -fun (() -> C).fixUnit(): suspend (Unit) -> C = - { - this() - } - -fun (suspend () -> C).fixUnit(): suspend (Unit) -> C = - { - this() - } - -fun (suspend (Unit) -> C).fixUnit(): suspend () -> C = - { - this(Unit) - } \ No newline at end of file +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/Composition.kt b/app/src/main/java/com/ivy/wallet/domain/action/Composition.kt new file mode 100644 index 0000000000..f9f39e51cf --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/Composition.kt @@ -0,0 +1,54 @@ +package com.ivy.wallet.domain.action + + +suspend infix fun (suspend (A) -> B).then(f: suspend (B) -> C): suspend (A) -> C = + { a -> + val b = this@then(a) + f(b) + } + +suspend infix fun (suspend () -> B).then(f: suspend (B) -> C): suspend () -> C = + { + val b = this@then() + f(b) + } + +suspend infix fun (suspend (A) -> B).then(act: Action): suspend (A) -> C = + { a -> + val b = this@then(a) + act(b) + } + +suspend infix fun (suspend () -> B).then(act: Action): suspend () -> C = + { + val b = this@then() + act(b) + } + +suspend infix fun (Action).then(f: suspend (B) -> C): suspend (A) -> C = + { a -> + val b = this@then(a) + f(b) + } + + +suspend infix fun (() -> B).then(f: suspend (B) -> C): suspend () -> C = + { + val b = this@then() + f(b) + } + +fun (() -> C).fixUnit(): suspend (Unit) -> C = + { + this() + } + +fun (suspend () -> C).fixUnit(): suspend (Unit) -> C = + { + this() + } + +fun (suspend (Unit) -> C).fixUnit(): suspend () -> C = + { + this(Unit) + } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt b/app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt new file mode 100644 index 0000000000..8f66a37365 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt @@ -0,0 +1,9 @@ +package com.ivy.wallet.domain.action + +suspend infix fun (suspend (Any) -> List).thenFilter( + predicate: (A) -> Boolean +): suspend (Any) -> List = + { a -> + val list = this(a) + list.filter(predicate) + } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt b/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt index f0b370473b..716623ab68 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt @@ -1,9 +1,9 @@ package com.ivy.wallet.domain.action abstract class FPAction : Action() { - protected abstract suspend fun I.recipe(): (suspend () -> O) + protected abstract suspend fun I.compose(): (suspend () -> O) override suspend fun I.willDo(): O { - return recipe().invoke() + return compose().invoke() } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt index 364fcb044e..3f18483b40 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -10,7 +10,7 @@ import javax.inject.Inject class AccTrnsAct @Inject constructor( private val transactionDao: TransactionDao ) : FPAction>() { - override suspend fun Input.recipe(): suspend () -> List = suspend { + override suspend fun Input.compose(): suspend () -> List = suspend { io { transactionDao.findAllByAccountAndBetween( accountId = accountId, diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt index c76212dd16..2921d3406f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt @@ -8,7 +8,7 @@ import javax.inject.Inject class AccountsAct @Inject constructor( private val accountDao: AccountDao ) : FPAction>() { - override suspend fun Unit.recipe(): suspend () -> List = suspend { + override suspend fun Unit.compose(): suspend () -> List = suspend { io { accountDao.findAll() } } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt index b3bc6f668a..fdc5294578 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt @@ -8,7 +8,7 @@ import javax.inject.Inject class BaseCurrencyAct @Inject constructor( private val settingsDao: SettingsDao ) : FPAction() { - override suspend fun Unit.recipe(): suspend () -> String { + override suspend fun Unit.compose(): suspend () -> String { return suspend { io { baseCurrencyCode(settingsDao) } } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt index eb6387a76c..01751a3105 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt @@ -15,7 +15,7 @@ class CalcAccBalanceAct @Inject constructor( private val accTrnsAct: AccTrnsAct ) : FPAction() { - override suspend fun Input.recipe(): suspend () -> Output = suspend { + override suspend fun Input.compose(): suspend () -> Output = suspend { AccTrnsAct.Input( accountId = account.id, range = ClosedTimeRange.allTimeIvy() diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index 818cc00b59..599a4b6079 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -1,8 +1,9 @@ package com.ivy.wallet.domain.action.wallet +import arrow.core.toOption import com.ivy.wallet.domain.action.FPAction import com.ivy.wallet.domain.action.account.AccountsAct -import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.fixUnit import com.ivy.wallet.domain.action.then import java.math.BigDecimal import javax.inject.Inject @@ -11,29 +12,32 @@ class CalcWalletBalanceAct @Inject constructor( private val accountsAct: AccountsAct, private val calcAccBalanceAct: CalcAccBalanceAct, private val exchangeAct: ExchangeAct, - private val baseCurrencyAct: BaseCurrencyAct ) : FPAction() { - override suspend fun Input.recipe(): suspend () -> BigDecimal = (accountsAct then { - it.filter { acc -> acc.includeInBalance } - } then { - it.map { acc -> calcAccBalanceAct(CalcAccBalanceAct.Input(acc)) } - } then baseCurrencyAct then { - it.map { balanceOutput -> - exchangeAct( - ExchangeAct.Input( - baseCurrency =, - fromCurrency = balanceOutput.account.currency.toOption(), - toCurrency =, - amount = balanceOutput.balance + override suspend fun Input.compose(): suspend () -> BigDecimal = recipe().fixUnit() + + private suspend fun Input.recipe(): suspend (Unit) -> BigDecimal = + accountsAct then { + it.filter { acc -> acc.includeInBalance } + } then { + it.map { acc -> calcAccBalanceAct(CalcAccBalanceAct.Input(acc)) } + } then { + it.map { balanceOutput -> + exchangeAct( + ExchangeAct.Input( + baseCurrency = baseCurrency, + fromCurrency = balanceOutput.account.currency.toOption(), + toCurrency = balanceCurrency, + amount = balanceOutput.balance + ) ) - ) + } + } then { balances -> + balances.sumOf { it.orNull() ?: BigDecimal.ZERO } } - } then { balances -> - balances.sumOf { it.orNull() ?: BigDecimal.ZERO } - }).fixUnit() data class Input( - val currency: String + val baseCurrency: String, + val balanceCurrency: String ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt index d00ae3e75d..cf756d705d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt @@ -11,7 +11,7 @@ class ExchangeAct @Inject constructor( private val exchangeRateDao: ExchangeRateDao, ) : FPAction>() { - override suspend fun Input.recipe(): suspend () -> Option = suspend { + override suspend fun Input.compose(): suspend () -> Option = suspend { io { exchange( baseCurrencyCode = baseCurrency, From 60e95fbc17342e8e7cb27331cdd35c55eb7d9058 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Thu, 21 Apr 2022 21:13:04 +0300 Subject: [PATCH 07/40] Implement declarative wallet balance calculation --- .../wallet/domain/action/CompositionFilter.kt | 17 ++++++++++ .../wallet/domain/action/CompositionMap.kt | 21 ++++++++++++ .../wallet/domain/action/CompositionSum.kt | 29 ++++++++++++++++ .../wallet/domain/action/CompositionUtils.kt | 9 ----- .../action/wallet/CalcWalletBalanceAct.kt | 34 ++++++++----------- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 16 +++++---- 6 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/CompositionFilter.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/CompositionMap.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/CompositionSum.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/CompositionFilter.kt b/app/src/main/java/com/ivy/wallet/domain/action/CompositionFilter.kt new file mode 100644 index 0000000000..f158a90cba --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/CompositionFilter.kt @@ -0,0 +1,17 @@ +package com.ivy.wallet.domain.action + +suspend infix fun (suspend (A) -> List).thenFilter( + predicate: (B) -> Boolean +): suspend (A) -> List = + { a -> + val list = this(a) + list.filter(predicate) + } + +suspend infix fun (Action>).thenFilter( + predicate: (B) -> Boolean +): suspend (A) -> List = + { a -> + val list = this(a) + list.filter(predicate) + } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/CompositionMap.kt b/app/src/main/java/com/ivy/wallet/domain/action/CompositionMap.kt new file mode 100644 index 0000000000..030693a946 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/CompositionMap.kt @@ -0,0 +1,21 @@ +package com.ivy.wallet.domain.action + +suspend infix fun (suspend (A) -> List).thenMap( + transform: suspend (B) -> C +): suspend (A) -> List = + { a -> + val list = this(a) + list.map { + transform(it) + } + } + +suspend infix fun (Action>).thenMap( + transform: suspend (B) -> C +): suspend (A) -> List = + { a -> + val list = this(a) + list.map { + transform(it) + } + } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/CompositionSum.kt b/app/src/main/java/com/ivy/wallet/domain/action/CompositionSum.kt new file mode 100644 index 0000000000..27ebc0d769 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/CompositionSum.kt @@ -0,0 +1,29 @@ +package com.ivy.wallet.domain.action + +import java.math.BigDecimal + +suspend infix fun (suspend (A) -> List).thenSum( + value: (B) -> BigDecimal +): suspend (A) -> BigDecimal = + { a -> + val list = this(a) + list.fold( + initial = BigDecimal.ZERO, + operation = { acc, b -> + acc + value(b) + } + ) + } + +suspend infix fun (Action>).thenSum( + value: (B) -> BigDecimal +): suspend (A) -> BigDecimal = + { a -> + val list = this(a) + list.fold( + initial = BigDecimal.ZERO, + operation = { acc, b -> + acc + value(b) + } + ) + } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt b/app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt deleted file mode 100644 index 8f66a37365..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/CompositionUtils.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ivy.wallet.domain.action - -suspend infix fun (suspend (Any) -> List).thenFilter( - predicate: (A) -> Boolean -): suspend (Any) -> List = - { a -> - val list = this(a) - list.filter(predicate) - } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index 599a4b6079..00337cddeb 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -1,10 +1,8 @@ package com.ivy.wallet.domain.action.wallet import arrow.core.toOption -import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.action.* import com.ivy.wallet.domain.action.account.AccountsAct -import com.ivy.wallet.domain.action.fixUnit -import com.ivy.wallet.domain.action.then import java.math.BigDecimal import javax.inject.Inject @@ -17,23 +15,21 @@ class CalcWalletBalanceAct @Inject constructor( override suspend fun Input.compose(): suspend () -> BigDecimal = recipe().fixUnit() private suspend fun Input.recipe(): suspend (Unit) -> BigDecimal = - accountsAct then { - it.filter { acc -> acc.includeInBalance } - } then { - it.map { acc -> calcAccBalanceAct(CalcAccBalanceAct.Input(acc)) } - } then { - it.map { balanceOutput -> - exchangeAct( - ExchangeAct.Input( - baseCurrency = baseCurrency, - fromCurrency = balanceOutput.account.currency.toOption(), - toCurrency = balanceCurrency, - amount = balanceOutput.balance - ) + accountsAct thenFilter { + it.includeInBalance + } thenMap { + calcAccBalanceAct(CalcAccBalanceAct.Input(it)) + } thenMap { + exchangeAct( + ExchangeAct.Input( + baseCurrency = baseCurrency, + fromCurrency = it.account.currency.toOption(), + toCurrency = balanceCurrency, + amount = it.balance ) - } - } then { balances -> - balances.sumOf { it.orNull() ?: BigDecimal.ZERO } + ) + } thenSum { + it.orNull() ?: BigDecimal.ZERO } data class Input( diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 1aef9faa04..eb5ed938c8 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -100,12 +100,16 @@ class HomeViewModel @Inject constructor( val timeRange = period.toRange(ivyContext.startDayOfMonth) - //TODO: Fix that! -// updateState { -// it.copy( -// balance = calcAccountBalanceAct(settings.currency) -// ) -// } + updateState { + it.copy( + balance = calcAccountBalanceAct( + CalcWalletBalanceAct.Input( + baseCurrency = settings.currency, + balanceCurrency = settings.currency + ) + ) + ) + } updateState { it.copy( From 69a208b59cc55bceecc5f0d069b5d6c26fc41fd8 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Thu, 21 Apr 2022 22:16:40 +0300 Subject: [PATCH 08/40] WIP: `domain.fp` re-work --- .../domain/action/{wallet => }/ExchangeAct.kt | 10 +-- .../domain/action/account/AccTrnsAct.kt | 2 +- .../domain/action/account/AccountsAct.kt | 2 +- .../{wallet => account}/CalcAccBalanceAct.kt | 7 +- .../domain/action/{ => framework}/Action.kt | 2 +- .../action/{ => framework}/Composition.kt | 2 +- .../{ => framework}/CompositionFilter.kt | 2 +- .../action/{ => framework}/CompositionMap.kt | 2 +- .../action/{ => framework}/CompositionSum.kt | 2 +- .../domain/action/{ => framework}/FPAction.kt | 2 +- .../domain/action/settings/BaseCurrencyAct.kt | 2 +- .../HistoryWithDateDivAct.kt | 5 +- .../domain/action/wallet/CalcOverdueAct.kt | 2 +- .../domain/action/wallet/CalcUpcomingAct.kt | 2 +- .../action/wallet/CalcWalletBalanceAct.kt | 4 +- .../fp/{ExchangeRates.kt => Exchange.kt} | 90 +++++-------------- .../domain/fp/core/CoreValueFunctions.kt | 28 ------ .../java/com/ivy/wallet/domain/fp/core/FP.kt | 5 ++ .../ivy/wallet/domain/fp/wallet/WalletCore.kt | 54 +++++++---- .../domain/fp/wallet/WalletTransactions.kt | 83 +++++++++-------- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 2 +- 21 files changed, 133 insertions(+), 177 deletions(-) rename app/src/main/java/com/ivy/wallet/domain/action/{wallet => }/ExchangeAct.kt (74%) rename app/src/main/java/com/ivy/wallet/domain/action/{wallet => account}/CalcAccBalanceAct.kt (86%) rename app/src/main/java/com/ivy/wallet/domain/action/{ => framework}/Action.kt (93%) rename app/src/main/java/com/ivy/wallet/domain/action/{ => framework}/Composition.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/action/{ => framework}/CompositionFilter.kt (89%) rename app/src/main/java/com/ivy/wallet/domain/action/{ => framework}/CompositionMap.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/action/{ => framework}/CompositionSum.kt (93%) rename app/src/main/java/com/ivy/wallet/domain/action/{ => framework}/FPAction.kt (80%) rename app/src/main/java/com/ivy/wallet/domain/action/{wallet => transaction}/HistoryWithDateDivAct.kt (82%) rename app/src/main/java/com/ivy/wallet/domain/fp/{ExchangeRates.kt => Exchange.kt} (53%) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/core/CoreValueFunctions.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt similarity index 74% rename from app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt index cf756d705d..ed02d082d5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/ExchangeAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt @@ -1,7 +1,7 @@ -package com.ivy.wallet.domain.action.wallet +package com.ivy.wallet.domain.action import arrow.core.Option -import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.action.framework.FPAction import com.ivy.wallet.domain.fp.exchange import com.ivy.wallet.io.persistence.dao.ExchangeRateDao import java.math.BigDecimal @@ -15,10 +15,10 @@ class ExchangeAct @Inject constructor( io { exchange( baseCurrencyCode = baseCurrency, - exchangeRateDao = exchangeRateDao, - fromAmount = amount, + amount = amount, fromCurrencyCode = fromCurrency, - toCurrencyCode = toCurrency + toCurrencyCode = toCurrency, + getExchangeRate = exchangeRateDao::findByBaseCurrencyAndCurrency ) } } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt index 3f18483b40..3af4ac9776 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.account -import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.action.framework.FPAction import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.fp.data.ClosedTimeRange import com.ivy.wallet.io.persistence.dao.TransactionDao diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt index 2921d3406f..4139fda1e1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.account -import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.action.framework.FPAction import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.io.persistence.dao.AccountDao import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt similarity index 86% rename from app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt index 01751a3105..52b7d431f4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -1,9 +1,8 @@ -package com.ivy.wallet.domain.action.wallet +package com.ivy.wallet.domain.action.account import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.action.FPAction -import com.ivy.wallet.domain.action.account.AccTrnsAct -import com.ivy.wallet.domain.action.then +import com.ivy.wallet.domain.action.framework.FPAction +import com.ivy.wallet.domain.action.framework.then import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.fp.account.AccountValueFunctions import com.ivy.wallet.domain.fp.account.calcAccValues diff --git a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt b/app/src/main/java/com/ivy/wallet/domain/action/framework/Action.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/action/Action.kt rename to app/src/main/java/com/ivy/wallet/domain/action/framework/Action.kt index 5de7d11243..07e9eabc6b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/framework/Action.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action +package com.ivy.wallet.domain.action.framework import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext diff --git a/app/src/main/java/com/ivy/wallet/domain/action/Composition.kt b/app/src/main/java/com/ivy/wallet/domain/action/framework/Composition.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/action/Composition.kt rename to app/src/main/java/com/ivy/wallet/domain/action/framework/Composition.kt index f9f39e51cf..806977879c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/Composition.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/framework/Composition.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action +package com.ivy.wallet.domain.action.framework suspend infix fun (suspend (A) -> B).then(f: suspend (B) -> C): suspend (A) -> C = diff --git a/app/src/main/java/com/ivy/wallet/domain/action/CompositionFilter.kt b/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionFilter.kt similarity index 89% rename from app/src/main/java/com/ivy/wallet/domain/action/CompositionFilter.kt rename to app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionFilter.kt index f158a90cba..2c0cb36f49 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/CompositionFilter.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionFilter.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action +package com.ivy.wallet.domain.action.framework suspend infix fun (suspend (A) -> List).thenFilter( predicate: (B) -> Boolean diff --git a/app/src/main/java/com/ivy/wallet/domain/action/CompositionMap.kt b/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionMap.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/action/CompositionMap.kt rename to app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionMap.kt index 030693a946..ee88be3d67 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/CompositionMap.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionMap.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action +package com.ivy.wallet.domain.action.framework suspend infix fun (suspend (A) -> List).thenMap( transform: suspend (B) -> C diff --git a/app/src/main/java/com/ivy/wallet/domain/action/CompositionSum.kt b/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionSum.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/action/CompositionSum.kt rename to app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionSum.kt index 27ebc0d769..739a0ac507 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/CompositionSum.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionSum.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action +package com.ivy.wallet.domain.action.framework import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt b/app/src/main/java/com/ivy/wallet/domain/action/framework/FPAction.kt similarity index 80% rename from app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt rename to app/src/main/java/com/ivy/wallet/domain/action/framework/FPAction.kt index 716623ab68..1100eacfb5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/FPAction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/framework/FPAction.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action +package com.ivy.wallet.domain.action.framework abstract class FPAction : Action() { protected abstract suspend fun I.compose(): (suspend () -> O) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt index fdc5294578..832530dc65 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.settings -import com.ivy.wallet.domain.action.FPAction +import com.ivy.wallet.domain.action.framework.FPAction import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode import com.ivy.wallet.io.persistence.dao.SettingsDao import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/HistoryWithDateDivAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt similarity index 82% rename from app/src/main/java/com/ivy/wallet/domain/action/wallet/HistoryWithDateDivAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt index 43b92e8ea4..e51d0a504a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/HistoryWithDateDivAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt @@ -1,10 +1,9 @@ -package com.ivy.wallet.domain.action.wallet +package com.ivy.wallet.domain.action.transaction -import com.ivy.wallet.domain.action.Action +import com.ivy.wallet.domain.action.framework.Action import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.fp.data.ClosedTimeRange import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.historyWithDateDividers import javax.inject.Inject class HistoryWithDateDivAct @Inject constructor( diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt index 0de83c8845..8d9194a5a5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.wallet -import com.ivy.wallet.domain.action.Action +import com.ivy.wallet.domain.action.framework.Action import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.fp.data.IncomeExpensePair import com.ivy.wallet.domain.logic.WalletLogic diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt index 0b82883c9a..9440020219 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.wallet -import com.ivy.wallet.domain.action.Action +import com.ivy.wallet.domain.action.framework.Action import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.fp.data.IncomeExpensePair import com.ivy.wallet.domain.logic.WalletLogic diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index 00337cddeb..d5f991aafd 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -1,8 +1,10 @@ package com.ivy.wallet.domain.action.wallet import arrow.core.toOption -import com.ivy.wallet.domain.action.* +import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.account.CalcAccBalanceAct +import com.ivy.wallet.domain.action.framework.* import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/ExchangeRates.kt b/app/src/main/java/com/ivy/wallet/domain/fp/Exchange.kt similarity index 53% rename from app/src/main/java/com/ivy/wallet/domain/fp/ExchangeRates.kt rename to app/src/main/java/com/ivy/wallet/domain/fp/Exchange.kt index 5899266a35..ae9c68d6eb 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/ExchangeRates.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/Exchange.kt @@ -7,90 +7,48 @@ import arrow.core.computations.option import arrow.core.toOption import com.ivy.wallet.domain.data.entity.ExchangeRate import com.ivy.wallet.domain.fp.core.Pure -import com.ivy.wallet.domain.fp.core.Total -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao +import com.ivy.wallet.domain.fp.core.SideEffect import com.ivy.wallet.utils.isNotNullOrBlank import java.math.BigDecimal -@Total -suspend fun exchangeToBaseCurrency( - exchangeRateDao: ExchangeRateDao, - baseCurrencyCode: String, - fromCurrencyCode: String, - fromAmount: BigDecimal, -): Option { - return exchangeToBaseCurrency( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = fromCurrencyCode.toOption(), - fromAmount = fromAmount - ) -} +data class ExchangeData( + val baseCurrency: String, + val fromCurrency: Option, + val toCurrency: String, +) -@Total -suspend fun exchangeToBaseCurrency( - exchangeRateDao: ExchangeRateDao, - baseCurrencyCode: String, - fromCurrencyCode: Option, - fromAmount: BigDecimal, -): Option { - return exchange( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = fromCurrencyCode, - fromAmount = fromAmount, - toCurrencyCode = baseCurrencyCode, - ) -} -@Total +@Pure suspend fun exchange( - exchangeRateDao: ExchangeRateDao, - baseCurrencyCode: String, - fromCurrencyCode: Option, - fromAmount: BigDecimal, - toCurrencyCode: String, -): Option { - return exchange( - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = fromCurrencyCode, - fromAmount = fromAmount, - toCurrencyCode = toCurrencyCode, - retrieveExchangeRate = exchangeRateDao::findByBaseCurrencyAndCurrency - ) -} + data: ExchangeData, + amount: BigDecimal, -@Total -suspend fun exchange( - baseCurrencyCode: String, - fromCurrencyCode: Option, - fromAmount: BigDecimal, - toCurrencyCode: String, - retrieveExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, + @SideEffect + getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, ): Option = option { - if (fromAmount == BigDecimal.ZERO) { + if (amount == BigDecimal.ZERO) { return@option BigDecimal.ZERO } - val fromCurrency = fromCurrencyCode.bind().validateCurrency().bind() - val toCurrency = toCurrencyCode.validateCurrency().bind() + val fromCurrency = data.fromCurrency.bind().validateCurrency().bind() + val toCurrency = data.toCurrency.validateCurrency().bind() if (fromCurrency == toCurrency) { - return@option fromAmount + return@option amount } - when (val baseCurrency = baseCurrencyCode.validateCurrency().bind()) { + when (val baseCurrency = data.baseCurrency.validateCurrency().bind()) { fromCurrency -> { //exchange from base currency to other currency //we need the rate from baseCurrency to toCurrency val rateFromTo = validExchangeRate( baseCurrency = fromCurrency, //fromCurrency = baseCurrency toCurrency = toCurrency, - retrieveExchangeRate = retrieveExchangeRate + retrieveExchangeRate = getExchangeRate ).bind() //toAmount = fromAmount * rateFromTo - fromAmount * rateFromTo + amount * rateFromTo } toCurrency -> { //exchange from other currency to base currency @@ -99,7 +57,7 @@ suspend fun exchange( val rateToFrom = validExchangeRate( baseCurrency = toCurrency, //toCurrency = baseCurrency toCurrency = fromCurrency, - retrieveExchangeRate = retrieveExchangeRate + retrieveExchangeRate = getExchangeRate ).bind() /* @@ -111,7 +69,7 @@ suspend fun exchange( EXPECTED: 10 EUR ~= 19.67 BGN */ - fromAmount / rateToFrom + amount / rateToFrom } else -> { //exchange from other currency to other currency @@ -120,17 +78,17 @@ suspend fun exchange( val rateBaseFrom = validExchangeRate( baseCurrency = baseCurrency, toCurrency = fromCurrency, - retrieveExchangeRate = retrieveExchangeRate + retrieveExchangeRate = getExchangeRate ).bind() val rateBaseTo = validExchangeRate( baseCurrency = baseCurrency, toCurrency = toCurrency, - retrieveExchangeRate = retrieveExchangeRate + retrieveExchangeRate = getExchangeRate ).bind() //Convert: toBaseCurrency -> toToCurrency - val amountBaseCurrency = fromAmount / rateBaseFrom + val amountBaseCurrency = amount / rateBaseFrom amountBaseCurrency * rateBaseTo } } @@ -141,7 +99,7 @@ private fun String.validateCurrency(): Option { return if (this.isNotNullOrBlank()) return Some(this) else None } -@Total +@Pure suspend fun validExchangeRate( baseCurrency: String, toCurrency: String, diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/CoreValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/core/CoreValueFunctions.kt deleted file mode 100644 index ce1d113b37..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/CoreValueFunctions.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.ivy.wallet.domain.fp.core - -import arrow.core.toOption -import com.ivy.wallet.domain.fp.data.FPTransaction -import com.ivy.wallet.domain.fp.exchange -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao -import java.math.BigDecimal - -data class ExchangeData( - val exchangeRateDao: ExchangeRateDao, - val accountDao: AccountDao, - val baseCurrencyCode: String, - val toCurrency: String, -) - -suspend fun amountInCurrency(fpTransaction: FPTransaction, data: ExchangeData): BigDecimal { - val fromCurrencyCode = - data.accountDao.findById(fpTransaction.accountId)?.currency.toOption() - - return exchange( - exchangeRateDao = data.exchangeRateDao, - baseCurrencyCode = data.baseCurrencyCode, - fromCurrencyCode = fromCurrencyCode, - fromAmount = fpTransaction.amount, - toCurrencyCode = data.toCurrency - ).orNull() ?: BigDecimal.ZERO -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt b/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt index f5d7feb972..2e4bda4b0c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt @@ -16,6 +16,11 @@ annotation class Total annotation class Partial(val inCaseOf: String = "") +@Target(AnnotationTarget.VALUE_PARAMETER) +@Retention(AnnotationRetention.SOURCE) +@MustBeDocumented +annotation class SideEffect + infix fun ((A) -> B).compose(fn2: (B) -> C): (A) -> C = { a -> val b = this(a) val c = fn2(b) diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt index 0006f1199f..65daf61c4d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt @@ -2,16 +2,19 @@ package com.ivy.wallet.domain.fp.wallet import arrow.core.NonEmptyList import arrow.core.Some +import arrow.core.toOption import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.entity.ExchangeRate import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.fp.ExchangeData import com.ivy.wallet.domain.fp.account.AccountValueFunction import com.ivy.wallet.domain.fp.account.calcAccValues +import com.ivy.wallet.domain.fp.core.SideEffect import com.ivy.wallet.domain.fp.core.Uncertain import com.ivy.wallet.domain.fp.core.mapIndexedNel import com.ivy.wallet.domain.fp.core.nonEmptyListOfZeros import com.ivy.wallet.domain.fp.data.* -import com.ivy.wallet.domain.fp.exchangeToBaseCurrency -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao +import com.ivy.wallet.domain.fp.exchange import com.ivy.wallet.utils.scopedIOThread import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -26,7 +29,10 @@ suspend fun calculateWalletValues( baseCurrencyCode: String, filterExcluded: Boolean = true, range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), - valueFunctions: NonEmptyList + valueFunctions: NonEmptyList, + + @SideEffect + getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, ): UncertainWalletValues { val uncertainWalletValues = walletDAOs.accountDao.findAll() .filter { !filterExcluded || it.includeInBalance } @@ -42,8 +48,8 @@ suspend fun calculateWalletValues( ) } .convertValuesInBaseCurrency( - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode + baseCurrency = baseCurrencyCode, + getExchangeRate = getExchangeRate ) return sumUncertainWalletValues( @@ -55,8 +61,10 @@ suspend fun calculateWalletValues( suspend fun sumAccountValuesInCurrency( accountTrns: List>>, baseCurrencyCode: String, - exchangeRateDao: ExchangeRateDao, - valueFunctions: NonEmptyList + valueFunctions: NonEmptyList, + + @SideEffect + getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, ): UncertainWalletValues { val uncertainWalletValues = accountTrns.map { (account, trns) -> Pair( @@ -68,8 +76,8 @@ suspend fun sumAccountValuesInCurrency( ) ) }.convertValuesInBaseCurrency( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrencyCode + baseCurrency = baseCurrencyCode, + getExchangeRate = getExchangeRate ) return sumUncertainWalletValues( @@ -84,7 +92,10 @@ suspend fun calculateWalletValuesWithAccountFilters( filterExcluded: Boolean = true, accountIdFilterList: List, range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), - valueFunctions: NonEmptyList + valueFunctions: NonEmptyList, + + @SideEffect + getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, ): UncertainWalletValues { val accounts = scopedIOThread { scope -> @@ -113,8 +124,8 @@ suspend fun calculateWalletValuesWithAccountFilters( ) } .convertValuesInBaseCurrency( - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode + baseCurrency = baseCurrencyCode, + getExchangeRate = getExchangeRate ) return sumUncertainWalletValues( @@ -124,16 +135,21 @@ suspend fun calculateWalletValuesWithAccountFilters( } private suspend fun Iterable.convertValuesInBaseCurrency( - exchangeRateDao: ExchangeRateDao, - baseCurrencyCode: String, + baseCurrency: String, + + @SideEffect + getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, ): List { return this.map { (account, values) -> val valuesInBaseCurrency = values.map { - exchangeToBaseCurrency( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = account.currencyCode, - fromAmount = it + exchange( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = account.currencyCode.toOption(), + toCurrency = baseCurrency + ), + amount = it, + getExchangeRate = getExchangeRate ) } val hasError = valuesInBaseCurrency.any { !it.isDefined() } diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt index 6742e592b3..dcf0232c80 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt @@ -1,49 +1,30 @@ package com.ivy.wallet.domain.fp.wallet +import arrow.core.Option +import arrow.core.toOption import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem +import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.fp.ExchangeData import com.ivy.wallet.domain.fp.core.* -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao -import com.ivy.wallet.io.persistence.dao.TransactionDao +import com.ivy.wallet.domain.fp.data.FPTransaction import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds +import java.math.BigDecimal +import java.util.* //TODO: overdue(range) //TODO: upcoming(range) -suspend fun historyWithDateDividers( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - range: ClosedTimeRange -): List { - return history( - transactionDao = walletDAOs.transactionDao, - range = range - ).withDateDividers( - exchangeRateDao = walletDAOs.exchangeRateDao, - accountDao = walletDAOs.accountDao, - baseCurrencyCode = baseCurrencyCode - ) -} - -suspend fun history( - transactionDao: TransactionDao, - range: ClosedTimeRange -): List { - return transactionDao.findAllBetween( - startDate = range.from, - endDate = range.to - ) -} - +@Pure suspend fun List.withDateDividers( - exchangeRateDao: ExchangeRateDao, - accountDao: AccountDao, baseCurrencyCode: String, + + @SideEffect + getAccount: suspend (accountId: UUID) -> Account?, + @SideEffect + exchange: suspend (ExchangeData, BigDecimal) -> Option ): List { val history = this if (history.isEmpty()) return emptyList() @@ -56,12 +37,12 @@ suspend fun List.withDateDividers( (date2.atStartOfDay().toEpochSeconds() - date1.atStartOfDay().toEpochSeconds()).toInt() } .flatMap { (date, transactionsForDate) -> - val baseCurrencyExchangeData = ExchangeData( - exchangeRateDao = exchangeRateDao, - accountDao = accountDao, - baseCurrencyCode = baseCurrencyCode, - toCurrency = baseCurrencyCode + val arg = AmountInCurrencyArgument( + baseCurrency = baseCurrencyCode, + getAccount = getAccount, + exchange = exchange ) + val fpTransactions = transactionsForDate.toFPTransactions() listOf( @@ -70,14 +51,38 @@ suspend fun List.withDateDividers( income = sum( incomes(fpTransactions), ::amountInCurrency, - baseCurrencyExchangeData + arg ).toDouble(), expenses = sum( expenses(fpTransactions), ::amountInCurrency, - baseCurrencyExchangeData + arg ).toDouble() ), ).plus(transactionsForDate) } +} + +data class AmountInCurrencyArgument( + val baseCurrency: String, + @SideEffect + val getAccount: suspend (accountId: UUID) -> Account?, + @SideEffect + val exchange: suspend (ExchangeData, BigDecimal) -> Option +) + +suspend fun amountInCurrency( + fpTransaction: FPTransaction, + arg: AmountInCurrencyArgument +): BigDecimal { + val fromCurrencyCode = arg.getAccount(fpTransaction.accountId)?.currency.toOption() + + return arg.exchange( + ExchangeData( + baseCurrency = arg.baseCurrency, + fromCurrency = fromCurrencyCode, + toCurrency = arg.baseCurrency + ), + fpTransaction.amount + ).orNull() ?: BigDecimal.ZERO } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index eb5ed938c8..cc1efa8ce7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -4,10 +4,10 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation import com.ivy.design.viewmodel.IvyViewModel +import com.ivy.wallet.domain.action.transaction.HistoryWithDateDivAct import com.ivy.wallet.domain.action.wallet.CalcOverdueAct import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct -import com.ivy.wallet.domain.action.wallet.HistoryWithDateDivAct import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.fp.data.WalletDAOs import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpense From b103bdae34b1e23a2ba38159bfe822ac1bf9d802 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Thu, 21 Apr 2022 22:35:50 +0300 Subject: [PATCH 09/40] WIP: Refactor --- .../action/account/CalcAccBalanceAct.kt | 7 +- .../domain/action/charts/BalanceChartAct.kt | 34 ++++++++++ .../domain/action/settings/BaseCurrencyAct.kt | 7 +- .../action/wallet/CalcWalletBalanceAct.kt | 11 +++- .../wallet/domain/fp/charts/WalletCharts.kt | 31 +++++---- .../domain/fp/wallet/WalletFunctions.kt | 66 +------------------ .../wallet/ui/accounts/AccountsViewModel.kt | 17 +++-- .../ivy/wallet/ui/balance/BalanceViewModel.kt | 20 +++--- .../ivy/wallet/ui/charts/ChartsViewModel.kt | 28 +++++--- 9 files changed, 102 insertions(+), 119 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt index 52b7d431f4..1ff98ee666 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -17,7 +17,7 @@ class CalcAccBalanceAct @Inject constructor( override suspend fun Input.compose(): suspend () -> Output = suspend { AccTrnsAct.Input( accountId = account.id, - range = ClosedTimeRange.allTimeIvy() + range = range ) } then accTrnsAct then { accTrns -> calcAccValues( @@ -33,11 +33,12 @@ class CalcAccBalanceAct @Inject constructor( } data class Input( - val account: Account + val account: Account, + val range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() ) data class Output( val account: Account, - val balance: BigDecimal + val balance: BigDecimal, ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt new file mode 100644 index 0000000000..20a75534c3 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt @@ -0,0 +1,34 @@ +package com.ivy.wallet.domain.action.charts + +import com.ivy.wallet.domain.action.framework.FPAction +import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct +import com.ivy.wallet.domain.fp.charts.ChartPeriod +import com.ivy.wallet.domain.fp.charts.SingleChartPoint +import com.ivy.wallet.domain.fp.charts.balanceChart +import javax.inject.Inject + +class BalanceChartAct @Inject constructor( + private val calcWalletBalanceAct: CalcWalletBalanceAct +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + io { + balanceChart( + period = period, + calcWalletBalance = { range -> + calcWalletBalanceAct( + CalcWalletBalanceAct.Input( + baseCurrency = baseCurrency, + range = range + ) + ) + } + ) + } + } + + data class Input( + val baseCurrency: String, + val period: ChartPeriod + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt index 832530dc65..5be79a4db4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt @@ -1,16 +1,13 @@ package com.ivy.wallet.domain.action.settings import com.ivy.wallet.domain.action.framework.FPAction -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode import com.ivy.wallet.io.persistence.dao.SettingsDao import javax.inject.Inject class BaseCurrencyAct @Inject constructor( private val settingsDao: SettingsDao ) : FPAction() { - override suspend fun Unit.compose(): suspend () -> String { - return suspend { - io { baseCurrencyCode(settingsDao) } - } + override suspend fun Unit.compose(): suspend () -> String = suspend { + io { settingsDao.findFirst().currency } } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index d5f991aafd..8a4977c43e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -5,6 +5,7 @@ import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.account.CalcAccBalanceAct import com.ivy.wallet.domain.action.framework.* +import com.ivy.wallet.domain.fp.data.ClosedTimeRange import java.math.BigDecimal import javax.inject.Inject @@ -20,7 +21,12 @@ class CalcWalletBalanceAct @Inject constructor( accountsAct thenFilter { it.includeInBalance } thenMap { - calcAccBalanceAct(CalcAccBalanceAct.Input(it)) + calcAccBalanceAct( + CalcAccBalanceAct.Input( + account = it, + range = range + ) + ) } thenMap { exchangeAct( ExchangeAct.Input( @@ -36,6 +42,7 @@ class CalcWalletBalanceAct @Inject constructor( data class Input( val baseCurrency: String, - val balanceCurrency: String + val balanceCurrency: String = baseCurrency, + val range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt b/app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt index 6411414586..2059991807 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt @@ -1,9 +1,10 @@ package com.ivy.wallet.domain.fp.charts +import com.ivy.wallet.domain.fp.core.Pure +import com.ivy.wallet.domain.fp.core.SideEffect import com.ivy.wallet.domain.fp.data.ClosedTimeRange import com.ivy.wallet.domain.fp.data.IncomeExpensePair import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletBalance import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpense import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpenseCount import com.ivy.wallet.utils.beginningOfIvyTime @@ -15,10 +16,12 @@ data class ToRange( val to: LocalDateTime ) +@Pure suspend fun balanceChart( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - period: ChartPeriod + period: ChartPeriod, + + @SideEffect + calcWalletBalance: suspend (ClosedTimeRange) -> BigDecimal ): List { val orderedPeriod = period.toRangesList().sortedBy { it.to.toEpochSeconds() @@ -26,21 +29,17 @@ suspend fun balanceChart( return generateBalanceChart( orderedPeriod = orderedPeriod.map { ToRange(it.to) }, - calculateWalletBalance = { range -> - calculateWalletBalance( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = true, - range = range - ).value - } + calcWalletBalance = calcWalletBalance ) } +@Pure tailrec suspend fun generateBalanceChart( orderedPeriod: List, - calculateWalletBalance: suspend (range: ClosedTimeRange) -> BigDecimal, - accumulator: List = emptyList() + accumulator: List = emptyList(), + + @SideEffect + calcWalletBalance: suspend (ClosedTimeRange) -> BigDecimal ): List { return if (orderedPeriod.isEmpty()) accumulator else { //recurse @@ -49,7 +48,7 @@ tailrec suspend fun generateBalanceChart( val chartPoint = ChartPoint( range = ClosedTimeRange.to(to = toDateTime), - value = calculateWalletBalance( + value = calcWalletBalance( ClosedTimeRange( from = previousChartPoint?.range?.to?.plusSeconds(1) ?: beginningOfIvyTime(), to = toDateTime @@ -59,7 +58,7 @@ tailrec suspend fun generateBalanceChart( generateBalanceChart( orderedPeriod = orderedPeriod.drop(1), - calculateWalletBalance = calculateWalletBalance, + calcWalletBalance = calcWalletBalance, accumulator = accumulator.plus(chartPoint) ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt index 2e1b844447..a7cc8da436 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt @@ -19,56 +19,13 @@ fun walletBufferDiff( return balance - settings.bufferAmount.toBigDecimal() } +@Deprecated("Side-effects must be handled by Actions") suspend fun baseCurrencyCode( settingsDao: SettingsDao ): String { return settingsDao.findFirst().currency } -suspend fun calculateWalletBalance( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::balance - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - -suspend fun calculateWalletIncome( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::income - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - suspend fun calculateWalletIncomeWithAccountFilters( walletDAOs: WalletDAOs, baseCurrencyCode: String, @@ -93,27 +50,6 @@ suspend fun calculateWalletIncomeWithAccountFilters( ) } -suspend fun calculateWalletExpense( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::expense - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} suspend fun calculateWalletExpenseWithAccountFilters( walletDAOs: WalletDAOs, diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt index a0601924e6..8bd3687730 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt @@ -3,6 +3,7 @@ package com.ivy.wallet.ui.accounts import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.event.AccountsUpdatedEvent import com.ivy.wallet.domain.fp.account.calculateAccountBalance @@ -10,7 +11,6 @@ import com.ivy.wallet.domain.fp.account.calculateAccountIncomeExpense import com.ivy.wallet.domain.fp.data.WalletDAOs import com.ivy.wallet.domain.fp.exchangeToBaseCurrency import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.domain.fp.wallet.calculateWalletBalance import com.ivy.wallet.domain.logic.AccountCreator import com.ivy.wallet.domain.sync.item.AccountSync import com.ivy.wallet.io.persistence.dao.AccountDao @@ -36,7 +36,8 @@ class AccountsViewModel @Inject constructor( private val accountSync: AccountSync, private val accountCreator: AccountCreator, private val ivyContext: IvyWalletCtx, - private val accountsAct: AccountsAct + private val accountsAct: AccountsAct, + private val calcWalletBalanceAct: CalcWalletBalanceAct ) : ViewModel() { @Subscribe @@ -104,13 +105,11 @@ class AccountsViewModel @Inject constructor( } } - _totalBalanceWithExcluded.value = ioThread { - calculateWalletBalance( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = false - ).value.toDouble() - } + _totalBalanceWithExcluded.value = calcWalletBalanceAct( + CalcWalletBalanceAct.Input( + baseCurrency = baseCurrencyCode + ) + ).toDouble() TestIdlingResource.decrement() } diff --git a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt index e521918d3b..e0457f0626 100644 --- a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt @@ -2,9 +2,9 @@ package com.ivy.wallet.ui.balance import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.domain.fp.wallet.calculateWalletBalance import com.ivy.wallet.domain.logic.PlannedPaymentsLogic import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx @@ -22,7 +22,9 @@ class BalanceViewModel @Inject constructor( private val walletDAOs: WalletDAOs, private val settingsDao: SettingsDao, private val plannedPaymentsLogic: PlannedPaymentsLogic, - private val ivyContext: IvyWalletCtx + private val ivyContext: IvyWalletCtx, + private val baseCurrencyAct: BaseCurrencyAct, + private val calcWalletBalanceAct: CalcWalletBalanceAct ) : ViewModel() { private val _period = MutableStateFlow(ivyContext.selectedPeriod) @@ -42,16 +44,14 @@ class BalanceViewModel @Inject constructor( fun start(period: TimePeriod = ivyContext.selectedPeriod) { viewModelScope.launch { - _baseCurrencyCode.value = ioThread { baseCurrencyCode(settingsDao) } + _baseCurrencyCode.value = baseCurrencyAct(Unit) _period.value = period - val currentBalance = ioThread { - calculateWalletBalance( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value - ).value.toDouble() - } + val currentBalance = calcWalletBalanceAct( + CalcWalletBalanceAct.Input(baseCurrencyCode.value) + ).toDouble() + _currentBalance.value = currentBalance val plannedPaymentsAmount = ioThread { diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt index f8374fd98a..7d1dc627a7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt @@ -2,9 +2,15 @@ package com.ivy.wallet.ui.charts import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.wallet.domain.action.charts.BalanceChartAct +import com.ivy.wallet.domain.action.framework.then +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.fp.charts.* +import com.ivy.wallet.domain.fp.charts.ChartPeriod +import com.ivy.wallet.domain.fp.charts.IncomeExpenseChartPoint +import com.ivy.wallet.domain.fp.charts.SingleChartPoint +import com.ivy.wallet.domain.fp.charts.incomeExpenseChart import com.ivy.wallet.domain.fp.data.WalletDAOs import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode import com.ivy.wallet.domain.logic.WalletCategoryLogic @@ -26,7 +32,9 @@ class ChartsViewModel @Inject constructor( private val walletDAOs: WalletDAOs, private val settingsDao: SettingsDao, private val categoryDao: CategoryDao, - private val walletCategoryLogic: WalletCategoryLogic + private val walletCategoryLogic: WalletCategoryLogic, + private val baseCurrencyAct: BaseCurrencyAct, + private val balanceChartAct: BalanceChartAct ) : ViewModel() { private val _period = MutableStateFlow(ChartPeriod.LAST_12_MONTHS) @@ -79,13 +87,15 @@ class ChartsViewModel @Inject constructor( _incomeExpenseChart.value = generateIncomeExpenseChart(period) } - private suspend fun generateBalanceChart(period: ChartPeriod) = ioThread { - balanceChart( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - period = period - ) - } + private suspend fun generateBalanceChart(period: ChartPeriod) = + (baseCurrencyAct then { baseCurrency -> + balanceChartAct( + BalanceChartAct.Input( + baseCurrency = baseCurrency, + period = period + ) + ) + })(Unit) private suspend fun generateIncomeExpenseChart(period: ChartPeriod) = ioThread { incomeExpenseChart( From 13dd3f8ae5df0dc2692ccbbd8ec69fad58848fe6 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 17:08:16 +0300 Subject: [PATCH 10/40] Rename `fp` to `pure` --- .../main/java/com/ivy/wallet/AppModuleDI.kt | 2 +- .../ivy/wallet/domain/action/ExchangeAct.kt | 2 +- .../domain/action/account/AccTrnsAct.kt | 2 +- .../action/account/CalcAccBalanceAct.kt | 6 ++-- .../domain/action/charts/BalanceChartAct.kt | 6 ++-- .../transaction/HistoryWithDateDivAct.kt | 4 +-- .../domain/action/wallet/CalcOverdueAct.kt | 2 +- .../domain/action/wallet/CalcUpcomingAct.kt | 2 +- .../action/wallet/CalcWalletBalanceAct.kt | 2 +- .../wallet/domain/{fp => pure}/Exchange.kt | 6 ++-- .../{fp => pure}/account/AccountCore.kt | 12 ++++---- .../{fp => pure}/account/AccountFunctions.kt | 6 ++-- .../account/AccountValueFunctions.kt | 6 ++-- .../{fp => pure}/category/CategoryCore.kt | 10 +++---- .../category/CategoryFunctions.kt | 6 ++-- .../category/CategoryValueFunctions.kt | 8 ++--- .../domain/{fp => pure}/charts/ChartPeriod.kt | 14 ++++----- .../domain/{fp => pure}/charts/ChartsCore.kt | 6 ++-- .../{fp => pure}/charts/WalletCharts.kt | 30 +++++++++---------- .../ivy/wallet/domain/{fp => pure}/core/FP.kt | 2 +- .../{fp => pure}/core/TransactionFunctions.kt | 6 ++-- .../domain/{fp => pure}/core/Uncertain.kt | 2 +- .../wallet/domain/{fp => pure}/core/Utils.kt | 2 +- .../domain/{fp => pure}/core/ValueFunction.kt | 4 +-- .../{fp => pure}/data/ClosedTimeRange.kt | 2 +- .../{fp => pure}/data/CurrencyConvError.kt | 2 +- .../domain/{fp => pure}/data/FPAccount.kt | 2 +- .../domain/{fp => pure}/data/FPTransaction.kt | 2 +- .../{fp => pure}/data/IncomeExpensePair.kt | 2 +- .../domain/{fp => pure}/data/WalletDAOs.kt | 2 +- .../domain/{fp => pure}/wallet/WalletCore.kt | 20 ++++++------- .../{fp => pure}/wallet/WalletFunctions.kt | 14 ++++----- .../{fp => pure}/wallet/WalletTransactions.kt | 8 ++--- .../wallet/ui/accounts/AccountsViewModel.kt | 9 +++--- .../ivy/wallet/ui/balance/BalanceViewModel.kt | 2 +- .../com/ivy/wallet/ui/charts/ChartsScreen.kt | 6 ++-- .../ivy/wallet/ui/charts/ChartsViewModel.kt | 12 ++++---- .../com/ivy/wallet/ui/charts/TimeValue.kt | 4 +-- .../wallet/ui/charts/charts/AccountCharts.kt | 2 +- .../wallet/ui/charts/charts/CategoryCharts.kt | 2 +- .../wallet/ui/charts/charts/WalletCharts.kt | 4 +-- .../java/com/ivy/wallet/ui/home/HomeState.kt | 2 +- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 6 ++-- .../ui/onboarding/model/FromToTimeRange.kt | 10 +++---- .../ivy/wallet/ui/reports/ReportViewModel.kt | 2 +- .../level1/PieChartStatisticViewModel.kt | 10 +++---- .../level2/ItemStatisticViewModel.kt | 12 ++++---- 47 files changed, 140 insertions(+), 145 deletions(-) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/Exchange.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/account/AccountCore.kt (86%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/account/AccountFunctions.kt (92%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/account/AccountValueFunctions.kt (93%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/category/CategoryCore.kt (92%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/category/CategoryFunctions.kt (95%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/category/CategoryValueFunctions.kt (93%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/charts/ChartPeriod.kt (89%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/charts/ChartsCore.kt (65%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/charts/WalletCharts.kt (86%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/core/FP.kt (94%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/core/TransactionFunctions.kt (85%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/core/Uncertain.kt (78%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/core/Utils.kt (93%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/core/ValueFunction.kt (94%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/ClosedTimeRange.kt (94%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/CurrencyConvError.kt (56%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/FPAccount.kt (94%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/FPTransaction.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/IncomeExpensePair.kt (85%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/WalletDAOs.kt (88%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/wallet/WalletCore.kt (92%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/wallet/WalletFunctions.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/wallet/WalletTransactions.kt (93%) diff --git a/app/src/main/java/com/ivy/wallet/AppModuleDI.kt b/app/src/main/java/com/ivy/wallet/AppModuleDI.kt index 502a42c43d..0fe70f6ab6 100644 --- a/app/src/main/java/com/ivy/wallet/AppModuleDI.kt +++ b/app/src/main/java/com/ivy/wallet/AppModuleDI.kt @@ -6,7 +6,6 @@ import com.google.gson.GsonBuilder import com.ivy.design.navigation.Navigation import com.ivy.wallet.android.billing.IvyBilling import com.ivy.wallet.android.notification.NotificationService -import com.ivy.wallet.domain.fp.data.WalletDAOs import com.ivy.wallet.domain.logic.* import com.ivy.wallet.domain.logic.bankintegrations.BankIntegrationsLogic import com.ivy.wallet.domain.logic.bankintegrations.SaltEdgeAccountMapper @@ -20,6 +19,7 @@ import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsCore import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic import com.ivy.wallet.domain.logic.zip.ExportZipLogic +import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.domain.sync.IvySync import com.ivy.wallet.domain.sync.item.* import com.ivy.wallet.domain.sync.uploader.* diff --git a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt index ed02d082d5..34b3152e6c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt @@ -2,7 +2,7 @@ package com.ivy.wallet.domain.action import arrow.core.Option import com.ivy.wallet.domain.action.framework.FPAction -import com.ivy.wallet.domain.fp.exchange +import com.ivy.wallet.domain.pure.exchange import com.ivy.wallet.io.persistence.dao.ExchangeRateDao import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt index 3af4ac9776..1c8429fccd 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -2,7 +2,7 @@ package com.ivy.wallet.domain.action.account import com.ivy.wallet.domain.action.framework.FPAction import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.io.persistence.dao.TransactionDao import java.util.* import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt index 1ff98ee666..c651ba72ac 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -4,9 +4,9 @@ import arrow.core.nonEmptyListOf import com.ivy.wallet.domain.action.framework.FPAction import com.ivy.wallet.domain.action.framework.then import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.fp.account.AccountValueFunctions -import com.ivy.wallet.domain.fp.account.calcAccValues -import com.ivy.wallet.domain.fp.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.account.AccountValueFunctions +import com.ivy.wallet.domain.pure.account.calcAccValues +import com.ivy.wallet.domain.pure.data.ClosedTimeRange import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt index 20a75534c3..715efe5444 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt @@ -2,9 +2,9 @@ package com.ivy.wallet.domain.action.charts import com.ivy.wallet.domain.action.framework.FPAction import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct -import com.ivy.wallet.domain.fp.charts.ChartPeriod -import com.ivy.wallet.domain.fp.charts.SingleChartPoint -import com.ivy.wallet.domain.fp.charts.balanceChart +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.balanceChart import javax.inject.Inject class BalanceChartAct @Inject constructor( diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt index e51d0a504a..3fda85b4ac 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt @@ -2,8 +2,8 @@ package com.ivy.wallet.domain.action.transaction import com.ivy.wallet.domain.action.framework.Action import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.WalletDAOs +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.WalletDAOs import javax.inject.Inject class HistoryWithDateDivAct @Inject constructor( diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt index 8d9194a5a5..669acd69c2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt @@ -2,8 +2,8 @@ package com.ivy.wallet.domain.action.wallet import com.ivy.wallet.domain.action.framework.Action import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.IncomeExpensePair import com.ivy.wallet.domain.logic.WalletLogic +import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt index 9440020219..caaed90dc8 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt @@ -2,8 +2,8 @@ package com.ivy.wallet.domain.action.wallet import com.ivy.wallet.domain.action.framework.Action import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.IncomeExpensePair import com.ivy.wallet.domain.logic.WalletLogic +import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index 8a4977c43e..aab216387f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -5,7 +5,7 @@ import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.account.CalcAccBalanceAct import com.ivy.wallet.domain.action.framework.* -import com.ivy.wallet.domain.fp.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.ClosedTimeRange import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/Exchange.kt b/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/fp/Exchange.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt index ae9c68d6eb..d0d8061431 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/Exchange.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp +package com.ivy.wallet.domain.pure import arrow.core.None import arrow.core.Option @@ -6,8 +6,8 @@ import arrow.core.Some import arrow.core.computations.option import arrow.core.toOption import com.ivy.wallet.domain.data.entity.ExchangeRate -import com.ivy.wallet.domain.fp.core.Pure -import com.ivy.wallet.domain.fp.core.SideEffect +import com.ivy.wallet.domain.pure.core.Pure +import com.ivy.wallet.domain.pure.core.SideEffect import com.ivy.wallet.utils.isNotNullOrBlank import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt similarity index 86% rename from app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt index 5e9a347071..e0abaa522a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt @@ -1,12 +1,12 @@ -package com.ivy.wallet.domain.fp.account +package com.ivy.wallet.domain.pure.account import arrow.core.NonEmptyList import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.core.Pure -import com.ivy.wallet.domain.fp.core.Total -import com.ivy.wallet.domain.fp.core.calculateValueFunctionsSum -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.toFPTransaction +import com.ivy.wallet.domain.pure.core.Pure +import com.ivy.wallet.domain.pure.core.Total +import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSum +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.toFPTransaction import com.ivy.wallet.io.persistence.dao.TransactionDao import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt similarity index 92% rename from app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt index e9031cf274..c5907b7b4a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt @@ -1,8 +1,8 @@ -package com.ivy.wallet.domain.fp.account +package com.ivy.wallet.domain.pure.account import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.io.persistence.dao.TransactionDao import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountValueFunctions.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/fp/account/AccountValueFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/account/AccountValueFunctions.kt index c804134621..5f5dbb8648 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountValueFunctions.kt @@ -1,8 +1,8 @@ -package com.ivy.wallet.domain.fp.account +package com.ivy.wallet.domain.pure.account import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.fp.core.ValueFunction -import com.ivy.wallet.domain.fp.data.FPTransaction +import com.ivy.wallet.domain.pure.core.ValueFunction +import com.ivy.wallet.domain.pure.data.FPTransaction import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt similarity index 92% rename from app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryCore.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt index 4ce2586dbb..6dc9dbc9d5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt @@ -1,11 +1,11 @@ -package com.ivy.wallet.domain.fp.category +package com.ivy.wallet.domain.pure.category import arrow.core.NonEmptyList import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.core.calculateValueFunctionsSumSuspend -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.data.toFPTransaction +import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSumSuspend +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.pure.data.toFPTransaction import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryFunctions.kt similarity index 95% rename from app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryFunctions.kt index 2c17284b6f..c5a6e7c5ea 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryFunctions.kt @@ -1,8 +1,8 @@ -package com.ivy.wallet.domain.fp.category +package com.ivy.wallet.domain.pure.category import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.WalletDAOs +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.WalletDAOs import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryValueFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt index bce496e14f..48f16f10e6 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt @@ -1,12 +1,12 @@ -package com.ivy.wallet.domain.fp.category +package com.ivy.wallet.domain.pure.category import arrow.core.Option import arrow.core.toOption import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.fp.core.SuspendValueFunction -import com.ivy.wallet.domain.fp.data.FPTransaction -import com.ivy.wallet.domain.fp.exchangeToBaseCurrency +import com.ivy.wallet.domain.pure.core.SuspendValueFunction +import com.ivy.wallet.domain.pure.data.FPTransaction +import com.ivy.wallet.domain.pure.exchangeToBaseCurrency import com.ivy.wallet.io.persistence.dao.ExchangeRateDao import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartPeriod.kt b/app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartPeriod.kt similarity index 89% rename from app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartPeriod.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartPeriod.kt index 60019d8211..40c1ec1ea0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartPeriod.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartPeriod.kt @@ -1,8 +1,6 @@ -package com.ivy.wallet.domain.fp.charts +package com.ivy.wallet.domain.pure.charts -import com.ivy.wallet.R -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.utils.dateNowUTC import com.ivy.wallet.utils.endOfDayNowUTC import com.ivy.wallet.utils.endOfMonth @@ -17,10 +15,10 @@ enum class ChartPeriod { fun display(): String { return when (this) { - LAST_12_MONTHS -> stringRes(R.string.last_12_months) - LAST_6_MONTHS -> stringRes(R.string.last_6_months) - LAST_4_WEEKS -> stringRes(R.string.last_4_weeks) - LAST_7_DAYS -> stringRes(R.string.last_7_days) + LAST_12_MONTHS -> "Last 12 months" + LAST_6_MONTHS -> "Last 6 months" + LAST_4_WEEKS -> "Last 4 weeks" + LAST_7_DAYS -> "Last 7 days" } } diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartsCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartsCore.kt similarity index 65% rename from app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartsCore.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartsCore.kt index 32cd162b2b..a8baaaf298 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartsCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartsCore.kt @@ -1,7 +1,7 @@ -package com.ivy.wallet.domain.fp.charts +package com.ivy.wallet.domain.pure.charts -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair import java.math.BigDecimal data class ChartPoint( diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt b/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt similarity index 86% rename from app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt index 2059991807..0465f7cfa5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt @@ -1,12 +1,11 @@ -package com.ivy.wallet.domain.fp.charts - -import com.ivy.wallet.domain.fp.core.Pure -import com.ivy.wallet.domain.fp.core.SideEffect -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.IncomeExpensePair -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpense -import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpenseCount +package com.ivy.wallet.domain.pure.charts + +import com.ivy.wallet.domain.pure.core.Pure +import com.ivy.wallet.domain.pure.core.SideEffect +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.pure.wallet.calculateWalletIncomeExpense import com.ivy.wallet.utils.beginningOfIvyTime import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal @@ -122,12 +121,13 @@ suspend fun incomeExpenseCountChart( return generateIncomeExpenseCountChart( orderedPeriod = orderedPeriod, calculateWalletIncomeExpenseCount = { range -> - calculateWalletIncomeExpenseCount( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - range = range, - filterExcluded = true - ).value + TODO() +// calculateWalletIncomeExpenseCount( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode, +// range = range, +// filterExcluded = true +// ).value } ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/FP.kt similarity index 94% rename from app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/core/FP.kt index 2e4bda4b0c..5cdc835a18 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/FP.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.core +package com.ivy.wallet.domain.pure.core @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.SOURCE) diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/TransactionFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt similarity index 85% rename from app/src/main/java/com/ivy/wallet/domain/fp/core/TransactionFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt index a48b38a31a..9e3c7ff7df 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/TransactionFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt @@ -1,9 +1,9 @@ -package com.ivy.wallet.domain.fp.core +package com.ivy.wallet.domain.pure.core import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.FPTransaction -import com.ivy.wallet.domain.fp.data.toFPTransaction +import com.ivy.wallet.domain.pure.data.FPTransaction +import com.ivy.wallet.domain.pure.data.toFPTransaction import java.math.BigDecimal suspend fun sum( diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/Uncertain.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/Uncertain.kt similarity index 78% rename from app/src/main/java/com/ivy/wallet/domain/fp/core/Uncertain.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/core/Uncertain.kt index 024501df1d..912eaf276b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/Uncertain.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/Uncertain.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.core +package com.ivy.wallet.domain.pure.core data class Uncertain, V>( val error: E, diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/Utils.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/Utils.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/fp/core/Utils.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/core/Utils.kt index dc953e5044..06d63fde6e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/Utils.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/Utils.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.core +package com.ivy.wallet.domain.pure.core import arrow.core.NonEmptyList import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/ValueFunction.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt similarity index 94% rename from app/src/main/java/com/ivy/wallet/domain/fp/core/ValueFunction.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt index 7dde3b18e5..a9d0267943 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/ValueFunction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt @@ -1,7 +1,7 @@ -package com.ivy.wallet.domain.fp.core +package com.ivy.wallet.domain.pure.core import arrow.core.NonEmptyList -import com.ivy.wallet.domain.fp.data.FPTransaction +import com.ivy.wallet.domain.pure.data.FPTransaction import java.math.BigDecimal typealias ValueFunction = (FPTransaction, A) -> BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/ClosedTimeRange.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/ClosedTimeRange.kt similarity index 94% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/ClosedTimeRange.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/ClosedTimeRange.kt index a89ce785d0..b9859b7340 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/ClosedTimeRange.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/ClosedTimeRange.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.utils.beginningOfIvyTime diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/CurrencyConvError.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/CurrencyConvError.kt similarity index 56% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/CurrencyConvError.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/CurrencyConvError.kt index fde5cdb0ae..040077ba4c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/CurrencyConvError.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/CurrencyConvError.kt @@ -1,3 +1,3 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data data class CurrencyConvError(val account: FPAccount) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/FPAccount.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt similarity index 94% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/FPAccount.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt index 0e5d8e3758..f0c0559c6a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/FPAccount.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data import arrow.core.Option import arrow.core.toOption diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/FPTransaction.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/FPTransaction.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt index ce220b9627..2b238d48a8 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/FPTransaction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data import arrow.core.Option import arrow.core.toOption diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/IncomeExpensePair.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/IncomeExpensePair.kt similarity index 85% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/IncomeExpensePair.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/IncomeExpensePair.kt index acfa28deb6..e42f1bce9f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/IncomeExpensePair.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/IncomeExpensePair.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/WalletDAOs.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/WalletDAOs.kt similarity index 88% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/WalletDAOs.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/WalletDAOs.kt index 69c8c44e3a..450ed0ea77 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/WalletDAOs.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/WalletDAOs.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.ExchangeRateDao diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt similarity index 92% rename from app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt index 65daf61c4d..5e2c0a4be2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.wallet +package com.ivy.wallet.domain.pure.wallet import arrow.core.NonEmptyList import arrow.core.Some @@ -6,15 +6,15 @@ import arrow.core.toOption import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.data.entity.ExchangeRate import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.ExchangeData -import com.ivy.wallet.domain.fp.account.AccountValueFunction -import com.ivy.wallet.domain.fp.account.calcAccValues -import com.ivy.wallet.domain.fp.core.SideEffect -import com.ivy.wallet.domain.fp.core.Uncertain -import com.ivy.wallet.domain.fp.core.mapIndexedNel -import com.ivy.wallet.domain.fp.core.nonEmptyListOfZeros -import com.ivy.wallet.domain.fp.data.* -import com.ivy.wallet.domain.fp.exchange +import com.ivy.wallet.domain.pure.ExchangeData +import com.ivy.wallet.domain.pure.account.AccountValueFunction +import com.ivy.wallet.domain.pure.account.calcAccValues +import com.ivy.wallet.domain.pure.core.SideEffect +import com.ivy.wallet.domain.pure.core.Uncertain +import com.ivy.wallet.domain.pure.core.mapIndexedNel +import com.ivy.wallet.domain.pure.core.nonEmptyListOfZeros +import com.ivy.wallet.domain.pure.data.* +import com.ivy.wallet.domain.pure.exchange import com.ivy.wallet.utils.scopedIOThread import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt index a7cc8da436..abc6171bac 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt @@ -1,13 +1,13 @@ -package com.ivy.wallet.domain.fp.wallet +package com.ivy.wallet.domain.pure.wallet import arrow.core.nonEmptyListOf import com.ivy.wallet.domain.data.entity.Settings -import com.ivy.wallet.domain.fp.account.AccountValueFunctions -import com.ivy.wallet.domain.fp.core.Uncertain -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.CurrencyConvError -import com.ivy.wallet.domain.fp.data.IncomeExpensePair -import com.ivy.wallet.domain.fp.data.WalletDAOs +import com.ivy.wallet.domain.pure.account.AccountValueFunctions +import com.ivy.wallet.domain.pure.core.Uncertain +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.CurrencyConvError +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.io.persistence.dao.SettingsDao import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt index dcf0232c80..3339b9d705 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.wallet +package com.ivy.wallet.domain.pure.wallet import arrow.core.Option import arrow.core.toOption @@ -6,9 +6,9 @@ import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.ExchangeData -import com.ivy.wallet.domain.fp.core.* -import com.ivy.wallet.domain.fp.data.FPTransaction +import com.ivy.wallet.domain.pure.ExchangeData +import com.ivy.wallet.domain.pure.core.* +import com.ivy.wallet.domain.pure.data.FPTransaction import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt index 8bd3687730..2b2b46755a 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt @@ -6,12 +6,11 @@ import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.fp.account.calculateAccountBalance -import com.ivy.wallet.domain.fp.account.calculateAccountIncomeExpense -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.exchangeToBaseCurrency -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode import com.ivy.wallet.domain.logic.AccountCreator +import com.ivy.wallet.domain.pure.account.calculateAccountBalance +import com.ivy.wallet.domain.pure.account.calculateAccountIncomeExpense +import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode import com.ivy.wallet.domain.sync.item.AccountSync import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao diff --git a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt index e0457f0626..75f5839d43 100644 --- a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt @@ -4,8 +4,8 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.action.settings.BaseCurrencyAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct -import com.ivy.wallet.domain.fp.data.WalletDAOs import com.ivy.wallet.domain.logic.PlannedPaymentsLogic +import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt index bd4751e839..a1f455efd9 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt @@ -22,9 +22,9 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.fp.charts.ChartPeriod -import com.ivy.wallet.domain.fp.charts.IncomeExpenseChartPoint -import com.ivy.wallet.domain.fp.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.IncomeExpenseChartPoint +import com.ivy.wallet.domain.pure.charts.SingleChartPoint import com.ivy.wallet.ui.Charts import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.charts.charts.accountCharts diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt index 7d1dc627a7..62b6e75b86 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt @@ -7,13 +7,13 @@ import com.ivy.wallet.domain.action.framework.then import com.ivy.wallet.domain.action.settings.BaseCurrencyAct import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.fp.charts.ChartPeriod -import com.ivy.wallet.domain.fp.charts.IncomeExpenseChartPoint -import com.ivy.wallet.domain.fp.charts.SingleChartPoint -import com.ivy.wallet.domain.fp.charts.incomeExpenseChart -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode import com.ivy.wallet.domain.logic.WalletCategoryLogic +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.IncomeExpenseChartPoint +import com.ivy.wallet.domain.pure.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.incomeExpenseChart +import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.onboarding.model.FromToTimeRange diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/TimeValue.kt b/app/src/main/java/com/ivy/wallet/ui/charts/TimeValue.kt index 5205ae623d..ba1ff83729 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/TimeValue.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/TimeValue.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.charts -import com.ivy.wallet.domain.fp.charts.ChartPeriod -import com.ivy.wallet.domain.fp.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.SingleChartPoint import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.ui.theme.components.charts.linechart.Value diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/charts/AccountCharts.kt b/app/src/main/java/com/ivy/wallet/ui/charts/charts/AccountCharts.kt index a0ddefe7d6..c752d4ad19 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/charts/AccountCharts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/charts/AccountCharts.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.charts.charts import androidx.compose.foundation.lazy.LazyListScope -import com.ivy.wallet.domain.fp.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.ChartPeriod fun LazyListScope.accountCharts(period: ChartPeriod) { diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt b/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt index c1297b8931..3c929e0879 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt @@ -17,7 +17,7 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.fp.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.ChartPeriod import com.ivy.wallet.stringRes import com.ivy.wallet.ui.charts.CategoryValues import com.ivy.wallet.ui.charts.toValue diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/charts/WalletCharts.kt b/app/src/main/java/com/ivy/wallet/ui/charts/charts/WalletCharts.kt index 97ca7c9977..30b6e2f712 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/charts/WalletCharts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/charts/WalletCharts.kt @@ -13,8 +13,8 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.fp.charts.ChartPeriod -import com.ivy.wallet.domain.fp.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.SingleChartPoint import com.ivy.wallet.ui.charts.toValues2 import com.ivy.wallet.ui.theme.Green import com.ivy.wallet.ui.theme.Ivy diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt index 1aab9a51ac..4322117f96 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt @@ -5,8 +5,8 @@ import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.data.entity.Category import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.IncomeExpensePair import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index cc1efa8ce7..493c84fe2e 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -9,13 +9,13 @@ import com.ivy.wallet.domain.action.wallet.CalcOverdueAct import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpense -import com.ivy.wallet.domain.fp.wallet.walletBufferDiff import com.ivy.wallet.domain.logic.CustomerJourneyLogic import com.ivy.wallet.domain.logic.PlannedPaymentsLogic import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.pure.wallet.calculateWalletIncomeExpense +import com.ivy.wallet.domain.pure.wallet.walletBufferDiff import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt index 8921b93819..f55b812796 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt @@ -1,9 +1,7 @@ package com.ivy.wallet.ui.onboarding.model -import com.ivy.wallet.R import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.utils.* import java.time.LocalDateTime @@ -38,13 +36,13 @@ data class FromToTimeRange( "${from.toLocalDate().formatDateOnly()} - ${to.toLocalDate().formatDateOnly()}" } from != null && to == null -> { - stringRes(R.string.from_date, from.toLocalDate().formatDateOnly()) + "From ${from.toLocalDate().formatDateOnly()}" } from == null && to != null -> { - stringRes(R.string.to_date, to.toLocalDate().formatDateOnly()) + "To ${to.toLocalDate().formatDateOnly()}" } else -> { - stringRes(R.string.range) + "Range" } } } diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt index b818810f0e..f77ff4c575 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt @@ -10,11 +10,11 @@ import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.data.entity.Category import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.wallet.withDateDividers import com.ivy.wallet.domain.logic.PlannedPaymentsLogic import com.ivy.wallet.domain.logic.WalletLogic import com.ivy.wallet.domain.logic.csv.ExportCSVLogic import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.pure.wallet.withDateDividers import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.RootActivity diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt index 0a0f898908..dced3748e3 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt @@ -7,13 +7,13 @@ import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.entity.Category import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.category.calculateCategoryExpenseWithAccountFilters -import com.ivy.wallet.domain.fp.category.calculateCategoryIncomeWithAccountFilters -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletExpenseWithAccountFilters -import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeWithAccountFilters import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency +import com.ivy.wallet.domain.pure.category.calculateCategoryExpenseWithAccountFilters +import com.ivy.wallet.domain.pure.category.calculateCategoryIncomeWithAccountFilters +import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.pure.wallet.calculateWalletExpenseWithAccountFilters +import com.ivy.wallet.domain.pure.wallet.calculateWalletIncomeWithAccountFilters import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt index d3f4d9656b..ee078878f3 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt @@ -10,14 +10,14 @@ import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.data.entity.Category import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.account.calculateAccountBalance -import com.ivy.wallet.domain.fp.account.calculateAccountIncomeExpense -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.exchangeToBaseCurrency -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.domain.fp.wallet.withDateDividers import com.ivy.wallet.domain.logic.* import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.pure.account.calculateAccountBalance +import com.ivy.wallet.domain.pure.account.calculateAccountIncomeExpense +import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.pure.exchangeToBaseCurrency +import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode +import com.ivy.wallet.domain.pure.wallet.withDateDividers import com.ivy.wallet.domain.sync.uploader.AccountUploader import com.ivy.wallet.domain.sync.uploader.CategoryUploader import com.ivy.wallet.io.persistence.dao.* From 3734ab941947526df38e26724bb1adb20dbde2a6 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 17:12:09 +0300 Subject: [PATCH 11/40] Move deprecated packages to `domain.deprecated` --- .../ivy/wallet/domain/{ => deprecated}/logic/AccountCreator.kt | 3 +-- .../ivy/wallet/domain/{ => deprecated}/logic/BudgetCreator.kt | 2 +- .../wallet/domain/{ => deprecated}/logic/CategoryCreator.kt | 3 +-- .../domain/{ => deprecated}/logic/CustomerJourneyLogic.kt | 2 +- .../ivy/wallet/domain/{ => deprecated}/logic/LoanCreator.kt | 3 +-- .../wallet/domain/{ => deprecated}/logic/LoanRecordCreator.kt | 2 +- .../ivy/wallet/domain/{ => deprecated}/logic/LogoutLogic.kt | 2 +- .../ivy/wallet/domain/{ => deprecated}/logic/PaywallLogic.kt | 2 +- .../domain/{ => deprecated}/logic/PlannedPaymentsGenerator.kt | 2 +- .../domain/{ => deprecated}/logic/PlannedPaymentsLogic.kt | 2 +- .../wallet/domain/{ => deprecated}/logic/PreloadDataLogic.kt | 2 +- .../{ => deprecated}/logic/SmartTitleSuggestionsLogic.kt | 2 +- .../wallet/domain/{ => deprecated}/logic/WalletAccountLogic.kt | 2 +- .../domain/{ => deprecated}/logic/WalletCategoryLogic.kt | 2 +- .../ivy/wallet/domain/{ => deprecated}/logic/WalletLogic.kt | 2 +- .../logic/bankintegrations/BankIntegrationsLogic.kt | 2 +- .../logic/bankintegrations/SaltEdgeAccountMapper.kt | 2 +- .../logic/bankintegrations/SaltEdgeCategoryMapper.kt | 2 +- .../logic/bankintegrations/SaltEdgeTransactionMapper.kt | 2 +- .../wallet/domain/{ => deprecated}/logic/csv/CSVImporter.kt | 2 +- .../ivy/wallet/domain/{ => deprecated}/logic/csv/CSVMapper.kt | 3 +-- .../wallet/domain/{ => deprecated}/logic/csv/CSVNormalizer.kt | 2 +- .../wallet/domain/{ => deprecated}/logic/csv/ExportCSVLogic.kt | 2 +- .../wallet/domain/{ => deprecated}/logic/csv/IvyFileReader.kt | 2 +- .../wallet/domain/{ => deprecated}/logic/csv/model/CSVRow.kt | 2 +- .../domain/{ => deprecated}/logic/csv/model/ImportResult.kt | 2 +- .../domain/{ => deprecated}/logic/csv/model/ImportType.kt | 2 +- .../domain/{ => deprecated}/logic/csv/model/RowMapping.kt | 2 +- .../{ => deprecated}/logic/currency/ExchangeRatesLogic.kt | 2 +- .../{ => deprecated}/logic/loantrasactions/LTLoanMapper.kt | 2 +- .../logic/loantrasactions/LTLoanRecordMapper.kt | 2 +- .../logic/loantrasactions/LoanTransactionsCore.kt | 2 +- .../logic/loantrasactions/LoanTransactionsLogic.kt | 2 +- .../domain/{ => deprecated}/logic/model/CreateAccountData.kt | 2 +- .../domain/{ => deprecated}/logic/model/CreateBudgetData.kt | 2 +- .../domain/{ => deprecated}/logic/model/CreateCategoryData.kt | 2 +- .../domain/{ => deprecated}/logic/model/CreateLoanData.kt | 2 +- .../{ => deprecated}/logic/model/CreateLoanRecordData.kt | 2 +- .../{ => deprecated}/logic/model/CustomerJourneyCardData.kt | 2 +- .../domain/{ => deprecated}/logic/model/EditLoanRecordData.kt | 2 +- .../logic/notification/TransactionReminderLogic.kt | 2 +- .../logic/notification/TransactionReminderWorker.kt | 2 +- .../wallet/domain/{ => deprecated}/logic/zip/ExportZipLogic.kt | 2 +- .../ivy/wallet/domain/{ => deprecated}/logic/zip/ZipUtils.kt | 2 +- .../com/ivy/wallet/domain/{ => deprecated}/sync/IvySync.kt | 2 +- .../wallet/domain/{ => deprecated}/sync/item/AccountSync.kt | 2 +- .../ivy/wallet/domain/{ => deprecated}/sync/item/BudgetSync.kt | 2 +- .../wallet/domain/{ => deprecated}/sync/item/CategorySync.kt | 2 +- .../wallet/domain/{ => deprecated}/sync/item/LoanRecordSync.kt | 2 +- .../ivy/wallet/domain/{ => deprecated}/sync/item/LoanSync.kt | 2 +- .../domain/{ => deprecated}/sync/item/PlannedPaymentSync.kt | 2 +- .../domain/{ => deprecated}/sync/item/TransactionSync.kt | 2 +- .../domain/{ => deprecated}/sync/uploader/AccountUploader.kt | 2 +- .../domain/{ => deprecated}/sync/uploader/BudgetUploader.kt | 2 +- .../domain/{ => deprecated}/sync/uploader/CategoryUploader.kt | 2 +- .../{ => deprecated}/sync/uploader/LoanRecordUploader.kt | 2 +- .../domain/{ => deprecated}/sync/uploader/LoanUploader.kt | 2 +- .../sync/uploader/PlannedPaymentRuleUploader.kt | 2 +- .../{ => deprecated}/sync/uploader/TransactionUploader.kt | 2 +- 59 files changed, 59 insertions(+), 63 deletions(-) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/AccountCreator.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/BudgetCreator.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/CategoryCreator.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/CustomerJourneyLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/LoanCreator.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/LoanRecordCreator.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/LogoutLogic.kt (93%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/PaywallLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/PlannedPaymentsGenerator.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/PlannedPaymentsLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/PreloadDataLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/SmartTitleSuggestionsLogic.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/WalletAccountLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/WalletCategoryLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/WalletLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/bankintegrations/BankIntegrationsLogic.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/bankintegrations/SaltEdgeAccountMapper.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/bankintegrations/SaltEdgeCategoryMapper.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/bankintegrations/SaltEdgeTransactionMapper.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/CSVImporter.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/CSVMapper.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/CSVNormalizer.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/ExportCSVLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/IvyFileReader.kt (88%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/model/CSVRow.kt (55%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/model/ImportResult.kt (76%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/model/ImportType.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/model/RowMapping.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/currency/ExchangeRatesLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/loantrasactions/LTLoanMapper.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/loantrasactions/LTLoanRecordMapper.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/loantrasactions/LoanTransactionsCore.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/loantrasactions/LoanTransactionsLogic.kt (95%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateAccountData.kt (81%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateBudgetData.kt (74%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateCategoryData.kt (72%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateLoanData.kt (87%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateLoanRecordData.kt (87%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CustomerJourneyCardData.kt (91%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/EditLoanRecordData.kt (83%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/notification/TransactionReminderLogic.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/notification/TransactionReminderWorker.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/zip/ExportZipLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/zip/ZipUtils.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/IvySync.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/AccountSync.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/BudgetSync.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/CategorySync.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/LoanRecordSync.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/LoanSync.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/PlannedPaymentSync.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/TransactionSync.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/AccountUploader.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/BudgetUploader.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/CategoryUploader.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/LoanRecordUploader.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/LoanUploader.kt (96%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/PlannedPaymentRuleUploader.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/TransactionUploader.kt (97%) diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/AccountCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/logic/AccountCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt index 87e84bd58f..53dcb707f8 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/AccountCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt @@ -1,6 +1,5 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic -import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.sync.item.TransactionSync diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/BudgetCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/BudgetCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt index 0042a802bb..8d49d89bc9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/BudgetCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.entity.Budget import com.ivy.wallet.domain.logic.model.CreateBudgetData diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/CategoryCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/logic/CategoryCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt index 0f74897ada..c50fc59623 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/CategoryCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt @@ -1,6 +1,5 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic -import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.entity.Category import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.domain.sync.uploader.CategoryUploader diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/CustomerJourneyLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/CustomerJourneyLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt index ccad0b54a4..d2d0aebde4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/CustomerJourneyLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/LoanCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/logic/LoanCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt index 23b6c4ee08..0242c7daab 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/LoanCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt @@ -1,6 +1,5 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic -import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.entity.Loan import com.ivy.wallet.domain.logic.model.CreateLoanData import com.ivy.wallet.domain.sync.uploader.LoanUploader diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/LoanRecordCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/LoanRecordCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt index 3789a4fc25..f1d9c152da 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/LoanRecordCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.entity.LoanRecord import com.ivy.wallet.domain.logic.model.CreateLoanRecordData diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/LogoutLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LogoutLogic.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/logic/LogoutLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LogoutLogic.kt index 8a83a3804f..92fa95f17d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/LogoutLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LogoutLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.design.navigation.Navigation import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/PaywallLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PaywallLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/PaywallLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PaywallLogic.kt index e0b3e82126..fbbeaaecf4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/PaywallLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PaywallLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.android.billingclient.api.Purchase import com.ivy.design.navigation.Navigation diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsGenerator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsGenerator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt index 918341158d..8c9a765f23 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsGenerator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.entity.PlannedPaymentRule import com.ivy.wallet.domain.data.entity.Transaction diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt index 80ae5301f9..bb37571758 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/PreloadDataLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/PreloadDataLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt index 06b7ac2620..49c9584d37 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/PreloadDataLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.R diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/SmartTitleSuggestionsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/SmartTitleSuggestionsLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt index c313425e15..54d8a22f47 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/SmartTitleSuggestionsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.io.persistence.dao.TransactionDao diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/WalletAccountLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/WalletAccountLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt index 493cedf7b2..81edf87e03 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/WalletAccountLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionHistoryItem diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/WalletCategoryLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/WalletCategoryLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt index 86eb786913..1316602d76 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/WalletCategoryLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/WalletLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/WalletLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt index c3570fd371..20b1b154ba 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/WalletLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/BankIntegrationsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/BankIntegrationsLogic.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/BankIntegrationsLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/BankIntegrationsLogic.kt index 97f5c4624b..da510959cb 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/BankIntegrationsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/BankIntegrationsLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.bankintegrations +package com.ivy.wallet.domain.deprecated.logic.bankintegrations import com.ivy.wallet.domain.data.bankintegrations.SEAccount import com.ivy.wallet.domain.data.bankintegrations.SEConnection diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeAccountMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeAccountMapper.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeAccountMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeAccountMapper.kt index 4dcc598632..51ef503bbf 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeAccountMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeAccountMapper.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.bankintegrations +package com.ivy.wallet.domain.deprecated.logic.bankintegrations import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.toArgb diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeCategoryMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeCategoryMapper.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeCategoryMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeCategoryMapper.kt index e87ceecb43..a47e597c3b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeCategoryMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeCategoryMapper.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.bankintegrations +package com.ivy.wallet.domain.deprecated.logic.bankintegrations import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.toArgb diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeTransactionMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeTransactionMapper.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeTransactionMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeTransactionMapper.kt index 256829d9b3..031849688c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeTransactionMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeTransactionMapper.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.bankintegrations +package com.ivy.wallet.domain.deprecated.logic.bankintegrations import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.bankintegrations.SEAccount diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVImporter.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVImporter.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt index edc55bb848..9d9b1f19e1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVImporter.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.IvyCurrency diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt index 7101669908..e1c2a054ee 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt @@ -1,11 +1,10 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.domain.logic.csv.model.ImportType import com.ivy.wallet.domain.logic.csv.model.JoinResult import com.ivy.wallet.domain.logic.csv.model.RowMapping -import com.ivy.wallet.utils.toLowerCaseLocal class CSVMapper { diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVNormalizer.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVNormalizer.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt index 29d19d1a8e..3b96b1a64f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVNormalizer.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import com.ivy.wallet.domain.logic.csv.model.ImportType diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/ExportCSVLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/ExportCSVLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt index 6df704811f..786db7ed5e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/ExportCSVLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import android.content.Context import android.net.Uri diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/IvyFileReader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/IvyFileReader.kt similarity index 88% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/IvyFileReader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/IvyFileReader.kt index 24734883cb..0ad0b9c05a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/IvyFileReader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/IvyFileReader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import android.content.Context import android.net.Uri diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/CSVRow.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/CSVRow.kt similarity index 55% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/model/CSVRow.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/CSVRow.kt index 3fa61d3aea..1b926a8f93 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/CSVRow.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/CSVRow.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv.model +package com.ivy.wallet.domain.deprecated.logic.csv.model data class CSVRow( val index: Int, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportResult.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportResult.kt similarity index 76% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportResult.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportResult.kt index 833026c420..681e3a2f37 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportResult.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportResult.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv.model +package com.ivy.wallet.domain.deprecated.logic.csv.model data class ImportResult( val rowsFound: Int, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportType.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportType.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportType.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportType.kt index d9028d0287..ebfb836b06 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportType.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportType.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv.model +package com.ivy.wallet.domain.deprecated.logic.csv.model import androidx.annotation.DrawableRes import androidx.compose.runtime.Composable diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/RowMapping.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/model/RowMapping.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt index 03c67fbdca..32256b39a9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/RowMapping.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv.model +package com.ivy.wallet.domain.deprecated.logic.csv.model import com.ivy.wallet.domain.data.entity.Category import com.ivy.wallet.domain.data.entity.Transaction diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/currency/ExchangeRatesLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/currency/ExchangeRatesLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt index 5b34df0b28..781966bfde 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/currency/ExchangeRatesLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.currency +package com.ivy.wallet.domain.deprecated.logic.currency import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.domain.data.entity.ExchangeRate diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt index dbf9afe159..81a0527b76 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.loantrasactions +package com.ivy.wallet.domain.deprecated.logic.loantrasactions import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.TransactionType diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanRecordMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanRecordMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt index 78e443409e..995009deb0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanRecordMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.loantrasactions +package com.ivy.wallet.domain.deprecated.logic.loantrasactions import com.ivy.wallet.domain.data.entity.Loan import com.ivy.wallet.domain.data.entity.LoanRecord diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsCore.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsCore.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt index 4d0b3e2caa..c4acbe6d42 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.loantrasactions +package com.ivy.wallet.domain.deprecated.logic.loantrasactions import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.R diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt similarity index 95% rename from app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt index 0ea34c1056..d6caa61964 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.loantrasactions +package com.ivy.wallet.domain.deprecated.logic.loantrasactions import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.utils.computationThread diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateAccountData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateAccountData.kt similarity index 81% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateAccountData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateAccountData.kt index afd0854982..2def1f6323 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateAccountData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateAccountData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import androidx.compose.ui.graphics.Color diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateBudgetData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateBudgetData.kt similarity index 74% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateBudgetData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateBudgetData.kt index 99a6ef502b..db29ec3812 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateBudgetData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateBudgetData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model data class CreateBudgetData( val name: String, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateCategoryData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateCategoryData.kt similarity index 72% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateCategoryData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateCategoryData.kt index b9913ba77f..95be242474 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateCategoryData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateCategoryData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import androidx.compose.ui.graphics.Color diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt similarity index 87% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt index 6bd69df44e..bbe49ad622 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import androidx.compose.ui.graphics.Color import com.ivy.wallet.domain.data.LoanType diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanRecordData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt similarity index 87% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanRecordData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt index 7392dfde34..8980be66b1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanRecordData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import com.ivy.wallet.domain.data.entity.Account import java.time.LocalDateTime diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CustomerJourneyCardData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CustomerJourneyCardData.kt similarity index 91% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CustomerJourneyCardData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CustomerJourneyCardData.kt index 0609932a1b..543c9c739f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CustomerJourneyCardData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CustomerJourneyCardData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import androidx.annotation.DrawableRes import androidx.compose.ui.graphics.Color diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/EditLoanRecordData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt similarity index 83% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/EditLoanRecordData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt index 93460dad76..f06a15be42 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/EditLoanRecordData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import com.ivy.wallet.domain.data.entity.LoanRecord diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderLogic.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderLogic.kt index 11c2db7c86..79b6a5e742 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.notification +package com.ivy.wallet.domain.deprecated.logic.notification import android.content.Context import androidx.work.ExistingPeriodicWorkPolicy diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderWorker.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderWorker.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderWorker.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderWorker.kt index 71964bbf66..8b9c854d37 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderWorker.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderWorker.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.notification +package com.ivy.wallet.domain.deprecated.logic.notification import android.app.PendingIntent import android.content.Context diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/zip/ExportZipLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/zip/ExportZipLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt index 9ccd5a0cd8..9714533e2d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/zip/ExportZipLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.zip +package com.ivy.wallet.domain.deprecated.logic.zip import android.content.Context import android.net.Uri diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/zip/ZipUtils.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ZipUtils.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/zip/ZipUtils.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ZipUtils.kt index 8139069415..8b35ba1015 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/zip/ZipUtils.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ZipUtils.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.zip +package com.ivy.wallet.domain.deprecated.logic.zip import android.content.Context import android.net.Uri diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/IvySync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/sync/IvySync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt index d2791015d8..1cc57f010d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/IvySync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync +package com.ivy.wallet.domain.deprecated.sync import com.ivy.wallet.domain.sync.item.* import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/AccountSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/AccountSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt index bf0a4d6dad..d7019a22db 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/AccountSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item import com.ivy.wallet.domain.sync.uploader.AccountUploader import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/BudgetSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/BudgetSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt index ed5158164b..3b83d66270 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/BudgetSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item import com.ivy.wallet.domain.sync.uploader.BudgetUploader import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/CategorySync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/CategorySync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt index 26e7553aa2..bd22a26e45 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/CategorySync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item import com.ivy.wallet.domain.sync.uploader.CategoryUploader import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/LoanRecordSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/LoanRecordSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt index b3209ad56a..ca0d2b08ef 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/LoanRecordSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item import com.ivy.wallet.domain.sync.uploader.LoanRecordUploader import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/LoanSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/LoanSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt index c6889ac7fd..6a682a5f6b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/LoanSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item import com.ivy.wallet.domain.sync.uploader.LoanUploader import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/PlannedPaymentSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/PlannedPaymentSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt index 5d1e49823b..4d4258a192 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/PlannedPaymentSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/TransactionSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/TransactionSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt index 08924bf2a5..ec357581db 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/TransactionSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item import com.ivy.wallet.domain.sync.uploader.TransactionUploader import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/AccountUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/AccountUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt index 9d0db4a07b..1331cb5b3d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/AccountUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader import com.ivy.wallet.domain.data.entity.Account import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/BudgetUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/BudgetUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt index 91a0b8b552..5d6e027c40 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/BudgetUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader import com.ivy.wallet.domain.data.entity.Budget import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/CategoryUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/CategoryUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt index 43dab1c576..fef9bbddcb 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/CategoryUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader import com.ivy.wallet.domain.data.entity.Category import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanRecordUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanRecordUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt index 61bbb13ff5..76edc98ef7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanRecordUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader import com.ivy.wallet.domain.data.entity.LoanRecord import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt index 8107b16f04..39c4144a55 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader import com.ivy.wallet.domain.data.entity.Loan import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/PlannedPaymentRuleUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/PlannedPaymentRuleUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt index e6965922ed..33645f0be0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/PlannedPaymentRuleUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader import com.ivy.wallet.domain.data.entity.PlannedPaymentRule import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/TransactionUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/TransactionUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt index f0c3008d4b..3077153154 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/TransactionUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader import com.ivy.wallet.domain.data.entity.Transaction import com.ivy.wallet.io.network.IvySession From 0f180b65b2707afe855210a0fd8658f761d908d7 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 17:18:07 +0300 Subject: [PATCH 12/40] Drop `wishlist_items` table --- .../domain/data/bankintegrations/SEAccount.kt | 23 ---------- .../bankintegrations/SEAccountConnection.kt | 10 ----- .../data/bankintegrations/SEConnection.kt | 30 ------------- .../data/bankintegrations/SECustomer.kt | 14 ------ .../data/bankintegrations/SETransaction.kt | 44 ------------------- .../wallet/domain/data/entity/WishlistItem.kt | 19 -------- .../wallet/io/persistence/IvyRoomDatabase.kt | 6 +-- .../io/persistence/dao/WishlistItemDao.kt | 26 ----------- .../Migration120to121_DropWishlistItem.kt | 10 +++++ 9 files changed, 12 insertions(+), 170 deletions(-) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccount.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccountConnection.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEConnection.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SECustomer.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SETransaction.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/entity/WishlistItem.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/dao/WishlistItemDao.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccount.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccount.kt deleted file mode 100644 index 08c68fc6bd..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccount.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class SEAccount( - @SerializedName("id") - val id: String, - - @SerializedName("name") - val name: String, - - @SerializedName("nature") - val nature: String, - - @SerializedName("balance") - val balance: Double, - - @SerializedName("currency_code") - val currency_code: String, - - @SerializedName("connection_id") - val connection_id: String, -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccountConnection.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccountConnection.kt deleted file mode 100644 index 48f50e5552..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccountConnection.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class SEAccountConnection( - @SerializedName("account") - val account: SEAccount, - @SerializedName("connection") - val connection: SEConnection -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEConnection.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEConnection.kt deleted file mode 100644 index f47ddcf08d..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEConnection.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.PrimaryKey -import com.google.gson.annotations.SerializedName -import java.time.LocalDateTime - -@Entity(tableName = "se_connections") -data class SEConnection( - @SerializedName("id") - @PrimaryKey @ColumnInfo(name = "id") - val id: String = "", - - @SerializedName("provider_code") - @ColumnInfo(name = "provider_code") - val provider_code: String = "", - - @SerializedName("provider_name") - @ColumnInfo(name = "provider_name") - val provider_name: String = "", - - @SerializedName("customer_id") - @ColumnInfo(name = "customer_id") - val customer_id: String = "", - - @SerializedName("next_refresh_possible_at") - @ColumnInfo(name = "next_refresh_possible_at") - var next_refresh_possible_at: LocalDateTime? = null, -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SECustomer.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SECustomer.kt deleted file mode 100644 index c67c98136a..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SECustomer.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class SECustomer( - @SerializedName("id") - val id: String = "", - - @SerializedName("identifier") - val identifier: String = "", - - @SerializedName("secret") - val secret: String = "" -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SETransaction.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SETransaction.kt deleted file mode 100644 index 480f1e821f..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SETransaction.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class SETransaction( - @SerializedName("id") - val id: String, - - @SerializedName("duplicated") - val duplicated: Boolean, - - @SerializedName("mode") - val mode: String, - - @SerializedName("status") - val status: String, - - @SerializedName("made_on") - val made_on: String, - - @SerializedName("amount") - val amount: Double, - - @SerializedName("currency_code") - val currency_code: String, - - @SerializedName("description") - val description: String, - - @SerializedName("category") - val category: String, - - @SerializedName("account_id") - val account_id: String, - - @SerializedName("created_at") - val created_at: String, - - @SerializedName("updated_at") - val updated_at: String, - - @SerializedName("extra") - val extra: Map? -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/WishlistItem.kt b/app/src/main/java/com/ivy/wallet/domain/data/entity/WishlistItem.kt deleted file mode 100644 index 9eb6b6cba5..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/WishlistItem.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.ivy.wallet.domain.data.entity - -import androidx.room.Entity -import androidx.room.PrimaryKey -import java.time.LocalDateTime -import java.util.* - -@Entity(tableName = "wishlist_items") -data class WishlistItem( - val name: String, - val price: Double, - val accountId: UUID, - val categoryId: UUID? = null, - val description: String?, - val plannedDateTime: LocalDateTime? = null, - val orderNum: Double = 0.0, - @PrimaryKey - val id: UUID = UUID.randomUUID() -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt index c103b00085..a99ad2e07c 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt @@ -13,7 +13,7 @@ import com.ivy.wallet.io.persistence.migration.* @Database( entities = [ Account::class, Transaction::class, Category::class, - WishlistItem::class, Settings::class, PlannedPaymentRule::class, + Settings::class, PlannedPaymentRule::class, User::class, ExchangeRate::class, Budget::class, Loan::class, LoanRecord::class ], @@ -30,8 +30,6 @@ abstract class IvyRoomDatabase : RoomDatabase() { abstract fun budgetDao(): BudgetDao - abstract fun wishlistItemDao(): WishlistItemDao - abstract fun plannedPaymentRuleDao(): PlannedPaymentRuleDao abstract fun settingsDao(): SettingsDao @@ -69,6 +67,7 @@ abstract class IvyRoomDatabase : RoomDatabase() { Migration117to118_Budgets(), Migration118to119_Loans(), Migration119to120_LoanTransactions(), + Migration120to121_DropWishlistItem() ) .build() } @@ -78,7 +77,6 @@ abstract class IvyRoomDatabase : RoomDatabase() { accountDao().deleteAll() transactionDao().deleteAll() categoryDao().deleteAll() - wishlistItemDao().deleteAll() settingsDao().deleteAll() plannedPaymentRuleDao().deleteAll() userDao().deleteAll() diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/WishlistItemDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/WishlistItemDao.kt deleted file mode 100644 index 714375ddd2..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/WishlistItemDao.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.ivy.wallet.io.persistence.dao - -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy -import androidx.room.Query -import com.ivy.wallet.domain.data.entity.WishlistItem -import java.util.* - -@Dao -interface WishlistItemDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: WishlistItem) - - @Query("SELECT * FROM wishlist_items ORDER BY orderNum ASC") - fun findAll(): List - - @Query("SELECT * FROM wishlist_items WHERE id = :id") - fun findById(id: UUID): WishlistItem? - - @Query("DELETE FROM wishlist_items WHERE id = :id") - fun deleteById(id: UUID) - - @Query("DELETE FROM wishlist_items") - fun deleteAll() -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt b/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt new file mode 100644 index 0000000000..dd7b0d3e99 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt @@ -0,0 +1,10 @@ +package com.ivy.wallet.io.persistence.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration120to121_DropWishlistItem : Migration(119, 120) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE wishlist_items") + } +} \ No newline at end of file From 1782f7a1bc492a58ee5a6a02c3bab9a9d0299162 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 17:58:56 +0300 Subject: [PATCH 13/40] Rework data object through the different layers (everything is broken & won't compile) --- app/proguard-rules.pro | 2 + .../domain/action/account/AccTrnsAct.kt | 2 +- .../domain/action/account/AccountsAct.kt | 2 +- .../action/account/CalcAccBalanceAct.kt | 2 +- .../domain/action/wallet/CalcOverdueAct.kt | 2 +- .../domain/action/wallet/CalcUpcomingAct.kt | 2 +- .../domain/data/IvyWalletCompleteData.kt | 2 +- .../domain/data/{entity => core}/Account.kt | 10 +- .../domain/data/{entity => core}/Budget.kt | 6 +- .../domain/data/{entity => core}/Category.kt | 10 +- .../wallet/domain/data/core/ExchangeRate.kt | 7 + .../domain/data/{entity => core}/Loan.kt | 6 +- .../data/{entity => core}/LoanRecord.kt | 6 +- .../{entity => core}/PlannedPaymentRule.kt | 6 +- .../ivy/wallet/domain/data/core/Settings.kt | 13 + .../data/{entity => core}/Transaction.kt | 15 +- .../com/ivy/wallet/domain/data/core/User.kt | 18 + .../wallet/domain/data/entity/ExchangeRate.kt | 10 - .../domain/deprecated/logic/AccountCreator.kt | 2 +- .../domain/deprecated/logic/BudgetCreator.kt | 2 +- .../deprecated/logic/CategoryCreator.kt | 2 +- .../domain/deprecated/logic/LoanCreator.kt | 2 +- .../deprecated/logic/LoanRecordCreator.kt | 2 +- .../logic/PlannedPaymentsGenerator.kt | 4 +- .../deprecated/logic/PlannedPaymentsLogic.kt | 6 +- .../deprecated/logic/PreloadDataLogic.kt | 66 ++-- .../logic/SmartTitleSuggestionsLogic.kt | 2 +- .../deprecated/logic/WalletAccountLogic.kt | 6 +- .../deprecated/logic/WalletCategoryLogic.kt | 6 +- .../domain/deprecated/logic/WalletLogic.kt | 4 +- .../bankintegrations/BankIntegrationsLogic.kt | 64 --- .../bankintegrations/SaltEdgeAccountMapper.kt | 67 ---- .../SaltEdgeCategoryMapper.kt | 371 ------------------ .../SaltEdgeTransactionMapper.kt | 165 -------- .../deprecated/logic/csv/CSVImporter.kt | 6 +- .../domain/deprecated/logic/csv/CSVMapper.kt | 2 +- .../deprecated/logic/csv/ExportCSVLogic.kt | 6 +- .../deprecated/logic/csv/model/RowMapping.kt | 4 +- .../logic/currency/ExchangeRatesLogic.kt | 8 +- .../logic/loantrasactions/LTLoanMapper.kt | 8 +- .../loantrasactions/LTLoanRecordMapper.kt | 6 +- .../loantrasactions/LoanTransactionsCore.kt | 2 +- .../loantrasactions/LoanTransactionsLogic.kt | 2 +- .../deprecated/logic/model/CreateLoanData.kt | 2 +- .../logic/model/CreateLoanRecordData.kt | 2 +- .../logic/model/EditLoanRecordData.kt | 2 +- .../sync/uploader/AccountUploader.kt | 2 +- .../sync/uploader/BudgetUploader.kt | 2 +- .../sync/uploader/CategoryUploader.kt | 2 +- .../sync/uploader/LoanRecordUploader.kt | 2 +- .../deprecated/sync/uploader/LoanUploader.kt | 2 +- .../uploader/PlannedPaymentRuleUploader.kt | 2 +- .../sync/uploader/TransactionUploader.kt | 2 +- .../com/ivy/wallet/domain/pure/Exchange.kt | 2 +- .../wallet/domain/pure/account/AccountCore.kt | 2 +- .../domain/pure/category/CategoryCore.kt | 2 +- .../pure/category/CategoryValueFunctions.kt | 2 +- .../domain/pure/core/TransactionFunctions.kt | 2 +- .../ivy/wallet/domain/pure/data/FPAccount.kt | 2 +- .../wallet/domain/pure/data/FPTransaction.kt | 2 +- .../wallet/domain/pure/wallet/WalletCore.kt | 6 +- .../domain/pure/wallet/WalletFunctions.kt | 2 +- .../domain/pure/wallet/WalletTransactions.kt | 4 +- .../ivy/wallet/io/network/data/AccountDTO.kt | 30 ++ .../ivy/wallet/io/network/data/BudgetDTO.kt | 66 ++++ .../ivy/wallet/io/network/data/CategoryDTO.kt | 24 ++ .../wallet/io/network/data/ExchangeRateDTO.kt | 13 + .../com/ivy/wallet/io/network/data/LoanDTO.kt | 35 ++ .../wallet/io/network/data/LoanRecordDTO.kt | 32 ++ .../io/network/data/PlannedPaymentRuleDTO.kt | 39 ++ .../ivy/wallet/io/network/data/SettingsDTO.kt | 25 ++ .../wallet/io/network/data/TransactionDTO.kt | 52 +++ .../com/ivy/wallet/io/network/data/UserDTO.kt | 30 ++ .../request/account/AccountsResponse.kt | 4 +- .../request/account/UpdateAccountRequest.kt | 4 +- .../io/network/request/auth/AuthResponse.kt | 2 +- .../request/auth/UpdateUserInfoResponse.kt | 2 +- .../bankintegrations/BankAccountsResponse.kt | 9 - .../BankConnectionSessionResponse.kt | 8 - .../BankConnectionsResponse.kt | 9 - .../BankTransactionsResponse.kt | 9 - .../network/request/budget/BudgetsResponse.kt | 4 +- .../request/budget/CrupdateBudgetRequest.kt | 4 +- .../category/UpdateWalletCategoryRequest.kt | 4 +- .../category/WalletCategoriesResponse.kt | 4 +- .../request/loan/LoanRecordsResponse.kt | 4 +- .../io/network/request/loan/LoansResponse.kt | 4 +- .../request/loan/UpdateLoanRecordRequest.kt | 4 +- .../network/request/loan/UpdateLoanRequest.kt | 4 +- .../planned/PlannedPaymentRulesResponse.kt | 4 +- .../UpdatePlannedPaymentRuleRequest.kt | 4 +- .../transaction/TransactionsResponse.kt | 4 +- .../transaction/UpdateTransactionRequest.kt | 4 +- .../wallet/io/persistence/IvyRoomDatabase.kt | 13 +- .../wallet/io/persistence/dao/AccountDao.kt | 15 +- .../wallet/io/persistence/dao/BudgetDao.kt | 12 +- .../wallet/io/persistence/dao/CategoryDao.kt | 15 +- .../io/persistence/dao/ExchangeRateDao.kt | 9 +- .../ivy/wallet/io/persistence/dao/LoanDao.kt | 12 +- .../io/persistence/dao/LoanRecordDao.kt | 17 +- .../persistence/dao/PlannedPaymentRuleDao.kt | 14 +- .../wallet/io/persistence/dao/SettingsDao.kt | 22 +- .../io/persistence/dao/TransactionDao.kt | 72 ++-- .../ivy/wallet/io/persistence/dao/UserDao.kt | 6 +- .../io/persistence/data/AccountEntity.kt | 36 ++ .../io/persistence/data/BudgetEntity.kt | 73 ++++ .../io/persistence/data/CategoryEntity.kt | 32 ++ .../io/persistence/data/ExchangeRateEntity.kt | 17 + .../wallet/io/persistence/data/LoanEntity.kt | 41 ++ .../io/persistence/data/LoanRecordEntity.kt | 38 ++ .../data/PlannedPaymentRuleEntity.kt | 46 +++ .../persistence/data/SettingsEntity.kt} | 15 +- .../io/persistence/data/TransactionEntity.kt | 72 ++++ .../persistence/data/UserEntity.kt} | 26 +- .../main/java/com/ivy/wallet/ui/Screens.kt | 2 +- .../com/ivy/wallet/ui/accounts/AccountData.kt | 2 +- .../com/ivy/wallet/ui/accounts/AccountsTab.kt | 2 +- .../wallet/ui/accounts/AccountsViewModel.kt | 2 +- .../com/ivy/wallet/ui/budget/BudgetScreen.kt | 6 +- .../ivy/wallet/ui/budget/BudgetViewModel.kt | 8 +- .../wallet/ui/budget/model/DisplayBudget.kt | 2 +- .../wallet/ui/category/CategoriesScreen.kt | 2 +- .../ivy/wallet/ui/category/CategoryData.kt | 2 +- .../ivy/wallet/ui/charts/CategoryValues.kt | 2 +- .../com/ivy/wallet/ui/charts/ChartsScreen.kt | 2 +- .../ivy/wallet/ui/charts/ChartsViewModel.kt | 3 +- .../wallet/ui/charts/charts/CategoryCharts.kt | 2 +- .../wallet/ui/edit/EditTransactionScreen.kt | 4 +- .../ui/edit/EditTransactionViewModel.kt | 8 +- .../com/ivy/wallet/ui/edit/core/Category.kt | 2 +- .../wallet/ui/edit/core/EditBottomSheet.kt | 2 +- .../java/com/ivy/wallet/ui/home/HomeState.kt | 6 +- .../java/com/ivy/wallet/ui/home/HomeTab.kt | 6 +- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 2 +- .../com/ivy/wallet/ui/loan/LoanViewModel.kt | 4 +- .../com/ivy/wallet/ui/loan/LoansScreen.kt | 2 +- .../ivy/wallet/ui/loan/data/DisplayLoan.kt | 2 +- .../wallet/ui/loan/data/DisplayLoanRecord.kt | 4 +- .../ui/loandetails/LoanDetailsScreen.kt | 6 +- .../ui/loandetails/LoanDetailsViewModel.kt | 8 +- .../wallet/ui/onboarding/OnboardingScreen.kt | 4 +- .../ui/onboarding/components/Suggestions.kt | 2 +- .../ui/onboarding/model/AccountBalance.kt | 2 +- .../ui/onboarding/model/FromToTimeRange.kt | 2 +- .../ui/onboarding/steps/OnboardingAccounts.kt | 2 +- .../onboarding/steps/OnboardingCategories.kt | 2 +- .../onboarding/viewmodel/OnboardingRouter.kt | 2 +- .../viewmodel/OnboardingViewModel.kt | 6 +- .../ivy/wallet/ui/paywall/PaywallScreen.kt | 8 +- .../ivy/wallet/ui/paywall/PaywallViewModel.kt | 8 +- .../ui/planned/edit/EditPlannedScreen.kt | 4 +- .../ui/planned/edit/EditPlannedViewModel.kt | 6 +- .../ui/planned/list/PlannedPaymentCard.kt | 6 +- .../planned/list/PlannedPaymentsLazyColumn.kt | 16 +- .../ui/planned/list/PlannedPaymentsScreen.kt | 6 +- .../planned/list/PlannedPaymentsViewModel.kt | 6 +- .../ivy/wallet/ui/reports/FilterOverlay.kt | 4 +- .../com/ivy/wallet/ui/reports/ReportFilter.kt | 4 +- .../com/ivy/wallet/ui/reports/ReportScreen.kt | 20 +- .../wallet/ui/reports/ReportScreenEvent.kt | 2 +- .../wallet/ui/reports/ReportScreenState.kt | 6 +- .../ivy/wallet/ui/reports/ReportViewModel.kt | 8 +- .../com/ivy/wallet/ui/search/SearchScreen.kt | 12 +- .../ivy/wallet/ui/search/SearchViewModel.kt | 4 +- .../ivy/wallet/ui/settings/SettingsScreen.kt | 2 +- .../wallet/ui/settings/SettingsViewModel.kt | 2 +- .../ui/statistic/level1/CategoryAmount.kt | 4 +- .../wallet/ui/statistic/level1/PieChart.kt | 2 +- .../level1/PieChartStatisticScreen.kt | 4 +- .../level1/PieChartStatisticViewModel.kt | 4 +- .../ui/statistic/level1/SelectedCategory.kt | 2 +- .../statistic/level2/ItemStatisticScreen.kt | 6 +- .../level2/ItemStatisticViewModel.kt | 6 +- .../java/com/ivy/wallet/ui/test/TestScreen.kt | 2 +- .../com/ivy/wallet/ui/test/TestViewModel.kt | 2 +- .../ui/theme/components/WrapContentRow.kt | 2 +- .../ivy/wallet/ui/theme/modal/BudgetModal.kt | 19 +- .../ivy/wallet/ui/theme/modal/LoanModal.kt | 4 +- .../wallet/ui/theme/modal/LoanRecordModal.kt | 4 +- .../ui/theme/modal/edit/AccountModal.kt | 2 +- .../ui/theme/modal/edit/CategoryModal.kt | 2 +- .../theme/modal/edit/ChooseCategoryModal.kt | 2 +- .../ui/theme/transaction/TransactionCard.kt | 8 +- .../ui/theme/transaction/Transactions.kt | 14 +- 184 files changed, 1166 insertions(+), 1188 deletions(-) rename app/src/main/java/com/ivy/wallet/domain/data/{entity => core}/Account.kt (62%) rename app/src/main/java/com/ivy/wallet/domain/data/{entity => core}/Budget.kt (89%) rename app/src/main/java/com/ivy/wallet/domain/data/{entity => core}/Category.kt (57%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt rename app/src/main/java/com/ivy/wallet/domain/data/{entity => core}/Loan.kt (77%) rename app/src/main/java/com/ivy/wallet/domain/data/{entity => core}/LoanRecord.kt (77%) rename app/src/main/java/com/ivy/wallet/domain/data/{entity => core}/PlannedPaymentRule.kt (78%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt rename app/src/main/java/com/ivy/wallet/domain/data/{entity => core}/Transaction.kt (77%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/User.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/entity/ExchangeRate.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/BankIntegrationsLogic.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeAccountMapper.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeCategoryMapper.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeTransactionMapper.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/AccountDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/BudgetDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/CategoryDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/ExchangeRateDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/LoanDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/LoanRecordDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/PlannedPaymentRuleDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/SettingsDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/TransactionDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/UserDTO.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankAccountsResponse.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionSessionResponse.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionsResponse.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankTransactionsResponse.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/AccountEntity.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/BudgetEntity.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/CategoryEntity.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/ExchangeRateEntity.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/LoanEntity.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/LoanRecordEntity.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/PlannedPaymentRuleEntity.kt rename app/src/main/java/com/ivy/wallet/{domain/data/entity/Settings.kt => io/persistence/data/SettingsEntity.kt} (56%) create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt rename app/src/main/java/com/ivy/wallet/{domain/data/entity/User.kt => io/persistence/data/UserEntity.kt} (63%) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 7f1f804381..d0b810ad20 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -140,6 +140,8 @@ -keep class com.ivy.wallet.domain.data.** { *; } -keep class com.ivy.wallet.ui.widget.** { *; } -keep class com.ivy.wallet.io.network.** { *; } +-keep class com.ivy.wallet.io.persistence.data.** { *; } +-keep class com.ivy.wallet.io.network.data.** { *; } -keep class com.ivy.wallet.domain.event.** { *; } # Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory, diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt index 1c8429fccd..65a3b80ee8 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.action.account import com.ivy.wallet.domain.action.framework.FPAction -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.io.persistence.dao.TransactionDao import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt index 4139fda1e1..eb4196e006 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.action.account import com.ivy.wallet.domain.action.framework.FPAction -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.io.persistence.dao.AccountDao import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt index c651ba72ac..025a0894f4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -3,7 +3,7 @@ package com.ivy.wallet.domain.action.account import arrow.core.nonEmptyListOf import com.ivy.wallet.domain.action.framework.FPAction import com.ivy.wallet.domain.action.framework.then -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.pure.account.AccountValueFunctions import com.ivy.wallet.domain.pure.account.calcAccValues import com.ivy.wallet.domain.pure.data.ClosedTimeRange diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt index 669acd69c2..80d2471ee2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.action.wallet import com.ivy.wallet.domain.action.framework.Action -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.WalletLogic import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.ui.onboarding.model.FromToTimeRange diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt index caaed90dc8..d65ce27952 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.action.wallet import com.ivy.wallet.domain.action.framework.Action -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.WalletLogic import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.ui.onboarding.model.FromToTimeRange 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 31b50cdb7d..143680c392 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,6 +1,6 @@ package com.ivy.wallet.domain.data -import com.ivy.wallet.domain.data.entity.* +import com.ivy.wallet.domain.data.core.* data class IvyWalletCompleteData( val accounts: List = emptyList(), diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Account.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt similarity index 62% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Account.kt rename to app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt index 12abeb68c1..293222e7b6 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Account.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt @@ -1,12 +1,9 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.domain.data.core import androidx.compose.ui.graphics.toArgb -import androidx.room.Entity -import androidx.room.PrimaryKey import com.ivy.wallet.ui.theme.Green import java.util.* -@Entity(tableName = "accounts") data class Account( val name: String, val currency: String? = null, @@ -15,13 +12,8 @@ data class Account( val orderNum: Double = 0.0, val includeInBalance: Boolean = true, - //SaltEdge integration ------- - val seAccountId: String? = null, - //SaltEdge integration ------- - val isSynced: Boolean = false, val isDeleted: Boolean = false, - @PrimaryKey val id: UUID = UUID.randomUUID() ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt similarity index 89% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt rename to app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt index 86693c0d1a..3836796898 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt @@ -1,10 +1,7 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.domain.data.core -import androidx.room.Entity -import androidx.room.PrimaryKey import java.util.* -@Entity(tableName = "budgets") data class Budget( val name: String, val amount: Double, @@ -16,7 +13,6 @@ data class Budget( val isDeleted: Boolean = false, val orderId: Double, - @PrimaryKey val id: UUID = UUID.randomUUID() ) { companion object { diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Category.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt similarity index 57% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Category.kt rename to app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt index 231722b953..7a7a13ddc4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Category.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt @@ -1,25 +1,17 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.domain.data.core import androidx.compose.ui.graphics.toArgb -import androidx.room.Entity -import androidx.room.PrimaryKey import com.ivy.wallet.ui.theme.Ivy import java.util.* -@Entity(tableName = "categories") data class Category( val name: String, val color: Int = Ivy.toArgb(), val icon: String? = null, val orderNum: Double = 0.0, - //SaltEdge integration ------- - val seCategoryName: String? = null, - //SaltEdge integration ------- - val isSynced: Boolean = false, val isDeleted: Boolean = false, - @PrimaryKey val id: UUID = UUID.randomUUID() ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt new file mode 100644 index 0000000000..c60c467821 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt @@ -0,0 +1,7 @@ +package com.ivy.wallet.domain.data.core + +data class ExchangeRate( + val baseCurrency: String, + val currency: String, + val rate: Double, +) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt similarity index 77% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt rename to app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt index 849c6d6767..7e3b6a3f92 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt @@ -1,11 +1,8 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.domain.data.core -import androidx.room.Entity -import androidx.room.PrimaryKey import com.ivy.wallet.domain.data.LoanType import java.util.* -@Entity(tableName = "loans") data class Loan( val name: String, val amount: Double, @@ -18,7 +15,6 @@ data class Loan( val isSynced: Boolean = false, val isDeleted: Boolean = false, - @PrimaryKey val id: UUID = UUID.randomUUID() ) { fun humanReadableType(): String { diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/LoanRecord.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt similarity index 77% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/LoanRecord.kt rename to app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt index f30df981f5..fbdf0ffbcd 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/LoanRecord.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt @@ -1,11 +1,8 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.domain.data.core -import androidx.room.Entity -import androidx.room.PrimaryKey import java.time.LocalDateTime import java.util.* -@Entity(tableName = "loan_records") data class LoanRecord( val loanId: UUID, val amount: Double, @@ -19,6 +16,5 @@ data class LoanRecord( val isSynced: Boolean = false, val isDeleted: Boolean = false, - @PrimaryKey val id: UUID = UUID.randomUUID() ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/PlannedPaymentRule.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt similarity index 78% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/PlannedPaymentRule.kt rename to app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt index bdac3aa3aa..b8254016a0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/PlannedPaymentRule.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt @@ -1,13 +1,10 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.domain.data.core -import androidx.room.Entity -import androidx.room.PrimaryKey import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType import java.time.LocalDateTime import java.util.* -@Entity(tableName = "planned_payment_rules") data class PlannedPaymentRule( val startDate: LocalDateTime?, val intervalN: Int?, @@ -24,6 +21,5 @@ data class PlannedPaymentRule( val isSynced: Boolean = false, val isDeleted: Boolean = false, - @PrimaryKey val id: UUID = UUID.randomUUID() ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt new file mode 100644 index 0000000000..c7b7faf7bc --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt @@ -0,0 +1,13 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.design.l0_system.Theme +import java.util.* + +data class Settings( + val theme: Theme, + val currency: String, + val bufferAmount: Double, + val name: String, + + val id: UUID = UUID.randomUUID() +) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Transaction.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt similarity index 77% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Transaction.kt rename to app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt index 8d4107ffa4..19167e1365 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Transaction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt @@ -1,13 +1,10 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.domain.data.core -import androidx.room.Entity -import androidx.room.PrimaryKey import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType import java.time.LocalDateTime import java.util.* -@Entity(tableName = "transactions") data class Transaction( val accountId: UUID, val type: TransactionType, @@ -30,22 +27,12 @@ data class Transaction( //This refers to the loan record id that is linked with a transaction val loanRecordId:UUID? = null, - //SaltEdge integration ------- - val seTransactionId: String? = null, - val seAutoCategoryId: UUID? = null, - //SaltEdge integration ------- - val isSynced: Boolean = false, val isDeleted: Boolean = false, - @PrimaryKey val id: UUID = UUID.randomUUID() ) : TransactionHistoryItem { - fun smartCategoryId(): UUID? { - return categoryId ?: seAutoCategoryId - } - fun isIdenticalWith(transaction: Transaction?): Boolean { if (transaction == null) return false diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt new file mode 100644 index 0000000000..51c1f433f4 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt @@ -0,0 +1,18 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.wallet.domain.data.AuthProviderType +import java.util.* + +data class User( + val email: String, + val authProviderType: AuthProviderType, + var firstName: String, + val lastName: String?, + val profilePicture: String?, + val color: Int, + + val testUser: Boolean = false, + var id: UUID +) { + fun names(): String = firstName + if (lastName != null) " $lastName" else "" +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/ExchangeRate.kt b/app/src/main/java/com/ivy/wallet/domain/data/entity/ExchangeRate.kt deleted file mode 100644 index d8689b9e4f..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/ExchangeRate.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ivy.wallet.domain.data.entity - -import androidx.room.Entity - -@Entity(tableName = "exchange_rates", primaryKeys = ["baseCurrency", "currency"]) -data class ExchangeRate( - val baseCurrency: String, - val currency: String, - val rate: Double, -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt index 53dcb707f8..ef14a4ccc2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.sync.item.TransactionSync import com.ivy.wallet.domain.sync.uploader.AccountUploader diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt index 8d49d89bc9..d8fd672352 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.domain.data.core.Budget import com.ivy.wallet.domain.logic.model.CreateBudgetData import com.ivy.wallet.domain.sync.uploader.BudgetUploader import com.ivy.wallet.io.persistence.dao.BudgetDao diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt index c50fc59623..fe558d25ea 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.domain.sync.uploader.CategoryUploader import com.ivy.wallet.io.persistence.dao.CategoryDao diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt index 0242c7daab..9ac205da7c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.domain.logic.model.CreateLoanData import com.ivy.wallet.domain.sync.uploader.LoanUploader import com.ivy.wallet.io.persistence.dao.LoanDao diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt index f1d9c152da..52ec399a74 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.LoanRecord import com.ivy.wallet.domain.logic.model.CreateLoanRecordData import com.ivy.wallet.domain.sync.uploader.LoanRecordUploader import com.ivy.wallet.io.persistence.dao.LoanRecordDao diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt index 8c9a765f23..b89bc936fe 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.persistence.dao.TransactionDao import java.time.LocalDateTime diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt index bb37571758..8ff123dabe 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt @@ -2,9 +2,9 @@ package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.currency.sumByDoublePlannedInBaseCurrency import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt index 49c9584d37..da2d9c289f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt @@ -1,14 +1,12 @@ package com.ivy.wallet.domain.deprecated.logic import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.stringRes import com.ivy.wallet.ui.onboarding.model.AccountBalance import com.ivy.wallet.ui.theme.* @@ -26,7 +24,7 @@ class PreloadDataLogic( fun preloadAccounts() { val cash = Account( - name = stringRes(R.string.cash), + name = "Cash", currency = null, color = Green.toArgb(), icon = "cash", @@ -35,7 +33,7 @@ class PreloadDataLogic( ) val bank = Account( - name = stringRes(R.string.bank), + name = "Bank", currency = null, color = IvyDark.toArgb(), icon = "bank", @@ -49,21 +47,21 @@ class PreloadDataLogic( fun accountSuggestions(baseCurrency: String): List = listOf( CreateAccountData( - name = stringRes(R.string.cash), + name = "Cash", currency = baseCurrency, color = Green, icon = "cash", balance = 0.0 ), CreateAccountData( - name = stringRes(R.string.bank), + name = "Bank", currency = baseCurrency, color = IvyDark, icon = "bank", balance = 0.0 ), CreateAccountData( - name = stringRes(R.string.revoult), + name = "Revolut", currency = baseCurrency, color = Blue, icon = "revolut", @@ -83,61 +81,61 @@ class PreloadDataLogic( private fun preloadCategoriesCreateData() = listOf( CreateCategoryData( - name = stringRes(R.string.food_drinks), + name = "Food & Drinks", color = Green, icon = "fooddrink" ), CreateCategoryData( - name = stringRes(R.string.bills_fees), + name = "Bills & Fees", color = Red, icon = "bills" ), CreateCategoryData( - name = stringRes(R.string.transport), + name = "Transport", color = YellowLight, icon = "transport" ), CreateCategoryData( - name = stringRes(R.string.groceries), + name = "Groceries", color = GreenLight, icon = "groceries" ), CreateCategoryData( - name = stringRes(R.string.entertainment), + name = "Entertainment", color = Orange, icon = "game" ), CreateCategoryData( - name = stringRes(R.string.shopping), + name = "Shopping", color = Ivy, icon = "shopping" ), CreateCategoryData( - name = stringRes(R.string.gifts), + name = "Gifts", color = RedLight, icon = "gift" ), CreateCategoryData( - name = stringRes(R.string.health), + name = "Health", color = IvyLight, icon = "health" ), CreateCategoryData( - name = stringRes(R.string.investments), + name = "Investments", color = IvyDark, icon = "leaf" ), CreateCategoryData( - name = stringRes(R.string.loans), + name = "Loans", color = BlueDark, icon = "loan" ), @@ -161,91 +159,91 @@ class PreloadDataLogic( .plus( listOf( CreateCategoryData( - name = stringRes(R.string.car), + name = "Car", color = Blue3, icon = "vehicle" ), CreateCategoryData( - name = stringRes(R.string.work), + name = "Work", color = Blue2Light, icon = "work" ), CreateCategoryData( - name = stringRes(R.string.home), + name = "Home", color = Green2, icon = "house" ), CreateCategoryData( - name = stringRes(R.string.restaurant), + name = "Restaurant", color = Orange3, icon = "restaurant" ), CreateCategoryData( - name = stringRes(R.string.family), + name = "Family", color = Red3Light, icon = "family" ), CreateCategoryData( - name = stringRes(R.string.social_life), + name = "Social Life", color = Blue2, icon = "people" ), CreateCategoryData( - name = stringRes(R.string.order_food), + name = "Order food", color = Orange2, icon = "orderfood2" ), CreateCategoryData( - name = stringRes(R.string.travel), + name = "Travel", color = BlueLight, icon = "travel" ), CreateCategoryData( - name = stringRes(R.string.fitness), + name = "Fitness", color = Purple2, icon = "fitness" ), CreateCategoryData( - name = stringRes(R.string.self_development), + name = "Self-development", color = Yellow, icon = "selfdevelopment" ), CreateCategoryData( - name = stringRes(R.string.clothes), + name = "Clothes", color = Green2Light, icon = "clothes2" ), CreateCategoryData( - name = stringRes(R.string.beauty), + name = "Beauty", color = Red3, icon = "makeup" ), CreateCategoryData( - name = stringRes(R.string.education), + name = "Education", color = Blue, icon = "education" ), CreateCategoryData( - name = stringRes(R.string.pet), + name = "Pet", color = Orange3Light, icon = "pet" ), CreateCategoryData( - name = stringRes(R.string.sports), + name = "Sports", color = Purple1, icon = "sports" ), diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt index 54d8a22f47..c516a3bac8 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.ui.edit.core.SUGGESTIONS_LIMIT import com.ivy.wallet.utils.capitalizeWords diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt index 81edf87e03..4aa7e2ef26 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt @@ -3,16 +3,14 @@ package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.stringRes import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import com.ivy.wallet.ui.onboarding.model.filterOverdue -import com.ivy.wallet.ui.onboarding.model.filterUpcoming import com.ivy.wallet.utils.timeNowUTC import java.time.LocalDateTime import kotlin.math.abs diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt index 1316602d76..292d08698f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt @@ -2,16 +2,14 @@ package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import com.ivy.wallet.ui.onboarding.model.filterOverdue -import com.ivy.wallet.ui.onboarding.model.filterUpcoming import java.util.* @Deprecated("Migrate to FP Style") diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt index 20b1b154ba..ce4c1f1008 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt @@ -3,15 +3,13 @@ package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import com.ivy.wallet.ui.onboarding.model.filterOverdue -import com.ivy.wallet.ui.onboarding.model.filterUpcoming import com.ivy.wallet.utils.beginningOfIvyTime import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/BankIntegrationsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/BankIntegrationsLogic.kt deleted file mode 100644 index da510959cb..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/BankIntegrationsLogic.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.ivy.wallet.domain.deprecated.logic.bankintegrations - -import com.ivy.wallet.domain.data.bankintegrations.SEAccount -import com.ivy.wallet.domain.data.bankintegrations.SEConnection -import com.ivy.wallet.domain.data.bankintegrations.SETransaction -import com.ivy.wallet.io.network.IvySession -import com.ivy.wallet.io.network.RestClient -import com.ivy.wallet.io.persistence.SharedPrefs -import com.ivy.wallet.ui.RootActivity - -@Deprecated("Use FP style, look into `domain.fp` package") -class BankIntegrationsLogic( - restClient: RestClient, - private val seTransactionMapper: SaltEdgeTransactionMapper, - private val ivySession: IvySession, - private val sharedPrefs: SharedPrefs -) { - private val bankIntegrationsService = restClient.bankIntegrationsService - - suspend fun connect( - rootActivity: RootActivity - ) { - val response = bankIntegrationsService.connectSession() - rootActivity.openUrlInBrowser(response.connectUrl) - } - - suspend fun fetchConnections(): List { - if (!hasBankConnection()) return emptyList() //do nothing if the user isn't logged in - - return bankIntegrationsService.getConnections().connections - } - - suspend fun sync() { - if (!hasBankConnection()) return //do nothing if the user isn't logged in - - val seAccounts = fetchAccounts() - val seTransactions = fetchTransactions() - - seTransactionMapper.save( - seAccounts = seAccounts, - seTransactions = seTransactions - ) - } - - private suspend fun hasBankConnection(): Boolean { - //TODO: Check for SEConnections in table - return ivySession.isLoggedIn() && sharedPrefs.getBoolean( - SharedPrefs.ENABLE_BANK_SYNC, - false - ) - } - - private suspend fun fetchAccounts(): List { - return bankIntegrationsService.getAccounts().accounts - } - - private suspend fun fetchTransactions(): List { - return bankIntegrationsService.getTransactions().transactions - } - - suspend fun removeCustomer() { - bankIntegrationsService.removeCustomer() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeAccountMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeAccountMapper.kt deleted file mode 100644 index 51ef503bbf..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeAccountMapper.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.ivy.wallet.domain.deprecated.logic.bankintegrations - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.bankintegrations.SEAccount -import com.ivy.wallet.domain.data.bankintegrations.SETransaction -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.ui.theme.components.IVY_COLOR_PICKER_COLORS_FREE -import com.ivy.wallet.utils.toLowerCaseLocal -import java.util.* - -@Deprecated("Use FP style, look into `domain.fp` package") -class SaltEdgeAccountMapper( - private val accountDao: AccountDao -) { - - fun mapAccount( - seAccounts: List, - seTransaction: SETransaction - ): UUID? { - val existingAccount = accountDao.findBySeAccountId( - seAccountId = seTransaction.account_id - ) - - val account = if (existingAccount == null) { - //create account - val seAccount = seAccounts.find { it.id == seTransaction.account_id } ?: return null - - val account = Account( - seAccountId = seAccount.id, - - name = seAccount.name, - color = mapColor(seAccount).toArgb(), - icon = mapIcon(seAccount), - - currency = IvyCurrency.fromCode(seAccount.currency_code)?.code, - orderNum = accountDao.findMaxOrderNum(), - - isSynced = false, - isDeleted = false - ) - - accountDao.save(account) - - account - } else existingAccount - - return account.id - } - - private fun mapColor(seAccount: SEAccount): Color { - //TODO: Create better mapping - return IVY_COLOR_PICKER_COLORS_FREE.shuffled().first() - } - - private fun mapIcon(seAccount: SEAccount): String? { - //TODO: Create better mapping - return when { - seAccount.name.toLowerCaseLocal().contains("revolut") -> { - "revolut" - } - else -> null - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeCategoryMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeCategoryMapper.kt deleted file mode 100644 index a47e597c3b..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeCategoryMapper.kt +++ /dev/null @@ -1,371 +0,0 @@ -package com.ivy.wallet.domain.deprecated.logic.bankintegrations - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.domain.data.bankintegrations.SETransaction -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.ui.theme.* -import com.ivy.wallet.ui.theme.components.IVY_COLOR_PICKER_COLORS_FREE -import com.ivy.wallet.utils.capitalizeLocal -import java.util.* - -/* -{ - "data": { - "business": { - "equipment_and_materials": [ - "electronics", - "software", - "supplies_and_furniture", - "raw_materials", - "consumer_goods" - ], - "financials": [ - "dividends", - "donations", - "interest", - "fees", - "fines", - "loans" - ], - "human_resources": [ - "wages", - "bonus", - "employee_benefits", - "education_and_trainings", - "staff_outsourcing", - "travel", - "entertainment", - "meals" - ], - "income": [ - "investments", - "sales", - "returns", - "prepayments" - ], - "insurance": [ - "business_insurance", - "liability_insurance", - "health_insurance", - "equipment_insurance", - "vehicle_insurance", - "professional_insurance" - ], - "real_estate": [ - "office_rent", - "mortgage", - "construction_and_repair" - ], - "services": [ - "contractors", - "accounting_and_auditing", - "legal", - "consulting", - "storage", - "marketing_and_media", - "online_subscriptions", - "it_services", - "cleaning" - ], - "taxes": [ - "vat", - "federal_taxes", - "property_taxes", - "income_taxes", - "duty_taxes", - "tax_return", - "payroll_taxes" - ], - "transport": [ - "shipping", - "leasing", - "gas_and_fuel", - "taxi", - "service_and_parts" - ], - "uncategorized": [], - "utilities": [ - "internet", - "phone", - "water", - "gas", - "electricity" - ] - }, - "personal": { - "auto_and_transport": [ - "car_rental", - "gas_and_fuel", - "parking", - "public_transportation", - "service_and_parts", - "taxi" - ], - "bills_and_utilities": [ - "internet", - "phone", - "television", - "utilities" - ], - "business_services": [ - "advertising", - "office_supplies", - "shipping" - ], - "education": [ - "books_and_supplies", - "student_loan", - "tuition" - ], - "entertainment": [ - "amusement", - "arts", - "games", - "movies_and_music", - "newspapers_and_magazines" - ], - "fees_and_charges": [ - "provider_fee", - "loans", - "service_fee", - "taxes" - ], - "food_and_dining": [ - "alcohol_and_bars", - "cafes_and_restaurants", - "groceries" - ], - "gifts_and_donations": [ - "charity", - "gifts" - ], - "health_and_fitness": [ - "doctor", - "personal_care", - "pharmacy", - "sports", - "wellness" - ], - "home": [ - "home_improvement", - "home_services", - "home_supplies", - "mortgage", - "rent" - ], - "income": [ - "bonus", - "investment_income", - "paycheck" - ], - "insurance": [ - "car_insurance", - "health_insurance", - "life_insurance", - "property_insurance" - ], - "kids": [ - "allowance", - "babysitter_and_daycare", - "baby_supplies", - "child_support", - "kids_activities", - "toys" - ], - "pets": [ - "pet_food_and_supplies", - "pet_grooming", - "veterinary" - ], - "shopping": [ - "clothing", - "electronics_and_software", - "sporting_goods" - ], - "transfer": [], - "travel": [ - "hotel", - "transportation", - "vacation" - ], - "uncategorized": [] - } - } -} - */ - -@Deprecated("Use FP style, look into `domain.fp` package") -class SaltEdgeCategoryMapper( - private val categoryDao: CategoryDao -) { - - fun mapSeAutoCategoryId( - seTransaction: SETransaction - ): UUID? { - val existingCategory = categoryDao.findBySeCategoryName( - seCategoryName = seTransaction.category - ) - - val seAutoCategory = if (existingCategory == null) { - //Try to map and create category - val seAutoCategory = mapSeCategoryName(seTransaction.category)?.copy( - orderNum = categoryDao.findMaxOrderNum(), - - isSynced = false, - isDeleted = false - ) - - if (seAutoCategory != null) { - categoryDao.save( - seAutoCategory - ) - } - - seAutoCategory - } else existingCategory - - return seAutoCategory?.id - } - - private fun mapSeCategoryName(seCategoryName: String): Category? { - if (seCategoryName == "uncategorized") return null - - val colorIcon = mapCategoryColorIcon(seCategoryName = seCategoryName) - - return Category( - name = seCategoryName - .replace("_", " ") - .capitalizeLocal(), - seCategoryName = seCategoryName, - color = (colorIcon?.first ?: IVY_COLOR_PICKER_COLORS_FREE.shuffled().first()).toArgb(), - icon = colorIcon?.second - ) - } - - private fun mapCategoryColorIcon(seCategoryName: String): Pair? { - return when (seCategoryName) { - "electronics" -> Pair(Blue, "atom") - "software" -> Pair(Blue3, "programming") - "supplies_and_furniture" -> Pair(Orange2Dark, "label") - "raw_materials" -> Pair(Green2Dark, "hike") - "consumer_goods" -> Pair(Blue3Light, "shopping") - "dividends" -> Pair(Orange3, "calculator") - "donations" -> Pair(Yellow, "relationship") - "interest" -> Pair(Purple1Light, "selfdevelopment") - "fees" -> Pair(Orange, "document") - "fines" -> Pair(Orange2Dark, "loan") - "loans" -> Pair(Blue2Dark, "loan") - "wages" -> Pair(IvyDark, "work") - "bonus" -> Pair(YellowLight, "diamond") - "employee_benefits" -> Pair(Blue2, "people") - "education_and_trainings" -> Pair(Blue, "education") - "staff_outsourcing" -> Pair(Green3, "people") - "travel" -> Pair(BlueLight, "travel") - "entertainment" -> Pair(Orange, "game") - "meals" -> Pair(Green2, "restaurant") - "investments" -> Pair(Green2Light, "document") - "sales" -> Pair(Yellow, "label") - "returns" -> Pair(OrangeLight, "category") - "prepayments" -> Pair(GreenLight, "bills") - "business_insurance" -> Pair(Blue2, "insurance") - "liability_insurance" -> Pair(Blue2, "insurance") - "health_insurance," -> Pair(Green2Light, "insurance") - "equipment_insurance" -> Pair(Blue2, "insurance") - "vehicle_insurance" -> Pair(Blue2, "insurance") - "professional_insurance" -> Pair(Blue2, "insurance") - "office_rent" -> Pair(BlueDark, "work") - "mortgage" -> Pair(Orange2Dark, "house") - "construction_and_repair" -> Pair(OrangeDark, "tools") - "contractors" -> Pair(Blue3Dark, "document") - "accounting_and_auditing" -> Pair(Blue3, "document") - "legal" -> Pair(Blue3Dark, "document") - "consulting" -> Pair(Blue2Light, "people") - "storage" -> Pair(Orange2Dark, "furniture") - "marketing_and_media" -> Pair(Orange, "rocket") - "online_subscriptions" -> Pair(Orange3, "connect") - "it_services" -> Pair(Blue, "programming") - "cleaning" -> Pair(Blue2Light, "house") - "vat" -> Pair(OrangeLight, "loan") - "federal_taxes" -> Pair(RedDark, "loan") - "property_taxes" -> Pair(RedDark, "loan") - "income_taxes" -> Pair(RedDark, "loan") - "duty_taxes" -> Pair(RedDark, "loan") - "tax_return" -> Pair(GreenDark, "loan") - "payroll_taxes" -> Pair(RedDark, "loan") - "shipping" -> Pair(Yellow, "shopping2") - "leasing" -> Pair(Green4, "house") - "gas_and_fuel" -> Pair(Green3Dark, "vehicle") - "taxi" -> Pair(YellowLight, "vehicle") - "service_and_parts" -> Pair(Green2, "tools") - "internet" -> Pair(BlueLight, "connect") - "phone" -> Pair(BlueLight, "bills") - "water" -> Pair(BlueLight, "bills") - "gas" -> Pair(Orange3Light, "bills") - "electricity" -> Pair(Blue2Light, "bills") - "car_rental" -> Pair(BlueDark, "vehicle") - "parking" -> Pair(GreenDark, "vehicle") - "public_transportation" -> Pair(Purple1, "transport") - "television" -> Pair(Green3Dark, "bills") - "utilities" -> Pair(Blue, "bills") - "advertising" -> Pair(Orange2, "rocket") - "office_supplies" -> Pair(BlueLight, "work") - "books_and_supplies" -> Pair(BlueLight, "document") - "student_loan" -> Pair(Blue2Dark, "loan") - "tuition" -> Pair(Blue2Dark, "education") - "education" -> Pair(Blue2Dark, "education") - "amusement" -> Pair(Orange, "rocket") - "arts" -> Pair(Red, "palette") - "games" -> Pair(Orange, "game") - "movies_and_music" -> Pair(Red, "music") - "newspapers_and_magazines" -> Pair(Orange, "document") - "provider_fee" -> Pair(RedLight, "loan") - "service_fee" -> Pair(RedDark, "loan") - "taxes" -> Pair(RedDark, "bills") - "alcohol_and_bars" -> Pair(Purple2Dark, "fooddrink") - "cafes_and_restaurants" -> Pair(Green, "coffee") - "groceries" -> Pair(Green4, "groceries") - "charity" -> Pair(GreenLight, "selfdevelopment") - "gifts" -> Pair(Red, "gift") - "doctor" -> Pair(Blue2Light, "health") - "personal_care" -> Pair(Blue2Light, "hairdresser") - "pharmacy" -> Pair(Blue2Light, "farmacy") - "sports" -> Pair(IvyLight, "sports") - "wellness" -> Pair(GreenLight, "fitness") - "home_improvement" -> Pair(Blue2Light, "house") - "home_services" -> Pair(Blue2Light, "house") - "home_supplies" -> Pair(Blue2Light, "house") - "rent" -> Pair(BlueDark, "house") - "investment_income" -> Pair(Green2Light, "leaf") - "paycheck" -> Pair(Green, "work") - "car_insurance" -> Pair(Blue2, "insurance") - "health_insurance" -> Pair(Blue2, "insurance") - "life_insurance" -> Pair(Green2Light, "insurance") - "property_insurance" -> Pair(Blue2, "insurance") - "allowance" -> Pair(GreenLight, "loan") - "babysitter_and_daycare" -> Pair(BlueLight, "family") - "baby_supplies" -> Pair(BlueLight, "shopping2") - "child_support" -> Pair(BlueLight, "family") - "kids_activities" -> Pair(Blue, "sports") - "toys" -> Pair(Yellow, "rocket") - "pet_food_and_supplies" -> Pair(Orange3Light, "pet") - "pet_grooming" -> Pair(Orange3Light, "pet") - "veterinary" -> Pair(Purple1, "pet") - "clothing" -> Pair(Red3, "clothes2") - "electronics_and_software" -> Pair(Blue, "atom") - "sporting_goods" -> Pair(Blue, "sports") - "hotel" -> Pair(Orange2Dark, "location") - "transportation" -> Pair(Yellow, "transport") - "vacation" -> Pair(Blue2Light, "travel") - - //Extra not documented categories - "bills_and_utilities" -> Pair(Red, "bills") - "business_services" -> Pair(BlueDark, "groceries") - "shopping" -> Pair(BlueLight, "shopping") - "income" -> Pair(Green, "work") - "transfer" -> Pair(Ivy, "bank") - else -> null - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeTransactionMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeTransactionMapper.kt deleted file mode 100644 index 031849688c..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/bankintegrations/SaltEdgeTransactionMapper.kt +++ /dev/null @@ -1,165 +0,0 @@ -package com.ivy.wallet.domain.deprecated.logic.bankintegrations - -import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.bankintegrations.SEAccount -import com.ivy.wallet.domain.data.bankintegrations.SETransaction -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.WalletAccountLogic -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.TransactionDao -import com.ivy.wallet.utils.ioThread -import timber.log.Timber -import java.time.LocalDate -import java.time.LocalDateTime -import java.time.LocalTime -import java.time.format.DateTimeFormatter -import java.util.* -import kotlin.math.absoluteValue - -@Deprecated("Use FP style, look into `domain.fp` package") -class SaltEdgeTransactionMapper( - private val transactionDao: TransactionDao, - private val seAccountMapper: SaltEdgeAccountMapper, - private val seCategoryMapper: SaltEdgeCategoryMapper, - private val accountDao: AccountDao, - private val walletAccountLogic: WalletAccountLogic -) { - - suspend fun save(seAccounts: List, seTransactions: List) { - ioThread { - syncTransactions( - seTransactions = seTransactions, - seAccounts = seAccounts - ) - - syncBalances( - seAccounts = seAccounts - ) - } - } - - private fun syncTransactions( - seTransactions: List, - seAccounts: List - ) { - seTransactions.mapNotNull { - mapSeTransaction( - seAccounts = seAccounts, - seTransaction = it - ) - }.forEach { - transactionDao.save(it) - } - } - - private fun syncBalances( - seAccounts: List - ) { - val seAccountToAccount = seAccounts.map { seAccount -> - seAccount to accountDao.findBySeAccountId(seAccount.id) - }.toMap() - - seAccountToAccount.forEach { (seAccount, account) -> - if (account != null) { - walletAccountLogic.adjustBalance( - account = account, - newBalance = seAccount.balance, - adjustTransactionTitle = "Auto-adjust bank account balance", - isFiat = true, - trnIsSyncedFlag = false - ) - } - } - } - - private fun mapSeTransaction( - seAccounts: List, - seTransaction: SETransaction - ): Transaction? { - val existingIvyTransaction = transactionDao.findBySeTransactionId( - seTransactionId = seTransaction.id - ) - - //Persist ---------------------------------------------------------------------- - val ivyTrnId = existingIvyTransaction?.id ?: UUID.randomUUID() - val categoryId = existingIvyTransaction?.categoryId - val title = existingIvyTransaction?.title ?: seTransaction.description - val description = existingIvyTransaction?.description - //Persist ---------------------------------------------------------------------- - - //Map -------------------------------------------------------------------------- - val accountId = seAccountMapper.mapAccount( - seAccounts = seAccounts, - seTransaction = seTransaction - ) ?: return null - - val seAutoCategoryId = seCategoryMapper.mapSeAutoCategoryId( - seTransaction = seTransaction - ) - - val type = if (seTransaction.amount > 0) - TransactionType.INCOME else TransactionType.EXPENSE - val amount = seTransaction.amount.absoluteValue - - val dateTime = mapDateTime(seTransaction = seTransaction) - //Map -------------------------------------------------------------------------- - - val finalTransaction = Transaction( - id = ivyTrnId, - type = type, - amount = amount, - accountId = accountId, - dateTime = dateTime, - - categoryId = categoryId, - seTransactionId = seTransaction.id, - seAutoCategoryId = seAutoCategoryId, - description = description, - title = title, - ) - val shouldUploadToSerer = !finalTransaction.isIdenticalWith(existingIvyTransaction) || - existingIvyTransaction?.isSynced == false - Timber.i("Should upload to server: $shouldUploadToSerer") - - return finalTransaction.copy( - isSynced = !shouldUploadToSerer, - isDeleted = false - ) - } - - private fun mapDateTime(seTransaction: SETransaction): LocalDateTime? { - val time = (seTransaction.extra?.get("time") as? String?) - ?.parseSaltEdgeTime() ?: LocalTime.of(12, 0, 0) - - return seTransaction.made_on - .parseSaltEdgeDate() - ?.atTime(time) ?: return null - } - - private fun String.parseSaltEdgeTime(): LocalTime? { - return try { - LocalTime.parse(this) - } catch (e: Exception) { - e.printStackTrace() - null - } - } - - private fun String.parseSaltEdgeDate(): LocalDate? { - return try { - return LocalDate.parse(this, DateTimeFormatter.ofPattern("yyyy-MM-dd")) - } catch (e: Exception) { - e.printStackTrace() - null - } - } - - private fun String.parseSaltEdgeDateTime(): LocalDateTime? { - return try { - return LocalDateTime.parse(this, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssz")) - } catch (e: Exception) { - e.printStackTrace() - null - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt index 9d9b1f19e1..6dadc36b44 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt @@ -3,9 +3,9 @@ package com.ivy.wallet.domain.deprecated.logic.csv import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.csv.model.CSVRow import com.ivy.wallet.domain.logic.csv.model.ImportResult import com.ivy.wallet.domain.logic.csv.model.RowMapping diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt index e1c2a054ee..61ddd35155 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.deprecated.logic.csv import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.csv.model.ImportType import com.ivy.wallet.domain.logic.csv.model.JoinResult import com.ivy.wallet.domain.logic.csv.model.RowMapping diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt index 786db7ed5e..af4b53837a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt @@ -3,9 +3,9 @@ package com.ivy.wallet.domain.deprecated.logic.csv import android.content.Context import android.net.Uri import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt index 32256b39a9..5bd01acb35 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.deprecated.logic.csv.model -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction data class RowMapping( val type: Int? = null, diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt index 781966bfde..831fbc3714 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt @@ -1,9 +1,9 @@ package com.ivy.wallet.domain.deprecated.logic.currency -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.ExchangeRate -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.ExchangeRate +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.service.CoinbaseService import com.ivy.wallet.io.persistence.dao.AccountDao diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt index 81a0527b76..ba088576e7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt @@ -2,10 +2,10 @@ package com.ivy.wallet.domain.deprecated.logic.loantrasactions import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.model.CreateLoanData import com.ivy.wallet.utils.computationThread import com.ivy.wallet.utils.scopedIOThread diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt index 995009deb0..fe7c9c25c1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.domain.deprecated.logic.loantrasactions -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.model.CreateLoanRecordData import com.ivy.wallet.utils.computationThread import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt index c4acbe6d42..cb89056747 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt @@ -4,7 +4,7 @@ import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.R import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.* +import com.ivy.wallet.domain.data.core.* import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.sync.uploader.TransactionUploader import com.ivy.wallet.io.persistence.dao.* diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt index d6caa61964..20c431e0a6 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic.loantrasactions -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.utils.computationThread data class LoanTransactionsLogic( diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt index bbe49ad622..826613c6e8 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt @@ -2,7 +2,7 @@ package com.ivy.wallet.domain.deprecated.logic.model import androidx.compose.ui.graphics.Color import com.ivy.wallet.domain.data.LoanType -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account data class CreateLoanData( val name: String, diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt index 8980be66b1..df578879ea 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic.model -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import java.time.LocalDateTime data class CreateLoanRecordData( diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt index f06a15be42..542db83cc9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic.model -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.LoanRecord data class EditLoanRecordData( val newLoanRecord: LoanRecord, diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt index 1331cb5b3d..c312873821 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.account.DeleteAccountRequest diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt index 5d6e027c40..9e127ab70a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.domain.data.core.Budget import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.budget.CrupdateBudgetRequest diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt index fef9bbddcb..247377a616 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.category.DeleteWalletCategoryRequest diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt index 76edc98ef7..a5e706ad73 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.LoanRecord import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.loan.DeleteLoanRecordRequest diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt index 39c4144a55..6a0593f150 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.loan.DeleteLoanRequest diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt index 33645f0be0..b8ded6de05 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.planned.DeletePlannedPaymentRuleRequest diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt index 3077153154..c07b92610f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.transaction.DeleteTransactionRequest diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt b/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt index d0d8061431..3095598b3e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt @@ -5,7 +5,7 @@ import arrow.core.Option import arrow.core.Some import arrow.core.computations.option import arrow.core.toOption -import com.ivy.wallet.domain.data.entity.ExchangeRate +import com.ivy.wallet.domain.data.core.ExchangeRate import com.ivy.wallet.domain.pure.core.Pure import com.ivy.wallet.domain.pure.core.SideEffect import com.ivy.wallet.utils.isNotNullOrBlank diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt index e0abaa522a..a27c307234 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.pure.account import arrow.core.NonEmptyList -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.core.Pure import com.ivy.wallet.domain.pure.core.Total import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSum diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt index 6dc9dbc9d5..4b34da7f27 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.pure.category import arrow.core.NonEmptyList -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSumSuspend import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.domain.pure.data.WalletDAOs diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt index 48f16f10e6..342c48dd03 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt @@ -3,7 +3,7 @@ package com.ivy.wallet.domain.pure.category import arrow.core.Option import arrow.core.toOption import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.pure.core.SuspendValueFunction import com.ivy.wallet.domain.pure.data.FPTransaction import com.ivy.wallet.domain.pure.exchangeToBaseCurrency diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt index 9e3c7ff7df..ffa27aaa18 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.pure.core import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.data.FPTransaction import com.ivy.wallet.domain.pure.data.toFPTransaction import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt index f0c0559c6a..3db8db2312 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt @@ -2,7 +2,7 @@ package com.ivy.wallet.domain.pure.data import arrow.core.Option import arrow.core.toOption -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import java.util.* data class FPAccount( diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt index 2b238d48a8..eafc522431 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt @@ -3,7 +3,7 @@ package com.ivy.wallet.domain.pure.data import arrow.core.Option import arrow.core.toOption import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import java.math.BigDecimal import java.time.LocalDateTime import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt index 5e2c0a4be2..147f111e65 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt @@ -3,9 +3,9 @@ package com.ivy.wallet.domain.pure.wallet import arrow.core.NonEmptyList import arrow.core.Some import arrow.core.toOption -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.ExchangeRate -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.ExchangeRate +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.ExchangeData import com.ivy.wallet.domain.pure.account.AccountValueFunction import com.ivy.wallet.domain.pure.account.calcAccValues diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt index abc6171bac..ffe736c8c2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.pure.wallet import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.data.entity.Settings +import com.ivy.wallet.domain.data.core.Settings import com.ivy.wallet.domain.pure.account.AccountValueFunctions import com.ivy.wallet.domain.pure.core.Uncertain import com.ivy.wallet.domain.pure.data.ClosedTimeRange diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt index 3339b9d705..6552d2aaa2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt @@ -4,8 +4,8 @@ import arrow.core.Option import arrow.core.toOption import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.ExchangeData import com.ivy.wallet.domain.pure.core.* import com.ivy.wallet.domain.pure.data.FPTransaction diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/AccountDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/AccountDTO.kt new file mode 100644 index 0000000000..37f758c248 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/AccountDTO.kt @@ -0,0 +1,30 @@ +package com.ivy.wallet.io.network.data + +import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.persistence.data.AccountEntity +import com.ivy.wallet.ui.theme.Green +import java.util.* + +data class AccountDTO( + val name: String, + val currency: String? = null, + val color: Int = Green.toArgb(), + val icon: String? = null, + val orderNum: Double = 0.0, + val includeInBalance: Boolean = true, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): AccountEntity = AccountEntity( + name = name, + currency = currency, + color = color, + icon = icon, + orderNum = orderNum, + includeInBalance = includeInBalance, + id = id, + isSynced = true, + isDeleted = false + ) +} + diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/BudgetDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/BudgetDTO.kt new file mode 100644 index 0000000000..c3e395afc8 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/BudgetDTO.kt @@ -0,0 +1,66 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.io.persistence.data.BudgetEntity +import java.util.* + +data class BudgetDTO( + val name: String, + val amount: Double, + + val categoryIdsSerialized: String?, + val accountIdsSerialized: String?, + + val orderId: Double, + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): BudgetEntity = BudgetEntity( + name = name, + amount = amount, + categoryIdsSerialized = categoryIdsSerialized, + accountIdsSerialized = accountIdsSerialized, + orderId = orderId, + id = id, + isSynced = true, + isDeleted = false + ) + + companion object { + fun serialize(ids: List): String { + return ids.joinToString(separator = ",") + } + + fun type(categoriesCount: Int): String { + return when (categoriesCount) { + 0 -> "Total Budget" + 1 -> "Category Budget" + else -> "Multi-Category ($categoriesCount) Budget" + } + } + } + + fun parseCategoryIds(): List { + return parseIdsString(categoryIdsSerialized) + } + + fun parseAccountIds(): List { + return parseIdsString(accountIdsSerialized) + } + + private fun parseIdsString(idsString: String?): List { + return try { + if (idsString == null) return emptyList() + + idsString + .split(",") + .map { UUID.fromString(it) } + } catch (e: Exception) { + e.printStackTrace() + emptyList() + } + } + + + fun validate(): Boolean { + return name.isNotEmpty() && amount > 0.0 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/CategoryDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/CategoryDTO.kt new file mode 100644 index 0000000000..a013b9de29 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/CategoryDTO.kt @@ -0,0 +1,24 @@ +package com.ivy.wallet.io.network.data + +import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.persistence.data.CategoryEntity +import com.ivy.wallet.ui.theme.Ivy +import java.util.* + +data class CategoryDTO( + val name: String, + val color: Int = Ivy.toArgb(), + val icon: String? = null, + val orderNum: Double = 0.0, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): CategoryEntity = CategoryEntity( + name = name, + color = color, + icon = icon, + orderNum = orderNum, + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/ExchangeRateDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/ExchangeRateDTO.kt new file mode 100644 index 0000000000..0dc2b63ee9 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/ExchangeRateDTO.kt @@ -0,0 +1,13 @@ +package com.ivy.wallet.io.network.data + +data class ExchangeRateDTO( + val baseCurrency: String, + val currency: String, + val rate: Double, +) { + fun toEntity(): ExchangeRateDTO = ExchangeRateDTO( + baseCurrency = baseCurrency, + currency = currency, + rate = rate + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/LoanDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/LoanDTO.kt new file mode 100644 index 0000000000..bccc945f43 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/LoanDTO.kt @@ -0,0 +1,35 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.domain.data.LoanType +import com.ivy.wallet.io.persistence.data.LoanEntity +import java.util.* + +data class LoanDTO( + val name: String, + val amount: Double, + val type: LoanType, + val color: Int = 0, + val icon: String? = null, + val orderNum: Double = 0.0, + val accountId: UUID? = null, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): LoanEntity = LoanEntity( + name = name, + amount = amount, + type = type, + color = color, + icon = icon, + orderNum = orderNum, + accountId = accountId, + id = id, + + isSynced = true, + isDeleted = false + ) + + fun humanReadableType(): String { + return if (type == LoanType.BORROW) "BORROWED" else "LENT" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/LoanRecordDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/LoanRecordDTO.kt new file mode 100644 index 0000000000..9062cec26f --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/LoanRecordDTO.kt @@ -0,0 +1,32 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.io.persistence.data.LoanRecordEntity +import java.time.LocalDateTime +import java.util.* + +data class LoanRecordDTO( + val loanId: UUID, + val amount: Double, + val note: String? = null, + val dateTime: LocalDateTime, + val interest: Boolean = false, + val accountId: UUID? = null, + //This is used store the converted amount for currencies which are different from the loan account currency + val convertedAmount: Double? = null, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): LoanRecordEntity = LoanRecordEntity( + loanId = loanId, + amount = amount, + note = note, + dateTime = dateTime, + interest = interest, + accountId = accountId, + convertedAmount = convertedAmount, + id = id, + + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/PlannedPaymentRuleDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/PlannedPaymentRuleDTO.kt new file mode 100644 index 0000000000..f9310370d3 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/PlannedPaymentRuleDTO.kt @@ -0,0 +1,39 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.domain.data.IntervalType +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.persistence.data.PlannedPaymentRuleEntity +import java.time.LocalDateTime +import java.util.* + +data class PlannedPaymentRuleDTO( + val startDate: LocalDateTime?, + val intervalN: Int?, + val intervalType: IntervalType?, + val oneTime: Boolean, + + val type: TransactionType, + val accountId: UUID, + val amount: Double = 0.0, + val categoryId: UUID? = null, + val title: String? = null, + val description: String? = null, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): PlannedPaymentRuleEntity = PlannedPaymentRuleEntity( + startDate = startDate, + intervalN = intervalN, + intervalType = intervalType, + oneTime = oneTime, + type = type, + accountId = accountId, + amount = amount, + categoryId = categoryId, + title = title, + id = id, + + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/SettingsDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/SettingsDTO.kt new file mode 100644 index 0000000000..49b0d54695 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/SettingsDTO.kt @@ -0,0 +1,25 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.design.l0_system.Theme +import com.ivy.wallet.io.persistence.data.SettingsEntity +import java.util.* + +data class SettingsDTO( + val theme: Theme, + val currency: String, + val bufferAmount: Double, + val name: String, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): SettingsEntity = SettingsEntity( + theme = theme, + currency = currency, + bufferAmount = bufferAmount, + name = name, + id = id, + + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/TransactionDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/TransactionDTO.kt new file mode 100644 index 0000000000..fa7c7f5f54 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/TransactionDTO.kt @@ -0,0 +1,52 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.persistence.data.TransactionEntity +import java.time.LocalDateTime +import java.util.* + +data class TransactionDTO( + val accountId: UUID, + val type: TransactionType, + val amount: Double, + val toAccountId: UUID? = null, + val toAmount: Double? = null, + val title: String? = null, + val description: String? = null, + val dateTime: LocalDateTime? = null, + val categoryId: UUID? = null, + val dueDate: LocalDateTime? = null, + + val recurringRuleId: UUID? = null, + + val attachmentUrl: String? = null, + + //This refers to the loan id that is linked with a transaction + val loanId: UUID? = null, + + //This refers to the loan record id that is linked with a transaction + val loanRecordId: UUID? = null, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): TransactionEntity = TransactionEntity( + accountId = accountId, + type = type, + amount = amount, + toAccountId = toAccountId, + toAmount = toAmount, + title = title, + description = description, + dateTime = dateTime, + categoryId = categoryId, + dueDate = dueDate, + recurringRuleId = recurringRuleId, + attachmentUrl = attachmentUrl, + loanId = loanId, + loanRecordId = loanRecordId, + id = id, + + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/UserDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/UserDTO.kt new file mode 100644 index 0000000000..fcb34ae15a --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/UserDTO.kt @@ -0,0 +1,30 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.domain.data.AuthProviderType +import com.ivy.wallet.io.persistence.data.UserEntity +import java.util.* + +data class UserDTO( + val email: String, + val authProviderType: AuthProviderType, + var firstName: String, + val lastName: String?, + val profilePicture: String?, + val color: Int, + + val testUser: Boolean = false, + var id: UUID +) { + fun toEntity(): UserEntity = UserEntity( + email = email, + authProviderType = authProviderType, + firstName = firstName, + lastName = lastName, + profilePicture = profilePicture, + color = color, + testUser = testUser, + id = id, + ) + + fun names(): String = firstName + if (lastName != null) " $lastName" else "" +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/account/AccountsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/account/AccountsResponse.kt index 31ae7b1250..fd0d885d68 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/account/AccountsResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/account/AccountsResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.account -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.io.network.data.AccountDTO data class AccountsResponse( - val accounts: List + val accounts: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/account/UpdateAccountRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/account/UpdateAccountRequest.kt index 9e3bca215e..d2136e8a6d 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/account/UpdateAccountRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/account/UpdateAccountRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.account -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.io.network.data.AccountDTO data class UpdateAccountRequest( - val account: Account? = null + val account: AccountDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/auth/AuthResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/auth/AuthResponse.kt index 674a7cf43e..62eddc5051 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/auth/AuthResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/auth/AuthResponse.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.auth import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User data class AuthResponse( @SerializedName("user") diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/auth/UpdateUserInfoResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/auth/UpdateUserInfoResponse.kt index 6570cfbdd6..d37241f64f 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/auth/UpdateUserInfoResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/auth/UpdateUserInfoResponse.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.auth import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User data class UpdateUserInfoResponse( @SerializedName("user") diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankAccountsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankAccountsResponse.kt deleted file mode 100644 index efa3904b45..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankAccountsResponse.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ivy.wallet.io.network.request.bankintegrations - -import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.bankintegrations.SEAccount - -data class BankAccountsResponse( - @SerializedName("accounts") - val accounts: List -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionSessionResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionSessionResponse.kt deleted file mode 100644 index db67cf0dc5..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionSessionResponse.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.ivy.wallet.io.network.request.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class BankConnectionSessionResponse( - @SerializedName("connectUrl") - val connectUrl: String -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionsResponse.kt deleted file mode 100644 index 1dae8bb2ca..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionsResponse.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ivy.wallet.io.network.request.bankintegrations - -import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.bankintegrations.SEConnection - -data class BankConnectionsResponse( - @SerializedName("connections") - val connections: List -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankTransactionsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankTransactionsResponse.kt deleted file mode 100644 index 2869ede286..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankTransactionsResponse.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ivy.wallet.io.network.request.bankintegrations - -import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.bankintegrations.SETransaction - -data class BankTransactionsResponse( - @SerializedName("transactions") - val transactions: List -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/budget/BudgetsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/budget/BudgetsResponse.kt index 3f3eb0c2ef..0a390092f8 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/budget/BudgetsResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/budget/BudgetsResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.budget -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.io.network.data.BudgetDTO data class BudgetsResponse( - val budgets: List + val budgets: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/budget/CrupdateBudgetRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/budget/CrupdateBudgetRequest.kt index 78f90f8af5..4273e5efb4 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/budget/CrupdateBudgetRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/budget/CrupdateBudgetRequest.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.budget -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.io.network.data.BudgetDTO data class CrupdateBudgetRequest( - val budget: Budget? = null + val budget: BudgetDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/category/UpdateWalletCategoryRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/category/UpdateWalletCategoryRequest.kt index 3fd9b1e4e8..5642bce39d 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/category/UpdateWalletCategoryRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/category/UpdateWalletCategoryRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.category -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.io.network.data.CategoryDTO data class UpdateWalletCategoryRequest( - val category: Category? = null + val category: CategoryDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/category/WalletCategoriesResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/category/WalletCategoriesResponse.kt index 1dd6db5340..41ff386004 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/category/WalletCategoriesResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/category/WalletCategoriesResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.category -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.io.network.data.CategoryDTO data class WalletCategoriesResponse( - val categories: List + val categories: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoanRecordsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoanRecordsResponse.kt index 9ab03665de..be6a3e030a 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoanRecordsResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoanRecordsResponse.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.loan -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.io.network.data.LoanRecordDTO data class LoanRecordsResponse( - val loanRecords: List + val loanRecords: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoansResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoansResponse.kt index 8acae599be..6397632fa8 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoansResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoansResponse.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.loan -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.io.network.data.LoanDTO data class LoansResponse( - val loans: List + val loans: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRecordRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRecordRequest.kt index 6b7f5bb300..b35a489089 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRecordRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRecordRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.loan -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.io.network.data.LoanRecordDTO data class UpdateLoanRecordRequest( - val loanRecord: LoanRecord? = null + val loanRecord: LoanRecordDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRequest.kt index 2a5eb75061..7b3f48408a 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.loan -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.io.network.data.LoanDTO data class UpdateLoanRequest( - val loan: Loan? = null + val loan: LoanDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/planned/PlannedPaymentRulesResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/planned/PlannedPaymentRulesResponse.kt index 7beb4bd362..5009e0cbaa 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/planned/PlannedPaymentRulesResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/planned/PlannedPaymentRulesResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.planned -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.io.network.data.PlannedPaymentRuleDTO data class PlannedPaymentRulesResponse( - val rules: List + val rules: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/planned/UpdatePlannedPaymentRuleRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/planned/UpdatePlannedPaymentRuleRequest.kt index d0e22444d3..f0e53df538 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/planned/UpdatePlannedPaymentRuleRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/planned/UpdatePlannedPaymentRuleRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.planned -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.io.network.data.PlannedPaymentRuleDTO data class UpdatePlannedPaymentRuleRequest( - val rule: PlannedPaymentRule? = null + val rule: PlannedPaymentRuleDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/transaction/TransactionsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/transaction/TransactionsResponse.kt index 7abf78d9a5..e09e65b88f 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/transaction/TransactionsResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/transaction/TransactionsResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.transaction -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.io.network.data.TransactionDTO data class TransactionsResponse( - val transactions: List + val transactions: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/transaction/UpdateTransactionRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/transaction/UpdateTransactionRequest.kt index 54a1258ac2..d0c26b57a0 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/transaction/UpdateTransactionRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/transaction/UpdateTransactionRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.transaction -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.io.network.data.TransactionDTO data class UpdateTransactionRequest( - val transaction: Transaction? = null + val transaction: TransactionDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt index a99ad2e07c..eb00ca7657 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt @@ -5,19 +5,19 @@ import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase import androidx.room.TypeConverters -import com.ivy.wallet.domain.data.entity.* import com.ivy.wallet.io.persistence.dao.* +import com.ivy.wallet.io.persistence.data.* import com.ivy.wallet.io.persistence.migration.* @Database( entities = [ - Account::class, Transaction::class, Category::class, - Settings::class, PlannedPaymentRule::class, - User::class, ExchangeRate::class, Budget::class, Loan::class, - LoanRecord::class + AccountEntity::class, TransactionEntity::class, CategoryEntity::class, + SettingsEntity::class, PlannedPaymentRuleEntity::class, + UserEntity::class, ExchangeRateEntity::class, BudgetEntity::class, + LoanEntity::class, LoanRecordEntity::class ], - version = 120, + version = 121, exportSchema = true ) @TypeConverters(RoomTypeConverters::class) @@ -67,7 +67,6 @@ abstract class IvyRoomDatabase : RoomDatabase() { Migration117to118_Budgets(), Migration118to119_Loans(), Migration119to120_LoanTransactions(), - Migration120to121_DropWishlistItem() ) .build() } diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt index f3bb21fbce..c7b4a7248e 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt @@ -4,28 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.io.persistence.data.AccountEntity import java.util.* @Dao interface AccountDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Account) + fun save(value: AccountEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM accounts WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM accounts WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM accounts WHERE id = :id") - fun findById(id: UUID): Account? - - @Query("SELECT * FROM accounts WHERE seAccountId = :seAccountId") - fun findBySeAccountId(seAccountId: String): Account? + fun findById(id: UUID): AccountEntity? @Query("UPDATE accounts SET isDeleted = 1, isSynced = 0 WHERE id = :id") fun flagDeleted(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt index bfc0e5b6d6..5644bcc8db 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt @@ -4,25 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.io.persistence.data.BudgetEntity import java.util.* @Dao interface BudgetDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Budget) + fun save(value: BudgetEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM budgets WHERE isDeleted = 0 ORDER BY orderId ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM budgets WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM budgets WHERE id = :id") - fun findById(id: UUID): Budget? + fun findById(id: UUID): BudgetEntity? @Query("DELETE FROM budgets WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt index 22f86856e4..609e7f3e5f 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt @@ -4,28 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.io.persistence.data.CategoryEntity import java.util.* @Dao interface CategoryDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Category) + fun save(value: CategoryEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM categories WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM categories WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM categories WHERE id = :id") - fun findById(id: UUID): Category? - - @Query("SELECT * FROM categories WHERE seCategoryName = :seCategoryName") - fun findBySeCategoryName(seCategoryName: String): Category? + fun findById(id: UUID): CategoryEntity? @Query("DELETE FROM categories WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt index 3d3c921f11..a85007ee8a 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt @@ -4,20 +4,19 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.ExchangeRate +import com.ivy.wallet.io.persistence.data.ExchangeRateEntity @Dao interface ExchangeRateDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: ExchangeRate) + fun save(value: ExchangeRateEntity) @Query("SELECT * FROM exchange_rates WHERE baseCurrency = :baseCurrency AND currency = :currency") fun findByBaseCurrencyAndCurrency( baseCurrency: String, currency: String - ): ExchangeRate? + ): ExchangeRateEntity? @Query("DELETE FROM exchange_rates") - fun deleteALl() { - } + fun deleteALl() } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt index 83c12e6d8e..349a3d28dd 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt @@ -4,25 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.io.persistence.data.LoanEntity import java.util.* @Dao interface LoanDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Loan) + fun save(value: LoanEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM loans WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM loans WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM loans WHERE id = :id") - fun findById(id: UUID): Loan? + fun findById(id: UUID): LoanEntity? @Query("DELETE FROM loans WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt index 058ccfa0df..fedc62336b 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt @@ -4,28 +4,31 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.io.persistence.data.LoanRecordEntity import java.util.* @Dao interface LoanRecordDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: LoanRecord) + fun save(value: LoanRecordEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM loan_records WHERE isDeleted = 0 ORDER BY dateTime DESC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM loan_records WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted( + synced: Boolean, + deleted: Boolean = false + ): List @Query("SELECT * FROM loan_records WHERE id = :id") - fun findById(id: UUID): LoanRecord? + fun findById(id: UUID): LoanRecordEntity? @Query("SELECT * FROM loan_records WHERE loanId = :loanId AND isDeleted = 0 ORDER BY dateTime DESC") - fun findAllByLoanId(loanId: UUID): List + fun findAllByLoanId(loanId: UUID): List @Query("DELETE FROM loan_records WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt index 458c4cd3fe..9986b3c2d6 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt @@ -4,31 +4,31 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.io.persistence.data.PlannedPaymentRuleEntity import java.util.* @Dao interface PlannedPaymentRuleDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: PlannedPaymentRule) + fun save(value: PlannedPaymentRuleEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM planned_payment_rules WHERE isDeleted = 0 ORDER BY amount DESC, startDate ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM planned_payment_rules WHERE isSynced = :synced AND isDeleted = :deleted") fun findByIsSyncedAndIsDeleted( synced: Boolean, deleted: Boolean = false - ): List + ): List @Query("SELECT * FROM planned_payment_rules WHERE isDeleted = 0 AND oneTime = :oneTime ORDER BY amount DESC, startDate ASC") - fun findAllByOneTime(oneTime: Boolean): List + fun findAllByOneTime(oneTime: Boolean): List @Query("SELECT * FROM planned_payment_rules WHERE id = :id AND isDeleted = 0") - fun findById(id: UUID): PlannedPaymentRule? + fun findById(id: UUID): PlannedPaymentRuleEntity? @Query("UPDATE planned_payment_rules SET isDeleted = 1, isSynced = 0 WHERE id = :id") fun flagDeleted(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt index b921cc578d..8e4a098676 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt @@ -4,29 +4,29 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Settings +import com.ivy.wallet.io.persistence.data.SettingsEntity import java.util.* @Dao interface SettingsDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Settings) + fun save(value: SettingsEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) - @Query("SELECT * FROM settings LIMIT 1") - fun findFirst(): Settings + @Query("SELECT * FROM SettingsEntity LIMIT 1") + fun findFirst(): SettingsEntity - @Query("SELECT * FROM settings") - fun findAll(): List + @Query("SELECT * FROM SettingsEntity") + fun findAll(): List - @Query("SELECT * FROM settings WHERE id = :id") - fun findById(id: UUID): Settings? + @Query("SELECT * FROM SettingsEntity WHERE id = :id") + fun findById(id: UUID): SettingsEntity? - @Query("DELETE FROM settings WHERE id = :id") + @Query("DELETE FROM SettingsEntity WHERE id = :id") fun deleteById(id: UUID) - @Query("DELETE FROM settings") + @Query("DELETE FROM SettingsEntity") fun deleteAll() } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt index 92cbc96bc4..e13fb1973a 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt @@ -5,30 +5,30 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.io.persistence.data.TransactionEntity import java.time.LocalDateTime import java.util.* @Dao interface TransactionDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Transaction) + fun save(value: TransactionEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM transactions WHERE isDeleted = 0 ORDER BY dateTime DESC, dueDate ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 LIMIT 1") - fun findAll_LIMIT_1(): List + fun findAll_LIMIT_1(): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type ORDER BY dateTime DESC") - fun findAllByType(type: TransactionType): List + fun findAllByType(type: TransactionType): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and accountId = :accountId ORDER BY dateTime DESC") - fun findAllByTypeAndAccount(type: TransactionType, accountId: UUID): List + fun findAllByTypeAndAccount(type: TransactionType, accountId: UUID): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and accountId = :accountId and dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByTypeAndAccountBetween( @@ -36,13 +36,13 @@ interface TransactionDao { accountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and toAccountId = :toAccountId ORDER BY dateTime DESC") fun findAllTransfersToAccount( toAccountId: UUID, type: TransactionType = TransactionType.TRANSFER - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and toAccountId = :toAccountId and dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllTransfersToAccountBetween( @@ -50,30 +50,30 @@ interface TransactionDao { startDate: LocalDateTime, endDate: LocalDateTime, type: TransactionType = TransactionType.TRANSFER - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllBetween(startDate: LocalDateTime, endDate: LocalDateTime): List + fun findAllBetween(startDate: LocalDateTime, endDate: LocalDateTime): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND accountId = :accountId AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByAccountAndBetween( accountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByCategoryAndBetween( categoryId: UUID, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL AND seAutoCategoryId IS NULL) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllUnspecifiedAndBetween( startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByCategoryAndTypeAndBetween( @@ -81,70 +81,76 @@ interface TransactionDao { type: TransactionType, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL AND seAutoCategoryId IS NULL) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllUnspecifiedAndTypeAndBetween( type: TransactionType, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND toAccountId = :toAccountId AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllToAccountAndBetween( toAccountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate ORDER BY dueDate ASC") - fun findAllDueToBetween(startDate: LocalDateTime, endDate: LocalDateTime): List + fun findAllDueToBetween( + startDate: LocalDateTime, + endDate: LocalDateTime + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) ORDER BY dateTime DESC, dueDate ASC") fun findAllDueToBetweenByCategory( startDate: LocalDateTime, endDate: LocalDateTime, categoryId: UUID - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId IS NULL AND seAutoCategoryId IS NULL) ORDER BY dateTime DESC, dueDate ASC") fun findAllDueToBetweenByCategoryUnspecified( startDate: LocalDateTime, endDate: LocalDateTime, - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND accountId = :accountId ORDER BY dateTime DESC, dueDate ASC") fun findAllDueToBetweenByAccount( startDate: LocalDateTime, endDate: LocalDateTime, accountId: UUID - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND recurringRuleId = :recurringRuleId ORDER BY dateTime DESC") - fun findAllByRecurringRuleId(recurringRuleId: UUID): List + fun findAllByRecurringRuleId(recurringRuleId: UUID): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate AND type = :type ORDER BY dateTime DESC") fun findAllBetweenAndType( startDate: LocalDateTime, endDate: LocalDateTime, type: TransactionType - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate AND recurringRuleId = :recurringRuleId ORDER BY dateTime DESC") fun findAllBetweenAndRecurringRuleId( startDate: LocalDateTime, endDate: LocalDateTime, recurringRuleId: UUID - ): List + ): List @Query("SELECT * FROM transactions WHERE id = :id") - fun findById(id: UUID): Transaction? + fun findById(id: UUID): TransactionEntity? @Query("SELECT * FROM transactions WHERE seTransactionId = :seTransactionId") - fun findBySeTransactionId(seTransactionId: String): Transaction? + fun findBySeTransactionId(seTransactionId: String): TransactionEntity? @Query("SELECT * FROM transactions WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted( + synced: Boolean, + deleted: Boolean = false + ): List @Query("UPDATE transactions SET isDeleted = 1, isSynced = 0 WHERE id = :id") fun flagDeleted(id: UUID) @@ -169,7 +175,7 @@ interface TransactionDao { //Smart Title Suggestions @Query("SELECT * FROM transactions WHERE title LIKE :pattern AND isDeleted = 0") - fun findAllByTitleMatchingPattern(pattern: String): List + fun findAllByTitleMatchingPattern(pattern: String): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND isDeleted = 0") fun countByTitleMatchingPattern( @@ -179,7 +185,7 @@ interface TransactionDao { @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) ORDER BY dateTime DESC") fun findAllByCategory( categoryId: UUID, - ): List + ): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND categoryId = :categoryId AND isDeleted = 0") fun countByTitleMatchingPatternAndCategoryId( @@ -190,7 +196,7 @@ interface TransactionDao { @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND accountId = :accountId ORDER BY dateTime DESC") fun findAllByAccount( accountId: UUID - ): List + ): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND accountId = :accountId AND isDeleted = 0") fun countByTitleMatchingPatternAndAccountId( @@ -201,15 +207,15 @@ interface TransactionDao { @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanId = :loanId AND loanRecordId IS NULL") fun findLoanTransaction( loanId: UUID - ): Transaction? + ): TransactionEntity? @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanRecordId = :loanRecordId") fun findLoanRecordTransaction( loanRecordId: UUID - ): Transaction? + ): TransactionEntity? @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanId = :loanId") fun findAllByLoanId( loanId: UUID - ): List + ): List } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt index 74e1cf61af..d76364d46f 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt @@ -4,16 +4,16 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.io.persistence.data.UserEntity import java.util.* @Dao interface UserDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(user: User) + fun save(user: UserEntity) @Query("SELECT * FROM users WHERE id = :userId") - fun findById(userId: UUID): User? + fun findById(userId: UUID): UserEntity? @Query("DELETE FROM users") fun deleteAll() diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/AccountEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/AccountEntity.kt new file mode 100644 index 0000000000..e4d4d8faf7 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/AccountEntity.kt @@ -0,0 +1,36 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.compose.ui.graphics.toArgb +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.ui.theme.Green +import java.util.* + +@Entity(tableName = "accounts") +data class AccountEntity( + val name: String, + val currency: String? = null, + val color: Int = Green.toArgb(), + val icon: String? = null, + val orderNum: Double = 0.0, + val includeInBalance: Boolean = true, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + @PrimaryKey + val id: UUID = UUID.randomUUID() +) { + fun toDomain(): Account = Account( + name = name, + currency = currency, + color = color, + icon = icon, + orderNum = orderNum, + includeInBalance = includeInBalance, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/BudgetEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/BudgetEntity.kt new file mode 100644 index 0000000000..7446b1ea6f --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/BudgetEntity.kt @@ -0,0 +1,73 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.core.Budget +import java.util.* + +@Entity(tableName = "budgets") +data class BudgetEntity( + val name: String, + val amount: Double, + + val categoryIdsSerialized: String?, + val accountIdsSerialized: String?, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + val orderId: Double, + @PrimaryKey + val id: UUID = UUID.randomUUID() +) { + fun toDomain(): Budget = Budget( + name = name, + amount = amount, + categoryIdsSerialized = categoryIdsSerialized, + accountIdsSerialized = accountIdsSerialized, + isSynced = isSynced, + isDeleted = isDeleted, + orderId = orderId, + id = id + ) + + companion object { + fun serialize(ids: List): String { + return ids.joinToString(separator = ",") + } + + fun type(categoriesCount: Int): String { + return when (categoriesCount) { + 0 -> "Total Budget" + 1 -> "Category Budget" + else -> "Multi-Category ($categoriesCount) Budget" + } + } + } + + fun parseCategoryIds(): List { + return parseIdsString(categoryIdsSerialized) + } + + fun parseAccountIds(): List { + return parseIdsString(accountIdsSerialized) + } + + private fun parseIdsString(idsString: String?): List { + return try { + if (idsString == null) return emptyList() + + idsString + .split(",") + .map { UUID.fromString(it) } + } catch (e: Exception) { + e.printStackTrace() + emptyList() + } + } + + + fun validate(): Boolean { + return name.isNotEmpty() && amount > 0.0 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/CategoryEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/CategoryEntity.kt new file mode 100644 index 0000000000..b6ebf86c68 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/CategoryEntity.kt @@ -0,0 +1,32 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.compose.ui.graphics.toArgb +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.ui.theme.Ivy +import java.util.* + +@Entity(tableName = "categories") +data class CategoryEntity( + val name: String, + val color: Int = Ivy.toArgb(), + val icon: String? = null, + val orderNum: Double = 0.0, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + @PrimaryKey + val id: UUID = UUID.randomUUID() +) { + fun toDomain(): Category = Category( + name = name, + color = color, + icon = icon, + orderNum = orderNum, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/ExchangeRateEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/ExchangeRateEntity.kt new file mode 100644 index 0000000000..873dc767bf --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/ExchangeRateEntity.kt @@ -0,0 +1,17 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.room.Entity +import com.ivy.wallet.domain.data.core.ExchangeRate + +@Entity(tableName = "exchange_rates", primaryKeys = ["baseCurrency", "currency"]) +data class ExchangeRateEntity( + val baseCurrency: String, + val currency: String, + val rate: Double, +) { + fun toDomain(): ExchangeRate = ExchangeRate( + baseCurrency = baseCurrency, + currency = currency, + rate = rate + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanEntity.kt new file mode 100644 index 0000000000..fe5a447cfe --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanEntity.kt @@ -0,0 +1,41 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.LoanType +import com.ivy.wallet.domain.data.core.Loan +import java.util.* + +@Entity(tableName = "loans") +data class LoanEntity( + val name: String, + val amount: Double, + val type: LoanType, + val color: Int = 0, + val icon: String? = null, + val orderNum: Double = 0.0, + val accountId: UUID? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + @PrimaryKey + val id: UUID = UUID.randomUUID() +) { + fun toDomain(): Loan = Loan( + name = name, + amount = amount, + type = type, + color = color, + icon = icon, + orderNum = orderNum, + accountId = accountId, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + + fun humanReadableType(): String { + return if (type == LoanType.BORROW) "BORROWED" else "LENT" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanRecordEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanRecordEntity.kt new file mode 100644 index 0000000000..af6487f78b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanRecordEntity.kt @@ -0,0 +1,38 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.core.LoanRecord +import java.time.LocalDateTime +import java.util.* + +@Entity(tableName = "loan_records") +data class LoanRecordEntity( + val loanId: UUID, + val amount: Double, + val note: String? = null, + val dateTime: LocalDateTime, + val interest: Boolean = false, + val accountId: UUID? = null, + //This is used store the converted amount for currencies which are different from the loan account currency + val convertedAmount: Double? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + @PrimaryKey + val id: UUID = UUID.randomUUID() +) { + fun toDomain(): LoanRecord = LoanRecord( + loanId = loanId, + amount = amount, + note = note, + dateTime = dateTime, + interest = interest, + accountId = accountId, + convertedAmount = convertedAmount, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/PlannedPaymentRuleEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/PlannedPaymentRuleEntity.kt new file mode 100644 index 0000000000..e38fa3c151 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/PlannedPaymentRuleEntity.kt @@ -0,0 +1,46 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.IntervalType +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import java.time.LocalDateTime +import java.util.* + +@Entity(tableName = "planned_payment_rules") +data class PlannedPaymentRuleEntity( + val startDate: LocalDateTime?, + val intervalN: Int?, + val intervalType: IntervalType?, + val oneTime: Boolean, + + val type: TransactionType, + val accountId: UUID, + val amount: Double = 0.0, + val categoryId: UUID? = null, + val title: String? = null, + val description: String? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + @PrimaryKey + val id: UUID = UUID.randomUUID() +) { + fun toDomain(): PlannedPaymentRule = PlannedPaymentRule( + startDate = startDate, + intervalN = intervalN, + intervalType = intervalType, + oneTime = oneTime, + type = type, + accountId = accountId, + amount = amount, + categoryId = categoryId, + title = title, + description = description, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Settings.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt similarity index 56% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Settings.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt index f352a3ee5f..7ab5131552 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Settings.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt @@ -1,12 +1,13 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.room.Entity import androidx.room.PrimaryKey import com.ivy.design.l0_system.Theme +import com.ivy.wallet.domain.data.core.Settings import java.util.* @Entity(tableName = "settings") -data class Settings( +data class SettingsEntity( val theme: Theme, val currency: String, val bufferAmount: Double, @@ -17,4 +18,12 @@ data class Settings( @PrimaryKey val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toDomain(): Settings = Settings( + theme = theme, + currency = currency, + bufferAmount = bufferAmount, + name = name, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt new file mode 100644 index 0000000000..8ba7ab3c68 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt @@ -0,0 +1,72 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.TransactionHistoryItem +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.Transaction +import java.time.LocalDateTime +import java.util.* + +@Entity(tableName = "transactions") +data class TransactionEntity( + val accountId: UUID, + val type: TransactionType, + val amount: Double, + val toAccountId: UUID? = null, + val toAmount: Double? = null, + val title: String? = null, + val description: String? = null, + val dateTime: LocalDateTime? = null, + val categoryId: UUID? = null, + val dueDate: LocalDateTime? = null, + + val recurringRuleId: UUID? = null, + + val attachmentUrl: String? = null, + + //This refers to the loan id that is linked with a transaction + val loanId: UUID? = null, + + //This refers to the loan record id that is linked with a transaction + val loanRecordId: UUID? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + @PrimaryKey + val id: UUID = UUID.randomUUID() +) : TransactionHistoryItem { + fun toDomain(): Transaction = Transaction( + accountId = accountId, + type = type, + amount = amount, + toAccountId = toAccountId, + toAmount = toAmount, + title = title, + description = description, + dateTime = dateTime, + categoryId = categoryId, + dueDate = dueDate, + recurringRuleId = recurringRuleId, + attachmentUrl = attachmentUrl, + loanId = loanId, + loanRecordId = loanRecordId, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + + fun isIdenticalWith(transaction: TransactionEntity?): Boolean { + if (transaction == null) return false + + //Set isSynced && isDeleted to false so they aren't accounted in the equals check + return this.copy( + isSynced = false, + isDeleted = false + ) == transaction.copy( + isSynced = false, + isDeleted = false + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/User.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/UserEntity.kt similarity index 63% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/User.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/UserEntity.kt index e6712cf52a..55f48c6ab9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/User.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/UserEntity.kt @@ -1,39 +1,43 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey -import com.google.gson.annotations.SerializedName import com.ivy.wallet.domain.data.AuthProviderType +import com.ivy.wallet.domain.data.core.User import java.util.* @Entity(tableName = "users") -data class User( - @SerializedName("email") +data class UserEntity( @ColumnInfo(name = "email") val email: String, - @SerializedName("authProviderType") + @ColumnInfo(name = "authProviderType") val authProviderType: AuthProviderType, - @SerializedName("firstName") @ColumnInfo(name = "firstName") var firstName: String, - @SerializedName("lastName") @ColumnInfo(name = "lastName") val lastName: String?, - @SerializedName("profilePictureUrl") @ColumnInfo(name = "profilePicture") val profilePicture: String?, - @SerializedName("color") @ColumnInfo(name = "color") val color: Int, - @SerializedName("testUser") @ColumnInfo(name = "testUser") val testUser: Boolean = false, - @SerializedName("id") @PrimaryKey @ColumnInfo(name = "id") var id: UUID ) { + fun toDomain(): User = User( + email = email, + authProviderType = authProviderType, + firstName = firstName, + lastName = lastName, + profilePicture = profilePicture, + color = color, + testUser = testUser, + id = id + ) + fun names(): String = firstName + if (lastName != null) " $lastName" else "" } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/Screens.kt b/app/src/main/java/com/ivy/wallet/ui/Screens.kt index 2aa1f881f1..d5f5be4a6f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/Screens.kt +++ b/app/src/main/java/com/ivy/wallet/ui/Screens.kt @@ -2,7 +2,7 @@ package com.ivy.wallet.ui import com.ivy.design.navigation.Screen import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.ui.paywall.PaywallReason import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountData.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountData.kt index 58ffb4cc36..62336b06e1 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountData.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountData.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.accounts import com.ivy.wallet.domain.data.Reorderable -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account data class AccountData( val account: Account, diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsTab.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsTab.kt index e47cc15cd8..7b6d4af7db 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsTab.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsTab.kt @@ -22,7 +22,7 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Main diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt index 2b2b46755a..09a1077bd8 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.event.AccountsUpdatedEvent import com.ivy.wallet.domain.logic.AccountCreator import com.ivy.wallet.domain.pure.account.calculateAccountBalance diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt index 08916b5347..e065a2cdca 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt @@ -20,9 +20,9 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateBudgetData import com.ivy.wallet.ui.BudgetScreen import com.ivy.wallet.ui.IvyWalletPreview diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt index 247831cb9d..03175ea802 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt @@ -4,10 +4,10 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.BudgetCreator import com.ivy.wallet.domain.logic.WalletLogic import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/model/DisplayBudget.kt b/app/src/main/java/com/ivy/wallet/ui/budget/model/DisplayBudget.kt index 89cfec2c6a..c7a69d18a3 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/model/DisplayBudget.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/model/DisplayBudget.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.budget.model import com.ivy.wallet.domain.data.Reorderable -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.domain.data.core.Budget data class DisplayBudget( val budget: Budget, diff --git a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt index a1335b9766..bf3192d8da 100644 --- a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt @@ -23,7 +23,7 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.ui.Categories import com.ivy.wallet.ui.ItemStatistic diff --git a/app/src/main/java/com/ivy/wallet/ui/category/CategoryData.kt b/app/src/main/java/com/ivy/wallet/ui/category/CategoryData.kt index 0bfc6f6aa5..5e0b3900f1 100644 --- a/app/src/main/java/com/ivy/wallet/ui/category/CategoryData.kt +++ b/app/src/main/java/com/ivy/wallet/ui/category/CategoryData.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.category import com.ivy.wallet.domain.data.Reorderable -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category data class CategoryData( val category: Category, diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/CategoryValues.kt b/app/src/main/java/com/ivy/wallet/ui/charts/CategoryValues.kt index a93a489b03..500d318587 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/CategoryValues.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/CategoryValues.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.ui.charts -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category class CategoryValues( val category: Category, diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt index a1f455efd9..2c6b781c01 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt @@ -21,7 +21,7 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.pure.charts.ChartPeriod import com.ivy.wallet.domain.pure.charts.IncomeExpenseChartPoint import com.ivy.wallet.domain.pure.charts.SingleChartPoint diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt index 62b6e75b86..2920c39c5c 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt @@ -6,7 +6,7 @@ import com.ivy.wallet.domain.action.charts.BalanceChartAct import com.ivy.wallet.domain.action.framework.then import com.ivy.wallet.domain.action.settings.BaseCurrencyAct import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.WalletCategoryLogic import com.ivy.wallet.domain.pure.charts.ChartPeriod import com.ivy.wallet.domain.pure.charts.IncomeExpenseChartPoint @@ -25,7 +25,6 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import javax.inject.Inject -import kotlin.math.absoluteValue @HiltViewModel class ChartsViewModel @Inject constructor( diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt b/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt index 3c929e0879..637886d048 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.pure.charts.ChartPeriod import com.ivy.wallet.stringRes import com.ivy.wallet.ui.charts.CategoryValues diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt index 3090dff966..8987f877de 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt @@ -25,8 +25,8 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.CustomExchangeRateState import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.ui.EditPlanned diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt index 69c1faa53c..4eeed39169 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt @@ -6,9 +6,9 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation import com.ivy.wallet.domain.data.CustomExchangeRateState import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.event.AccountsUpdatedEvent import com.ivy.wallet.domain.logic.* import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic @@ -213,7 +213,7 @@ class EditTransactionViewModel @Inject constructor( _toAccount.value = transaction.toAccountId?.let { ioThread { accountDao.findById(it) } } - _category.value = transaction.smartCategoryId()?.let { + _category.value = transaction.categoryId?.let { ioThread { categoryDao.findById(it) } } _amount.value = transaction.amount diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/core/Category.kt b/app/src/main/java/com/ivy/wallet/ui/edit/core/Category.kt index b43e101c52..bcf2dcfa05 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/core/Category.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/core/Category.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.theme.Gradient import com.ivy.wallet.ui.theme.components.IvyBorderButton diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/core/EditBottomSheet.kt b/app/src/main/java/com/ivy/wallet/ui/edit/core/EditBottomSheet.kt index 7feaf65cc7..e1d68b5a99 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/core/EditBottomSheet.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/core/EditBottomSheet.kt @@ -34,7 +34,7 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.ivyWalletCtx import com.ivy.wallet.ui.theme.* diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt index 4322117f96..3c676c0ad9 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt @@ -2,9 +2,9 @@ package com.ivy.wallet.ui.home import com.ivy.design.l0_system.Theme import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.ui.IvyWalletCtx diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt index 50d427b3b5..bbe1a07db1 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt @@ -24,9 +24,9 @@ import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData import com.ivy.wallet.stringRes import com.ivy.wallet.ui.IvyWalletPreview diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 493c84fe2e..79b2a5aa95 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -8,7 +8,7 @@ import com.ivy.wallet.domain.action.transaction.HistoryWithDateDivAct import com.ivy.wallet.domain.action.wallet.CalcOverdueAct import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.CustomerJourneyLogic import com.ivy.wallet.domain.logic.PlannedPaymentsLogic import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt index 8f377521ee..9ac38c9761 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt @@ -2,8 +2,8 @@ package com.ivy.wallet.ui.loan import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.domain.event.AccountsUpdatedEvent import com.ivy.wallet.domain.logic.AccountCreator import com.ivy.wallet.domain.logic.LoanCreator diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/LoansScreen.kt b/app/src/main/java/com/ivy/wallet/ui/loan/LoansScreen.kt index 9469325d4b..d4eb917f48 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/LoansScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/LoansScreen.kt @@ -25,7 +25,7 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.LoanType -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.LoanDetails import com.ivy.wallet.ui.Loans diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoan.kt b/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoan.kt index 54a61b7e24..00655cc7b6 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoan.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoan.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.loan.data import com.ivy.wallet.domain.data.Reorderable -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.utils.getDefaultFIATCurrency data class DisplayLoan( diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoanRecord.kt b/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoanRecord.kt index 936613c09e..4f73ac75cb 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoanRecord.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoanRecord.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.loan.data -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.LoanRecord data class DisplayLoanRecord( val loanRecord: LoanRecord, diff --git a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt index 7592822814..8c80072b46 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt @@ -30,9 +30,9 @@ import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.data.core.LoanRecord import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.logic.model.CreateLoanRecordData import com.ivy.wallet.domain.logic.model.EditLoanRecordData diff --git a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt index 78381571b8..f857af2349 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt @@ -3,10 +3,10 @@ package com.ivy.wallet.ui.loandetails import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.event.AccountsUpdatedEvent import com.ivy.wallet.domain.logic.AccountCreator import com.ivy.wallet.domain.logic.LoanCreator diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt index 3d16df6d0d..458fcd6d93 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt @@ -9,8 +9,8 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt index ef962be248..42bd0ace25 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletComponentPreview diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/AccountBalance.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/AccountBalance.kt index cbf19e34d7..36049d07d4 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/AccountBalance.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/AccountBalance.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.ui.onboarding.model -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account data class AccountBalance( val account: Account, diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt index f55b812796..f99c454cc0 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.ui.onboarding.model -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.utils.* import java.time.LocalDateTime diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt index 491f4aa236..20b4cba285 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt @@ -22,7 +22,7 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Paywall diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt index e51dbb96dd..f54d41288e 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt @@ -25,7 +25,7 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.onboarding.components.OnboardingProgressSlider diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt index 04a36e53d7..d1a1b86fb7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.MutableLiveData import com.ivy.design.navigation.Navigation import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.analytics.AnalyticsEvent -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.LogoutLogic import com.ivy.wallet.domain.logic.PreloadDataLogic import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic 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 2ecd126936..65ee515dc8 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 @@ -6,9 +6,9 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Settings +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Settings import com.ivy.wallet.domain.logic.* import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.model.CreateAccountData diff --git a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallScreen.kt b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallScreen.kt index e76c588830..650c1730fb 100644 --- a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallScreen.kt @@ -25,10 +25,10 @@ import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.android.billing.Plan import com.ivy.wallet.android.billing.PlanType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Paywall import com.ivy.wallet.ui.RootActivity diff --git a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt index b76148cc13..b5d0a25420 100644 --- a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt @@ -8,10 +8,10 @@ import com.ivy.wallet.android.billing.IvyBilling import com.ivy.wallet.android.billing.Plan import com.ivy.wallet.android.billing.PlanType import com.ivy.wallet.domain.data.analytics.AnalyticsEvent -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.domain.logic.PaywallLogic import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.persistence.dao.AccountDao diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt index 7570d7140d..f4bcd457dd 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt @@ -19,8 +19,8 @@ import com.google.accompanist.insets.statusBarsPadding import com.ivy.wallet.R import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.ui.EditPlanned diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt index 3c30048c24..65be48952b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt @@ -6,9 +6,9 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.domain.event.AccountsUpdatedEvent import com.ivy.wallet.domain.logic.AccountCreator import com.ivy.wallet.domain.logic.CategoryCreator diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentCard.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentCard.kt index cf4f689437..495b063289 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentCard.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentCard.kt @@ -23,9 +23,9 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.Gradient diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsLazyColumn.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsLazyColumn.kt index f94775464b..ce62f9d763 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsLazyColumn.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsLazyColumn.kt @@ -6,7 +6,6 @@ import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp @@ -17,10 +16,9 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.design.navigation.Navigation import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.theme.Gray @@ -113,7 +111,7 @@ private fun LazyListScope.plannedPaymentItems( SectionDivider( expanded = oneTimeExpanded, setExpanded = setOneTimeExpanded, - title = stringRes(R.string.one_time_payments), + title = "One time payments", titleColor = UI.colors.pureInverse, baseCurrency = currency, income = oneTimeIncome, @@ -145,7 +143,7 @@ private fun LazyListScope.plannedPaymentItems( SectionDivider( expanded = recurringExpanded, setExpanded = setRecurringExpanded, - title = stringRes(R.string.recurring_payments), + title = "Recurring payments", titleColor = UI.colors.pureInverse, baseCurrency = currency, income = recurringIncome, @@ -214,7 +212,7 @@ private fun LazyItemScope.NoPlannedPaymentsEmptyState() { Spacer(Modifier.height(24.dp)) Text( - text = stringResource(R.string.no_planned_payments), + text = "No planned payments", style = UI.typo.b1.style( color = Gray, fontWeight = FontWeight.ExtraBold @@ -224,7 +222,7 @@ private fun LazyItemScope.NoPlannedPaymentsEmptyState() { Spacer(Modifier.height(8.dp)) Text( - text = stringResource(R.string.no_planned_payments_description), + text = "You don't have any planed payments.\nPress the '⚡' bottom at the bottom to add one.", style = UI.typo.b2.style( color = Gray, fontWeight = FontWeight.Medium, diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsScreen.kt index 8568c94325..d1e19ec616 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsScreen.kt @@ -21,9 +21,9 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.PlannedPayments diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt index c3797f97f4..60375340a5 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt @@ -3,9 +3,9 @@ package com.ivy.wallet.ui.planned.list import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.domain.logic.PlannedPaymentsLogic import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/FilterOverlay.kt b/app/src/main/java/com/ivy/wallet/ui/reports/FilterOverlay.kt index 268463b3e8..cb4b771085 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/FilterOverlay.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/FilterOverlay.kt @@ -25,8 +25,8 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.ivyWalletCtx import com.ivy.wallet.ui.theme.* diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportFilter.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportFilter.kt index e4ca11a807..09cdc4cf1c 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportFilter.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportFilter.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.ui.reports import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.onboarding.model.TimePeriod import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreen.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreen.kt index cb66786a5a..f85b27a6c4 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreen.kt @@ -13,7 +13,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview @@ -26,9 +25,8 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.PieChartStatistic import com.ivy.wallet.ui.Report @@ -116,7 +114,7 @@ private fun BoxWithConstraintsScope.UI( modifier = Modifier.padding( start = 32.dp ), - text = stringResource(R.string.reports), + text = "Reports", style = UI.typo.h2.style( fontWeight = FontWeight.ExtraBold ) @@ -209,9 +207,9 @@ private fun BoxWithConstraintsScope.UI( onPayOrGet = { onEventHandler.invoke(ReportScreenEvent.OnPayOrGet(transaction = it)) }, - emptyStateTitle = stringRes(R.string.no_transactions), + emptyStateTitle = "No transactions", - emptyStateText = stringRes(R.string.no_transactions_for_your_filter) + emptyStateText = "You don't have any transactions for your filter." ) } else { item { @@ -265,7 +263,7 @@ private fun NoFilterEmptyState( Spacer(Modifier.height(8.dp)) Text( - text = stringResource(R.string.no_filter), + text = "No Filter", style = UI.typo.b1.style( color = Gray, fontWeight = FontWeight.ExtraBold @@ -276,7 +274,7 @@ private fun NoFilterEmptyState( Text( modifier = Modifier.padding(horizontal = 32.dp), - text = stringResource(R.string.invalid_filter_warning), + text = "To generate a report you must first set a valid filter.", style = UI.typo.b2.style( color = Gray, fontWeight = FontWeight.Medium, @@ -288,7 +286,7 @@ private fun NoFilterEmptyState( IvyButton( iconStart = R.drawable.ic_filter_xs, - text = stringResource(R.string.set_filter) + text = "Set Filter" ) { setFilterOverlayVisible(true) } @@ -313,7 +311,7 @@ private fun Toolbar( //Export CSV IvyOutlinedButton( - text = stringResource(R.string.export), + text = "Export", iconTint = Green, textColor = Green, solidBackground = true, diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenEvent.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenEvent.kt index c4360d4e9c..7fb7283d3b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenEvent.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenEvent.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.reports import android.content.Context -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction sealed class ReportScreenEvent { data class OnFilter(val filter: ReportFilter?) : ReportScreenEvent() diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenState.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenState.kt index 7f06456657..4c6fbcb4db 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenState.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenState.kt @@ -1,9 +1,9 @@ package com.ivy.wallet.ui.reports import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import java.util.* data class ReportScreenState( diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt index f77ff4c575..8be7853106 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt @@ -7,9 +7,9 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation import com.ivy.design.viewmodel.IvyViewModel import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.PlannedPaymentsLogic import com.ivy.wallet.domain.logic.WalletLogic import com.ivy.wallet.domain.logic.csv.ExportCSVLogic @@ -209,7 +209,7 @@ class ReportViewModel @Inject constructor( .filter { trn -> //Filter by Categories - filterCategoryIds.contains(trn.smartCategoryId()) || (trn.type == TransactionType.TRANSFER) + filterCategoryIds.contains(trn.categoryId) || (trn.type == TransactionType.TRANSFER) } .filter { //Filter by Amount diff --git a/app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt b/app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt index 95c5c72f61..2385784cf2 100644 --- a/app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt @@ -14,7 +14,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -24,9 +23,8 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Search import com.ivy.wallet.ui.ivyWalletCtx @@ -125,8 +123,8 @@ private fun UI( history = transactions, onPayOrGet = { }, dateDividerMarginTop = 16.dp, - emptyStateTitle = stringRes(R.string.no_transactions), - emptyStateText = stringRes(R.string.no_transactions_for_query, searchQueryTextFieldValue.text) + emptyStateTitle = "No transactions", + emptyStateText = "You don't have any transactions for \"${searchQueryTextFieldValue.text}\" query." ) item { @@ -171,7 +169,7 @@ private fun SearchInput( .padding(vertical = 12.dp) .focusRequester(searchFocus), value = searchQueryTextFieldValue, - hint = stringResource(R.string.search_transactions), + hint = "Search transactions", onValueChanged = { onSetSearchQueryTextField(it) } diff --git a/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt index 4ac8e422c5..95a52146c2 100644 --- a/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt @@ -3,8 +3,8 @@ package com.ivy.wallet.ui.search import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.withDateDividers import com.ivy.wallet.io.persistence.dao.AccountDao diff --git a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt index e9913a7942..95c2615f1c 100644 --- a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt @@ -35,7 +35,7 @@ import com.ivy.wallet.Constants.URL_IVY_CONTRIBUTORS import com.ivy.wallet.R import com.ivy.wallet.domain.data.AuthProviderType import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User import com.ivy.wallet.ui.* import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.IvyButton diff --git a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt index d5b969acba..4110a67f91 100644 --- a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.data.analytics.AnalyticsEvent -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User import com.ivy.wallet.domain.logic.LogoutLogic import com.ivy.wallet.domain.logic.csv.ExportCSVLogic import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/CategoryAmount.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/CategoryAmount.kt index 425b198aec..3f8c39e9ac 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/CategoryAmount.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/CategoryAmount.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.statistic.level1 -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction data class CategoryAmount( val category: Category?, diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChart.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChart.kt index 2084d934b3..541b279ff9 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChart.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChart.kt @@ -22,7 +22,7 @@ import androidx.compose.ui.viewinterop.AndroidView import com.ivy.design.l0_system.UI import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletComponentPreview import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.IvyIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticScreen.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticScreen.kt index 24ca1787a0..6ff491aa2f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticScreen.kt @@ -31,8 +31,8 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.ui.* import com.ivy.wallet.ui.onboarding.model.TimePeriod import com.ivy.wallet.ui.theme.* diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt index dced3748e3..66b35583b0 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt @@ -5,8 +5,8 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency import com.ivy.wallet.domain.pure.category.calculateCategoryExpenseWithAccountFilters diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/SelectedCategory.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/SelectedCategory.kt index 6b355b4030..ca05361aba 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/SelectedCategory.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/SelectedCategory.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.ui.statistic.level1 -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category data class SelectedCategory( val category: Category? //null - Unspecified diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticScreen.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticScreen.kt index 1a622fe669..8139f49541 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticScreen.kt @@ -30,9 +30,9 @@ import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.stringRes import com.ivy.wallet.ui.* import com.ivy.wallet.ui.onboarding.model.TimePeriod diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt index ee078878f3..7a4d302921 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt @@ -7,9 +7,9 @@ import com.ivy.design.navigation.Navigation import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.* import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.pure.account.calculateAccountBalance diff --git a/app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt b/app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt index 509396dd95..4a80bb1000 100644 --- a/app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import com.ivy.design.api.navigation -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User import com.ivy.wallet.ui.AnalyticsReport import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Test diff --git a/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt index d8bd81a844..99c33b991a 100644 --- a/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt @@ -3,7 +3,7 @@ package com.ivy.wallet.ui.test import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic import com.ivy.wallet.domain.sync.item.CategorySync import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/components/WrapContentRow.kt b/app/src/main/java/com/ivy/wallet/ui/theme/components/WrapContentRow.kt index 95ffd68a5c..22baf4a433 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/components/WrapContentRow.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/components/WrapContentRow.kt @@ -18,7 +18,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.ivy.design.l0_system.UI -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt index 81b3daf04f..c5e9b2d256 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt @@ -14,7 +14,6 @@ import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.testTag -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardCapitalization @@ -24,10 +23,9 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style -import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateBudgetData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.reports.ListItem @@ -121,8 +119,7 @@ fun BoxWithConstraintsScope.BudgetModal( verticalAlignment = Alignment.CenterVertically ) { ModalTitle( - text = if (modal?.budget != null) stringResource(R.string.edit_budget) else stringResource( - R.string.create_budget) + text = if (modal?.budget != null) "Edit budget" else "Create budget" ) if (initialBudget != null) { @@ -140,7 +137,7 @@ fun BoxWithConstraintsScope.BudgetModal( Spacer(Modifier.height(24.dp)) ModalNameInput( - hint = stringResource(R.string.budget_name), + hint = "Budget name", autoFocusKeyboard = modal?.autoFocusKeyboard ?: true, textFieldValue = nameTextFieldValue, setTextFieldValue = { @@ -161,7 +158,7 @@ fun BoxWithConstraintsScope.BudgetModal( Spacer(Modifier.height(24.dp)) ModalAmountSection( - label = stringResource(R.string.budget_amount_uppercase), + label = "BUDGET AMOUNT", currency = modal?.baseCurrency ?: "", amount = amount, amountPaddingTop = 24.dp, @@ -186,8 +183,8 @@ fun BoxWithConstraintsScope.BudgetModal( DeleteModal( visible = deleteModalVisible, - title = stringResource(R.string.confirm_deletion), - description = stringResource(R.string.confirm_budget_deletion_warning, nameTextFieldValue.text), + title = "Confirm deletion", + description = "Are you sure that you want to delete \"${nameTextFieldValue.text}\" budget?", dismiss = { deleteModalVisible = false } ) { if (initialBudget != null) { diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt index a682999de1..7427b67ad8 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt @@ -26,8 +26,8 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.LoanType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.logic.model.CreateLoanData import com.ivy.wallet.ui.IvyWalletPreview diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt index ade51e898e..7b4836dee7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt @@ -21,8 +21,8 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.LoanRecord import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.domain.logic.model.CreateLoanRecordData import com.ivy.wallet.domain.logic.model.EditLoanRecordData diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt index f2871d7b37..61d970e3e0 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt @@ -21,7 +21,7 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.logic.model.CreateAccountData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.Gray diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt index 047f5a18b7..03534829bb 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt @@ -25,7 +25,7 @@ import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.Ivy diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/ChooseCategoryModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/ChooseCategoryModal.kt index 4550113178..07d3d2ada2 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/ChooseCategoryModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/ChooseCategoryModal.kt @@ -21,7 +21,7 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.ItemIconSDefaultIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt index d6346f6b12..b5cc9acf71 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt @@ -25,9 +25,9 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.* @@ -198,7 +198,7 @@ private fun TransactionHeaderRow( verticalAlignment = Alignment.CenterVertically ) { val category = - transaction.smartCategoryId() + transaction.categoryId ?.let { targetId -> categories.find { it.id == targetId } } if (category != null) { IvyButton( diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/Transactions.kt b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/Transactions.kt index 3b48f8e8a8..75976ee907 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/Transactions.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/Transactions.kt @@ -9,7 +9,6 @@ import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Dp @@ -20,10 +19,9 @@ import com.ivy.design.navigation.Navigation import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.ui.EditTransaction import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.theme.Gray @@ -52,7 +50,7 @@ fun LazyListScope.transactions( history: List, lastItemSpacer: Dp? = null, onPayOrGet: (Transaction) -> Unit, - emptyStateTitle: String = stringRes(R.string.no_transactions), + emptyStateTitle: String = "No transactions", emptyStateText: String, dateDividerMarginTop: Dp? = null ) { @@ -61,7 +59,7 @@ fun LazyListScope.transactions( SectionDivider( expanded = upcomingExpanded, setExpanded = setUpcomingExpanded, - title = stringResource(R.string.upcoming), + title = "Upcoming", titleColor = Orange, baseCurrency = baseCurrency, income = upcomingIncome, @@ -93,7 +91,7 @@ fun LazyListScope.transactions( SectionDivider( expanded = overdueExpanded, setExpanded = setOverdueExpanded, - title = stringResource(R.string.overdue), + title = "Overdue", titleColor = Red, baseCurrency = baseCurrency, income = overdueIncome, From d805d1417ff596f0d399d8d95f15c4e214adad4f Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 18:49:10 +0300 Subject: [PATCH 14/40] WIP: `ivy-fp` module --- .../ivy/wallet/domain/action/ExchangeAct.kt | 16 ++--- .../domain/action/account/AccTrnsAct.kt | 5 +- .../domain/action/account/AccountsAct.kt | 4 +- .../action/account/CalcAccBalanceAct.kt | 4 +- .../domain/action/charts/BalanceChartAct.kt | 2 +- .../domain/action/settings/BaseCurrencyAct.kt | 2 +- .../action/transaction/AddDateDividersAct.kt | 36 +++++++++++ .../action/transaction/HistoryTrnsAct.kt | 26 ++++++++ .../transaction/HistoryWithDateDivAct.kt | 25 -------- .../domain/action/wallet/CalcOverdueAct.kt | 2 +- .../domain/action/wallet/CalcUpcomingAct.kt | 2 +- .../action/wallet/CalcWalletBalanceAct.kt | 2 +- .../com/ivy/wallet/domain/pure/Exchange.kt | 4 +- .../com/ivy/wallet/domain/pure/IvyCore.kt | 2 + .../wallet/domain/pure/account/AccountCore.kt | 4 +- .../wallet/domain/pure/charts/WalletCharts.kt | 4 +- .../wallet/domain/pure/wallet/WalletCore.kt | 2 +- .../domain/pure/wallet/WalletTransactions.kt | 7 ++- .../io/persistence/data/TransactionEntity.kt | 3 +- .../ivy/wallet/ui/charts/ChartsViewModel.kt | 2 +- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 8 +-- .../ivy/wallet/ui/reports/ReportViewModel.kt | 2 +- .../com/ivy/wallet/buildsrc/dependencies.kt | 16 +++++ ivy-fp/.gitignore | 1 + ivy-fp/build.gradle.kts | 60 +++++++++++++++++++ ivy-fp/consumer-rules.pro | 0 ivy-fp/proguard-rules.pro | 21 +++++++ .../com/ivy/design/ExampleInstrumentedTest.kt | 22 +++++++ ivy-fp/src/main/AndroidManifest.xml | 4 ++ .../src/main/java/com/ivy/fp/Composition.kt | 20 +++++-- .../main/java/com/ivy/fp/action}/Action.kt | 2 +- .../java/com/ivy/fp/action}/Composition.kt | 2 +- .../com/ivy/fp/action}/CompositionFilter.kt | 2 +- .../java/com/ivy/fp/action}/CompositionMap.kt | 12 +++- .../java/com/ivy/fp/action}/CompositionSum.kt | 2 +- .../main/java/com/ivy/fp/action}/FPAction.kt | 2 +- .../com/ivy/fp}/viewmodel/IvyViewModel.kt | 2 +- .../com/ivy/fp}/viewmodel/ViewmodelUtils.kt | 2 +- .../java/com/ivy/design/ExampleUnitTest.kt | 16 +++++ settings.gradle.kts | 6 +- 40 files changed, 280 insertions(+), 76 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt create mode 100644 ivy-fp/.gitignore create mode 100644 ivy-fp/build.gradle.kts create mode 100644 ivy-fp/consumer-rules.pro create mode 100644 ivy-fp/proguard-rules.pro create mode 100644 ivy-fp/src/androidTest/java/com/ivy/design/ExampleInstrumentedTest.kt create mode 100644 ivy-fp/src/main/AndroidManifest.xml rename app/src/main/java/com/ivy/wallet/domain/pure/core/FP.kt => ivy-fp/src/main/java/com/ivy/fp/Composition.kt (63%) rename {app/src/main/java/com/ivy/wallet/domain/action/framework => ivy-fp/src/main/java/com/ivy/fp/action}/Action.kt (93%) rename {app/src/main/java/com/ivy/wallet/domain/action/framework => ivy-fp/src/main/java/com/ivy/fp/action}/Composition.kt (96%) rename {app/src/main/java/com/ivy/wallet/domain/action/framework => ivy-fp/src/main/java/com/ivy/fp/action}/CompositionFilter.kt (89%) rename {app/src/main/java/com/ivy/wallet/domain/action/framework => ivy-fp/src/main/java/com/ivy/fp/action}/CompositionMap.kt (64%) rename {app/src/main/java/com/ivy/wallet/domain/action/framework => ivy-fp/src/main/java/com/ivy/fp/action}/CompositionSum.kt (93%) rename {app/src/main/java/com/ivy/wallet/domain/action/framework => ivy-fp/src/main/java/com/ivy/fp/action}/FPAction.kt (80%) rename {ivy-design/src/main/java/com/ivy/design => ivy-fp/src/main/java/com/ivy/fp}/viewmodel/IvyViewModel.kt (94%) rename {ivy-design/src/main/java/com/ivy/design => ivy-fp/src/main/java/com/ivy/fp}/viewmodel/ViewmodelUtils.kt (83%) create mode 100644 ivy-fp/src/test/java/com/ivy/design/ExampleUnitTest.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt index 34b3152e6c..b806e34914 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt @@ -1,7 +1,9 @@ package com.ivy.wallet.domain.action import arrow.core.Option -import com.ivy.wallet.domain.action.framework.FPAction +import com.ivy.fp.action.FPAction +import com.ivy.fp.then +import com.ivy.wallet.domain.pure.ExchangeData import com.ivy.wallet.domain.pure.exchange import com.ivy.wallet.io.persistence.dao.ExchangeRateDao import java.math.BigDecimal @@ -14,20 +16,18 @@ class ExchangeAct @Inject constructor( override suspend fun Input.compose(): suspend () -> Option = suspend { io { exchange( - baseCurrencyCode = baseCurrency, + data = data, amount = amount, - fromCurrencyCode = fromCurrency, - toCurrencyCode = toCurrency, - getExchangeRate = exchangeRateDao::findByBaseCurrencyAndCurrency + getExchangeRate = exchangeRateDao::findByBaseCurrencyAndCurrency then { + it?.toDomain() + } ) } } data class Input( - val baseCurrency: String, - val fromCurrency: Option, - val toCurrency: String, + val data: ExchangeData, val amount: BigDecimal ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt index 65a3b80ee8..a7a60939d0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.action.account -import com.ivy.wallet.domain.action.framework.FPAction +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.io.persistence.dao.TransactionDao @@ -22,6 +23,8 @@ class AccTrnsAct @Inject constructor( endDate = range.to ) } + } thenMap { + it.toDomain() } class Input( diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt index eb4196e006..e0017c7b03 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.account -import com.ivy.wallet.domain.action.framework.FPAction +import com.ivy.fp.action.FPAction import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.io.persistence.dao.AccountDao import javax.inject.Inject @@ -9,6 +9,6 @@ class AccountsAct @Inject constructor( private val accountDao: AccountDao ) : FPAction>() { override suspend fun Unit.compose(): suspend () -> List = suspend { - io { accountDao.findAll() } + io { accountDao.findAll().map { it.toDomain() } } } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt index 025a0894f4..13ee664184 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.domain.action.account import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.action.framework.FPAction -import com.ivy.wallet.domain.action.framework.then +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.pure.account.AccountValueFunctions import com.ivy.wallet.domain.pure.account.calcAccValues diff --git a/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt index 715efe5444..9f5a570121 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.charts -import com.ivy.wallet.domain.action.framework.FPAction +import com.ivy.fp.action.FPAction import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.pure.charts.ChartPeriod import com.ivy.wallet.domain.pure.charts.SingleChartPoint diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt index 5be79a4db4..6d989e8ff4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.settings -import com.ivy.wallet.domain.action.framework.FPAction +import com.ivy.fp.action.FPAction import com.ivy.wallet.io.persistence.dao.SettingsDao import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt new file mode 100644 index 0000000000..0b8e727f9c --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt @@ -0,0 +1,36 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.then +import com.ivy.wallet.domain.action.ExchangeAct +import com.ivy.wallet.domain.data.TransactionHistoryItem +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.wallet.withDateDividers +import com.ivy.wallet.io.persistence.dao.AccountDao +import javax.inject.Inject + +class AddDateDividersAct @Inject constructor( + private val accountDao: AccountDao, + private val exchangeAct: ExchangeAct +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + transactions.withDateDividers( + baseCurrencyCode = baseCurrency, + getAccount = accountDao::findById then { it?.toDomain() }, + exchange = { data, amount -> + exchangeAct( + ExchangeAct.Input( + data = data, + amount = amount + ) + ) + } + ) + } + + data class Input( + val baseCurrency: String, + val transactions: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt new file mode 100644 index 0000000000..e168f89038 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt @@ -0,0 +1,26 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.io.persistence.dao.TransactionDao +import javax.inject.Inject + +class HistoryTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + io { + transactionDao.findAllBetween( + startDate = range.from, + endDate = range.to + ) + } + } thenMap { it.toDomain() } + + data class Input( + val range: ClosedTimeRange + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt deleted file mode 100644 index 3fda85b4ac..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivAct.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.ivy.wallet.domain.action.transaction - -import com.ivy.wallet.domain.action.framework.Action -import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.pure.data.ClosedTimeRange -import com.ivy.wallet.domain.pure.data.WalletDAOs -import javax.inject.Inject - -class HistoryWithDateDivAct @Inject constructor( - private val walletDAOs: WalletDAOs -) : Action>() { - - override suspend fun Input.willDo(): List = io { - historyWithDateDividers( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - range = timeRange - ) - } - - data class Input( - val timeRange: ClosedTimeRange, - val baseCurrencyCode: String - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt index 80d2471ee2..3e219fd491 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.wallet -import com.ivy.wallet.domain.action.framework.Action +import com.ivy.fp.action.Action import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.WalletLogic import com.ivy.wallet.domain.pure.data.IncomeExpensePair diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt index d65ce27952..562b23762a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.action.wallet -import com.ivy.wallet.domain.action.framework.Action +import com.ivy.fp.action.Action import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.logic.WalletLogic import com.ivy.wallet.domain.pure.data.IncomeExpensePair diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index aab216387f..92a742a2af 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -1,10 +1,10 @@ package com.ivy.wallet.domain.action.wallet import arrow.core.toOption +import com.ivy.fp.action.* import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.account.CalcAccBalanceAct -import com.ivy.wallet.domain.action.framework.* import com.ivy.wallet.domain.pure.data.ClosedTimeRange import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt b/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt index 3095598b3e..dd6755b038 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt @@ -5,9 +5,9 @@ import arrow.core.Option import arrow.core.Some import arrow.core.computations.option import arrow.core.toOption +import com.ivy.fp.Pure +import com.ivy.fp.SideEffect import com.ivy.wallet.domain.data.core.ExchangeRate -import com.ivy.wallet.domain.pure.core.Pure -import com.ivy.wallet.domain.pure.core.SideEffect import com.ivy.wallet.utils.isNotNullOrBlank import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt new file mode 100644 index 0000000000..bca1206d53 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt @@ -0,0 +1,2 @@ +package com.ivy.wallet.domain.pure + diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt index a27c307234..11f6cc50a2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt @@ -1,9 +1,9 @@ package com.ivy.wallet.domain.pure.account import arrow.core.NonEmptyList +import com.ivy.fp.Pure +import com.ivy.fp.Total import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.core.Pure -import com.ivy.wallet.domain.pure.core.Total import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSum import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.domain.pure.data.toFPTransaction diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt b/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt index 0465f7cfa5..e32e1a0cda 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.domain.pure.charts -import com.ivy.wallet.domain.pure.core.Pure -import com.ivy.wallet.domain.pure.core.SideEffect +import com.ivy.fp.Pure +import com.ivy.fp.SideEffect import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.domain.pure.data.WalletDAOs diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt index 147f111e65..6f3e90866f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt @@ -3,13 +3,13 @@ package com.ivy.wallet.domain.pure.wallet import arrow.core.NonEmptyList import arrow.core.Some import arrow.core.toOption +import com.ivy.fp.SideEffect import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.ExchangeRate import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.ExchangeData import com.ivy.wallet.domain.pure.account.AccountValueFunction import com.ivy.wallet.domain.pure.account.calcAccValues -import com.ivy.wallet.domain.pure.core.SideEffect import com.ivy.wallet.domain.pure.core.Uncertain import com.ivy.wallet.domain.pure.core.mapIndexedNel import com.ivy.wallet.domain.pure.core.nonEmptyListOfZeros diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt index 6552d2aaa2..67efc552f0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt @@ -2,12 +2,17 @@ package com.ivy.wallet.domain.pure.wallet import arrow.core.Option import arrow.core.toOption +import com.ivy.fp.Pure +import com.ivy.fp.SideEffect import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.ExchangeData -import com.ivy.wallet.domain.pure.core.* +import com.ivy.wallet.domain.pure.core.expenses +import com.ivy.wallet.domain.pure.core.incomes +import com.ivy.wallet.domain.pure.core.sum +import com.ivy.wallet.domain.pure.core.toFPTransactions import com.ivy.wallet.domain.pure.data.FPTransaction import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt index 8ba7ab3c68..9a7eefee00 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt @@ -2,7 +2,6 @@ package com.ivy.wallet.io.persistence.data import androidx.room.Entity import androidx.room.PrimaryKey -import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Transaction import java.time.LocalDateTime @@ -36,7 +35,7 @@ data class TransactionEntity( @PrimaryKey val id: UUID = UUID.randomUUID() -) : TransactionHistoryItem { +) { fun toDomain(): Transaction = Transaction( accountId = accountId, type = type, diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt index 2920c39c5c..439a2f4933 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt @@ -2,8 +2,8 @@ package com.ivy.wallet.ui.charts import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.fp.action.then import com.ivy.wallet.domain.action.charts.BalanceChartAct -import com.ivy.wallet.domain.action.framework.then import com.ivy.wallet.domain.action.settings.BaseCurrencyAct import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Category diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 79b2a5aa95..9f70a0ce6b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -3,8 +3,8 @@ package com.ivy.wallet.ui.home import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation -import com.ivy.design.viewmodel.IvyViewModel -import com.ivy.wallet.domain.action.transaction.HistoryWithDateDivAct +import com.ivy.fp.viewmodel.IvyViewModel +import com.ivy.wallet.domain.action.transaction.AddDateDividersAct import com.ivy.wallet.domain.action.wallet.CalcOverdueAct import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct @@ -49,7 +49,7 @@ class HomeViewModel @Inject constructor( private val calcAccountBalanceAct: CalcWalletBalanceAct, private val calcUpcomingAct: CalcUpcomingAct, private val calcOverdueAct: CalcOverdueAct, - private val historyWithDateDivAct: HistoryWithDateDivAct, + private val historyWithDateDivAct: AddDateDividersAct, ) : IvyViewModel() { override val mutableState: MutableStateFlow = MutableStateFlow( HomeState.initial(ivyWalletCtx = ivyContext) @@ -154,7 +154,7 @@ class HomeViewModel @Inject constructor( updateState { it.copy( history = historyWithDateDivAct( - HistoryWithDateDivAct.Input( + AddDateDividersAct.Input( timeRange = timeRange.toCloseTimeRange(), baseCurrencyCode = stateVal().baseCurrencyCode ) diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt index 8be7853106..3bc73a6bef 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt @@ -5,7 +5,7 @@ import androidx.compose.ui.graphics.toArgb import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation -import com.ivy.design.viewmodel.IvyViewModel +import com.ivy.fp.viewmodel.IvyViewModel import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category diff --git a/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt b/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt index c251639973..dc72f5bdf5 100644 --- a/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt @@ -46,6 +46,7 @@ fun DependencyHandler.appModuleDependencies( kotlinVersion: String = GlobalVersions.kotlinVersion ) { implementation(project(":ivy-design")) + implementation(project(":ivy-fp")) Kotlin(version = kotlinVersion) Coroutines(version = "1.5.0") @@ -91,6 +92,21 @@ fun DependencyHandler.ivyDesignModuleDependencies( Lifecycle(version = "2.3.1") } +fun DependencyHandler.ivyFPModuleDependencies( + kotlinVersion: String = GlobalVersions.kotlinVersion +) { + Kotlin(version = kotlinVersion) + Coroutines(version = "1.5.0") + FunctionalProgramming( + arrowVersion = "1.0.1", + kotestVersion = "5.1.0", + kotlinVersion = kotlinVersion + ) + + AndroidX() + Lifecycle(version = "2.3.1") +} + //--------------------------------------------------------------------------------- diff --git a/ivy-fp/.gitignore b/ivy-fp/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/ivy-fp/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/ivy-fp/build.gradle.kts b/ivy-fp/build.gradle.kts new file mode 100644 index 0000000000..01ad4e706a --- /dev/null +++ b/ivy-fp/build.gradle.kts @@ -0,0 +1,60 @@ +import com.ivy.wallet.buildsrc.Project +import com.ivy.wallet.buildsrc.ivyFPModuleDependencies + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") + id("kotlin-android") + id("kotlin-kapt") +} + +android { + compileSdk = Project.compileSdkVersion + + defaultConfig { + minSdk = Project.minSdk + targetSdk = Project.targetSdk + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = true + + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = "1.8" + } + + buildFeatures { + compose = true + } + + composeOptions { + kotlinCompilerExtensionVersion = com.ivy.wallet.buildsrc.GlobalVersions.compose + } + + packagingOptions { + //Exclude this files so Jetpack Compose UI tests can build + resources.excludes.add("META-INF/AL2.0") + resources.excludes.add("META-INF/LGPL2.1") + //------------------------------------------------------- + } +} + +dependencies { + ivyFPModuleDependencies() +} \ No newline at end of file diff --git a/ivy-fp/consumer-rules.pro b/ivy-fp/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ivy-fp/proguard-rules.pro b/ivy-fp/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/ivy-fp/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/ivy-fp/src/androidTest/java/com/ivy/design/ExampleInstrumentedTest.kt b/ivy-fp/src/androidTest/java/com/ivy/design/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..272e42be83 --- /dev/null +++ b/ivy-fp/src/androidTest/java/com/ivy/design/ExampleInstrumentedTest.kt @@ -0,0 +1,22 @@ +package com.ivy.design + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.ivy.fp.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/ivy-fp/src/main/AndroidManifest.xml b/ivy-fp/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..6333616ab1 --- /dev/null +++ b/ivy-fp/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/FP.kt b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt similarity index 63% rename from app/src/main/java/com/ivy/wallet/domain/pure/core/FP.kt rename to ivy-fp/src/main/java/com/ivy/fp/Composition.kt index 5cdc835a18..8300dbde5f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/FP.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.pure.core +package com.ivy.fp @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.SOURCE) @@ -21,14 +21,22 @@ annotation class Partial(val inCaseOf: String = "") @MustBeDocumented annotation class SideEffect -infix fun ((A) -> B).compose(fn2: (B) -> C): (A) -> C = { a -> +infix fun ((A) -> B).then(f: (B) -> C): (A) -> C = { a -> val b = this(a) - val c = fn2(b) - c + f(b) } infix fun ((B) -> C).after(fn1: (A) -> B): (A) -> C = { a -> val b = fn1(a) - val c = this(b) - c + this(b) +} + +infix fun ((A, B) -> C).then(f: (C) -> D): (A, B) -> D = { a, b -> + val c = this(a, b) + f(c) +} + +infix fun ((A, B, C) -> D).then(f: (D) -> E): (A, B, C) -> E = { a, b, c -> + val d = this(a, b, c) + f(d) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/framework/Action.kt b/ivy-fp/src/main/java/com/ivy/fp/action/Action.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/action/framework/Action.kt rename to ivy-fp/src/main/java/com/ivy/fp/action/Action.kt index 07e9eabc6b..cc3b8e728c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/framework/Action.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/Action.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action.framework +package com.ivy.fp.action import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext diff --git a/app/src/main/java/com/ivy/wallet/domain/action/framework/Composition.kt b/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt similarity index 96% rename from app/src/main/java/com/ivy/wallet/domain/action/framework/Composition.kt rename to ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt index 806977879c..e2cf008b4e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/framework/Composition.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action.framework +package com.ivy.fp.action suspend infix fun (suspend (A) -> B).then(f: suspend (B) -> C): suspend (A) -> C = diff --git a/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionFilter.kt b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt similarity index 89% rename from app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionFilter.kt rename to ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt index 2c0cb36f49..9d7ec8906a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionFilter.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action.framework +package com.ivy.fp.action suspend infix fun (suspend (A) -> List).thenFilter( predicate: (B) -> Boolean diff --git a/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionMap.kt b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt similarity index 64% rename from app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionMap.kt rename to ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt index ee88be3d67..5c11a6aa1b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionMap.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action.framework +package com.ivy.fp.action suspend infix fun (suspend (A) -> List).thenMap( transform: suspend (B) -> C @@ -10,6 +10,16 @@ suspend infix fun (suspend (A) -> List).thenMap( } } +suspend infix fun (suspend () -> List).thenMap( + transform: suspend (B) -> C +): suspend () -> List = + { + val list = this() + list.map { + transform(it) + } + } + suspend infix fun (Action>).thenMap( transform: suspend (B) -> C ): suspend (A) -> List = diff --git a/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionSum.kt b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionSum.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionSum.kt rename to ivy-fp/src/main/java/com/ivy/fp/action/CompositionSum.kt index 739a0ac507..72b42f7f47 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/framework/CompositionSum.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionSum.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action.framework +package com.ivy.fp.action import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/action/framework/FPAction.kt b/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt similarity index 80% rename from app/src/main/java/com/ivy/wallet/domain/action/framework/FPAction.kt rename to ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt index 1100eacfb5..279981ce62 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/framework/FPAction.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action.framework +package com.ivy.fp.action abstract class FPAction : Action() { protected abstract suspend fun I.compose(): (suspend () -> O) diff --git a/ivy-design/src/main/java/com/ivy/design/viewmodel/IvyViewModel.kt b/ivy-fp/src/main/java/com/ivy/fp/viewmodel/IvyViewModel.kt similarity index 94% rename from ivy-design/src/main/java/com/ivy/design/viewmodel/IvyViewModel.kt rename to ivy-fp/src/main/java/com/ivy/fp/viewmodel/IvyViewModel.kt index 0773e2c062..9562f5fb97 100644 --- a/ivy-design/src/main/java/com/ivy/design/viewmodel/IvyViewModel.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/viewmodel/IvyViewModel.kt @@ -1,4 +1,4 @@ -package com.ivy.design.viewmodel +package com.ivy.fp.viewmodel import androidx.lifecycle.ViewModel import kotlinx.coroutines.flow.MutableStateFlow diff --git a/ivy-design/src/main/java/com/ivy/design/viewmodel/ViewmodelUtils.kt b/ivy-fp/src/main/java/com/ivy/fp/viewmodel/ViewmodelUtils.kt similarity index 83% rename from ivy-design/src/main/java/com/ivy/design/viewmodel/ViewmodelUtils.kt rename to ivy-fp/src/main/java/com/ivy/fp/viewmodel/ViewmodelUtils.kt index 28f36a8122..4d93e3baa9 100644 --- a/ivy-design/src/main/java/com/ivy/design/viewmodel/ViewmodelUtils.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/viewmodel/ViewmodelUtils.kt @@ -1,4 +1,4 @@ -package com.ivy.design.viewmodel +package com.ivy.fp.viewmodel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow diff --git a/ivy-fp/src/test/java/com/ivy/design/ExampleUnitTest.kt b/ivy-fp/src/test/java/com/ivy/design/ExampleUnitTest.kt new file mode 100644 index 0000000000..08ade6083f --- /dev/null +++ b/ivy-fp/src/test/java/com/ivy/design/ExampleUnitTest.kt @@ -0,0 +1,16 @@ +package com.ivy.design + +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 707897c694..00c27d4b09 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,8 +1,5 @@ import java.net.URI -include(":ivy-design") - - dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { @@ -15,4 +12,7 @@ dependencyResolutionManagement { } rootProject.name = "Ivy Wallet" include(":app") +include(":ivy-design") +include(":ivy-fp") + \ No newline at end of file From 5b4343f7b1bd85c0de796a17d365d2c7fb85f6a2 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 19:05:38 +0300 Subject: [PATCH 15/40] WIP: Composition --- .../com/ivy/wallet/domain/action/ExchangeAct.kt | 10 ++++++++-- .../domain/action/transaction/AddDateDividersAct.kt | 10 ++-------- .../domain/action/wallet/CalcWalletBalanceAct.kt | 9 ++++++--- ivy-fp/src/main/java/com/ivy/fp/Composition.kt | 13 +++++++++++++ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt index b806e34914..016088db4c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt @@ -12,7 +12,6 @@ import javax.inject.Inject class ExchangeAct @Inject constructor( private val exchangeRateDao: ExchangeRateDao, ) : FPAction>() { - override suspend fun Input.compose(): suspend () -> Option = suspend { io { exchange( @@ -25,9 +24,16 @@ class ExchangeAct @Inject constructor( } } - data class Input( val data: ExchangeData, val amount: BigDecimal ) } + +fun exchangeActInput( + data: ExchangeData, + amount: BigDecimal +): ExchangeAct.Input = ExchangeAct.Input( + data = data, + amount = amount +) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt index 0b8e727f9c..d990adc4f5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt @@ -3,6 +3,7 @@ package com.ivy.wallet.domain.action.transaction import com.ivy.fp.action.FPAction import com.ivy.fp.then import com.ivy.wallet.domain.action.ExchangeAct +import com.ivy.wallet.domain.action.exchangeActInput import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.wallet.withDateDividers @@ -18,14 +19,7 @@ class AddDateDividersAct @Inject constructor( transactions.withDateDividers( baseCurrencyCode = baseCurrency, getAccount = accountDao::findById then { it?.toDomain() }, - exchange = { data, amount -> - exchangeAct( - ExchangeAct.Input( - data = data, - amount = amount - ) - ) - } + exchange = ::exchangeActInput then exchangeAct ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index 92a742a2af..8f95557abc 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -5,6 +5,7 @@ import com.ivy.fp.action.* import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.account.CalcAccBalanceAct +import com.ivy.wallet.domain.pure.ExchangeData import com.ivy.wallet.domain.pure.data.ClosedTimeRange import java.math.BigDecimal import javax.inject.Inject @@ -30,9 +31,11 @@ class CalcWalletBalanceAct @Inject constructor( } thenMap { exchangeAct( ExchangeAct.Input( - baseCurrency = baseCurrency, - fromCurrency = it.account.currency.toOption(), - toCurrency = balanceCurrency, + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = it.account.currency.toOption(), + toCurrency = balanceCurrency + ), amount = it.balance ) ) diff --git a/ivy-fp/src/main/java/com/ivy/fp/Composition.kt b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt index 8300dbde5f..ef58f201cf 100644 --- a/ivy-fp/src/main/java/com/ivy/fp/Composition.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt @@ -1,5 +1,7 @@ package com.ivy.fp +import com.ivy.fp.action.Action + @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.SOURCE) @MustBeDocumented @@ -36,6 +38,17 @@ infix fun ((A, B) -> C).then(f: (C) -> D): (A, B) -> D = { a, b -> f(c) } +infix fun ((A, B) -> C).then(act: Action): suspend (A, B) -> D = { a, b -> + val c = this(a, b) + act(c) +} + +suspend infix fun (suspend (A, B) -> C).then(f: suspend (C) -> D): suspend (A, B) -> D = + { a, b -> + val c = this(a, b) + f(c) + } + infix fun ((A, B, C) -> D).then(f: (D) -> E): (A, B, C) -> E = { a, b, c -> val d = this(a, b, c) f(d) From 63837c4b6694342db6466ed20dded5318032aabb Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 19:24:20 +0300 Subject: [PATCH 16/40] WIP: Actions --- .../ivy/wallet/domain/action/ExchangeAct.kt | 2 +- .../domain/action/category/CategoriesAct.kt | 17 +++++++++ .../action/category/CategoryTrnsBetweenAct.kt | 37 +++++++++++++++++++ .../action/transaction/AddDateDividersAct.kt | 4 +- .../level2/ItemStatisticViewModel.kt | 9 ++--- 5 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/category/CategoriesAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/category/CategoryTrnsBetweenAct.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt index 016088db4c..d561ca3bb5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt @@ -30,7 +30,7 @@ class ExchangeAct @Inject constructor( ) } -fun exchangeActInput( +fun actInput( data: ExchangeData, amount: BigDecimal ): ExchangeAct.Input = ExchangeAct.Input( diff --git a/app/src/main/java/com/ivy/wallet/domain/action/category/CategoriesAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoriesAct.kt new file mode 100644 index 0000000000..f0c5869cdd --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoriesAct.kt @@ -0,0 +1,17 @@ +package com.ivy.wallet.domain.action.category + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.io.persistence.dao.CategoryDao +import javax.inject.Inject + +class CategoriesAct @Inject constructor( + private val categoryDao: CategoryDao +) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { + io { + categoryDao.findAll() + } + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryTrnsBetweenAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryTrnsBetweenAct.kt new file mode 100644 index 0000000000..1303090ac9 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryTrnsBetweenAct.kt @@ -0,0 +1,37 @@ +package com.ivy.wallet.domain.action.category + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.io.persistence.dao.TransactionDao +import java.util.* +import javax.inject.Inject + +class CategoryTrnsBetweenAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + io { + transactionDao.findAllByCategoryAndBetween( + startDate = between.from, + endDate = between.to, + categoryId = categoryId + ) + } + } thenMap { it.toDomain() } + + data class Input( + val categoryId: UUID, + val between: ClosedTimeRange + ) +} + +fun actInput( + categoryId: UUID, + between: ClosedTimeRange +) = CategoryTrnsBetweenAct.Input( + categoryId = categoryId, + between = between +) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt index d990adc4f5..1c657e29ed 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt @@ -3,7 +3,7 @@ package com.ivy.wallet.domain.action.transaction import com.ivy.fp.action.FPAction import com.ivy.fp.then import com.ivy.wallet.domain.action.ExchangeAct -import com.ivy.wallet.domain.action.exchangeActInput +import com.ivy.wallet.domain.action.actInput import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.wallet.withDateDividers @@ -19,7 +19,7 @@ class AddDateDividersAct @Inject constructor( transactions.withDateDividers( baseCurrencyCode = baseCurrency, getAccount = accountDao::findById then { it?.toDomain() }, - exchange = ::exchangeActInput then exchangeAct + exchange = ::actInput then exchangeAct ) } diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt index 7a4d302921..ff90c17f5d 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt @@ -10,16 +10,15 @@ import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.sync.uploader.AccountUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.CategoryUploader import com.ivy.wallet.domain.pure.account.calculateAccountBalance import com.ivy.wallet.domain.pure.account.calculateAccountIncomeExpense import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.pure.exchangeToBaseCurrency import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode import com.ivy.wallet.domain.pure.wallet.withDateDividers -import com.ivy.wallet.domain.sync.uploader.AccountUploader -import com.ivy.wallet.domain.sync.uploader.CategoryUploader import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.stringRes import com.ivy.wallet.ui.ItemStatistic From ea91845b4adbb85beb2d02342d08de678d4362e8 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 20:04:31 +0300 Subject: [PATCH 17/40] WIP: Clean-up `domain.pure` --- .../action/account/CalcAccBalanceAct.kt | 10 +- ...idersAct.kt => TrnsWithDateDividersAct.kt} | 10 +- .../wallet/domain/data/core/Transaction.kt | 26 +-- ...ValueFunctions.kt => AccValueFunctions.kt} | 28 +-- ...ValueFunctions.kt => CatValueFunctions.kt} | 57 +++--- .../com/ivy/wallet/domain/pure/IvyCore.kt | 19 ++ .../wallet/domain/pure/account/AccountCore.kt | 73 ------- .../domain/pure/account/AccountFunctions.kt | 82 -------- .../domain/pure/category/CategoryCore.kt | 101 --------- .../domain/pure/category/CategoryFunctions.kt | 135 ------------ .../domain/pure/core/TransactionFunctions.kt | 14 +- .../wallet/domain/pure/core/ValueFunction.kt | 10 +- .../wallet/domain/pure/data/FPTransaction.kt | 46 ----- .../TrnDateDividers.kt} | 28 +-- .../wallet/domain/pure/wallet/WalletCore.kt | 192 ------------------ .../domain/pure/wallet/WalletFunctions.kt | 130 ------------ .../io/persistence/data/TransactionEntity.kt | 6 +- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 6 +- 18 files changed, 100 insertions(+), 873 deletions(-) rename app/src/main/java/com/ivy/wallet/domain/action/transaction/{AddDateDividersAct.kt => TrnsWithDateDividersAct.kt} (75%) rename app/src/main/java/com/ivy/wallet/domain/pure/{account/AccountValueFunctions.kt => AccValueFunctions.kt} (71%) rename app/src/main/java/com/ivy/wallet/domain/pure/{category/CategoryValueFunctions.kt => CatValueFunctions.kt} (61%) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryFunctions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt rename app/src/main/java/com/ivy/wallet/domain/pure/{wallet/WalletTransactions.kt => transaction/TrnDateDividers.kt} (79%) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt index 13ee664184..a3710d093d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -4,8 +4,8 @@ import arrow.core.nonEmptyListOf import com.ivy.fp.action.FPAction import com.ivy.fp.action.then import com.ivy.wallet.domain.data.core.Account -import com.ivy.wallet.domain.pure.account.AccountValueFunctions -import com.ivy.wallet.domain.pure.account.calcAccValues +import com.ivy.wallet.domain.pure.AccountValueFunctions +import com.ivy.wallet.domain.pure.calcValues import com.ivy.wallet.domain.pure.data.ClosedTimeRange import java.math.BigDecimal import javax.inject.Inject @@ -20,9 +20,9 @@ class CalcAccBalanceAct @Inject constructor( range = range ) } then accTrnsAct then { accTrns -> - calcAccValues( - accountId = account.id, - accountsTrns = accTrns, + calcValues( + transactions = accTrns, + arg = account.id, valueFunctions = nonEmptyListOf(AccountValueFunctions::balance) ).head } then { balance -> diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDividersAct.kt similarity index 75% rename from app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDividersAct.kt index 1c657e29ed..845d3aa94b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AddDateDividersAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDividersAct.kt @@ -6,18 +6,20 @@ import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.actInput import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.wallet.withDateDividers +import com.ivy.wallet.domain.pure.transaction.transactionsWithDateDividers import com.ivy.wallet.io.persistence.dao.AccountDao import javax.inject.Inject -class AddDateDividersAct @Inject constructor( +class TrnsWithDateDividersAct @Inject constructor( private val accountDao: AccountDao, private val exchangeAct: ExchangeAct -) : FPAction>() { +) : FPAction>() { override suspend fun Input.compose(): suspend () -> List = suspend { - transactions.withDateDividers( + transactionsWithDateDividers( + transactions = transactions, baseCurrencyCode = baseCurrency, + getAccount = accountDao::findById then { it?.toDomain() }, exchange = ::actInput then exchangeAct ) diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt index 19167e1365..de7b33d373 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt @@ -2,15 +2,16 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType +import java.math.BigDecimal import java.time.LocalDateTime import java.util.* data class Transaction( val accountId: UUID, val type: TransactionType, - val amount: Double, + val amount: BigDecimal, val toAccountId: UUID? = null, - val toAmount: Double? = null, + val toAmount: BigDecimal, val title: String? = null, val description: String? = null, val dateTime: LocalDateTime? = null, @@ -25,24 +26,7 @@ data class Transaction( val loanId: UUID? = null, //This refers to the loan record id that is linked with a transaction - val loanRecordId:UUID? = null, - - val isSynced: Boolean = false, - val isDeleted: Boolean = false, + val loanRecordId: UUID? = null, val id: UUID = UUID.randomUUID() -) : TransactionHistoryItem { - - fun isIdenticalWith(transaction: Transaction?): Boolean { - if (transaction == null) return false - - //Set isSynced && isDeleted to false so they aren't accounted in the equals check - return this.copy( - isSynced = false, - isDeleted = false - ) == transaction.copy( - isSynced = false, - isDeleted = false - ) - } -} \ No newline at end of file +) : TransactionHistoryItem \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/AccValueFunctions.kt similarity index 71% rename from app/src/main/java/com/ivy/wallet/domain/pure/account/AccountValueFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/AccValueFunctions.kt index 5f5dbb8648..66ff1176e0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/AccValueFunctions.kt @@ -1,8 +1,8 @@ -package com.ivy.wallet.domain.pure.account +package com.ivy.wallet.domain.pure import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.core.ValueFunction -import com.ivy.wallet.domain.pure.data.FPTransaction import java.math.BigDecimal import java.util.* @@ -10,16 +10,16 @@ typealias AccountValueFunction = ValueFunction object AccountValueFunctions { fun balance( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId) { //Account's transactions when (type) { TransactionType.INCOME -> amount TransactionType.EXPENSE -> amount.negate() TransactionType.TRANSFER -> { - if (toAccountId.orNull() != accountId) { + if (toAccountId != accountId) { //transfer to another account amount.negate() } else { @@ -30,39 +30,39 @@ object AccountValueFunctions { } } else { //potential transfer to account? - toAccountId.orNull()?.takeIf { it == accountId } ?: return BigDecimal.ZERO + toAccountId?.takeIf { it == accountId } ?: return BigDecimal.ZERO toAmount } } fun income( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId && type == TransactionType.INCOME) amount else BigDecimal.ZERO } fun expense( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId && type == TransactionType.EXPENSE) amount else BigDecimal.ZERO } fun incomeCount( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId && type == TransactionType.INCOME) BigDecimal.ONE else BigDecimal.ZERO } fun expenseCount( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId && type == TransactionType.EXPENSE) BigDecimal.ONE else BigDecimal.ZERO } diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/CatValueFunctions.kt similarity index 61% rename from app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/CatValueFunctions.kt index 342c48dd03..077926a1d8 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/CatValueFunctions.kt @@ -1,13 +1,12 @@ -package com.ivy.wallet.domain.pure.category +package com.ivy.wallet.domain.pure import arrow.core.Option import arrow.core.toOption +import com.ivy.fp.SideEffect import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.core.SuspendValueFunction -import com.ivy.wallet.domain.pure.data.FPTransaction -import com.ivy.wallet.domain.pure.exchangeToBaseCurrency -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao import java.math.BigDecimal import java.util.* @@ -16,17 +15,17 @@ typealias CategoryValueFunction = SuspendValueFunction, - val exchangeRateDao: ExchangeRateDao, - val baseCurrencyCode: String, + + @SideEffect + val exchangeToBaseCurrency: suspend (Option, BigDecimal) -> Option ) suspend fun balance( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.INCOME -> amount.toBaseCurrencyOrZero(arg, accountId) TransactionType.EXPENSE -> amount.toBaseCurrencyOrZero(arg, accountId).negate() @@ -36,10 +35,10 @@ object CategoryValueFunctions { } suspend fun income( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.INCOME -> amount.toBaseCurrencyOrZero(arg, accountId) else -> BigDecimal.ZERO @@ -48,10 +47,10 @@ object CategoryValueFunctions { } suspend fun expense( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.EXPENSE -> amount.toBaseCurrencyOrZero(arg, accountId) else -> BigDecimal.ZERO @@ -60,10 +59,10 @@ object CategoryValueFunctions { } suspend fun incomeCount( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.INCOME -> BigDecimal.ONE else -> BigDecimal.ZERO @@ -72,10 +71,10 @@ object CategoryValueFunctions { } suspend fun expenseCount( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.EXPENSE -> BigDecimal.ONE else -> BigDecimal.ZERO @@ -84,24 +83,20 @@ object CategoryValueFunctions { } private suspend fun BigDecimal.toBaseCurrencyOrZero( - argument: Argument, + arg: Argument, accountId: UUID ): BigDecimal { return this.convertToBaseCurrency( - argument = argument, + arg = arg, accountId = accountId ).orNull() ?: BigDecimal.ZERO } private suspend fun BigDecimal.convertToBaseCurrency( accountId: UUID, - argument: Argument + arg: Argument ): Option { - return exchangeToBaseCurrency( - exchangeRateDao = argument.exchangeRateDao, - baseCurrencyCode = argument.baseCurrencyCode, - fromAmount = this, - fromCurrencyCode = argument.accounts.find { it.id == accountId }?.currency.toOption() - ) + val trnCurrency = arg.accounts.find { it.id == accountId }?.currency.toOption() + return arg.exchangeToBaseCurrency(trnCurrency, this) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt index bca1206d53..e93dafd137 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt @@ -1,2 +1,21 @@ package com.ivy.wallet.domain.pure +import arrow.core.NonEmptyList +import com.ivy.fp.Pure +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.core.ValueFunction +import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSum +import java.math.BigDecimal + +@Pure +fun calcValues( + transactions: List, + valueFunctions: NonEmptyList>, + arg: Arg +): NonEmptyList { + return calculateValueFunctionsSum( + valueFunctionArgument = arg, + transactions = transactions, + valueFunctions = valueFunctions + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt deleted file mode 100644 index 11f6cc50a2..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountCore.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.ivy.wallet.domain.pure.account - -import arrow.core.NonEmptyList -import com.ivy.fp.Pure -import com.ivy.fp.Total -import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSum -import com.ivy.wallet.domain.pure.data.ClosedTimeRange -import com.ivy.wallet.domain.pure.data.toFPTransaction -import com.ivy.wallet.io.persistence.dao.TransactionDao -import java.math.BigDecimal -import java.util.* - -@Total -suspend fun calcAccValues( - transactionDao: TransactionDao, - accountId: UUID, - range: ClosedTimeRange, - valueFunctions: NonEmptyList -): NonEmptyList { - return calcAccValues( - accountId = accountId, - retrieveAccountTransactions = { - transactionDao.findAllByAccountAndBetween( - accountId = accountId, - startDate = range.from, - endDate = range.to - ) - }, - retrieveToAccountTransfers = { - transactionDao.findAllToAccountAndBetween( - toAccountId = accountId, - startDate = range.from, - endDate = range.to - ) - }, - valueFunctions = valueFunctions - ) -} - -@Total -suspend fun calcAccValues( - accountId: UUID, - retrieveAccountTransactions: suspend (UUID) -> List, - retrieveToAccountTransfers: suspend (UUID) -> List, - valueFunctions: NonEmptyList -): NonEmptyList { - val accountTrns = retrieveAccountTransactions(accountId) - .plus(retrieveToAccountTransfers(accountId)) - .map { it.toFPTransaction() } - - return calculateValueFunctionsSum( - valueFunctionArgument = accountId, - transactions = accountTrns, - valueFunctions = valueFunctions - ) -} - -@Pure -fun calcAccValues( - accountId: UUID, - accountsTrns: List, - valueFunctions: NonEmptyList -): NonEmptyList { - val accountTrns = accountsTrns - .map { it.toFPTransaction() } - - return calculateValueFunctionsSum( - valueFunctionArgument = accountId, - transactions = accountTrns, - valueFunctions = valueFunctions - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt deleted file mode 100644 index c5907b7b4a..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.ivy.wallet.domain.pure.account - -import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.pure.data.ClosedTimeRange -import com.ivy.wallet.domain.pure.data.IncomeExpensePair -import com.ivy.wallet.io.persistence.dao.TransactionDao -import java.math.BigDecimal -import java.util.* - - -suspend fun calculateAccountBalance( - transactionDao: TransactionDao, - accountId: UUID, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() -): BigDecimal { - return calcAccValues( - transactionDao = transactionDao, - accountId = accountId, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::balance - ) - ).head -} - -data class AccountStats( - val balance: BigDecimal, - val income: BigDecimal, - val expense: BigDecimal, - val incomeCount: Int, - val expenseCount: Int -) - -suspend fun calculateAccountStats( - transactionDao: TransactionDao, - accountId: UUID, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() -): AccountStats { - val values = calcAccValues( - transactionDao = transactionDao, - accountId = accountId, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::balance, - AccountValueFunctions::income, - AccountValueFunctions::expense, - AccountValueFunctions::incomeCount, - AccountValueFunctions::expenseCount - ) - ) - - return AccountStats( - balance = values[0], - income = values[1], - expense = values[2], - incomeCount = values[3].toInt(), - expenseCount = values[4].toInt() - ) -} - -suspend fun calculateAccountIncomeExpense( - transactionDao: TransactionDao, - accountId: UUID, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() -): IncomeExpensePair { - val values = calcAccValues( - transactionDao = transactionDao, - accountId = accountId, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::income, - AccountValueFunctions::expense, - ) - ) - - return IncomeExpensePair( - income = values[0], - expense = values[1], - ) -} - - diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt deleted file mode 100644 index 4b34da7f27..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryCore.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.ivy.wallet.domain.pure.category - -import arrow.core.NonEmptyList -import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSumSuspend -import com.ivy.wallet.domain.pure.data.ClosedTimeRange -import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.pure.data.toFPTransaction -import java.math.BigDecimal -import java.util.* - -suspend fun calculateCategoryValues( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, - valueFunctions: NonEmptyList -): NonEmptyList { - return calculateCategoryValues( - argument = CategoryValueFunctions.Argument( - categoryId = categoryId, - accounts = walletDAOs.accountDao.findAll(), - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode - ), - retrieveCategoryTransactions = { forCategoryId -> - if (forCategoryId == null) { - walletDAOs.transactionDao.findAllUnspecifiedAndBetween( - startDate = range.from, - endDate = range.to - ) - } else { - walletDAOs.transactionDao.findAllByCategoryAndBetween( - categoryId = forCategoryId, - startDate = range.from, - endDate = range.to - ) - } - - }, - valueFunctions = valueFunctions - ) -} - -suspend fun calculateCategoryValuesWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, - accountIdFilterSet: Set, - valueFunctions: NonEmptyList -): NonEmptyList { - return calculateCategoryValues( - argument = CategoryValueFunctions.Argument( - categoryId = categoryId, - accounts = walletDAOs.accountDao.findAll(), - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode - ), - retrieveCategoryTransactions = { forCategoryId -> - if (forCategoryId == null) { - walletDAOs.transactionDao.findAllUnspecifiedAndBetween( - startDate = range.from, - endDate = range.to - ).filter { - if (accountIdFilterSet.isNotEmpty()) - accountIdFilterSet.contains(it.accountId) - else - true - } - } else { - walletDAOs.transactionDao.findAllByCategoryAndBetween( - categoryId = forCategoryId, - startDate = range.from, - endDate = range.to - ).filter { - if (accountIdFilterSet.isNotEmpty()) - accountIdFilterSet.contains(it.accountId) - else - true - } - } - }, - valueFunctions = valueFunctions - ) -} - -suspend fun calculateCategoryValues( - argument: CategoryValueFunctions.Argument, - retrieveCategoryTransactions: suspend (UUID?) -> List, - valueFunctions: NonEmptyList -): NonEmptyList { - val categoryTrns = retrieveCategoryTransactions(argument.categoryId) - .map { it.toFPTransaction() } - - return calculateValueFunctionsSumSuspend( - valueFunctionArgument = argument, - transactions = categoryTrns, - valueFunctions = valueFunctions - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryFunctions.kt deleted file mode 100644 index c5a6e7c5ea..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/category/CategoryFunctions.kt +++ /dev/null @@ -1,135 +0,0 @@ -package com.ivy.wallet.domain.pure.category - -import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.pure.data.ClosedTimeRange -import com.ivy.wallet.domain.pure.data.WalletDAOs -import java.math.BigDecimal -import java.util.* - -suspend fun calculateCategoryBalance( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::balance - ) - ).head -} - -data class CategoryStats( - val balance: BigDecimal, - val income: BigDecimal, - val expense: BigDecimal, - val incomeCount: BigDecimal, - val expenseCount: BigDecimal -) - -suspend fun calculateCategoryStats( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, -): CategoryStats { - val values = calculateCategoryValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::income, - CategoryValueFunctions::expense, - CategoryValueFunctions::incomeCount, - CategoryValueFunctions::expenseCount - ) - ) - - val income = values[0] - val expense = values[1] - - return CategoryStats( - balance = income - expense, - income = income, - expense = expense, - incomeCount = values[2], - expenseCount = values[3] - ) -} - -suspend fun calculateCategoryIncome( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::income - ) - ).head -} - -suspend fun calculateCategoryIncomeWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - accountIdFilterList: List, - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValuesWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - accountIdFilterSet = accountIdFilterList.toHashSet(), - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::income - ) - ).head -} - -suspend fun calculateCategoryExpense( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::expense - ) - ).head -} - -suspend fun calculateCategoryExpenseWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - accountIdList: List = emptyList(), - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValuesWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - accountIdFilterSet = accountIdList.toHashSet(), - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::expense - ) - ).head -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt index ffa27aaa18..4ef158109e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt @@ -2,12 +2,10 @@ package com.ivy.wallet.domain.pure.core import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.data.FPTransaction -import com.ivy.wallet.domain.pure.data.toFPTransaction import java.math.BigDecimal suspend fun sum( - transactions: List, + transactions: List, valueFunction: SuspendValueFunction, argument: A ): BigDecimal { @@ -16,18 +14,14 @@ suspend fun sum( } } -fun expenses(transactions: List): List { +fun expenses(transactions: List): List { return transactions.filter { it.type == TransactionType.EXPENSE } } -fun incomes(transactions: List): List { +fun incomes(transactions: List): List { return transactions.filter { it.type == TransactionType.INCOME } } -fun transfers(transactions: List): List { +fun transfers(transactions: List): List { return transactions.filter { it.type == TransactionType.TRANSFER } -} - -fun List.toFPTransactions(): List { - return this.map { it.toFPTransaction() } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt index a9d0267943..7c464e7d8b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt @@ -1,15 +1,15 @@ package com.ivy.wallet.domain.pure.core import arrow.core.NonEmptyList -import com.ivy.wallet.domain.pure.data.FPTransaction +import com.ivy.wallet.domain.data.core.Transaction import java.math.BigDecimal -typealias ValueFunction = (FPTransaction, A) -> BigDecimal -typealias SuspendValueFunction = suspend (FPTransaction, A) -> BigDecimal +typealias ValueFunction = (Transaction, A) -> BigDecimal +typealias SuspendValueFunction = suspend (Transaction, A) -> BigDecimal internal tailrec fun calculateValueFunctionsSum( valueFunctionArgument: A, - transactions: List, + transactions: List, valueFunctions: NonEmptyList>, sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) ): NonEmptyList { @@ -29,7 +29,7 @@ internal tailrec fun calculateValueFunctionsSum( internal tailrec suspend fun calculateValueFunctionsSumSuspend( valueFunctionArgument: A, - transactions: List, + transactions: List, valueFunctions: NonEmptyList>, sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) ): NonEmptyList { diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt deleted file mode 100644 index eafc522431..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/data/FPTransaction.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.ivy.wallet.domain.pure.data - -import arrow.core.Option -import arrow.core.toOption -import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.core.Transaction -import java.math.BigDecimal -import java.time.LocalDateTime -import java.util.* - -data class FPTransaction( - val id: UUID, - val type: TransactionType, - val accountId: UUID, - val categoryId: Option, - val amount: BigDecimal, - val toAccountId: Option, - val toAmount: BigDecimal, - val dateTime: Option, - - val loanId: Option, - val loanRecordId:Option, - - val title: Option, - val description: Option, - val dueDate: Option, - val recurringRuleId: Option -) - -fun Transaction.toFPTransaction(): FPTransaction = - FPTransaction( - id = id, - accountId = accountId, - type = type, - amount = amount.toBigDecimal(), - toAccountId = toAccountId.toOption(), - toAmount = toAmount?.toBigDecimal() ?: amount.toBigDecimal(), - title = title.toOption(), - description = description.toOption(), - dateTime = dateTime.toOption(), - categoryId = categoryId.toOption(), - dueDate = dueDate.toOption(), - recurringRuleId = recurringRuleId.toOption(), - loanId = loanId.toOption(), - loanRecordId = loanRecordId.toOption() - ) diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt similarity index 79% rename from app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt index 67efc552f0..53956ae9d7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletTransactions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.pure.wallet +package com.ivy.wallet.domain.pure.transaction import arrow.core.Option import arrow.core.toOption @@ -12,18 +12,14 @@ import com.ivy.wallet.domain.pure.ExchangeData import com.ivy.wallet.domain.pure.core.expenses import com.ivy.wallet.domain.pure.core.incomes import com.ivy.wallet.domain.pure.core.sum -import com.ivy.wallet.domain.pure.core.toFPTransactions -import com.ivy.wallet.domain.pure.data.FPTransaction import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal import java.util.* -//TODO: overdue(range) -//TODO: upcoming(range) - @Pure -suspend fun List.withDateDividers( +suspend fun transactionsWithDateDividers( + transactions: List, baseCurrencyCode: String, @SideEffect @@ -31,10 +27,9 @@ suspend fun List.withDateDividers( @SideEffect exchange: suspend (ExchangeData, BigDecimal) -> Option ): List { - val history = this - if (history.isEmpty()) return emptyList() + if (transactions.isEmpty()) return emptyList() - return history + return transactions .groupBy { it.dateTime?.convertUTCtoLocal()?.toLocalDate() } .filterKeys { it != null } .toSortedMap { date1, date2 -> @@ -48,19 +43,18 @@ suspend fun List.withDateDividers( exchange = exchange ) - val fpTransactions = transactionsForDate.toFPTransactions() listOf( TransactionHistoryDateDivider( date = date!!, income = sum( - incomes(fpTransactions), - ::amountInCurrency, + incomes(transactionsForDate), + ::exchangeInCurrency, arg ).toDouble(), expenses = sum( - expenses(fpTransactions), - ::amountInCurrency, + expenses(transactionsForDate), + ::exchangeInCurrency, arg ).toDouble() ), @@ -76,8 +70,8 @@ data class AmountInCurrencyArgument( val exchange: suspend (ExchangeData, BigDecimal) -> Option ) -suspend fun amountInCurrency( - fpTransaction: FPTransaction, +suspend fun exchangeInCurrency( + fpTransaction: Transaction, arg: AmountInCurrencyArgument ): BigDecimal { val fromCurrencyCode = arg.getAccount(fpTransaction.accountId)?.currency.toOption() diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt deleted file mode 100644 index 6f3e90866f..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletCore.kt +++ /dev/null @@ -1,192 +0,0 @@ -package com.ivy.wallet.domain.pure.wallet - -import arrow.core.NonEmptyList -import arrow.core.Some -import arrow.core.toOption -import com.ivy.fp.SideEffect -import com.ivy.wallet.domain.data.core.Account -import com.ivy.wallet.domain.data.core.ExchangeRate -import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.ExchangeData -import com.ivy.wallet.domain.pure.account.AccountValueFunction -import com.ivy.wallet.domain.pure.account.calcAccValues -import com.ivy.wallet.domain.pure.core.Uncertain -import com.ivy.wallet.domain.pure.core.mapIndexedNel -import com.ivy.wallet.domain.pure.core.nonEmptyListOfZeros -import com.ivy.wallet.domain.pure.data.* -import com.ivy.wallet.domain.pure.exchange -import com.ivy.wallet.utils.scopedIOThread -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import java.math.BigDecimal -import java.util.* - -typealias UncertainWalletValues = Uncertain, NonEmptyList> -typealias AccountValuesPair = Pair> - -suspend fun calculateWalletValues( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), - valueFunctions: NonEmptyList, - - @SideEffect - getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, -): UncertainWalletValues { - val uncertainWalletValues = walletDAOs.accountDao.findAll() - .filter { !filterExcluded || it.includeInBalance } - .map { account -> - Pair( - first = account.toFPAccount(baseCurrencyCode), - second = calcAccValues( - transactionDao = walletDAOs.transactionDao, - accountId = account.id, - range = range, - valueFunctions = valueFunctions - ) - ) - } - .convertValuesInBaseCurrency( - baseCurrency = baseCurrencyCode, - getExchangeRate = getExchangeRate - ) - - return sumUncertainWalletValues( - valueN = valueFunctions.size, - uncertainWalletValues = uncertainWalletValues - ) -} - -suspend fun sumAccountValuesInCurrency( - accountTrns: List>>, - baseCurrencyCode: String, - valueFunctions: NonEmptyList, - - @SideEffect - getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, -): UncertainWalletValues { - val uncertainWalletValues = accountTrns.map { (account, trns) -> - Pair( - first = account.toFPAccount(baseCurrencyCode), - second = calcAccValues( - accountId = account.id, - accountsTrns = trns, - valueFunctions = valueFunctions - ) - ) - }.convertValuesInBaseCurrency( - baseCurrency = baseCurrencyCode, - getExchangeRate = getExchangeRate - ) - - return sumUncertainWalletValues( - valueN = valueFunctions.size, - uncertainWalletValues = uncertainWalletValues - ) -} - -suspend fun calculateWalletValuesWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - accountIdFilterList: List, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), - valueFunctions: NonEmptyList, - - @SideEffect - getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, -): UncertainWalletValues { - - val accounts = scopedIOThread { scope -> - if (accountIdFilterList.isNotEmpty()) - accountIdFilterList.map { accId -> - scope.async { - walletDAOs.accountDao.findById(accId) - } - }.awaitAll().filterNotNull() - else { - walletDAOs.accountDao.findAll() - } - } - - val uncertainWalletValues = accounts - .filter { !filterExcluded || it.includeInBalance } - .map { account -> - Pair( - first = account.toFPAccount(baseCurrencyCode), - second = calcAccValues( - transactionDao = walletDAOs.transactionDao, - accountId = account.id, - range = range, - valueFunctions = valueFunctions - ) - ) - } - .convertValuesInBaseCurrency( - baseCurrency = baseCurrencyCode, - getExchangeRate = getExchangeRate - ) - - return sumUncertainWalletValues( - valueN = valueFunctions.size, - uncertainWalletValues = uncertainWalletValues - ) -} - -private suspend fun Iterable.convertValuesInBaseCurrency( - baseCurrency: String, - - @SideEffect - getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, -): List { - return this.map { (account, values) -> - val valuesInBaseCurrency = values.map { - exchange( - data = ExchangeData( - baseCurrency = baseCurrency, - fromCurrency = account.currencyCode.toOption(), - toCurrency = baseCurrency - ), - amount = it, - getExchangeRate = getExchangeRate - ) - } - val hasError = valuesInBaseCurrency.any { !it.isDefined() } - - Uncertain( - error = if (hasError) - listOf(CurrencyConvError(account = account)) else emptyList(), - value = if (!hasError) { - //if there is no error all values must be Some() - valuesInBaseCurrency.map { (it as Some).value } - } else nonEmptyListOfZeros(values.size) - ) - } -} - -private tailrec fun sumUncertainWalletValues( - valueN: Int, - uncertainWalletValues: List, - sum: UncertainWalletValues = Uncertain( - error = emptyList(), - value = nonEmptyListOfZeros(n = valueN) - ) -): UncertainWalletValues { - return if (uncertainWalletValues.isEmpty()) sum else { - val uncertainValues = uncertainWalletValues.first() - - sumUncertainWalletValues( - valueN = valueN, - uncertainWalletValues = uncertainWalletValues.drop(1), - sum = Uncertain( - error = sum.error.plus(uncertainValues.error), - value = if (uncertainValues.isCertain()) { - sum.value.mapIndexedNel { index, value -> - value.plus(uncertainValues.value[index]) - } - } else sum.value //no need to sum it, if it's uncertain (it'll be all ZEROs) - ) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt deleted file mode 100644 index ffe736c8c2..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/wallet/WalletFunctions.kt +++ /dev/null @@ -1,130 +0,0 @@ -package com.ivy.wallet.domain.pure.wallet - -import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.data.core.Settings -import com.ivy.wallet.domain.pure.account.AccountValueFunctions -import com.ivy.wallet.domain.pure.core.Uncertain -import com.ivy.wallet.domain.pure.data.ClosedTimeRange -import com.ivy.wallet.domain.pure.data.CurrencyConvError -import com.ivy.wallet.domain.pure.data.IncomeExpensePair -import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.io.persistence.dao.SettingsDao -import java.math.BigDecimal -import java.util.* - -fun walletBufferDiff( - settings: Settings, - balance: BigDecimal -): BigDecimal { - return balance - settings.bufferAmount.toBigDecimal() -} - -@Deprecated("Side-effects must be handled by Actions") -suspend fun baseCurrencyCode( - settingsDao: SettingsDao -): String { - return settingsDao.findFirst().currency -} - -suspend fun calculateWalletIncomeWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - accountIdFilterList: List, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValuesWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - accountIdFilterList = accountIdFilterList, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::income - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - - -suspend fun calculateWalletExpenseWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - accountIdFilterList: List, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValuesWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - accountIdFilterList = accountIdFilterList, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::expense - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - -suspend fun calculateWalletIncomeExpense( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange, -): Uncertain, IncomeExpensePair> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::income, - AccountValueFunctions::expense - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = IncomeExpensePair( - income = uncertainValues.value[0], - expense = uncertainValues.value[1] - ) - ) -} - -suspend fun calculateWalletIncomeExpenseCount( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange, -): Uncertain, Pair> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::incomeCount, - AccountValueFunctions::expenseCount - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = Pair( - uncertainValues.value[0], uncertainValues.value[1] - ) - ) -} - -//TODO: upcomingIncomeExpense -//TODO: overdueIncomeExpense diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt index 9a7eefee00..749a803622 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt @@ -39,9 +39,9 @@ data class TransactionEntity( fun toDomain(): Transaction = Transaction( accountId = accountId, type = type, - amount = amount, + amount = amount.toBigDecimal(), toAccountId = toAccountId, - toAmount = toAmount, + toAmount = toAmount?.toBigDecimal() ?: amount.toBigDecimal(), title = title, description = description, dateTime = dateTime, @@ -51,8 +51,6 @@ data class TransactionEntity( attachmentUrl = attachmentUrl, loanId = loanId, loanRecordId = loanRecordId, - isSynced = isSynced, - isDeleted = isDeleted, id = id ) diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 9f70a0ce6b..1c82aab262 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation import com.ivy.fp.viewmodel.IvyViewModel -import com.ivy.wallet.domain.action.transaction.AddDateDividersAct +import com.ivy.wallet.domain.action.transaction.TrnsWithDateDividersAct import com.ivy.wallet.domain.action.wallet.CalcOverdueAct import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct @@ -49,7 +49,7 @@ class HomeViewModel @Inject constructor( private val calcAccountBalanceAct: CalcWalletBalanceAct, private val calcUpcomingAct: CalcUpcomingAct, private val calcOverdueAct: CalcOverdueAct, - private val historyWithDateDivAct: AddDateDividersAct, + private val historyWithDateDivAct: TrnsWithDateDividersAct, ) : IvyViewModel() { override val mutableState: MutableStateFlow = MutableStateFlow( HomeState.initial(ivyWalletCtx = ivyContext) @@ -154,7 +154,7 @@ class HomeViewModel @Inject constructor( updateState { it.copy( history = historyWithDateDivAct( - AddDateDividersAct.Input( + TrnsWithDateDividersAct.Input( timeRange = timeRange.toCloseTimeRange(), baseCurrencyCode = stateVal().baseCurrencyCode ) From d784c5da6397723410f28353e7d2d4a5cb988d3d Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 20:06:57 +0300 Subject: [PATCH 18/40] WIP: Clean-up `domain.pure` --- .../wallet/domain/action/account/CalcAccBalanceAct.kt | 2 +- .../com/ivy/wallet/domain/pure/{core => }/Utils.kt | 2 +- .../com/ivy/wallet/domain/pure/{ => core}/IvyCore.kt | 4 +--- .../core/{TransactionFunctions.kt => TrnFunctions.kt} | 0 .../java/com/ivy/wallet/domain/pure/core/Uncertain.kt | 10 ---------- .../com/ivy/wallet/domain/pure/core/ValueFunction.kt | 3 +++ 6 files changed, 6 insertions(+), 15 deletions(-) rename app/src/main/java/com/ivy/wallet/domain/pure/{core => }/Utils.kt (93%) rename app/src/main/java/com/ivy/wallet/domain/pure/{ => core}/IvyCore.kt (74%) rename app/src/main/java/com/ivy/wallet/domain/pure/core/{TransactionFunctions.kt => TrnFunctions.kt} (100%) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/core/Uncertain.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt index a3710d093d..3b8217f505 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -5,7 +5,7 @@ import com.ivy.fp.action.FPAction import com.ivy.fp.action.then import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.pure.AccountValueFunctions -import com.ivy.wallet.domain.pure.calcValues +import com.ivy.wallet.domain.pure.core.calcValues import com.ivy.wallet.domain.pure.data.ClosedTimeRange import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/Utils.kt b/app/src/main/java/com/ivy/wallet/domain/pure/Utils.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/pure/core/Utils.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/Utils.kt index 06d63fde6e..658ea551c4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/Utils.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/Utils.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.pure.core +package com.ivy.wallet.domain.pure import arrow.core.NonEmptyList import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt similarity index 74% rename from app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt index e93dafd137..d6f2f7ee83 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/IvyCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt @@ -1,10 +1,8 @@ -package com.ivy.wallet.domain.pure +package com.ivy.wallet.domain.pure.core import arrow.core.NonEmptyList import com.ivy.fp.Pure import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.core.ValueFunction -import com.ivy.wallet.domain.pure.core.calculateValueFunctionsSum import java.math.BigDecimal @Pure diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/TrnFunctions.kt similarity index 100% rename from app/src/main/java/com/ivy/wallet/domain/pure/core/TransactionFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/core/TrnFunctions.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/Uncertain.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/Uncertain.kt deleted file mode 100644 index 912eaf276b..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/Uncertain.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ivy.wallet.domain.pure.core - -data class Uncertain, V>( - val error: E, - val value: V -) { - fun isCertain(): Boolean { - return error.isEmpty() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt index 7c464e7d8b..33faaa9ae7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt @@ -2,6 +2,9 @@ package com.ivy.wallet.domain.pure.core import arrow.core.NonEmptyList import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.mapIndexedNel +import com.ivy.wallet.domain.pure.mapIndexedNelSuspend +import com.ivy.wallet.domain.pure.nonEmptyListOfZeros import java.math.BigDecimal typealias ValueFunction = (Transaction, A) -> BigDecimal From 6c600b719c59194ec051d8f132bfe7dd325244b9 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Fri, 22 Apr 2022 20:10:03 +0300 Subject: [PATCH 19/40] WIP: Clean-up `domain.pure` --- .../ivy/wallet/domain/pure/core/IvyCore.kt | 57 +++++++++++++++++-- .../wallet/domain/pure/core/ValueFunction.kt | 51 ----------------- .../domain/pure/data/CurrencyConvError.kt | 3 - .../wallet/domain/pure/{ => util}/Utils.kt | 2 +- 4 files changed, 53 insertions(+), 60 deletions(-) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/data/CurrencyConvError.kt rename app/src/main/java/com/ivy/wallet/domain/pure/{ => util}/Utils.kt (93%) diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt index d6f2f7ee83..4acf1e651f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt @@ -3,6 +3,9 @@ package com.ivy.wallet.domain.pure.core import arrow.core.NonEmptyList import com.ivy.fp.Pure import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.util.mapIndexedNel +import com.ivy.wallet.domain.pure.util.mapIndexedNelSuspend +import com.ivy.wallet.domain.pure.util.nonEmptyListOfZeros import java.math.BigDecimal @Pure @@ -10,10 +13,54 @@ fun calcValues( transactions: List, valueFunctions: NonEmptyList>, arg: Arg +): NonEmptyList = calculateValueFunctionsSum( + valueFunctionArgument = arg, + transactions = transactions, + valueFunctions = valueFunctions +) + + +typealias ValueFunction = (Transaction, A) -> BigDecimal +typealias SuspendValueFunction = suspend (Transaction, A) -> BigDecimal + +@Pure +internal tailrec fun calculateValueFunctionsSum( + valueFunctionArgument: A, + transactions: List, + valueFunctions: NonEmptyList>, + sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) +): NonEmptyList { + return if (transactions.isEmpty()) + sum + else + calculateValueFunctionsSum( + valueFunctionArgument = valueFunctionArgument, + transactions = transactions.drop(1), + valueFunctions = valueFunctions, + sum = sum.mapIndexedNel { index, sumValue -> + val valueFunction = valueFunctions[index] + sumValue + valueFunction(transactions.first(), valueFunctionArgument) + } + ) +} + +@Pure +internal tailrec suspend fun calculateValueFunctionsSumSuspend( + valueFunctionArgument: A, + transactions: List, + valueFunctions: NonEmptyList>, + sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) ): NonEmptyList { - return calculateValueFunctionsSum( - valueFunctionArgument = arg, - transactions = transactions, - valueFunctions = valueFunctions - ) + return if (transactions.isEmpty()) + sum + else + calculateValueFunctionsSumSuspend( + valueFunctionArgument = valueFunctionArgument, + transactions = transactions.drop(1), + valueFunctions = valueFunctions, + sum = sum.mapIndexedNelSuspend { index, sumValue -> + val valueFunction = valueFunctions[index] + sumValue + valueFunction(transactions.first(), valueFunctionArgument) + } + ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt b/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt deleted file mode 100644 index 33faaa9ae7..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/ValueFunction.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.ivy.wallet.domain.pure.core - -import arrow.core.NonEmptyList -import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.mapIndexedNel -import com.ivy.wallet.domain.pure.mapIndexedNelSuspend -import com.ivy.wallet.domain.pure.nonEmptyListOfZeros -import java.math.BigDecimal - -typealias ValueFunction = (Transaction, A) -> BigDecimal -typealias SuspendValueFunction = suspend (Transaction, A) -> BigDecimal - -internal tailrec fun calculateValueFunctionsSum( - valueFunctionArgument: A, - transactions: List, - valueFunctions: NonEmptyList>, - sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) -): NonEmptyList { - return if (transactions.isEmpty()) - sum - else - calculateValueFunctionsSum( - valueFunctionArgument = valueFunctionArgument, - transactions = transactions.drop(1), - valueFunctions = valueFunctions, - sum = sum.mapIndexedNel { index, sumValue -> - val valueFunction = valueFunctions[index] - sumValue + valueFunction(transactions.first(), valueFunctionArgument) - } - ) -} - -internal tailrec suspend fun calculateValueFunctionsSumSuspend( - valueFunctionArgument: A, - transactions: List, - valueFunctions: NonEmptyList>, - sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) -): NonEmptyList { - return if (transactions.isEmpty()) - sum - else - calculateValueFunctionsSumSuspend( - valueFunctionArgument = valueFunctionArgument, - transactions = transactions.drop(1), - valueFunctions = valueFunctions, - sum = sum.mapIndexedNelSuspend { index, sumValue -> - val valueFunction = valueFunctions[index] - sumValue + valueFunction(transactions.first(), valueFunctionArgument) - } - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/data/CurrencyConvError.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/CurrencyConvError.kt deleted file mode 100644 index 040077ba4c..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/data/CurrencyConvError.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.ivy.wallet.domain.pure.data - -data class CurrencyConvError(val account: FPAccount) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/Utils.kt b/app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/pure/Utils.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt index 658ea551c4..3c4162ed04 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/Utils.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.pure +package com.ivy.wallet.domain.pure.util import arrow.core.NonEmptyList import java.math.BigDecimal From 490eef0e46f73e8698ccb55772e48bf071a83f1a Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 19:20:55 +0300 Subject: [PATCH 20/40] WIP: Re-work domain logic --- .../domain/action/account/AccTrnsAct.kt | 3 +- .../action/account/CalcAccBalanceAct.kt | 6 +- .../action/settings/CalcBufferDiffAct.kt | 17 ++++ .../domain/action/settings/SettingsAct.kt | 15 ++++ .../transaction/HistoryWithDateDivsAct.kt | 27 ++++++ ...eDividersAct.kt => TrnsWithDateDivsAct.kt} | 4 +- .../viewmodel/home/CalcBalanceIncsExpsAct.kt | 83 +++++++++++++++++ .../viewmodel/home/CalcHomeDueStatsAct.kt | 4 + .../ivy/wallet/domain/data/core/Settings.kt | 5 +- .../com/ivy/wallet/domain/pure/Exchange.kt | 2 +- .../domain/pure/account/AccountFunctions.kt | 6 ++ .../ivy/wallet/domain/pure/data/FPAccount.kt | 29 ------ .../{ => transaction}/AccValueFunctions.kt | 3 +- .../{ => transaction}/CatValueFunctions.kt | 3 +- .../FoldTransactions.kt} | 49 +++++++--- .../pure/transaction/TrnDateDividers.kt | 7 +- .../{core => transaction}/TrnFunctions.kt | 13 +-- .../com/ivy/wallet/domain/pure/util/Utils.kt | 5 ++ .../io/persistence/data/SettingsEntity.kt | 4 +- .../java/com/ivy/wallet/ui/home/HomeState.kt | 13 ++- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 90 ++++++++++--------- .../viewmodel/OnboardingViewModel.kt | 2 +- .../java/com/ivy/fp/action/CompositionMap.kt | 20 +++++ 23 files changed, 289 insertions(+), 121 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt rename app/src/main/java/com/ivy/wallet/domain/action/transaction/{TrnsWithDateDividersAct.kt => TrnsWithDateDivsAct.kt} (88%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncsExpsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt rename app/src/main/java/com/ivy/wallet/domain/pure/{ => transaction}/AccValueFunctions.kt (95%) rename app/src/main/java/com/ivy/wallet/domain/pure/{ => transaction}/CatValueFunctions.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/pure/{core/IvyCore.kt => transaction/FoldTransactions.kt} (66%) rename app/src/main/java/com/ivy/wallet/domain/pure/{core => transaction}/TrnFunctions.kt (65%) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt index a7a60939d0..97c86a0972 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -31,4 +31,5 @@ class AccTrnsAct @Inject constructor( val accountId: UUID, val range: ClosedTimeRange ) -} \ No newline at end of file +} + diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt index 3b8217f505..04dc6c1112 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -4,9 +4,9 @@ import arrow.core.nonEmptyListOf import com.ivy.fp.action.FPAction import com.ivy.fp.action.then import com.ivy.wallet.domain.data.core.Account -import com.ivy.wallet.domain.pure.AccountValueFunctions -import com.ivy.wallet.domain.pure.core.calcValues import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions +import com.ivy.wallet.domain.pure.transaction.foldTransactions import java.math.BigDecimal import javax.inject.Inject @@ -20,7 +20,7 @@ class CalcAccBalanceAct @Inject constructor( range = range ) } then accTrnsAct then { accTrns -> - calcValues( + foldTransactions( transactions = accTrns, arg = account.id, valueFunctions = nonEmptyListOf(AccountValueFunctions::balance) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.kt new file mode 100644 index 0000000000..845362449d --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.kt @@ -0,0 +1,17 @@ +package com.ivy.wallet.domain.action.settings + +import com.ivy.fp.action.FPAction +import java.math.BigDecimal +import javax.inject.Inject + +class CalcBufferDiffAct @Inject constructor() : FPAction() { + + override suspend fun Input.compose(): suspend () -> BigDecimal = { + balance - buffer + } + + data class Input( + val balance: BigDecimal, + val buffer: BigDecimal + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.kt new file mode 100644 index 0000000000..e354ffb166 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.settings + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Settings +import com.ivy.wallet.io.persistence.dao.SettingsDao +import javax.inject.Inject + +class SettingsAct @Inject constructor( + private val settingsDao: SettingsDao +) : FPAction() { + override suspend fun Unit.compose(): suspend () -> Settings = suspend { + io { settingsDao.findFirst() } + } then { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt new file mode 100644 index 0000000000..12ef6bc5ff --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt @@ -0,0 +1,27 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.TransactionHistoryItem +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import javax.inject.Inject + +class HistoryWithDateDivsAct @Inject constructor( + private val historyTrnsAct: HistoryTrnsAct, + private val trnsWithDateDivsAct: TrnsWithDateDivsAct +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + HistoryTrnsAct.Input(range) + } then historyTrnsAct then { trns -> + TrnsWithDateDivsAct.Input( + baseCurrency = baseCurrency, + transactions = trns + ) + } then trnsWithDateDivsAct + + data class Input( + val range: ClosedTimeRange, + val baseCurrency: String + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDividersAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt similarity index 88% rename from app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDividersAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt index 845d3aa94b..4b9abea22d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDividersAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt @@ -10,10 +10,10 @@ import com.ivy.wallet.domain.pure.transaction.transactionsWithDateDividers import com.ivy.wallet.io.persistence.dao.AccountDao import javax.inject.Inject -class TrnsWithDateDividersAct @Inject constructor( +class TrnsWithDateDivsAct @Inject constructor( private val accountDao: AccountDao, private val exchangeAct: ExchangeAct -) : FPAction>() { +) : FPAction>() { override suspend fun Input.compose(): suspend () -> List = suspend { transactionsWithDateDividers( diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncsExpsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncsExpsAct.kt new file mode 100644 index 0000000000..37d4af0fda --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncsExpsAct.kt @@ -0,0 +1,83 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import arrow.core.nonEmptyListOf +import arrow.core.toOption +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.action.ExchangeAct +import com.ivy.wallet.domain.action.account.AccTrnsAct +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.pure.ExchangeData +import com.ivy.wallet.domain.pure.account.filterExcluded +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions +import com.ivy.wallet.domain.pure.transaction.foldTransactions +import com.ivy.wallet.domain.pure.util.orZero +import java.math.BigDecimal +import javax.inject.Inject + +class CalcBalanceIncsExpsAct @Inject constructor( + private val accTrnsAct: AccTrnsAct, + private val exchangeAct: ExchangeAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + filterExcluded(accounts) + } thenMap { acc -> + Pair( + acc, + accTrnsAct( + AccTrnsAct.Input( + accountId = acc.id, + range = range + ) + ) + ) + } thenMap { (acc, trns) -> + Pair( + acc, + foldTransactions( + transactions = trns, + valueFunctions = nonEmptyListOf( + AccountValueFunctions::balance, + AccountValueFunctions::income, + AccountValueFunctions::expense + ), + arg = acc.id + ) + ) + } thenMap { (acc, stats) -> + stats.map { + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = acc.currency.toOption() + ), + amount = it + ), + ).orZero() + } + } then { statsList -> + Output( + balance = statsList[0].sumOf { it }, + incomeExpense = IncomeExpensePair( + income = statsList[1].sumOf { it }, + expense = statsList[2].sumOf { it } + ) + ) + } + + data class Input( + val baseCurrency: String, + val accounts: List, + val range: ClosedTimeRange, + ) + + data class Output( + val balance: BigDecimal, + val incomeExpense: IncomeExpensePair, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt new file mode 100644 index 0000000000..4486669ceb --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt @@ -0,0 +1,4 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +class CalcHomeDueStatsAct { +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt index c7b7faf7bc..c4ece000c0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt @@ -1,12 +1,13 @@ package com.ivy.wallet.domain.data.core import com.ivy.design.l0_system.Theme +import java.math.BigDecimal import java.util.* data class Settings( val theme: Theme, - val currency: String, - val bufferAmount: Double, + val baseCurrency: String, + val bufferAmount: BigDecimal, val name: String, val id: UUID = UUID.randomUUID() diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt b/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt index dd6755b038..549f61f698 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt @@ -14,7 +14,7 @@ import java.math.BigDecimal data class ExchangeData( val baseCurrency: String, val fromCurrency: Option, - val toCurrency: String, + val toCurrency: String = baseCurrency, ) diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt new file mode 100644 index 0000000000..8ce07dff3b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt @@ -0,0 +1,6 @@ +package com.ivy.wallet.domain.pure.account + +import com.ivy.wallet.domain.data.core.Account + +fun filterExcluded(accounts: List): List = + accounts.filter { it.includeInBalance } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt deleted file mode 100644 index 3db8db2312..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.ivy.wallet.domain.pure.data - -import arrow.core.Option -import arrow.core.toOption -import com.ivy.wallet.domain.data.core.Account -import java.util.* - -data class FPAccount( - val id: UUID, - val name: String, - val currencyCode: String, - val color: Int, - val icon: Option, - val orderNum: Double, - val includeInBalance: Boolean, -) - -fun Account.toFPAccount( - baseCurrencyCode: String -): FPAccount = - FPAccount( - id = id, - name = name, - currencyCode = currency ?: baseCurrencyCode, - color = color, - icon = icon.toOption(), - orderNum = orderNum, - includeInBalance = includeInBalance - ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/AccValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/AccValueFunctions.kt similarity index 95% rename from app/src/main/java/com/ivy/wallet/domain/pure/AccValueFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/transaction/AccValueFunctions.kt index 66ff1176e0..0d1e4391be 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/AccValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/AccValueFunctions.kt @@ -1,8 +1,7 @@ -package com.ivy.wallet.domain.pure +package com.ivy.wallet.domain.pure.transaction import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.core.ValueFunction import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/CatValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/pure/CatValueFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt index 077926a1d8..144f306d2b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/CatValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.pure +package com.ivy.wallet.domain.pure.transaction import arrow.core.Option import arrow.core.toOption @@ -6,7 +6,6 @@ import com.ivy.fp.SideEffect import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.core.SuspendValueFunction import java.math.BigDecimal import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt similarity index 66% rename from app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt index 4acf1e651f..b2a1490f1c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/IvyCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt @@ -1,6 +1,7 @@ -package com.ivy.wallet.domain.pure.core +package com.ivy.wallet.domain.pure.transaction import arrow.core.NonEmptyList +import arrow.core.nonEmptyListOf import com.ivy.fp.Pure import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.util.mapIndexedNel @@ -8,32 +9,31 @@ import com.ivy.wallet.domain.pure.util.mapIndexedNelSuspend import com.ivy.wallet.domain.pure.util.nonEmptyListOfZeros import java.math.BigDecimal +typealias ValueFunction = (Transaction, A) -> BigDecimal +typealias SuspendValueFunction = suspend (Transaction, A) -> BigDecimal + @Pure -fun calcValues( +fun foldTransactions( transactions: List, valueFunctions: NonEmptyList>, arg: Arg -): NonEmptyList = calculateValueFunctionsSum( +): NonEmptyList = sumTransactionsInternal( valueFunctionArgument = arg, transactions = transactions, valueFunctions = valueFunctions ) - -typealias ValueFunction = (Transaction, A) -> BigDecimal -typealias SuspendValueFunction = suspend (Transaction, A) -> BigDecimal - @Pure -internal tailrec fun calculateValueFunctionsSum( - valueFunctionArgument: A, +internal tailrec fun sumTransactionsInternal( transactions: List, + valueFunctionArgument: A, valueFunctions: NonEmptyList>, sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) ): NonEmptyList { return if (transactions.isEmpty()) sum else - calculateValueFunctionsSum( + sumTransactionsInternal( valueFunctionArgument = valueFunctionArgument, transactions = transactions.drop(1), valueFunctions = valueFunctions, @@ -45,16 +45,27 @@ internal tailrec fun calculateValueFunctionsSum( } @Pure -internal tailrec suspend fun calculateValueFunctionsSumSuspend( - valueFunctionArgument: A, +suspend fun foldTransactionsSuspend( transactions: List, + valueFunctions: NonEmptyList>, + arg: Arg +): NonEmptyList = sumTransactionsSuspendInternal( + transactions = transactions, + valueFunctions = valueFunctions, + valueFunctionArgument = arg +) + +@Pure +internal tailrec suspend fun sumTransactionsSuspendInternal( + transactions: List, + valueFunctionArgument: A, valueFunctions: NonEmptyList>, sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) ): NonEmptyList { return if (transactions.isEmpty()) sum else - calculateValueFunctionsSumSuspend( + sumTransactionsSuspendInternal( valueFunctionArgument = valueFunctionArgument, transactions = transactions.drop(1), valueFunctions = valueFunctions, @@ -63,4 +74,16 @@ internal tailrec suspend fun calculateValueFunctionsSumSuspend( sumValue + valueFunction(transactions.first(), valueFunctionArgument) } ) +} + +suspend fun sumTransactions( + transactions: List, + valueFunction: SuspendValueFunction, + argument: A +): BigDecimal { + return sumTransactionsSuspendInternal( + transactions = transactions, + valueFunctionArgument = argument, + valueFunctions = nonEmptyListOf(valueFunction) + ).head } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt index 53956ae9d7..6451642120 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt @@ -9,9 +9,6 @@ import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.ExchangeData -import com.ivy.wallet.domain.pure.core.expenses -import com.ivy.wallet.domain.pure.core.incomes -import com.ivy.wallet.domain.pure.core.sum import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal @@ -47,12 +44,12 @@ suspend fun transactionsWithDateDividers( listOf( TransactionHistoryDateDivider( date = date!!, - income = sum( + income = sumTransactions( incomes(transactionsForDate), ::exchangeInCurrency, arg ).toDouble(), - expenses = sum( + expenses = sumTransactions( expenses(transactionsForDate), ::exchangeInCurrency, arg diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/core/TrnFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt similarity index 65% rename from app/src/main/java/com/ivy/wallet/domain/pure/core/TrnFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt index 4ef158109e..519ffc8325 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/core/TrnFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt @@ -1,18 +1,7 @@ -package com.ivy.wallet.domain.pure.core +package com.ivy.wallet.domain.pure.transaction import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Transaction -import java.math.BigDecimal - -suspend fun sum( - transactions: List, - valueFunction: SuspendValueFunction, - argument: A -): BigDecimal { - return transactions.sumOf { - valueFunction(it, argument) - } -} fun expenses(transactions: List): List { return transactions.filter { it.type == TransactionType.EXPENSE } diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt b/app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt index 3c4162ed04..71c53d3627 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.pure.util import arrow.core.NonEmptyList +import arrow.core.Option import java.math.BigDecimal fun NonEmptyList.mapIndexedNel( @@ -25,4 +26,8 @@ fun nonEmptyListOfZeros(n: Int): NonEmptyList { return NonEmptyList.fromListUnsafe( List(n) { BigDecimal.ZERO } ) +} + +fun Option.orZero(): BigDecimal { + return this.orNull() ?: BigDecimal.ZERO } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt index 7ab5131552..f153edabde 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt @@ -21,8 +21,8 @@ data class SettingsEntity( ) { fun toDomain(): Settings = Settings( theme = theme, - currency = currency, - bufferAmount = bufferAmount, + baseCurrency = currency, + bufferAmount = bufferAmount.toBigDecimal(), name = name, id = id ) diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt index 3c676c0ad9..2a87bca951 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt @@ -5,7 +5,7 @@ import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod @@ -15,20 +15,25 @@ data class HomeState( val theme: Theme, val name: String, val baseCurrencyCode: String, + val buffer: BigDecimal, + val period: TimePeriod, + val accounts: List, val categories: List, + + val history: List, + val monthly: IncomeExpensePair, val balance: BigDecimal, - val buffer: BigDecimal, val bufferDiff: BigDecimal, - val monthly: IncomeExpensePair, + val upcoming: IncomeExpensePair, val upcomingTrns: List, val upcomingExpanded: Boolean, val overdue: IncomeExpensePair, val overdueTrns: List, val overdueExpanded: Boolean, - val history: List, + val customerJourneyCards: List, val hideCurrentBalance: Boolean ) { diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 1c82aab262..0fe250632a 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -4,18 +4,21 @@ import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation import com.ivy.fp.viewmodel.IvyViewModel -import com.ivy.wallet.domain.action.transaction.TrnsWithDateDividersAct +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.settings.CalcBufferDiffAct +import com.ivy.wallet.domain.action.settings.SettingsAct +import com.ivy.wallet.domain.action.transaction.HistoryWithDateDivsAct +import com.ivy.wallet.domain.action.viewmodel.home.CalcBalanceIncsExpsAct import com.ivy.wallet.domain.action.wallet.CalcOverdueAct import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.CustomerJourneyLogic -import com.ivy.wallet.domain.logic.PlannedPaymentsLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.pure.wallet.calculateWalletIncomeExpense -import com.ivy.wallet.domain.pure.wallet.walletBufferDiff import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao @@ -49,7 +52,12 @@ class HomeViewModel @Inject constructor( private val calcAccountBalanceAct: CalcWalletBalanceAct, private val calcUpcomingAct: CalcUpcomingAct, private val calcOverdueAct: CalcOverdueAct, - private val historyWithDateDivAct: TrnsWithDateDividersAct, + private val historyWithDateDivsAct: HistoryWithDateDivsAct, + private val calcBalanceIncsExpsAct: CalcBalanceIncsExpsAct, + private val settingsAct: SettingsAct, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val calcBufferDiffAct: CalcBufferDiffAct, ) : IvyViewModel() { override val mutableState: MutableStateFlow = MutableStateFlow( HomeState.initial(ivyWalletCtx = ivyContext) @@ -74,15 +82,18 @@ class HomeViewModel @Inject constructor( viewModelScope.launch { TestIdlingResource.increment() - val settings = ioThread { settingsDao.findFirst() } + val settings = settingsAct(Unit) - val hideCurrentBalance = sharedPrefs.getBoolean(SharedPrefs.HIDE_CURRENT_BALANCE, false) + val hideCurrentBalance = sharedPrefs.getBoolean( + SharedPrefs.HIDE_CURRENT_BALANCE, + false + ) updateState { it.copy( theme = settings.theme, name = settings.name, - baseCurrencyCode = settings.currency, + baseCurrencyCode = settings.baseCurrency, period = period, hideCurrentBalance = hideCurrentBalance ) @@ -91,47 +102,41 @@ class HomeViewModel @Inject constructor( //This method is used to restore the theme when user imports locally backed up data loadNewTheme(settings.theme) + val accounts = accountsAct(Unit) + updateState { it.copy( - categories = ioThread { categoryDao.findAll() }, - accounts = ioThread { walletDAOs.accountDao.findAll() } + categories = categoriesAct(Unit), + accounts = accounts ) } val timeRange = period.toRange(ivyContext.startDayOfMonth) + .toCloseTimeRange() - updateState { - it.copy( - balance = calcAccountBalanceAct( - CalcWalletBalanceAct.Input( - baseCurrency = settings.currency, - balanceCurrency = settings.currency - ) - ) + val monthlyStats = calcBalanceIncsExpsAct( + CalcBalanceIncsExpsAct.Input( + baseCurrency = settings.baseCurrency, + accounts = accounts, + range = timeRange ) - } + ) updateState { it.copy( - buffer = settings.bufferAmount.toBigDecimal(), - bufferDiff = ioThread { - walletBufferDiff( - settings = settings, - balance = stateVal().balance - ) - } + balance = monthlyStats.balance, + monthly = monthlyStats.incomeExpense ) } updateState { it.copy( - monthly = ioThread { - calculateWalletIncomeExpense( - walletDAOs = walletDAOs, - baseCurrencyCode = stateVal().baseCurrencyCode, - range = timeRange.toCloseTimeRange() - ).value - } + history = historyWithDateDivsAct( + HistoryWithDateDivsAct.Input( + range = timeRange, + baseCurrency = settings.baseCurrency + ) + ) ) } @@ -153,18 +158,19 @@ class HomeViewModel @Inject constructor( updateState { it.copy( - history = historyWithDateDivAct( - TrnsWithDateDividersAct.Input( - timeRange = timeRange.toCloseTimeRange(), - baseCurrencyCode = stateVal().baseCurrencyCode - ) - ) + customerJourneyCards = ioThread { customerJourneyLogic.loadCards() } ) } updateState { it.copy( - customerJourneyCards = ioThread { customerJourneyLogic.loadCards() } + buffer = settings.bufferAmount, + bufferDiff = calcBufferDiffAct( + CalcBufferDiffAct.Input( + balance = monthlyStats.balance, + buffer = settings.bufferAmount + ) + ) ) } 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 65ee515dc8..d7cfe4e211 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 @@ -132,7 +132,7 @@ class OnboardingViewModel @Inject constructor( Settings( theme = if (isSystemDarkMode) Theme.DARK else Theme.LIGHT, name = "", - currency = defaultCurrency.code, + baseCurrency = defaultCurrency.code, bufferAmount = 1000.0 ) ) diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt index 5c11a6aa1b..ab160bf533 100644 --- a/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt @@ -20,6 +20,26 @@ suspend infix fun (suspend () -> List).thenMap( } } +suspend infix fun (suspend () -> List).thenFlatMap( + transform: suspend (B) -> List +): suspend () -> List = + { + val list = this() + list.flatMap { + transform(it) + } + } + +suspend infix fun (suspend () -> List).thenMap( + act: Action +): suspend () -> List = + { + val list = this() + list.map { + act(it) + } + } + suspend infix fun (Action>).thenMap( transform: suspend (B) -> C ): suspend (A) -> List = From 985a49f4a09895439028be92fd6983e35be84eb2 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 20:17:49 +0300 Subject: [PATCH 21/40] Re-work HomeViewModel.kt --- .../domain/action/account/AccountByIdAct.kt | 18 +++++ .../action/{ => exchange}/ExchangeAct.kt | 6 +- .../domain/action/transaction/DueTrnsAct.kt | 22 ++++++ .../action/transaction/HistoryTrnsAct.kt | 12 +-- .../transaction/HistoryWithDateDivsAct.kt | 2 +- .../action/transaction/TrnsWithDateDivsAct.kt | 4 +- ...sAct.kt => CalcBalanceIncomeExpenseAct.kt} | 6 +- .../viewmodel/home/CalcHomeDueStatsAct.kt | 4 - .../action/viewmodel/home/DueTrnsInfoAct.kt | 73 +++++++++++++++++++ .../action/viewmodel/home/HasTrnsAct.kt | 15 ++++ .../action/viewmodel/home/OverdueAct.kt | 37 ++++++++++ .../action/viewmodel/home/UpcomingAct.kt | 37 ++++++++++ .../domain/action/wallet/CalcOverdueAct.kt | 29 -------- .../domain/action/wallet/CalcUpcomingAct.kt | 29 -------- .../action/wallet/CalcWalletBalanceAct.kt | 4 +- .../domain/pure/{ => exchange}/Exchange.kt | 2 +- .../domain/pure/exchange/ExchangeTrns.kt | 34 +++++++++ .../pure/transaction/CatValueFunctions.kt | 5 +- .../pure/transaction/FoldTransactions.kt | 2 +- .../pure/transaction/TrnDateDividers.kt | 35 ++------- .../domain/pure/transaction/TrnFunctions.kt | 15 +++- .../java/com/ivy/wallet/ui/home/HomeTab.kt | 7 +- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 53 ++++++++------ .../src/main/java/com/ivy/fp/Composition.kt | 2 +- .../java/com/ivy/fp/action/Composition.kt | 6 +- .../com/ivy/fp/action/CompositionFilter.kt | 11 +++ 26 files changed, 327 insertions(+), 143 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.kt rename app/src/main/java/com/ivy/wallet/domain/action/{ => exchange}/ExchangeAct.kt (85%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.kt rename app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/{CalcBalanceIncsExpsAct.kt => CalcBalanceIncomeExpenseAct.kt} (92%) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt rename app/src/main/java/com/ivy/wallet/domain/pure/{ => exchange}/Exchange.kt (98%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.kt new file mode 100644 index 0000000000..da343e503a --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.kt @@ -0,0 +1,18 @@ +package com.ivy.wallet.domain.action.account + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.io.persistence.dao.AccountDao +import java.util.* +import javax.inject.Inject + +class AccountByIdAct @Inject constructor( + private val accountDao: AccountDao +) : FPAction() { + override suspend fun UUID.compose(): suspend () -> Account? = suspend { + this //accountId + } then accountDao::findById then { + it?.toDomain() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/exchange/ExchangeAct.kt similarity index 85% rename from app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/exchange/ExchangeAct.kt index d561ca3bb5..7906d11a7b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/ExchangeAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/exchange/ExchangeAct.kt @@ -1,10 +1,10 @@ -package com.ivy.wallet.domain.action +package com.ivy.wallet.domain.action.exchange import arrow.core.Option import com.ivy.fp.action.FPAction import com.ivy.fp.then -import com.ivy.wallet.domain.pure.ExchangeData -import com.ivy.wallet.domain.pure.exchange +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.exchange.exchange import com.ivy.wallet.io.persistence.dao.ExchangeRateDao import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.kt new file mode 100644 index 0000000000..f61f349354 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.kt @@ -0,0 +1,22 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.io.persistence.dao.TransactionDao +import javax.inject.Inject + +class DueTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + + override suspend fun ClosedTimeRange.compose(): suspend () -> List = suspend { + io { + transactionDao.findAllDueToBetween( + startDate = from, + endDate = to + ) + } + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt index e168f89038..66442f80f3 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt @@ -9,18 +9,14 @@ import javax.inject.Inject class HistoryTrnsAct @Inject constructor( private val transactionDao: TransactionDao -) : FPAction>() { +) : FPAction>() { - override suspend fun Input.compose(): suspend () -> List = suspend { + override suspend fun ClosedTimeRange.compose(): suspend () -> List = suspend { io { transactionDao.findAllBetween( - startDate = range.from, - endDate = range.to + startDate = from, + endDate = to ) } } thenMap { it.toDomain() } - - data class Input( - val range: ClosedTimeRange - ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt index 12ef6bc5ff..2449faf0fc 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt @@ -12,7 +12,7 @@ class HistoryWithDateDivsAct @Inject constructor( ) : FPAction>() { override suspend fun Input.compose(): suspend () -> List = suspend { - HistoryTrnsAct.Input(range) + range } then historyTrnsAct then { trns -> TrnsWithDateDivsAct.Input( baseCurrency = baseCurrency, diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt index 4b9abea22d..08d09ad07c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt @@ -2,8 +2,8 @@ package com.ivy.wallet.domain.action.transaction import com.ivy.fp.action.FPAction import com.ivy.fp.then -import com.ivy.wallet.domain.action.ExchangeAct -import com.ivy.wallet.domain.action.actInput +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.exchange.actInput import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.transaction.transactionsWithDateDividers diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncsExpsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt similarity index 92% rename from app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncsExpsAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt index 37d4af0fda..22a530d4f5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncsExpsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt @@ -3,7 +3,6 @@ package com.ivy.wallet.domain.action.viewmodel.home import arrow.core.nonEmptyListOf import arrow.core.toOption import com.ivy.fp.action.FPAction -import com.ivy.fp.action.then import com.ivy.fp.action.thenMap import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.account.AccTrnsAct @@ -14,14 +13,13 @@ import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions import com.ivy.wallet.domain.pure.transaction.foldTransactions -import com.ivy.wallet.domain.pure.util.orZero import java.math.BigDecimal import javax.inject.Inject -class CalcBalanceIncsExpsAct @Inject constructor( +class CalcBalanceIncomeExpenseAct @Inject constructor( private val accTrnsAct: AccTrnsAct, private val exchangeAct: ExchangeAct -) : FPAction() { +) : FPAction() { override suspend fun Input.compose(): suspend () -> Output = suspend { filterExcluded(accounts) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt deleted file mode 100644 index 4486669ceb..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.ivy.wallet.domain.action.viewmodel.home - -class CalcHomeDueStatsAct { -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt new file mode 100644 index 0000000000..35bbde9c46 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt @@ -0,0 +1,73 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.lambda +import com.ivy.fp.action.then +import com.ivy.fp.then +import com.ivy.wallet.domain.action.account.AccountByIdAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.exchange.actInput +import com.ivy.wallet.domain.action.transaction.DueTrnsAct +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.exchange.ExchangeTrnArgument +import com.ivy.wallet.domain.pure.exchange.exchangeInCurrency +import com.ivy.wallet.domain.pure.transaction.expenses +import com.ivy.wallet.domain.pure.transaction.incomes +import com.ivy.wallet.domain.pure.transaction.sumTrns +import com.ivy.wallet.utils.timeNowUTC +import java.time.LocalDateTime +import javax.inject.Inject + +class DueTrnsInfoAct @Inject constructor( + private val dueTrnsAct: DueTrnsAct, + private val accountByIdAct: AccountByIdAct, + private val exchangeAct: ExchangeAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + range + } then dueTrnsAct then { trns -> + val timeNow = timeNowUTC() + trns.filter { + this.dueFilter(it, timeNow) + } + } then { upcomingTrns -> + //We have due transactions in different currencies + val exchangeArg = ExchangeTrnArgument( + baseCurrency = baseCurrency, + exchange = ::actInput then exchangeAct, + getAccount = accountByIdAct.lambda() + ) + + io { + Output( + dueIncomeExpense = IncomeExpensePair( + income = sumTrns( + incomes(upcomingTrns), + ::exchangeInCurrency, + exchangeArg + ), + expense = sumTrns( + expenses(upcomingTrns), + ::exchangeInCurrency, + exchangeArg + ) + ), + dueTrns = upcomingTrns + ) + } + } + + data class Input( + val range: ClosedTimeRange, + val baseCurrency: String, + val dueFilter: (Transaction, LocalDateTime) -> Boolean + ) + + data class Output( + val dueIncomeExpense: IncomeExpensePair, + val dueTrns: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.kt new file mode 100644 index 0000000000..9f11f4911c --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.io.persistence.dao.TransactionDao +import javax.inject.Inject + +class HasTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction() { + override suspend fun Unit.compose(): suspend () -> Boolean = suspend { + io { + transactionDao.findAll_LIMIT_1().isNotEmpty() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.kt new file mode 100644 index 0000000000..b1f5075d57 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.kt @@ -0,0 +1,37 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.isOverdue +import javax.inject.Inject + +class OverdueAct @Inject constructor( + private val dueTrnsInfoAct: DueTrnsInfoAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + DueTrnsInfoAct.Input( + range = range, + baseCurrency = baseCurrency, + dueFilter = ::isOverdue + ) + } then dueTrnsInfoAct then { + Output( + overdue = it.dueIncomeExpense, + overdueTrns = it.dueTrns + ) + } + + data class Input( + val range: ClosedTimeRange, + val baseCurrency: String + ) + + data class Output( + val overdue: IncomeExpensePair, + val overdueTrns: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.kt new file mode 100644 index 0000000000..35536be366 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.kt @@ -0,0 +1,37 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.isUpcoming +import javax.inject.Inject + +class UpcomingAct @Inject constructor( + private val dueTrnsInfoAct: DueTrnsInfoAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + DueTrnsInfoAct.Input( + range = range, + baseCurrency = baseCurrency, + dueFilter = ::isUpcoming + ) + } then dueTrnsInfoAct then { + Output( + upcoming = it.dueIncomeExpense, + upcomingTrns = it.dueTrns + ) + } + + data class Input( + val range: ClosedTimeRange, + val baseCurrency: String + ) + + data class Output( + val upcoming: IncomeExpensePair, + val upcomingTrns: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt deleted file mode 100644 index 3e219fd491..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.ivy.wallet.domain.action.wallet - -import com.ivy.fp.action.Action -import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.WalletLogic -import com.ivy.wallet.domain.pure.data.IncomeExpensePair -import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import javax.inject.Inject - -class CalcOverdueAct @Inject constructor( - private val walletLogic: WalletLogic -) : Action() { - - override suspend fun FromToTimeRange.willDo(): Output = io { - //TODO: Rework & optimize this - Output( - overdue = IncomeExpensePair( - income = walletLogic.calculateOverdueIncome(this).toBigDecimal(), - expense = walletLogic.calculateOverdueExpenses(this).toBigDecimal() - ), - overdueTrns = walletLogic.overdueTransactions(this) - ) - } - - data class Output( - val overdue: IncomeExpensePair, - val overdueTrns: List - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt deleted file mode 100644 index 562b23762a..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.ivy.wallet.domain.action.wallet - -import com.ivy.fp.action.Action -import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.WalletLogic -import com.ivy.wallet.domain.pure.data.IncomeExpensePair -import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import javax.inject.Inject - -class CalcUpcomingAct @Inject constructor( - private val walletLogic: WalletLogic -) : Action() { - - override suspend fun FromToTimeRange.willDo(): Output = io { - //TODO: Rework & optimize this - Output( - upcoming = IncomeExpensePair( - income = walletLogic.calculateUpcomingIncome(this).toBigDecimal(), - expense = walletLogic.calculateUpcomingExpenses(this).toBigDecimal() - ), - upcomingTrns = walletLogic.upcomingTransactions(this) - ) - } - - data class Output( - val upcoming: IncomeExpensePair, - val upcomingTrns: List - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index 8f95557abc..5ed7282518 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -2,11 +2,11 @@ package com.ivy.wallet.domain.action.wallet import arrow.core.toOption import com.ivy.fp.action.* -import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.account.CalcAccBalanceAct -import com.ivy.wallet.domain.pure.ExchangeData +import com.ivy.wallet.domain.action.exchange.ExchangeAct import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.exchange.ExchangeData import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/Exchange.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/exchange/Exchange.kt index 549f61f698..f2927168af 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/Exchange.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/Exchange.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.pure +package com.ivy.wallet.domain.pure.exchange import arrow.core.None import arrow.core.Option diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt new file mode 100644 index 0000000000..35a21b48c9 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt @@ -0,0 +1,34 @@ +package com.ivy.wallet.domain.pure.exchange + +import arrow.core.Option +import arrow.core.toOption +import com.ivy.fp.SideEffect +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import java.math.BigDecimal +import java.util.* + + +data class ExchangeTrnArgument( + val baseCurrency: String, + @SideEffect + val getAccount: suspend (accountId: UUID) -> Account?, + @SideEffect + val exchange: suspend (ExchangeData, BigDecimal) -> Option +) + +suspend fun exchangeInCurrency( + transaction: Transaction, + arg: ExchangeTrnArgument +): BigDecimal { + val fromCurrencyCode = arg.getAccount(transaction.accountId)?.currency.toOption() + + return arg.exchange( + ExchangeData( + baseCurrency = arg.baseCurrency, + fromCurrency = fromCurrencyCode, + toCurrency = arg.baseCurrency + ), + transaction.amount + ).orNull() ?: BigDecimal.ZERO +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt index 144f306d2b..217d4d2fd9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt @@ -17,7 +17,10 @@ object CategoryValueFunctions { val accounts: List, @SideEffect - val exchangeToBaseCurrency: suspend (Option, BigDecimal) -> Option + val exchangeToBaseCurrency: suspend ( + fromCurrency: Option, + amount: BigDecimal + ) -> Option ) suspend fun balance( diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt index b2a1490f1c..54dc741231 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt @@ -76,7 +76,7 @@ internal tailrec suspend fun sumTransactionsSuspendInternal( ) } -suspend fun sumTransactions( +suspend fun sumTrns( transactions: List, valueFunction: SuspendValueFunction, argument: A diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt index 6451642120..c774c85b21 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt @@ -1,14 +1,15 @@ package com.ivy.wallet.domain.pure.transaction import arrow.core.Option -import arrow.core.toOption import com.ivy.fp.Pure import com.ivy.fp.SideEffect import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.pure.ExchangeData +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.exchange.ExchangeTrnArgument +import com.ivy.wallet.domain.pure.exchange.exchangeInCurrency import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal @@ -34,7 +35,7 @@ suspend fun transactionsWithDateDividers( (date2.atStartOfDay().toEpochSeconds() - date1.atStartOfDay().toEpochSeconds()).toInt() } .flatMap { (date, transactionsForDate) -> - val arg = AmountInCurrencyArgument( + val arg = ExchangeTrnArgument( baseCurrency = baseCurrencyCode, getAccount = getAccount, exchange = exchange @@ -44,12 +45,12 @@ suspend fun transactionsWithDateDividers( listOf( TransactionHistoryDateDivider( date = date!!, - income = sumTransactions( + income = sumTrns( incomes(transactionsForDate), ::exchangeInCurrency, arg ).toDouble(), - expenses = sumTransactions( + expenses = sumTrns( expenses(transactionsForDate), ::exchangeInCurrency, arg @@ -57,28 +58,4 @@ suspend fun transactionsWithDateDividers( ), ).plus(transactionsForDate) } -} - -data class AmountInCurrencyArgument( - val baseCurrency: String, - @SideEffect - val getAccount: suspend (accountId: UUID) -> Account?, - @SideEffect - val exchange: suspend (ExchangeData, BigDecimal) -> Option -) - -suspend fun exchangeInCurrency( - fpTransaction: Transaction, - arg: AmountInCurrencyArgument -): BigDecimal { - val fromCurrencyCode = arg.getAccount(fpTransaction.accountId)?.currency.toOption() - - return arg.exchange( - ExchangeData( - baseCurrency = arg.baseCurrency, - fromCurrency = fromCurrencyCode, - toCurrency = arg.baseCurrency - ), - fpTransaction.amount - ).orNull() ?: BigDecimal.ZERO } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt index 519ffc8325..452df3bd8a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt @@ -1,16 +1,29 @@ package com.ivy.wallet.domain.pure.transaction +import com.ivy.fp.Pure import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Transaction +import java.time.LocalDateTime +@Pure fun expenses(transactions: List): List { return transactions.filter { it.type == TransactionType.EXPENSE } } +@Pure fun incomes(transactions: List): List { return transactions.filter { it.type == TransactionType.INCOME } } +@Pure fun transfers(transactions: List): List { return transactions.filter { it.type == TransactionType.TRANSFER } -} \ No newline at end of file +} + +@Pure +fun isUpcoming(transaction: Transaction, timeNowUTC: LocalDateTime): Boolean = + timeNowUTC.isBefore(transaction.dueDate) + +@Pure +fun isOverdue(transaction: Transaction, timeNowUTC: LocalDateTime): Boolean = + timeNowUTC.isAfter(transaction.dueDate) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt index bbe1a07db1..c2518c2968 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt @@ -27,7 +27,7 @@ import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.stringRes import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Main @@ -445,7 +445,10 @@ fun HomeLazyColumn( history = history, onPayOrGet = onPayOrGet, emptyStateTitle = stringRes(R.string.no_transactions), - emptyStateText = stringRes(R.string.no_transactions_description, period.toDisplayLong(ivyContext.startDayOfMonth)) + emptyStateText = stringRes( + R.string.no_transactions_description, + period.toDisplayLong(ivyContext.startDayOfMonth) + ) ) } } diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 0fe250632a..b57b074fc5 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -9,18 +9,16 @@ import com.ivy.wallet.domain.action.category.CategoriesAct import com.ivy.wallet.domain.action.settings.CalcBufferDiffAct import com.ivy.wallet.domain.action.settings.SettingsAct import com.ivy.wallet.domain.action.transaction.HistoryWithDateDivsAct -import com.ivy.wallet.domain.action.viewmodel.home.CalcBalanceIncsExpsAct -import com.ivy.wallet.domain.action.wallet.CalcOverdueAct -import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct -import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct +import com.ivy.wallet.domain.action.viewmodel.home.CalcBalanceIncomeExpenseAct +import com.ivy.wallet.domain.action.viewmodel.home.HasTrnsAct +import com.ivy.wallet.domain.action.viewmodel.home.OverdueAct +import com.ivy.wallet.domain.action.viewmodel.home.UpcomingAct import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData -import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.io.persistence.SharedPrefs -import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.BalanceScreen import com.ivy.wallet.ui.IvyWalletCtx @@ -40,24 +38,22 @@ import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( - private val walletDAOs: WalletDAOs, - private val settingsDao: SettingsDao, - private val categoryDao: CategoryDao, private val ivyContext: IvyWalletCtx, private val nav: Navigation, + private val settingsDao: SettingsDao, private val exchangeRatesLogic: ExchangeRatesLogic, private val plannedPaymentsLogic: PlannedPaymentsLogic, private val customerJourneyLogic: CustomerJourneyLogic, private val sharedPrefs: SharedPrefs, - private val calcAccountBalanceAct: CalcWalletBalanceAct, - private val calcUpcomingAct: CalcUpcomingAct, - private val calcOverdueAct: CalcOverdueAct, private val historyWithDateDivsAct: HistoryWithDateDivsAct, - private val calcBalanceIncsExpsAct: CalcBalanceIncsExpsAct, + private val calcBalanceIncomeExpenseAct: CalcBalanceIncomeExpenseAct, private val settingsAct: SettingsAct, private val accountsAct: AccountsAct, private val categoriesAct: CategoriesAct, private val calcBufferDiffAct: CalcBufferDiffAct, + private val upcomingAct: UpcomingAct, + private val overdueAct: OverdueAct, + private val hasTrnsAct: HasTrnsAct ) : IvyViewModel() { override val mutableState: MutableStateFlow = MutableStateFlow( HomeState.initial(ivyWalletCtx = ivyContext) @@ -83,6 +79,7 @@ class HomeViewModel @Inject constructor( TestIdlingResource.increment() val settings = settingsAct(Unit) + val baseCurrency = settings.baseCurrency val hideCurrentBalance = sharedPrefs.getBoolean( SharedPrefs.HIDE_CURRENT_BALANCE, @@ -93,7 +90,7 @@ class HomeViewModel @Inject constructor( it.copy( theme = settings.theme, name = settings.name, - baseCurrencyCode = settings.baseCurrency, + baseCurrencyCode = baseCurrency, period = period, hideCurrentBalance = hideCurrentBalance ) @@ -114,9 +111,9 @@ class HomeViewModel @Inject constructor( val timeRange = period.toRange(ivyContext.startDayOfMonth) .toCloseTimeRange() - val monthlyStats = calcBalanceIncsExpsAct( - CalcBalanceIncsExpsAct.Input( - baseCurrency = settings.baseCurrency, + val monthlyStats = calcBalanceIncomeExpenseAct( + CalcBalanceIncomeExpenseAct.Input( + baseCurrency = baseCurrency, accounts = accounts, range = timeRange ) @@ -134,14 +131,19 @@ class HomeViewModel @Inject constructor( history = historyWithDateDivsAct( HistoryWithDateDivsAct.Input( range = timeRange, - baseCurrency = settings.baseCurrency + baseCurrency = baseCurrency ) ) ) } updateState { - val result = calcUpcomingAct(timeRange) + val result = upcomingAct( + UpcomingAct.Input( + range = timeRange, + baseCurrency = baseCurrency + ) + ) it.copy( upcoming = result.upcoming, upcomingTrns = result.upcomingTrns @@ -149,7 +151,12 @@ class HomeViewModel @Inject constructor( } updateState { - val result = calcOverdueAct(timeRange) + val result = overdueAct( + OverdueAct.Input( + range = timeRange, + baseCurrency = baseCurrency + ) + ) it.copy( overdue = result.overdue, overdueTrns = result.overdueTrns @@ -194,9 +201,7 @@ class HomeViewModel @Inject constructor( viewModelScope.launch { TestIdlingResource.increment() - val hasTransactions = ioThread { - walletDAOs.transactionDao.findAll_LIMIT_1().isNotEmpty() - } + val hasTransactions = hasTrnsAct(Unit) if (hasTransactions) { //has transactions show him "Balance" screen nav.navigateTo(BalanceScreen) diff --git a/ivy-fp/src/main/java/com/ivy/fp/Composition.kt b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt index ef58f201cf..684c40b766 100644 --- a/ivy-fp/src/main/java/com/ivy/fp/Composition.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt @@ -10,7 +10,7 @@ annotation class Pure @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.SOURCE) @MustBeDocumented -annotation class Total +annotation class Total(val sideEffect: String = "") @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.SOURCE) diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt b/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt index e2cf008b4e..2e33c0b663 100644 --- a/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt @@ -51,4 +51,8 @@ fun (suspend () -> C).fixUnit(): suspend (Unit) -> C = fun (suspend (Unit) -> C).fixUnit(): suspend () -> C = { this(Unit) - } \ No newline at end of file + } + +fun (Action).lambda(): suspend (A) -> B = { a -> + this(a) +} \ No newline at end of file diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt index 9d7ec8906a..2bc93750e7 100644 --- a/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt @@ -15,3 +15,14 @@ suspend infix fun (Action>).thenFilter( val list = this(a) list.filter(predicate) } + + +suspend infix fun (suspend () -> List).thenFilter( + predicate: suspend (B) -> Boolean +): suspend () -> List = + { + val list = this() + list.filter { + predicate(it) + } + } From 60982c2830d98c2abea38eb3243a41d9d46ebf94 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 20:33:45 +0300 Subject: [PATCH 22/40] WIP: The Great Refactor --- .../ivy/wallet/domain/data/core/Account.kt | 16 ++- .../com/ivy/wallet/domain/data/core/Budget.kt | 12 ++ .../ivy/wallet/domain/data/core/Category.kt | 13 +- .../wallet/domain/data/core/ExchangeRate.kt | 8 +- .../com/ivy/wallet/domain/data/core/Loan.kt | 14 ++ .../ivy/wallet/domain/data/core/LoanRecord.kt | 22 ++- .../domain/data/core/PlannedPaymentRule.kt | 19 ++- .../ivy/wallet/domain/data/core/Settings.kt | 11 +- .../wallet/domain/data/core/Transaction.kt | 29 +++- .../com/ivy/wallet/domain/data/core/User.kt | 12 ++ .../domain/deprecated/logic/WalletLogic.kt | 133 ------------------ .../sync/uploader/AccountUploader.kt | 4 +- 12 files changed, 148 insertions(+), 145 deletions(-) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt index 293222e7b6..279c16e58e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.persistence.data.AccountEntity import com.ivy.wallet.ui.theme.Green import java.util.* @@ -16,4 +17,17 @@ data class Account( val isDeleted: Boolean = false, val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toEntity(): AccountEntity = AccountEntity( + name = name, + currency = currency, + color = color, + icon = icon, + orderNum = orderNum, + includeInBalance = includeInBalance, + isSynced = isSynced, + isDeleted = isDeleted, + id = id, + + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt index 3836796898..30bebb3784 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.domain.data.core +import com.ivy.wallet.io.persistence.data.BudgetEntity import java.util.* data class Budget( @@ -15,6 +16,17 @@ data class Budget( val orderId: Double, val id: UUID = UUID.randomUUID() ) { + fun toEntity(): BudgetEntity = BudgetEntity( + name = name, + amount = amount, + categoryIdsSerialized = categoryIdsSerialized, + accountIdsSerialized = accountIdsSerialized, + isSynced = isSynced, + isDeleted = isDeleted, + orderId = orderId, + id = id, + ) + companion object { fun serialize(ids: List): String { return ids.joinToString(separator = ",") diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt index 7a7a13ddc4..2213fcd536 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.persistence.data.CategoryEntity import com.ivy.wallet.ui.theme.Ivy import java.util.* @@ -14,4 +15,14 @@ data class Category( val isDeleted: Boolean = false, val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toEntity(): CategoryEntity = CategoryEntity( + name = name, + color = color, + icon = icon, + orderNum = orderNum, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt index c60c467821..97cc401b29 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt @@ -4,4 +4,10 @@ data class ExchangeRate( val baseCurrency: String, val currency: String, val rate: Double, -) \ No newline at end of file +) { + fun toEntity(): ExchangeRate = ExchangeRate( + baseCurrency = baseCurrency, + currency = currency, + rate = rate + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt index 7e3b6a3f92..8e9df4d34f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.LoanType +import com.ivy.wallet.io.persistence.data.LoanEntity import java.util.* data class Loan( @@ -17,6 +18,19 @@ data class Loan( val id: UUID = UUID.randomUUID() ) { + fun toEntity(): LoanEntity = LoanEntity( + name = name, + amount = amount, + type = type, + color = color, + icon = icon, + orderNum = orderNum, + accountId = accountId, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + fun humanReadableType(): String { return if (type == LoanType.BORROW) "BORROWED" else "LENT" } diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt index fbdf0ffbcd..fe348d2086 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.domain.data.core +import com.ivy.wallet.io.persistence.data.LoanRecordEntity import java.time.LocalDateTime import java.util.* @@ -8,13 +9,26 @@ data class LoanRecord( val amount: Double, val note: String? = null, val dateTime: LocalDateTime, - val interest:Boolean = false, - val accountId : UUID? = null, + val interest: Boolean = false, + val accountId: UUID? = null, //This is used store the converted amount for currencies which are different from the loan account currency - val convertedAmount :Double? = null, + val convertedAmount: Double? = null, val isSynced: Boolean = false, val isDeleted: Boolean = false, val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toEntity(): LoanRecordEntity = LoanRecordEntity( + loanId = loanId, + amount = amount, + note = note, + dateTime = dateTime, + interest = interest, + accountId = accountId, + convertedAmount = convertedAmount, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt index b8254016a0..eb70585771 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt @@ -2,6 +2,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.persistence.data.PlannedPaymentRuleEntity import java.time.LocalDateTime import java.util.* @@ -22,4 +23,20 @@ data class PlannedPaymentRule( val isDeleted: Boolean = false, val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toEntity(): PlannedPaymentRuleEntity = PlannedPaymentRuleEntity( + startDate = startDate, + intervalN = intervalN, + intervalType = intervalType, + oneTime = oneTime, + type = type, + accountId = accountId, + amount = amount, + categoryId = categoryId, + title = title, + description = description, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt index c4ece000c0..6bb1424044 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.design.l0_system.Theme +import com.ivy.wallet.io.persistence.data.SettingsEntity import java.math.BigDecimal import java.util.* @@ -11,4 +12,12 @@ data class Settings( val name: String, val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toEntity(): SettingsEntity = SettingsEntity( + theme = theme, + currency = baseCurrency, + bufferAmount = bufferAmount.toDouble(), + name = name, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt index de7b33d373..54bff53e2e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt @@ -2,11 +2,13 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.persistence.data.TransactionEntity import java.math.BigDecimal import java.time.LocalDateTime import java.util.* data class Transaction( + //TODO: Remove default values & introduce Transaction#dummy() method val accountId: UUID, val type: TransactionType, val amount: BigDecimal, @@ -29,4 +31,29 @@ data class Transaction( val loanRecordId: UUID? = null, val id: UUID = UUID.randomUUID() -) : TransactionHistoryItem \ No newline at end of file +) : TransactionHistoryItem { + fun toEntity(): TransactionEntity = TransactionEntity( + accountId = accountId, + type = type, + amount = amount.toDouble(), + toAccountId = toAccountId, + toAmount = toAmount.toDouble(), + title = title, + description = description, + dateTime = dateTime, + categoryId = categoryId, + dueDate = dueDate, + + recurringRuleId = recurringRuleId, + + attachmentUrl = attachmentUrl, + + //This refers to the loan id that is linked with a transaction + loanId = loanId, + + //This refers to the loan record id that is linked with a transaction + loanRecordId = loanRecordId, + + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt index 51c1f433f4..b02459c201 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.AuthProviderType +import com.ivy.wallet.io.persistence.data.UserEntity import java.util.* data class User( @@ -14,5 +15,16 @@ data class User( val testUser: Boolean = false, var id: UUID ) { + fun toEntity(): UserEntity = UserEntity( + email = email, + authProviderType = authProviderType, + firstName = firstName, + lastName = lastName, + profilePicture = profilePicture, + color = color, + testUser = testUser, + id = id + ) + fun names(): String = firstName + if (lastName != null) " $lastName" else "" } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt deleted file mode 100644 index ce4c1f1008..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletLogic.kt +++ /dev/null @@ -1,133 +0,0 @@ -package com.ivy.wallet.domain.deprecated.logic - -import com.ivy.wallet.domain.data.TransactionHistoryDateDivider -import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.SettingsDao -import com.ivy.wallet.io.persistence.dao.TransactionDao -import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import com.ivy.wallet.utils.beginningOfIvyTime -import com.ivy.wallet.utils.convertUTCtoLocal -import com.ivy.wallet.utils.toEpochSeconds -import java.time.LocalDate - -@Deprecated("Migrate to FP Style") -class WalletLogic( - private val accountDao: AccountDao, - private val transactionDao: TransactionDao, - private val settingsDao: SettingsDao, - private val exchangeRatesLogic: ExchangeRatesLogic, -) { - fun history(range: FromToTimeRange): List { - return transactionDao.findAllBetween( - startDate = range.from(), - endDate = range.to() - ).withDateDividers( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ) - } - - fun calculateUpcomingIncome(range: FromToTimeRange): Double { - return calculateIncome(upcomingTransactions(range)) - } - - fun calculateUpcomingExpenses(range: FromToTimeRange): Double { - return calculateExpenses(upcomingTransactions(range)) - } - - fun calculateOverdueIncome(range: FromToTimeRange): Double { - return calculateIncome(overdueTransactions(range)) - } - - fun calculateOverdueExpenses(range: FromToTimeRange): Double { - return calculateExpenses(overdueTransactions(range)) - } - - fun calculateIncome(transactions: List): Double { - return calculate(transactions, TransactionType.INCOME) - } - - fun calculateExpenses(transactions: List): Double { - return calculate(transactions, TransactionType.EXPENSE) - } - - private fun calculate(transactions: List, trnType: TransactionType): Double { - return transactions - .filter { it.type == trnType } - .sumInBaseCurrency( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ) - } - - fun upcomingTransactions(range: FromToTimeRange): List { - return transactionDao.findAllDueToBetween( - startDate = range.upcomingFrom(), - endDate = range.to() - ).filterUpcoming() - } - - fun overdueTransactions(range: FromToTimeRange): List { - return transactionDao.findAllDueToBetween( - startDate = beginningOfIvyTime(), - endDate = range.overdueTo() - ).filterOverdue() - } -} - -@Deprecated("Migrate to FP Style") -fun List.withDateDividers( - exchangeRatesLogic: ExchangeRatesLogic, - settingsDao: SettingsDao, - accountDao: AccountDao -): List { - val trns = this - if (trns.isEmpty()) return trns - - val historyWithDividers = mutableListOf() - - val dateTransactionsMap = mutableMapOf>() - for (transaction in trns) { - if (transaction.dateTime != null) { - val date = transaction.dateTime.convertUTCtoLocal().toLocalDate() - dateTransactionsMap[date]?.add(transaction) ?: run { - dateTransactionsMap[date] = mutableListOf(transaction) - } - } - } - - dateTransactionsMap.toSortedMap { date1, date2 -> - (date2.atStartOfDay().toEpochSeconds() - date1.atStartOfDay().toEpochSeconds()).toInt() - }.forEach { (date, trns) -> - historyWithDividers.add( - TransactionHistoryDateDivider( - date = date, - income = trns - .filter { it.type == TransactionType.INCOME } - .sumInBaseCurrency( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ), - expenses = trns - .filter { it.type == TransactionType.EXPENSE } - .sumInBaseCurrency( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ) - ) - ) - - historyWithDividers.addAll(trns) - } - - return historyWithDividers -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt index c312873821..952bc59d5d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt @@ -25,7 +25,7 @@ class AccountUploader( //update service.update( UpdateAccountRequest( - account = item + account = item.toEntity() ) ) @@ -33,7 +33,7 @@ class AccountUploader( accountDao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Account updated: $item.") } catch (e: Exception) { From 9cd5d0f618b6cd9b0d3a5b6f40f8ecbc9e01273d Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 20:43:30 +0300 Subject: [PATCH 23/40] Fix `sync` package errors --- .../ivy/wallet/domain/data/core/Account.kt | 14 +++++++-- .../com/ivy/wallet/domain/data/core/Budget.kt | 10 +++++++ .../ivy/wallet/domain/data/core/Category.kt | 9 ++++++ .../wallet/domain/data/core/ExchangeRate.kt | 11 ++++++- .../com/ivy/wallet/domain/data/core/Loan.kt | 12 ++++++++ .../ivy/wallet/domain/data/core/LoanRecord.kt | 12 ++++++++ .../domain/data/core/PlannedPaymentRule.kt | 15 ++++++++++ .../ivy/wallet/domain/data/core/Settings.kt | 9 ++++++ .../wallet/domain/data/core/Transaction.kt | 30 +++++++++++++++---- .../com/ivy/wallet/domain/data/core/User.kt | 12 ++++++++ .../wallet/domain/deprecated/sync/IvySync.kt | 2 +- .../deprecated/sync/item/AccountSync.kt | 6 ++-- .../domain/deprecated/sync/item/BudgetSync.kt | 6 ++-- .../deprecated/sync/item/CategorySync.kt | 6 ++-- .../deprecated/sync/item/LoanRecordSync.kt | 6 ++-- .../domain/deprecated/sync/item/LoanSync.kt | 6 ++-- .../sync/item/PlannedPaymentSync.kt | 6 ++-- .../deprecated/sync/item/TransactionSync.kt | 6 ++-- .../sync/uploader/AccountUploader.kt | 2 +- .../sync/uploader/BudgetUploader.kt | 4 +-- .../sync/uploader/CategoryUploader.kt | 4 +-- .../sync/uploader/LoanRecordUploader.kt | 4 +-- .../deprecated/sync/uploader/LoanUploader.kt | 4 +-- .../uploader/PlannedPaymentRuleUploader.kt | 4 +-- .../sync/uploader/TransactionUploader.kt | 4 +-- 25 files changed, 160 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt index 279c16e58e..e11d51d9b5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.network.data.AccountDTO import com.ivy.wallet.io.persistence.data.AccountEntity import com.ivy.wallet.ui.theme.Green import java.util.* @@ -27,7 +28,16 @@ data class Account( includeInBalance = includeInBalance, isSynced = isSynced, isDeleted = isDeleted, - id = id, + id = id + ) - ) + fun toDTO(): AccountDTO = AccountDTO( + name = name, + currency = currency, + color = color, + icon = icon, + orderNum = orderNum, + includeInBalance = includeInBalance, + id = id + ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt index 30bebb3784..73ac44ad77 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.domain.data.core +import com.ivy.wallet.io.network.data.BudgetDTO import com.ivy.wallet.io.persistence.data.BudgetEntity import java.util.* @@ -27,6 +28,15 @@ data class Budget( id = id, ) + fun toDTO(): BudgetDTO = BudgetDTO( + name = name, + amount = amount, + categoryIdsSerialized = categoryIdsSerialized, + accountIdsSerialized = accountIdsSerialized, + orderId = orderId, + id = id + ) + companion object { fun serialize(ids: List): String { return ids.joinToString(separator = ",") diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt index 2213fcd536..49ad3a650b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.network.data.CategoryDTO import com.ivy.wallet.io.persistence.data.CategoryEntity import com.ivy.wallet.ui.theme.Ivy import java.util.* @@ -25,4 +26,12 @@ data class Category( isDeleted = isDeleted, id = id ) + + fun toDTO(): CategoryDTO = CategoryDTO( + name = name, + color = color, + icon = icon, + orderNum = orderNum, + id = id + ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt index 97cc401b29..7f2240e66b 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt @@ -1,11 +1,20 @@ package com.ivy.wallet.domain.data.core +import com.ivy.wallet.io.network.data.ExchangeRateDTO +import com.ivy.wallet.io.persistence.data.ExchangeRateEntity + data class ExchangeRate( val baseCurrency: String, val currency: String, val rate: Double, ) { - fun toEntity(): ExchangeRate = ExchangeRate( + fun toEntity(): ExchangeRateEntity = ExchangeRateEntity( + baseCurrency = baseCurrency, + currency = currency, + rate = rate + ) + + fun toDTO(): ExchangeRateDTO = ExchangeRateDTO( baseCurrency = baseCurrency, currency = currency, rate = rate diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt index 8e9df4d34f..4646aa73a6 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.LoanType +import com.ivy.wallet.io.network.data.LoanDTO import com.ivy.wallet.io.persistence.data.LoanEntity import java.util.* @@ -31,6 +32,17 @@ data class Loan( id = id ) + fun toDTO(): LoanDTO = LoanDTO( + name = name, + amount = amount, + type = type, + color = color, + icon = icon, + orderNum = orderNum, + accountId = accountId, + id = id + ) + fun humanReadableType(): String { return if (type == LoanType.BORROW) "BORROWED" else "LENT" } diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt index fe348d2086..c0b72b7e4f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.domain.data.core +import com.ivy.wallet.io.network.data.LoanRecordDTO import com.ivy.wallet.io.persistence.data.LoanRecordEntity import java.time.LocalDateTime import java.util.* @@ -31,4 +32,15 @@ data class LoanRecord( isDeleted = isDeleted, id = id ) + + fun toDTO(): LoanRecordDTO = LoanRecordDTO( + loanId = loanId, + amount = amount, + note = note, + dateTime = dateTime, + interest = interest, + accountId = accountId, + convertedAmount = convertedAmount, + id = id + ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt index eb70585771..dceb2a3a59 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt @@ -2,6 +2,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.network.data.PlannedPaymentRuleDTO import com.ivy.wallet.io.persistence.data.PlannedPaymentRuleEntity import java.time.LocalDateTime import java.util.* @@ -39,4 +40,18 @@ data class PlannedPaymentRule( isDeleted = isDeleted, id = id ) + + fun toDTO(): PlannedPaymentRuleDTO = PlannedPaymentRuleDTO( + startDate = startDate, + intervalN = intervalN, + intervalType = intervalType, + oneTime = oneTime, + type = type, + accountId = accountId, + amount = amount, + categoryId = categoryId, + title = title, + description = description, + id = id + ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt index 6bb1424044..3970eadd55 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.design.l0_system.Theme +import com.ivy.wallet.io.network.data.SettingsDTO import com.ivy.wallet.io.persistence.data.SettingsEntity import java.math.BigDecimal import java.util.* @@ -20,4 +21,12 @@ data class Settings( name = name, id = id ) + + fun toDTO(): SettingsDTO = SettingsDTO( + theme = theme, + currency = baseCurrency, + bufferAmount = bufferAmount.toDouble(), + name = name, + id = id + ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt index 54bff53e2e..86d2734698 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt @@ -2,6 +2,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.network.data.TransactionDTO import com.ivy.wallet.io.persistence.data.TransactionEntity import java.math.BigDecimal import java.time.LocalDateTime @@ -30,6 +31,10 @@ data class Transaction( //This refers to the loan record id that is linked with a transaction val loanRecordId: UUID? = null, + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + val id: UUID = UUID.randomUUID() ) : TransactionHistoryItem { fun toEntity(): TransactionEntity = TransactionEntity( @@ -43,17 +48,30 @@ data class Transaction( dateTime = dateTime, categoryId = categoryId, dueDate = dueDate, - recurringRuleId = recurringRuleId, - attachmentUrl = attachmentUrl, - - //This refers to the loan id that is linked with a transaction loanId = loanId, - - //This refers to the loan record id that is linked with a transaction loanRecordId = loanRecordId, + id = id, + isSynced = isSynced, + isDeleted = isDeleted + ) + fun toDTO(): TransactionDTO = TransactionDTO( + accountId = accountId, + type = type, + amount = amount.toDouble(), + toAccountId = toAccountId, + toAmount = toAmount.toDouble(), + title = title, + description = description, + dateTime = dateTime, + categoryId = categoryId, + dueDate = dueDate, + recurringRuleId = recurringRuleId, + attachmentUrl = attachmentUrl, + loanId = loanId, + loanRecordId = loanRecordId, id = id ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt index b02459c201..031b6ca12d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt @@ -1,6 +1,7 @@ package com.ivy.wallet.domain.data.core import com.ivy.wallet.domain.data.AuthProviderType +import com.ivy.wallet.io.network.data.UserDTO import com.ivy.wallet.io.persistence.data.UserEntity import java.util.* @@ -26,5 +27,16 @@ data class User( id = id ) + fun toDTO(): UserDTO = UserDTO( + email = email, + authProviderType = authProviderType, + firstName = firstName, + lastName = lastName, + profilePicture = profilePicture, + color = color, + testUser = testUser, + id = id + ) + fun names(): String = firstName + if (lastName != null) " $lastName" else "" } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt index 1cc57f010d..41cb2a9941 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync -import com.ivy.wallet.domain.sync.item.* +import com.ivy.wallet.domain.deprecated.sync.item.* import com.ivy.wallet.io.network.IvySession class IvySync( diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt index d7019a22db..6181a6d4c7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.AccountUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.AccountUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class AccountSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -63,7 +63,7 @@ class AccountSync( response.accounts.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt index 3b83d66270..022c54b2bf 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.BudgetUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.BudgetUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class BudgetSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -63,7 +63,7 @@ class BudgetSync( response.budgets.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt index bd22a26e45..b3327ddfa7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.CategoryUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.CategoryUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class CategorySync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -63,7 +63,7 @@ class CategorySync( response.categories.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt index ca0d2b08ef..cb0ece3006 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.LoanRecordUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.LoanRecordUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class LoanRecordSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -64,7 +64,7 @@ class LoanRecordSync( response.loanRecords.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt index 6a682a5f6b..f4e6e634ae 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.LoanUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.LoanUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class LoanSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -63,7 +63,7 @@ class LoanSync( response.loans.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt index 4d4258a192..46e80e4a1e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.PlannedPaymentRuleUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -41,7 +41,7 @@ class PlannedPaymentSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -65,7 +65,7 @@ class PlannedPaymentSync( response.rules.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt index ec357581db..1b97b9df6f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.TransactionUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class TransactionSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -64,7 +64,7 @@ class TransactionSync( response.transactions.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt index 952bc59d5d..a71735cab2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt @@ -25,7 +25,7 @@ class AccountUploader( //update service.update( UpdateAccountRequest( - account = item.toEntity() + account = item.toDTO() ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt index 9e127ab70a..17d609d890 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt @@ -23,7 +23,7 @@ class BudgetUploader( //update service.update( CrupdateBudgetRequest( - budget = item + budget = item.toDTO() ) ) @@ -31,7 +31,7 @@ class BudgetUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Budget updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt index 247377a616..c0d452bdd1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt @@ -23,7 +23,7 @@ class CategoryUploader( //update service.update( UpdateWalletCategoryRequest( - category = item + category = item.toDTO() ) ) @@ -31,7 +31,7 @@ class CategoryUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Category updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt index a5e706ad73..14809c41ff 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt @@ -23,7 +23,7 @@ class LoanRecordUploader( //update service.updateRecord( UpdateLoanRecordRequest( - loanRecord = item + loanRecord = item.toDTO() ) ) @@ -31,7 +31,7 @@ class LoanRecordUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Loan record updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt index 6a0593f150..5ddb17d2af 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt @@ -23,7 +23,7 @@ class LoanUploader( //update service.update( UpdateLoanRequest( - loan = item + loan = item.toDTO() ) ) @@ -31,7 +31,7 @@ class LoanUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Loan updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt index b8ded6de05..a4d264f6dc 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt @@ -23,7 +23,7 @@ class PlannedPaymentRuleUploader( //update service.update( UpdatePlannedPaymentRuleRequest( - rule = item + rule = item.toDTO() ) ) @@ -31,7 +31,7 @@ class PlannedPaymentRuleUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("PlannedPaymentRule updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt index c07b92610f..78cdabd6d5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt @@ -23,7 +23,7 @@ class TransactionUploader( //update service.update( UpdateTransactionRequest( - transaction = item + transaction = item.toDTO() ) ) @@ -31,7 +31,7 @@ class TransactionUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Transaction updated: $item.") } catch (e: Exception) { From db326e437d927d4e2a649fd07687ae1250e27725 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 20:54:46 +0300 Subject: [PATCH 24/40] WIP: Fix build errors --- .../main/java/com/ivy/wallet/AppModuleDI.kt | 93 ++---------- .../deprecated/logic/CustomerJourneyLogic.kt | 2 +- .../wallet/io/persistence/dao/SettingsDao.kt | 10 +- .../io/persistence/dao/TransactionDao.kt | 17 +-- .../wallet/ui/accounts/AccountsViewModel.kt | 4 +- .../ui/bankintegrations/ConnectBankScreen.kt | 133 ------------------ .../bankintegrations/ConnectBankViewModel.kt | 93 ------------ ivy-fp/build.gradle.kts | 8 -- 8 files changed, 27 insertions(+), 333 deletions(-) delete mode 100644 app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankScreen.kt delete mode 100644 app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankViewModel.kt diff --git a/app/src/main/java/com/ivy/wallet/AppModuleDI.kt b/app/src/main/java/com/ivy/wallet/AppModuleDI.kt index 0fe70f6ab6..d204a1baf9 100644 --- a/app/src/main/java/com/ivy/wallet/AppModuleDI.kt +++ b/app/src/main/java/com/ivy/wallet/AppModuleDI.kt @@ -6,23 +6,19 @@ import com.google.gson.GsonBuilder import com.ivy.design.navigation.Navigation import com.ivy.wallet.android.billing.IvyBilling import com.ivy.wallet.android.notification.NotificationService -import com.ivy.wallet.domain.logic.* -import com.ivy.wallet.domain.logic.bankintegrations.BankIntegrationsLogic -import com.ivy.wallet.domain.logic.bankintegrations.SaltEdgeAccountMapper -import com.ivy.wallet.domain.logic.bankintegrations.SaltEdgeCategoryMapper -import com.ivy.wallet.domain.logic.bankintegrations.SaltEdgeTransactionMapper -import com.ivy.wallet.domain.logic.csv.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.loantrasactions.LTLoanMapper -import com.ivy.wallet.domain.logic.loantrasactions.LTLoanRecordMapper -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsCore -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic -import com.ivy.wallet.domain.logic.zip.ExportZipLogic +import com.ivy.wallet.domain.deprecated.logic.* +import com.ivy.wallet.domain.deprecated.logic.csv.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LTLoanMapper +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LTLoanRecordMapper +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsCore +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.logic.zip.ExportZipLogic +import com.ivy.wallet.domain.deprecated.sync.IvySync +import com.ivy.wallet.domain.deprecated.sync.item.* +import com.ivy.wallet.domain.deprecated.sync.uploader.* import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.sync.IvySync -import com.ivy.wallet.domain.sync.item.* -import com.ivy.wallet.domain.sync.uploader.* import com.ivy.wallet.io.network.* import com.ivy.wallet.io.network.error.ErrorCode import com.ivy.wallet.io.persistence.IvyRoomDatabase @@ -117,9 +113,6 @@ object AppModuleDI { @Provides fun provideBudgetDao(db: IvyRoomDatabase): BudgetDao = db.budgetDao() - @Provides - fun provideWishlistItemDao(db: IvyRoomDatabase): WishlistItemDao = db.wishlistItemDao() - @Provides fun provideSettingsDao(db: IvyRoomDatabase): SettingsDao = db.settingsDao() @@ -133,18 +126,6 @@ object AppModuleDI { fun provideTrnRecurringRuleDao(db: IvyRoomDatabase): PlannedPaymentRuleDao = db.plannedPaymentRuleDao() - @Provides - fun provideWalletLogic( - accountDao: AccountDao, - transactionDao: TransactionDao, - settingsDao: SettingsDao, - exchangeRatesLogic: ExchangeRatesLogic, - ): WalletLogic = WalletLogic( - accountDao = accountDao, - transactionDao = transactionDao, - settingsDao = settingsDao, - exchangeRatesLogic = exchangeRatesLogic, - ) @Provides fun provideWalletAccountLogic( @@ -658,56 +639,6 @@ object AppModuleDI { ) } - @Provides - fun provideSaltEdgeLogic( - restClient: RestClient, - seTransactionsMapper: SaltEdgeTransactionMapper, - ivySession: IvySession, - sharedPrefs: SharedPrefs - ): BankIntegrationsLogic { - return BankIntegrationsLogic( - restClient = restClient, - seTransactionMapper = seTransactionsMapper, - ivySession = ivySession, - sharedPrefs = sharedPrefs - ) - } - - @Provides - fun provideSeTransactionMapper( - transactionDao: TransactionDao, - seAccountMapper: SaltEdgeAccountMapper, - seCategoryMapper: SaltEdgeCategoryMapper, - accountDao: AccountDao, - walletAccountLogic: WalletAccountLogic - ): SaltEdgeTransactionMapper { - return SaltEdgeTransactionMapper( - transactionDao = transactionDao, - seAccountMapper = seAccountMapper, - seCategoryMapper = seCategoryMapper, - accountDao = accountDao, - walletAccountLogic = walletAccountLogic - ) - } - - @Provides - fun provideSeAccountMapper( - accountDao: AccountDao - ): SaltEdgeAccountMapper { - return SaltEdgeAccountMapper( - accountDao = accountDao - ) - } - - @Provides - fun provideSeCategoryMapper( - categoryDao: CategoryDao - ): SaltEdgeCategoryMapper { - return SaltEdgeCategoryMapper( - categoryDao = categoryDao - ) - } - @Provides fun provideCustomerJourneyLogic( transactionDao: TransactionDao, diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt index d2d0aebde4..2f45174949 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt @@ -5,7 +5,7 @@ import androidx.compose.ui.tooling.preview.Preview import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.PlannedPaymentRuleDao import com.ivy.wallet.io.persistence.dao.TransactionDao diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt index 8e4a098676..a77a89f405 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt @@ -15,18 +15,18 @@ interface SettingsDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun save(value: List) - @Query("SELECT * FROM SettingsEntity LIMIT 1") + @Query("SELECT * FROM settings LIMIT 1") fun findFirst(): SettingsEntity - @Query("SELECT * FROM SettingsEntity") + @Query("SELECT * FROM settings") fun findAll(): List - @Query("SELECT * FROM SettingsEntity WHERE id = :id") + @Query("SELECT * FROM settings WHERE id = :id") fun findById(id: UUID): SettingsEntity? - @Query("DELETE FROM SettingsEntity WHERE id = :id") + @Query("DELETE FROM settings WHERE id = :id") fun deleteById(id: UUID) - @Query("DELETE FROM SettingsEntity") + @Query("DELETE FROM settings") fun deleteAll() } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt index e13fb1973a..b89d721f8a 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt @@ -62,20 +62,20 @@ interface TransactionDao { endDate: LocalDateTime ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByCategoryAndBetween( categoryId: UUID, startDate: LocalDateTime, endDate: LocalDateTime ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL AND seAutoCategoryId IS NULL) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllUnspecifiedAndBetween( startDate: LocalDateTime, endDate: LocalDateTime ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByCategoryAndTypeAndBetween( categoryId: UUID, type: TransactionType, @@ -83,7 +83,7 @@ interface TransactionDao { endDate: LocalDateTime ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL AND seAutoCategoryId IS NULL) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllUnspecifiedAndTypeAndBetween( type: TransactionType, startDate: LocalDateTime, @@ -103,14 +103,14 @@ interface TransactionDao { endDate: LocalDateTime ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) ORDER BY dateTime DESC, dueDate ASC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId = :categoryId) ORDER BY dateTime DESC, dueDate ASC") fun findAllDueToBetweenByCategory( startDate: LocalDateTime, endDate: LocalDateTime, categoryId: UUID ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId IS NULL AND seAutoCategoryId IS NULL) ORDER BY dateTime DESC, dueDate ASC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId IS NULL) ORDER BY dateTime DESC, dueDate ASC") fun findAllDueToBetweenByCategoryUnspecified( startDate: LocalDateTime, endDate: LocalDateTime, @@ -143,9 +143,6 @@ interface TransactionDao { @Query("SELECT * FROM transactions WHERE id = :id") fun findById(id: UUID): TransactionEntity? - @Query("SELECT * FROM transactions WHERE seTransactionId = :seTransactionId") - fun findBySeTransactionId(seTransactionId: String): TransactionEntity? - @Query("SELECT * FROM transactions WHERE isSynced = :synced AND isDeleted = :deleted") fun findByIsSyncedAndIsDeleted( synced: Boolean, @@ -182,7 +179,7 @@ interface TransactionDao { pattern: String, ): Long - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) ORDER BY dateTime DESC") fun findAllByCategory( categoryId: UUID, ): List diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt index 09a1077bd8..e15f70ed8b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt @@ -5,13 +5,13 @@ import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.sync.item.AccountSync import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator import com.ivy.wallet.domain.pure.account.calculateAccountBalance import com.ivy.wallet.domain.pure.account.calculateAccountIncomeExpense import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode -import com.ivy.wallet.domain.sync.item.AccountSync import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx diff --git a/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankScreen.kt b/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankScreen.kt deleted file mode 100644 index 1723dd09ca..0000000000 --- a/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankScreen.kt +++ /dev/null @@ -1,133 +0,0 @@ -package com.ivy.wallet.ui.bankintegrations - -import androidx.compose.foundation.layout.* -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.lifecycle.viewmodel.compose.viewModel -import com.google.accompanist.insets.systemBarsPadding -import com.ivy.wallet.R -import com.ivy.design.l0_system.UI -import com.ivy.design.l0_system.style -import com.ivy.wallet.ui.ConnectBank -import com.ivy.wallet.ui.IvyWalletPreview -import com.ivy.wallet.ui.RootActivity -import com.ivy.wallet.ui.theme.Orange -import com.ivy.wallet.ui.theme.components.IvyButton -import com.ivy.wallet.ui.theme.components.IvySwitch -import com.ivy.wallet.utils.OpResult -import com.ivy.wallet.utils.onScreenStart - -@Composable -fun BoxWithConstraintsScope.ConnectBankScreen(screen: ConnectBank) { - val viewModel: ConnectBankViewModel = viewModel() - - val opSyncTransactions by viewModel.opSyncTransactions.observeAsState() - val bankSyncEnabled by viewModel.bankSyncEnabled.observeAsState(false) - - onScreenStart { - viewModel.start() - } - - val ivyActivity = LocalContext.current as RootActivity - UI( - opSyncTransactions = opSyncTransactions, - bankSyncEnabled = bankSyncEnabled, - - onConnect = { - viewModel.connectBank( - rootActivity = ivyActivity - ) - }, - onFetchTransactions = viewModel::syncTransactions, - onRemoveCustomer = viewModel::removeCustomer, - onSetBankSyncEnabled = viewModel::setBankSyncEnabled - ) -} - -@Composable -private fun UI( - opSyncTransactions: OpResult?, - bankSyncEnabled: Boolean, - - onConnect: () -> Unit = {}, - onFetchTransactions: () -> Unit = {}, - onRemoveCustomer: () -> Unit = {}, - - onSetBankSyncEnabled: (Boolean) -> Unit = {} -) { - Column( - modifier = Modifier - .fillMaxSize() - .systemBarsPadding(), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center - ) { - IvyButton(text = stringResource(R.string.connect)) { - onConnect() - } - - Spacer(Modifier.height(24.dp)) - - IvyButton(text = stringResource(R.string.sync_transactions)) { - onFetchTransactions() - } - - if (opSyncTransactions is OpResult.Loading) { - Spacer(Modifier.height(24.dp)) - - Text( - text = stringResource(R.string.syncing_transactions), - style = UI.typo.b2.style( - color = Orange, - fontWeight = FontWeight.ExtraBold - ) - ) - } - - Spacer(Modifier.height(24.dp)) - - Row( - verticalAlignment = Alignment.CenterVertically - ) { - Text( - stringResource(R.string.bank_sync_enabled) - ) - - Spacer(Modifier.width(16.dp)) - - IvySwitch( - enabled = bankSyncEnabled - ) { - onSetBankSyncEnabled(it) - } - } - - Spacer(Modifier.height(24.dp)) - - IvyButton(text = stringResource(R.string.remove_customer)) { - onRemoveCustomer() - } - } -} - -@Preview -@Composable -private fun Preview() { - IvyWalletPreview { - UI( - opSyncTransactions = null, - bankSyncEnabled = true, - - onConnect = {} - ) - } -} diff --git a/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankViewModel.kt deleted file mode 100644 index 36a5860c40..0000000000 --- a/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankViewModel.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.ivy.wallet.ui.bankintegrations - -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.logic.bankintegrations.BankIntegrationsLogic -import com.ivy.wallet.domain.sync.IvySync -import com.ivy.wallet.io.network.IvySession -import com.ivy.wallet.io.persistence.SharedPrefs -import com.ivy.wallet.io.persistence.dao.UserDao -import com.ivy.wallet.ui.RootActivity -import com.ivy.wallet.utils.OpResult -import com.ivy.wallet.utils.TestIdlingResource -import com.ivy.wallet.utils.asLiveData -import com.ivy.wallet.utils.ioThread -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.launch -import javax.inject.Inject - -@HiltViewModel -class ConnectBankViewModel @Inject constructor( - private val bankIntegrationsLogic: BankIntegrationsLogic, - private val ivySession: IvySession, - private val userDao: UserDao, - private val ivySync: IvySync, - private val sharedPrefs: SharedPrefs -) : ViewModel() { - - private val _opSyncTransactions = MutableLiveData>() - val opSyncTransactions = _opSyncTransactions.asLiveData() - - private val _bankSyncEnabled = MutableLiveData(false) - val bankSyncEnabled = _bankSyncEnabled.asLiveData() - - fun start() { - _bankSyncEnabled.value = sharedPrefs.getBoolean(SharedPrefs.ENABLE_BANK_SYNC, false) - } - - fun connectBank(rootActivity: RootActivity) { - viewModelScope.launch { - TestIdlingResource.increment() - - try { - val user = ivySession.getUserIdSafe()?.let { - ioThread { userDao.findById(it) } - } - - if (user != null) { - bankIntegrationsLogic.connect(rootActivity) - } - } catch (e: Exception) { - e.printStackTrace() - } - - TestIdlingResource.decrement() - } - } - - fun syncTransactions() { - viewModelScope.launch { - TestIdlingResource.increment() - - _opSyncTransactions.value = OpResult.loading() - - try { - bankIntegrationsLogic.sync() - ioThread { - ivySync.sync() - } - - _opSyncTransactions.value = OpResult.success(Unit) - } catch (e: Exception) { - e.printStackTrace() - _opSyncTransactions.value = OpResult.failure(e) - } - - TestIdlingResource.decrement() - } - } - - fun setBankSyncEnabled(enabled: Boolean) { - sharedPrefs.putBoolean(SharedPrefs.ENABLE_BANK_SYNC, enabled) - _bankSyncEnabled.value = enabled - } - - fun removeCustomer() { - viewModelScope.launch { - TestIdlingResource.increment() - bankIntegrationsLogic.removeCustomer() - TestIdlingResource.decrement() - } - } -} \ No newline at end of file diff --git a/ivy-fp/build.gradle.kts b/ivy-fp/build.gradle.kts index 01ad4e706a..51215e516c 100644 --- a/ivy-fp/build.gradle.kts +++ b/ivy-fp/build.gradle.kts @@ -39,14 +39,6 @@ android { jvmTarget = "1.8" } - buildFeatures { - compose = true - } - - composeOptions { - kotlinCompilerExtensionVersion = com.ivy.wallet.buildsrc.GlobalVersions.compose - } - packagingOptions { //Exclude this files so Jetpack Compose UI tests can build resources.excludes.add("META-INF/AL2.0") From a5e0b5cb63fbbbc1e32375f9fb33be30edbbfbe6 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 21:29:27 +0300 Subject: [PATCH 25/40] Fix AccountsViewModel.kt --- .../action/account/CalcAccIncomeExpenseAct.kt | 50 ++++++++++++++ .../viewmodel/account/AccountDataAct.kt | 65 +++++++++++++++++++ .../action/wallet/CalcWalletBalanceAct.kt | 5 +- .../wallet/ui/accounts/AccountsViewModel.kt | 55 +++++----------- 4 files changed, 134 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccIncomeExpenseAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/account/AccountDataAct.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccIncomeExpenseAct.kt new file mode 100644 index 0000000000..2538904d02 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccIncomeExpenseAct.kt @@ -0,0 +1,50 @@ +package com.ivy.wallet.domain.action.account + +import arrow.core.nonEmptyListOf +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions +import com.ivy.wallet.domain.pure.transaction.foldTransactions +import javax.inject.Inject + +class CalcAccIncomeExpenseAct @Inject constructor( + private val accTrnsAct: AccTrnsAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + AccTrnsAct.Input( + accountId = account.id, + range = range + ) + } then accTrnsAct then { accTrns -> + foldTransactions( + transactions = accTrns, + arg = account.id, + valueFunctions = nonEmptyListOf( + AccountValueFunctions::income, + AccountValueFunctions::expense + ) + ) + } then { values -> + Output( + account = account, + incomeExpensePair = IncomeExpensePair( + income = values[0], + expense = values[1] + ) + ) + } + + data class Input( + val account: Account, + val range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() + ) + + data class Output( + val account: Account, + val incomeExpensePair: IncomeExpensePair + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/account/AccountDataAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/account/AccountDataAct.kt new file mode 100644 index 0000000000..68265aeddd --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/account/AccountDataAct.kt @@ -0,0 +1,65 @@ +package com.ivy.wallet.domain.action.viewmodel.account + +import arrow.core.toOption +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.action.account.CalcAccBalanceAct +import com.ivy.wallet.domain.action.account.CalcAccIncomeExpenseAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.ui.accounts.AccountData +import javax.inject.Inject + +class AccountDataAct @Inject constructor( + private val exchangeAct: ExchangeAct, + private val calcAccBalanceAct: CalcAccBalanceAct, + private val calcAccIncomeExpenseAct: CalcAccIncomeExpenseAct +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + accounts + } thenMap { acc -> + val balance = calcAccBalanceAct( + CalcAccBalanceAct.Input( + account = acc + ) + ).balance + + val balanceBaseCurrency = if (acc.currency != baseCurrency) { + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = acc.currency.toOption() + ), + amount = balance + ) + ).orNull() + } else { + null + } + + val incomeExpensePair = calcAccIncomeExpenseAct( + CalcAccIncomeExpenseAct.Input( + account = acc, + range = range + ) + ).incomeExpensePair + + AccountData( + account = acc, + balance = balance.toDouble(), + balanceBaseCurrency = balanceBaseCurrency?.toDouble(), + monthlyIncome = incomeExpensePair.income.toDouble(), + monthlyExpenses = incomeExpensePair.expense.toDouble(), + ) + } + + data class Input( + val accounts: List, + val baseCurrency: String, + val range: ClosedTimeRange + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index 5ed7282518..67e18f12d5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -20,7 +20,7 @@ class CalcWalletBalanceAct @Inject constructor( private suspend fun Input.recipe(): suspend (Unit) -> BigDecimal = accountsAct thenFilter { - it.includeInBalance + withExcluded || it.includeInBalance } thenMap { calcAccBalanceAct( CalcAccBalanceAct.Input( @@ -46,6 +46,7 @@ class CalcWalletBalanceAct @Inject constructor( data class Input( val baseCurrency: String, val balanceCurrency: String = baseCurrency, - val range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() + val range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), + val withExcluded: Boolean = false ) } diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt index e15f70ed8b..3b69257b77 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt @@ -3,15 +3,14 @@ package com.ivy.wallet.ui.accounts import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.viewmodel.account.AccountDataAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.deprecated.logic.AccountCreator import com.ivy.wallet.domain.deprecated.sync.item.AccountSync import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.pure.account.calculateAccountBalance -import com.ivy.wallet.domain.pure.account.calculateAccountIncomeExpense import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx @@ -36,7 +35,9 @@ class AccountsViewModel @Inject constructor( private val accountCreator: AccountCreator, private val ivyContext: IvyWalletCtx, private val accountsAct: AccountsAct, - private val calcWalletBalanceAct: CalcWalletBalanceAct + private val calcWalletBalanceAct: CalcWalletBalanceAct, + private val baseCurrencyAct: BaseCurrencyAct, + private val accountDataAct: AccountDataAct ) : ViewModel() { @Subscribe @@ -66,47 +67,23 @@ class AccountsViewModel @Inject constructor( ) //this must be monthly val range = period.toRange(ivyContext.startDayOfMonth) - val baseCurrencyCode = ioThread { baseCurrencyCode(settingsDao) } + val baseCurrencyCode = baseCurrencyAct(Unit) _baseCurrencyCode.value = baseCurrencyCode val accs = accountsAct(Unit) - _accounts.value = ioThread { - accs.map { - val balance = calculateAccountBalance( - transactionDao = walletDAOs.transactionDao, - accountId = it.id - ) - val balanceBaseCurrency = if (it.currency != baseCurrencyCode) { - exchangeToBaseCurrency( - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = it.currency ?: baseCurrencyCode, - fromAmount = balance - ).orNull()?.toDouble() - } else { - null - } - - val incomeExpensePair = calculateAccountIncomeExpense( - transactionDao = walletDAOs.transactionDao, - accountId = it.id, - range = range.toCloseTimeRange() - ) - - AccountData( - account = it, - balance = balance.toDouble(), - balanceBaseCurrency = balanceBaseCurrency, - monthlyIncome = incomeExpensePair.income.toDouble(), - monthlyExpenses = incomeExpensePair.expense.toDouble(), - ) - } - } + _accounts.value = accountDataAct( + AccountDataAct.Input( + accounts = accs, + range = range.toCloseTimeRange(), + baseCurrency = baseCurrencyCode + ) + ) _totalBalanceWithExcluded.value = calcWalletBalanceAct( CalcWalletBalanceAct.Input( - baseCurrency = baseCurrencyCode + baseCurrency = baseCurrencyCode, + withExcluded = true ) ).toDouble() @@ -121,7 +98,7 @@ class AccountsViewModel @Inject constructor( ioThread { newOrder.mapIndexed { index, accountData -> accountDao.save( - accountData.account.copy( + accountData.account.toEntity().copy( orderNum = index.toDouble(), isSynced = false ) From 8eb42e001bb646a052e87763823dbd81e27da3d6 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 21:35:01 +0300 Subject: [PATCH 26/40] Move FPAction.kt to run on IO thread by default --- .../ivy/wallet/domain/action/account/AccountsAct.kt | 1 + ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt index e0017c7b03..f199a896ba 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt @@ -8,6 +8,7 @@ import javax.inject.Inject class AccountsAct @Inject constructor( private val accountDao: AccountDao ) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { io { accountDao.findAll().map { it.toDomain() } } } diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt b/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt index 279981ce62..0283a4350d 100644 --- a/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt @@ -1,9 +1,17 @@ package com.ivy.fp.action +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + abstract class FPAction : Action() { protected abstract suspend fun I.compose(): (suspend () -> O) + protected open fun dispatcher(): CoroutineDispatcher = Dispatchers.IO + override suspend fun I.willDo(): O { - return compose().invoke() + return withContext(dispatcher()) { + compose().invoke() + } } } \ No newline at end of file From 34605f98488f8b23ff21aefa04cd6ee177c41664 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 22:00:02 +0300 Subject: [PATCH 27/40] Fix BudgetViewModel.kt --- .../wallet/domain/action/budget/BudgetsAct.kt | 15 +++ .../domain/pure/transaction/TrnFunctions.kt | 11 +- .../java/com/ivy/wallet/ui/RootViewModel.kt | 4 +- .../ivy/wallet/ui/balance/BalanceViewModel.kt | 6 +- .../com/ivy/wallet/ui/budget/BudgetScreen.kt | 37 +++--- .../ivy/wallet/ui/budget/BudgetViewModel.kt | 106 +++++++++--------- ivy-fp/src/main/java/com/ivy/fp/Utils.kt | 11 ++ 7 files changed, 116 insertions(+), 74 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/budget/BudgetsAct.kt create mode 100644 ivy-fp/src/main/java/com/ivy/fp/Utils.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/budget/BudgetsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/budget/BudgetsAct.kt new file mode 100644 index 0000000000..46c713f841 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/budget/BudgetsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.budget + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.io.persistence.dao.BudgetDao +import javax.inject.Inject + +class BudgetsAct @Inject constructor( + private val budgetDao: BudgetDao +) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { + budgetDao.findAll() + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt index 452df3bd8a..331ac45bc0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt @@ -1,7 +1,10 @@ package com.ivy.wallet.domain.pure.transaction +import arrow.core.Option +import arrow.core.toOption import com.ivy.fp.Pure import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction import java.time.LocalDateTime @@ -26,4 +29,10 @@ fun isUpcoming(transaction: Transaction, timeNowUTC: LocalDateTime): Boolean = @Pure fun isOverdue(transaction: Transaction, timeNowUTC: LocalDateTime): Boolean = - timeNowUTC.isAfter(transaction.dueDate) \ No newline at end of file + timeNowUTC.isAfter(transaction.dueDate) + +@Pure +fun trnCurrency( + transaction: Transaction, + accounts: List +): Option = accounts.find { it.id == transaction.accountId }?.currency.toOption() \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/RootViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/RootViewModel.kt index edaa1b9c89..a55ef7c9a5 100644 --- a/app/src/main/java/com/ivy/wallet/ui/RootViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/RootViewModel.kt @@ -11,8 +11,8 @@ import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.android.billing.IvyBilling import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.logic.PaywallLogic -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.logic.PaywallLogic +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.persistence.SharedPrefs diff --git a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt index 75f5839d43..974f06022b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt @@ -4,9 +4,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.action.settings.BaseCurrencyAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct -import com.ivy.wallet.domain.logic.PlannedPaymentsLogic -import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.io.persistence.dao.SettingsDao +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod import com.ivy.wallet.utils.dateNowUTC @@ -19,8 +17,6 @@ import javax.inject.Inject @HiltViewModel class BalanceViewModel @Inject constructor( - private val walletDAOs: WalletDAOs, - private val settingsDao: SettingsDao, private val plannedPaymentsLogic: PlannedPaymentsLogic, private val ivyContext: IvyWalletCtx, private val baseCurrencyAct: BaseCurrencyAct, diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt index e065a2cdca..acff620c95 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.Text import androidx.compose.runtime.* -import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag @@ -23,7 +22,7 @@ import com.ivy.wallet.R import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Budget import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateBudgetData +import com.ivy.wallet.domain.deprecated.logic.model.CreateBudgetData import com.ivy.wallet.ui.BudgetScreen import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.budget.model.DisplayBudget @@ -45,13 +44,13 @@ import com.ivy.wallet.utils.onScreenStart fun BoxWithConstraintsScope.BudgetScreen(screen: BudgetScreen) { val viewModel: BudgetViewModel = viewModel() - val timeRange by viewModel.timeRange.observeAsState() - val baseCurrency by viewModel.baseCurrencyCode.observeAsState("") - val categories by viewModel.categories.observeAsState(emptyList()) - val accounts by viewModel.accounts.observeAsState(emptyList()) - val budgets by viewModel.budgets.observeAsState(emptyList()) - val appBudgetMax by viewModel.appBudgetMax.observeAsState(0.0) - val categoryBudgetsTotal by viewModel.categoryBudgetsTotal.observeAsState(0.0) + val timeRange by viewModel.timeRange.collectAsState() + val baseCurrency by viewModel.baseCurrencyCode.collectAsState() + val categories by viewModel.categories.collectAsState() + val accounts by viewModel.accounts.collectAsState() + val budgets by viewModel.budgets.collectAsState() + val appBudgetMax by viewModel.appBudgetMax.collectAsState() + val categoryBudgetsTotal by viewModel.categoryBudgetsTotal.collectAsState() onScreenStart { viewModel.start() @@ -231,11 +230,19 @@ private fun Toolbar( Spacer(Modifier.height(4.dp)) val categoryBudgetText = if (categoryBudgetsTotal > 0) { - stringResource(R.string.for_categories, categoryBudgetsTotal.format(baseCurrency), baseCurrency) + stringResource( + R.string.for_categories, + categoryBudgetsTotal.format(baseCurrency), + baseCurrency + ) } else "" val appBudgetMaxText = if (appBudgetMax > 0) { - stringResource(R.string.app_budget, appBudgetMax.format(baseCurrency), baseCurrency) + stringResource( + R.string.app_budget, + appBudgetMax.format(baseCurrency), + baseCurrency + ) } else "" val hasBothBudgetTypes = @@ -243,8 +250,12 @@ private fun Toolbar( Text( modifier = Modifier.testTag("budgets_info_text"), text = if (hasBothBudgetTypes) - stringResource(R.string.budget_info_both, categoryBudgetText, appBudgetMaxText) - else stringResource(R.string.budget_info, categoryBudgetText, appBudgetMaxText), + stringResource( + R.string.budget_info_both, + categoryBudgetText, + appBudgetMaxText + ) + else stringResource(R.string.budget_info, categoryBudgetText, appBudgetMaxText), style = UI.typo.nC.style( color = Gray, fontWeight = FontWeight.ExtraBold diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt index 03175ea802..820b2749ec 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt @@ -1,18 +1,24 @@ package com.ivy.wallet.ui.budget -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.fp.sumOfSuspend +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.budget.BudgetsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.transaction.HistoryTrnsAct import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Budget import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.BudgetCreator -import com.ivy.wallet.domain.logic.WalletLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CreateBudgetData -import com.ivy.wallet.domain.sync.item.BudgetSync +import com.ivy.wallet.domain.deprecated.logic.BudgetCreator +import com.ivy.wallet.domain.deprecated.logic.model.CreateBudgetData +import com.ivy.wallet.domain.deprecated.sync.item.BudgetSync +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.transaction.trnCurrency import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.BudgetDao @@ -20,10 +26,11 @@ import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.budget.model.DisplayBudget -import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.ui.onboarding.model.TimePeriod +import com.ivy.wallet.ui.onboarding.model.toCloseTimeRange import com.ivy.wallet.utils.* import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -32,54 +39,50 @@ class BudgetViewModel @Inject constructor( private val sharedPrefs: SharedPrefs, private val settingsDao: SettingsDao, private val budgetDao: BudgetDao, - private val walletLogic: WalletLogic, private val categoryDao: CategoryDao, private val accountDao: AccountDao, - private val exchangeRatesLogic: ExchangeRatesLogic, private val budgetCreator: BudgetCreator, private val budgetSync: BudgetSync, - private val ivyContext: IvyWalletCtx + private val ivyContext: IvyWalletCtx, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val budgetsAct: BudgetsAct, + private val baseCurrencyAct: BaseCurrencyAct, + private val historyTrnsAct: HistoryTrnsAct, + private val exchangeAct: ExchangeAct ) : ViewModel() { - private val _timeRange = MutableLiveData() - val timeRange = _timeRange.asLiveData() + private val _timeRange = MutableStateFlow(ivyContext.selectedPeriod.toRange(1)) + val timeRange = _timeRange.readOnly() - private val _baseCurrencyCode = MutableLiveData(getDefaultFIATCurrency().currencyCode) - val baseCurrencyCode = _baseCurrencyCode.asLiveData() + private val _baseCurrencyCode = MutableStateFlow(getDefaultFIATCurrency().currencyCode) + val baseCurrencyCode = _baseCurrencyCode.readOnly() - private val _budgets = MutableLiveData>() - val budgets = _budgets.asLiveData() + private val _budgets = MutableStateFlow>(emptyList()) + val budgets = _budgets.readOnly() - private val _categories = MutableLiveData>() - val categories = _categories.asLiveData() + private val _categories = MutableStateFlow>(emptyList()) + val categories = _categories.readOnly() - private val _accounts = MutableLiveData>() - val accounts = _accounts.asLiveData() + private val _accounts = MutableStateFlow>(emptyList()) + val accounts = _accounts.readOnly() - private val _categoryBudgetsTotal = MutableLiveData() - val categoryBudgetsTotal = _categoryBudgetsTotal.asLiveData() + private val _categoryBudgetsTotal = MutableStateFlow(0.0) + val categoryBudgetsTotal = _categoryBudgetsTotal.readOnly() - private val _appBudgetMax = MutableLiveData() - val appBudgetMax = _appBudgetMax.asLiveData() + private val _appBudgetMax = MutableStateFlow(0.0) + val appBudgetMax = _appBudgetMax.readOnly() fun start() { viewModelScope.launch { TestIdlingResource.increment() - _categories.value = ioThread { - categoryDao.findAll() - }!! + _categories.value = categoriesAct(Unit) - val accounts = ioThread { - accountDao.findAll() - } + val accounts = accountsAct(Unit) _accounts.value = accounts - val settings = ioThread { - settingsDao.findFirst() - } - - val baseCurrency = settings.currency + val baseCurrency = baseCurrencyAct(Unit) _baseCurrencyCode.value = baseCurrency val startDateOfMonth = ivyContext.initStartDayOfMonthInMemory(sharedPrefs = sharedPrefs) @@ -88,13 +91,7 @@ class BudgetViewModel @Inject constructor( ).toRange(startDateOfMonth = startDateOfMonth) _timeRange.value = timeRange - val transactions = ioThread { - walletLogic.history(range = timeRange) - }.filterIsInstance(Transaction::class.java) - - val budgets = ioThread { - budgetDao.findAll() - } + val budgets = budgetsAct(Unit) _appBudgetMax.value = budgets .filter { it.categoryIdsSerialized.isNullOrBlank() } @@ -110,7 +107,7 @@ class BudgetViewModel @Inject constructor( budget = it, spentAmount = calculateSpentAmount( budget = it, - transactions = transactions, + transactions = historyTrnsAct(timeRange.toCloseTimeRange()), accounts = accounts, baseCurrencyCode = baseCurrency ) @@ -122,25 +119,20 @@ class BudgetViewModel @Inject constructor( } } - private fun calculateSpentAmount( + private suspend fun calculateSpentAmount( budget: Budget, transactions: List, baseCurrencyCode: String, accounts: List ): Double { + //TODO: Re-work this by creating an FPAction for it val accountsFilter = budget.parseAccountIds() val categoryFilter = budget.parseCategoryIds() return transactions .filter { accountsFilter.isEmpty() || accountsFilter.contains(it.accountId) } .filter { categoryFilter.isEmpty() || categoryFilter.contains(it.categoryId) } - .sumOf { - val amountBaseCurrency = exchangeRatesLogic.amountBaseCurrency( - transaction = it, - baseCurrency = baseCurrencyCode, - accounts = accounts - ) - + .sumOfSuspend { when (it.type) { TransactionType.INCOME -> { //decrement spent amount if it's not global budget @@ -149,7 +141,15 @@ class BudgetViewModel @Inject constructor( } TransactionType.EXPENSE -> { //increment spent amount - amountBaseCurrency + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrencyCode, + fromCurrency = trnCurrency(it, accounts) + ), + amount = it.amount + ) + ).orNull()?.toDouble() ?: 0.0 } TransactionType.TRANSFER -> { //ignore transfers for simplicity @@ -203,7 +203,7 @@ class BudgetViewModel @Inject constructor( ioThread { newOrder.forEachIndexed { index, item -> budgetDao.save( - item.budget.copy( + item.budget.toEntity().copy( orderId = index.toDouble(), isSynced = false ) diff --git a/ivy-fp/src/main/java/com/ivy/fp/Utils.kt b/ivy-fp/src/main/java/com/ivy/fp/Utils.kt new file mode 100644 index 0000000000..563d8eac57 --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/Utils.kt @@ -0,0 +1,11 @@ +package com.ivy.fp + +suspend fun List.sumOfSuspend( + selector: suspend (A) -> Double +): Double { + var sum = 0.0 + for (item in this) { + sum += selector(item) + } + return sum +} \ No newline at end of file From d9402d5f19f9c58543197884a3fa9c72736d0a7f Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 23:38:11 +0300 Subject: [PATCH 28/40] WIP: Fix build errors --- .../domain/action/category/CategoryByIdAct.kt | 15 ++ .../domain/action/transaction/TrnByIdAct.kt | 18 +++ .../wallet/ui/category/CategoriesScreen.kt | 7 +- .../wallet/ui/category/CategoriesViewModel.kt | 33 +++-- .../wallet/ui/edit/EditTransactionScreen.kt | 34 +++-- .../ui/edit/EditTransactionViewModel.kt | 136 ++++++++++-------- .../ui/theme/modal/edit/AccountModal.kt | 2 +- .../ui/theme/modal/edit/CategoryModal.kt | 2 +- 8 files changed, 150 insertions(+), 97 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/category/CategoryByIdAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnByIdAct.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryByIdAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryByIdAct.kt new file mode 100644 index 0000000000..00beafbf43 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryByIdAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.category + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.io.persistence.dao.CategoryDao +import java.util.* +import javax.inject.Inject + +class CategoryByIdAct @Inject constructor( + private val categoryDao: CategoryDao +) : FPAction() { + override suspend fun UUID.compose(): suspend () -> Category? = suspend { + categoryDao.findById(this)?.toDomain() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnByIdAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnByIdAct.kt new file mode 100644 index 0000000000..d075b66dd6 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnByIdAct.kt @@ -0,0 +1,18 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.io.persistence.dao.TransactionDao +import java.util.* +import javax.inject.Inject + +class TrnByIdAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction() { + override suspend fun UUID.compose(): suspend () -> Transaction? = suspend { + this //transactionId + } then transactionDao::findById then { + it?.toDomain() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt index bf3192d8da..2de0618bd3 100644 --- a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.* import androidx.compose.foundation.layout.* import androidx.compose.material.Text import androidx.compose.runtime.* -import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -24,7 +23,7 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.Categories import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview @@ -43,8 +42,8 @@ import com.ivy.wallet.utils.onScreenStart fun BoxWithConstraintsScope.CategoriesScreen(screen: Categories) { val viewModel: CategoriesViewModel = viewModel() - val currency by viewModel.currency.observeAsState("") - val categories by viewModel.categories.observeAsState(emptyList()) + val currency by viewModel.currency.collectAsState() + val categories by viewModel.categories.collectAsState() onScreenStart { viewModel.start() diff --git a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt index 1ec260669d..e50e62ef6f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt @@ -1,20 +1,22 @@ package com.ivy.wallet.ui.category -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.logic.CategoryCreator -import com.ivy.wallet.domain.logic.WalletCategoryLogic -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.sync.item.CategorySync +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.deprecated.logic.CategoryCreator +import com.ivy.wallet.domain.deprecated.logic.WalletCategoryLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.sync.item.CategorySync import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod import com.ivy.wallet.utils.TestIdlingResource -import com.ivy.wallet.utils.asLiveData import com.ivy.wallet.utils.ioThread +import com.ivy.wallet.utils.readOnly import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -25,14 +27,16 @@ class CategoriesViewModel @Inject constructor( private val categoryLogic: WalletCategoryLogic, private val categorySync: CategorySync, private val categoryCreator: CategoryCreator, - private val ivyContext: IvyWalletCtx + private val categoriesAct: CategoriesAct, + private val ivyContext: IvyWalletCtx, + private val baseCurrencyAct: BaseCurrencyAct ) : ViewModel() { - private val _currency = MutableLiveData() - val currency = _currency.asLiveData() + private val _currency = MutableStateFlow("") + val currency = _currency.readOnly() - private val _categories = MutableLiveData>() - val categories = _categories.asLiveData() + private val _categories = MutableStateFlow>(emptyList()) + val categories = _categories.readOnly() fun start() { viewModelScope.launch { @@ -42,11 +46,10 @@ class CategoriesViewModel @Inject constructor( startDayOfMonth = ivyContext.startDayOfMonth ).toRange(ivyContext.startDayOfMonth) //this must be monthly - _currency.value = ioThread { settingsDao.findFirst().currency }!! + _currency.value = baseCurrencyAct(Unit) _categories.value = ioThread { - categoryDao - .findAll() + categoriesAct(Unit) .map { CategoryData( category = it, @@ -77,7 +80,7 @@ class CategoriesViewModel @Inject constructor( ioThread { newOrder.forEachIndexed { index, categoryData -> categoryDao.save( - categoryData.category.copy( + categoryData.category.toEntity().copy( orderNum = index.toDouble(), isSynced = false ) diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt index 8987f877de..6059431725 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt @@ -27,8 +27,8 @@ import com.ivy.wallet.domain.data.CustomExchangeRateState import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.EditTransaction import com.ivy.wallet.ui.IvyWalletPreview @@ -54,24 +54,24 @@ fun BoxWithConstraintsScope.EditTransactionScreen(screen: EditTransaction) { val viewModel: EditTransactionViewModel = viewModel() val transactionType by viewModel.transactionType.observeAsState(screen.type) - val initialTitle by viewModel.initialTitle.observeAsState() + val initialTitle by viewModel.initialTitle.collectAsState() val titleSuggestions by viewModel.titleSuggestions.collectAsState() - val currency by viewModel.currency.observeAsState("") - val description by viewModel.description.observeAsState() - val dateTime by viewModel.dateTime.observeAsState() - val category by viewModel.category.observeAsState() - val account by viewModel.account.observeAsState() - val toAccount by viewModel.toAccount.observeAsState() - val dueDate by viewModel.dueDate.observeAsState() - val amount by viewModel.amount.observeAsState(0.0) + val currency by viewModel.currency.collectAsState() + val description by viewModel.description.collectAsState() + val dateTime by viewModel.dateTime.collectAsState() + val category by viewModel.category.collectAsState() + val account by viewModel.account.collectAsState() + val toAccount by viewModel.toAccount.collectAsState() + val dueDate by viewModel.dueDate.collectAsState() + val amount by viewModel.amount.collectAsState() val loanData by viewModel.displayLoanHelper.collectAsState() val backgroundProcessing by viewModel.backgroundProcessingStarted.collectAsState() val customExchangeRateState by viewModel.customExchangeRateState.collectAsState() - val categories by viewModel.categories.observeAsState(emptyList()) - val accounts by viewModel.accounts.observeAsState(emptyList()) + val categories by viewModel.categories.collectAsState(emptyList()) + val accounts by viewModel.accounts.collectAsState(emptyList()) - val hasChanges by viewModel.hasChanges.observeAsState(false) + val hasChanges by viewModel.hasChanges.collectAsState(false) onScreenStart { viewModel.start(screen) @@ -387,7 +387,11 @@ private fun BoxWithConstraintsScope.UI( } } else { //no changes, pay - ModalCheck(label = if (transactionType == TransactionType.EXPENSE) stringResource(R.string.pay) else stringResource(R.string.get)) { + ModalCheck( + label = if (transactionType == TransactionType.EXPENSE) stringResource( + R.string.pay + ) else stringResource(R.string.get) + ) { onPayPlannedPayment() } } diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt index 4eeed39169..f8c8fb2107 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt @@ -4,18 +4,23 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.action.account.AccountByIdAct +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.category.CategoryByIdAct +import com.ivy.wallet.domain.action.transaction.TrnByIdAct import com.ivy.wallet.domain.data.CustomExchangeRateState import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.sync.uploader.TransactionUploader import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.ui.EditTransaction @@ -28,6 +33,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import org.greenrobot.eventbus.EventBus +import java.math.BigDecimal import java.time.LocalDateTime import java.util.* import javax.inject.Inject @@ -49,50 +55,55 @@ class EditTransactionViewModel @Inject constructor( private val paywallLogic: PaywallLogic, private val plannedPaymentsLogic: PlannedPaymentsLogic, private val smartTitleSuggestionsLogic: SmartTitleSuggestionsLogic, - private val loanTransactionsLogic: LoanTransactionsLogic + private val loanTransactionsLogic: LoanTransactionsLogic, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val trnByIdAct: TrnByIdAct, + private val categoryByIdAct: CategoryByIdAct, + private val accountByIdAct: AccountByIdAct ) : ViewModel() { private val _transactionType = MutableLiveData() val transactionType = _transactionType - private val _initialTitle = MutableLiveData() - val initialTitle = _initialTitle.asLiveData() + private val _initialTitle = MutableStateFlow(null) + val initialTitle = _initialTitle.readOnly() private val _titleSuggestions = MutableStateFlow(emptySet()) val titleSuggestions = _titleSuggestions.asStateFlow() - private val _currency = MutableLiveData() - val currency = _currency.asLiveData() + private val _currency = MutableStateFlow("") + val currency = _currency.readOnly() - private val _description = MutableLiveData() - val description = _description.asLiveData() + private val _description = MutableStateFlow(null) + val description = _description.readOnly() - private val _dateTime = MutableLiveData() - val dateTime = _dateTime.asLiveData() + private val _dateTime = MutableStateFlow(null) + val dateTime = _dateTime.readOnly() - private val _dueDate = MutableLiveData() - val dueDate = _dueDate.asLiveData() + private val _dueDate = MutableStateFlow(null) + val dueDate = _dueDate.readOnly() - private val _accounts = MutableLiveData>() - val accounts = _accounts.asLiveData() + private val _accounts = MutableStateFlow>(emptyList()) + val accounts = _accounts.readOnly() - private val _categories = MutableLiveData>() - val categories = _categories.asLiveData() + private val _categories = MutableStateFlow>(emptyList()) + val categories = _categories.readOnly() - private val _account = MutableLiveData() - val account = _account.asLiveData() + private val _account = MutableStateFlow(null) + val account = _account.readOnly() - private val _toAccount = MutableLiveData() - val toAccount = _toAccount.asLiveData() + private val _toAccount = MutableStateFlow(null) + val toAccount = _toAccount.readOnly() - private val _category = MutableLiveData() - val category = _category.asLiveData() + private val _category = MutableStateFlow(null) + val category = _category.readOnly() - private val _amount = MutableLiveData(0.0) - val amount = _amount.asLiveData() + private val _amount = MutableStateFlow(0.0) + val amount = _amount.readOnly() - private val _hasChanges = MutableLiveData(false) - val hasChanges = _hasChanges.asLiveData() + private val _hasChanges = MutableStateFlow(false) + val hasChanges = _hasChanges.readOnly() private val _displayLoanHelper: MutableStateFlow = MutableStateFlow(EditTransactionDisplayLoan()) @@ -123,19 +134,19 @@ class EditTransactionViewModel @Inject constructor( baseUserCurrency = baseCurrency() - val accounts = ioThread { accountDao.findAll() }!! + val accounts = accountsAct(Unit) if (accounts.isEmpty()) { closeScreen() return@launch } _accounts.value = accounts - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit) reset() loadedTransaction = screen.initialTransactionId?.let { - ioThread { transactionDao.findById(it)!! } + trnByIdAct(it) } ?: Transaction( accountId = defaultAccountId( screen = screen, @@ -143,7 +154,8 @@ class EditTransactionViewModel @Inject constructor( ), categoryId = screen.categoryId, type = screen.type, - amount = 0.0, + amount = BigDecimal.ZERO, + toAmount = BigDecimal.ZERO ) display(loadedTransaction!!) @@ -208,33 +220,34 @@ class EditTransactionViewModel @Inject constructor( _dateTime.value = transaction.dateTime _description.value = transaction.description _dueDate.value = transaction.dueDate - val selectedAccount = ioThread { accountDao.findById(transaction.accountId)!! } + val selectedAccount = accountByIdAct(transaction.accountId)!! _account.value = selectedAccount _toAccount.value = transaction.toAccountId?.let { - ioThread { accountDao.findById(it) } + accountByIdAct(it) } _category.value = transaction.categoryId?.let { - ioThread { categoryDao.findById(it) } + categoryByIdAct(it) } - _amount.value = transaction.amount + _amount.value = transaction.amount.toDouble() updateCurrency(account = selectedAccount) - transaction.toAmount?.let { - val exchangeRate = it / transaction.amount - val toAccountCurrency = - _accounts.value?.find { acc -> acc.id == transaction.toAccountId }?.currency - _customExchangeRateState.value = - _customExchangeRateState.value.copy( - showCard = toAccountCurrency != account.value?.currency, - exchangeRate = exchangeRate, - convertedAmount = it, - toCurrencyCode = toAccountCurrency, - fromCurrencyCode = currency.value - ) - } ?: let { - _customExchangeRateState.value = CustomExchangeRateState() - } + //TODO: Fix that +// transaction.toAmount?.let { +// val exchangeRate = it / transaction.amount +// val toAccountCurrency = +// _accounts.value?.find { acc -> acc.id == transaction.toAccountId }?.currency +// _customExchangeRateState.value = +// _customExchangeRateState.value.copy( +// showCard = toAccountCurrency != account.value?.currency, +// exchangeRate = exchangeRate, +// convertedAmount = it, +// toCurrencyCode = toAccountCurrency, +// fromCurrencyCode = currency.value +// ) +// } ?: let { +// _customExchangeRateState.value = CustomExchangeRateState() +// } _displayLoanHelper.value = getDisplayLoanHelper(trans = transaction) } @@ -248,7 +261,7 @@ class EditTransactionViewModel @Inject constructor( fun onAmountChanged(newAmount: Double) { viewModelScope.launch { loadedTransaction = loadedTransaction().copy( - amount = newAmount + amount = newAmount.toBigDecimal() ) _amount.value = newAmount updateCustomExchangeRateState(amt = newAmount) @@ -418,7 +431,7 @@ class EditTransactionViewModel @Inject constructor( TestIdlingResource.increment() categoryCreator.createCategory(data) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit) //Select the newly created category onCategoryChanged(it) @@ -433,7 +446,7 @@ class EditTransactionViewModel @Inject constructor( TestIdlingResource.increment() categoryCreator.editCategory(updatedCategory) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit) } TestIdlingResource.decrement() @@ -446,7 +459,7 @@ class EditTransactionViewModel @Inject constructor( accountCreator.createAccount(data) { EventBus.getDefault().post(AccountsUpdatedEvent()) - _accounts.value = ioThread { accountDao.findAll() }!! + _accounts.value = accountsAct(Unit) } TestIdlingResource.decrement() @@ -484,12 +497,13 @@ class EditTransactionViewModel @Inject constructor( private suspend fun saveInternal(closeScreen: Boolean) { try { ioThread { - val amount = amount.value ?: error("no amount") + val amount = amount.value.toBigDecimal() loadedTransaction = loadedTransaction().copy( accountId = account.value?.id ?: error("no accountId"), toAccountId = toAccount.value?.id, - toAmount = _customExchangeRateState.value.convertedAmount, + toAmount = _customExchangeRateState.value.convertedAmount?.toBigDecimal() + ?: amount, title = title?.trim(), description = description.value?.trim(), amount = amount, @@ -522,7 +536,7 @@ class EditTransactionViewModel @Inject constructor( accountsChanged = false } - transactionDao.save(loadedTransaction()) + transactionDao.save(loadedTransaction().toEntity()) } if (closeScreen) { diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt index 61d970e3e0..a62f4d9656 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt @@ -22,7 +22,7 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.core.Account -import com.ivy.wallet.domain.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.Gray import com.ivy.wallet.ui.theme.Ivy diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt index 03534829bb..991aa7506b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt @@ -26,7 +26,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.ivy.wallet.R import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.Ivy import com.ivy.wallet.ui.theme.components.ItemIconMDefaultIcon From 208827e524b54dffb6264385134567d9b59a8159 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 23 Apr 2022 23:56:56 +0300 Subject: [PATCH 29/40] WIP: Fix build errors --- .../wallet/domain/action/loan/LoanByIdAct.kt | 15 +++++++ .../ivy/wallet/domain/action/loan/LoansAct.kt | 15 +++++++ .../home/CalcBalanceIncomeExpenseAct.kt | 6 ++- .../ivy/wallet/ui/charts/ChartsViewModel.kt | 25 ++++++----- .../wallet/ui/csvimport/ImportViewModel.kt | 14 +++---- .../com/ivy/wallet/ui/loan/LoanViewModel.kt | 28 ++++++++----- .../ui/loandetails/LoanDetailsViewModel.kt | 34 +++++++-------- .../com/ivy/wallet/ui/main/MainViewModel.kt | 8 ++-- .../viewmodel/OnboardingViewModel.kt | 41 ++++++++++--------- .../ivy/wallet/ui/reports/ReportViewModel.kt | 33 ++++++++------- 10 files changed, 132 insertions(+), 87 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt new file mode 100644 index 0000000000..9e771cc9cd --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.loan + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.io.persistence.dao.LoanDao +import java.util.* +import javax.inject.Inject + +class LoanByIdAct @Inject constructor( + private val loanDao: LoanDao +) : FPAction() { + override suspend fun UUID.compose(): suspend () -> Loan? = suspend { + loanDao.findById(this)?.toDomain() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt new file mode 100644 index 0000000000..86c2c8fc23 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.loan + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.io.persistence.dao.LoanDao +import javax.inject.Inject + +class LoansAct @Inject constructor( + private val loanDao: LoanDao +) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { + loanDao.findAll() + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt index 22a530d4f5..250a940fb4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt @@ -3,16 +3,18 @@ package com.ivy.wallet.domain.action.viewmodel.home import arrow.core.nonEmptyListOf import arrow.core.toOption import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then import com.ivy.fp.action.thenMap -import com.ivy.wallet.domain.action.ExchangeAct import com.ivy.wallet.domain.action.account.AccTrnsAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct import com.ivy.wallet.domain.data.core.Account -import com.ivy.wallet.domain.pure.ExchangeData import com.ivy.wallet.domain.pure.account.filterExcluded import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.exchange.ExchangeData import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions import com.ivy.wallet.domain.pure.transaction.foldTransactions +import com.ivy.wallet.domain.pure.util.orZero import java.math.BigDecimal import javax.inject.Inject diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt index 439a2f4933..b18cc06f0f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt @@ -7,13 +7,12 @@ import com.ivy.wallet.domain.action.charts.BalanceChartAct import com.ivy.wallet.domain.action.settings.BaseCurrencyAct import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.WalletCategoryLogic +import com.ivy.wallet.domain.deprecated.logic.WalletCategoryLogic import com.ivy.wallet.domain.pure.charts.ChartPeriod import com.ivy.wallet.domain.pure.charts.IncomeExpenseChartPoint import com.ivy.wallet.domain.pure.charts.SingleChartPoint import com.ivy.wallet.domain.pure.charts.incomeExpenseChart import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.onboarding.model.FromToTimeRange @@ -75,7 +74,7 @@ class ChartsViewModel @Inject constructor( fun start() { viewModelScope.launch { - _baseCurrencyCode.value = ioThread { baseCurrencyCode(settingsDao) } +// _baseCurrencyCode.value = ioThread { baseCurrencyCode(settingsDao) } walletCharts(period = period.value) } @@ -137,16 +136,16 @@ class ChartsViewModel @Inject constructor( period: ChartPeriod, category: Category ) { - _categoryExpenseValues.value = categoryExpenseValues.loadCategoryValue( - period = period, - category = category, - calculateValue = { range -> - walletCategoryLogic.calculateCategoryExpenses( - category = category, - range = range - ).absoluteValue - } - ) +// _categoryExpenseValues.value = categoryExpenseValues.loadCategoryValue( +// period = period, +// category = category, +// calculateValue = { range -> +// walletCategoryLogic.calculateCategoryExpenses( +// category = category, +// range = range +// ).absoluteValue +// } +// ) } private suspend fun loadCategoryExpenseCount( diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt index 1087eb0fc5..5cec1d883a 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt @@ -6,13 +6,13 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation -import com.ivy.wallet.domain.logic.csv.CSVImporter -import com.ivy.wallet.domain.logic.csv.CSVMapper -import com.ivy.wallet.domain.logic.csv.CSVNormalizer -import com.ivy.wallet.domain.logic.csv.IvyFileReader -import com.ivy.wallet.domain.logic.csv.model.ImportResult -import com.ivy.wallet.domain.logic.csv.model.ImportType -import com.ivy.wallet.domain.logic.zip.ExportZipLogic +import com.ivy.wallet.domain.deprecated.logic.csv.CSVImporter +import com.ivy.wallet.domain.deprecated.logic.csv.CSVMapper +import com.ivy.wallet.domain.deprecated.logic.csv.CSVNormalizer +import com.ivy.wallet.domain.deprecated.logic.csv.IvyFileReader +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType +import com.ivy.wallet.domain.deprecated.logic.zip.ExportZipLogic import com.ivy.wallet.ui.Import import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.viewmodel.OnboardingViewModel diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt index 9ac38c9761..4bb3f115d7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt @@ -2,15 +2,18 @@ package com.ivy.wallet.ui.loan import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.loan.LoansAct import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.logic.LoanCreator +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData +import com.ivy.wallet.domain.deprecated.sync.item.LoanSync import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.logic.LoanCreator -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanData -import com.ivy.wallet.domain.sync.item.LoanSync import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.LoanDao @@ -42,7 +45,10 @@ class LoanViewModel @Inject constructor( private val sharedPrefs: SharedPrefs, private val accountDao: AccountDao, private val accountCreator: AccountCreator, - private val loanTransactionsLogic: LoanTransactionsLogic + private val loanTransactionsLogic: LoanTransactionsLogic, + private val loansAct: LoansAct, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct ) : ViewModel() { private val _baseCurrencyCode = MutableStateFlow(getDefaultFIATCurrency().currencyCode) @@ -75,7 +81,7 @@ class LoanViewModel @Inject constructor( initialiseAccounts() _loans.value = ioThread { - loanDao.findAll() + loansAct(Unit) .map { loan -> val amountPaid = calculateAmountPaid(loan) val loanAmount = loan.amount @@ -111,7 +117,7 @@ class LoanViewModel @Inject constructor( } private suspend fun initialiseAccounts() { - val accounts = ioThread { accountDao.findAll() } + val accounts = accountsAct(Unit) _accounts.value = accounts _selectedAccount.value = defaultAccountId(accounts) _selectedAccount.value?.let { @@ -142,7 +148,7 @@ class LoanViewModel @Inject constructor( ioThread { newOrder.forEachIndexed { index, item -> loanDao.save( - item.loan.copy( + item.loan.toEntity().copy( orderNum = index.toDouble(), isSynced = false ) @@ -165,7 +171,7 @@ class LoanViewModel @Inject constructor( accountCreator.createAccount(data) { EventBus.getDefault().post(AccountsUpdatedEvent()) - _accounts.value = ioThread { accountDao.findAll() }!! + _accounts.value = accountsAct(Unit) _state.value = state.value.copy(accounts = _accounts.value) } diff --git a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt index f857af2349..b8f3b7eb0f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt @@ -3,18 +3,20 @@ package com.ivy.wallet.ui.loandetails import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.loan.LoanByIdAct import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.domain.data.core.LoanRecord import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.logic.LoanCreator +import com.ivy.wallet.domain.deprecated.logic.LoanRecordCreator +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.EditLoanRecordData import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.logic.LoanCreator -import com.ivy.wallet.domain.logic.LoanRecordCreator -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData -import com.ivy.wallet.domain.logic.model.EditLoanRecordData import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.LoanDetails @@ -42,7 +44,9 @@ class LoanDetailsViewModel @Inject constructor( private val accountDao: AccountDao, private val accountCreator: AccountCreator, private val loanTransactionsLogic: LoanTransactionsLogic, - private val nav: Navigation + private val nav: Navigation, + private val accountsAct: AccountsAct, + private val loanByIdAct: LoanByIdAct ) : ViewModel() { private val _baseCurrency = MutableStateFlow("") @@ -87,13 +91,9 @@ class LoanDetailsViewModel @Inject constructor( _baseCurrency.value = it } - _accounts.value = ioThread { - accountDao.findAll() - } + _accounts.value = accountsAct(Unit) - _loan.value = ioThread { - loanDao.findById(id = loanId) - } + _loan.value = loanByIdAct(loanId) loan.value?.let { loan -> _selectedLoanAccount.value = accounts.value.find { @@ -120,7 +120,7 @@ class LoanDetailsViewModel @Inject constructor( ) DisplayLoanRecord( - it, + it.toDomain(), account = account, loanRecordTransaction = trans != null, loanRecordCurrencyCode = account?.currency ?: defaultCurrencyCode, @@ -148,7 +148,7 @@ class LoanDetailsViewModel @Inject constructor( } associatedTransaction = ioThread { - transactionDao.findLoanTransaction(loanId = loan.value!!.id) + transactionDao.findLoanTransaction(loanId = loan.value!!.id)?.toDomain() } associatedTransaction?.let { @@ -296,7 +296,7 @@ class LoanDetailsViewModel @Inject constructor( accountCreator.createAccount(data) { EventBus.getDefault().post(AccountsUpdatedEvent()) - _accounts.value = ioThread { accountDao.findAll() } + _accounts.value = accountsAct(Unit) } TestIdlingResource.decrement() diff --git a/app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt index 4068c1da28..e4e7906d7c 100644 --- a/app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt @@ -4,11 +4,11 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.sync.IvySync import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.sync.IvySync import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.Main 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 d7cfe4e211..4d8c66f9aa 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 @@ -5,16 +5,18 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Settings -import com.ivy.wallet.domain.logic.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic -import com.ivy.wallet.domain.sync.IvySync +import com.ivy.wallet.domain.deprecated.logic.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.sync.IvySync import com.ivy.wallet.io.network.FCMClient import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.network.IvySession @@ -48,6 +50,9 @@ class OnboardingViewModel @Inject constructor( private val categoryDao: CategoryDao, private val accountCreator: AccountCreator, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + //Only OnboardingRouter stuff sharedPrefs: SharedPrefs, ivySync: IvySync, @@ -133,8 +138,8 @@ class OnboardingViewModel @Inject constructor( theme = if (isSystemDarkMode) Theme.DARK else Theme.LIGHT, name = "", baseCurrency = defaultCurrency.code, - bufferAmount = 1000.0 - ) + bufferAmount = 1000.0.toBigDecimal() + ).toEntity() ) } @@ -283,15 +288,13 @@ class OnboardingViewModel @Inject constructor( } } - private suspend fun accountsWithBalance(): List = ioThread { - accountDao.findAll() - .map { - AccountBalance( - account = it, - balance = accountLogic.calculateAccountBalance(it) - ) - } - } + private suspend fun accountsWithBalance(): List = accountsAct(Unit) + .map { + AccountBalance( + account = it, + balance = accountLogic.calculateAccountBalance(it) + ) + } fun onAddAccountsDone() { viewModelScope.launch { @@ -320,7 +323,7 @@ class OnboardingViewModel @Inject constructor( TestIdlingResource.increment() categoryCreator.editCategory(updatedCategory) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! } TestIdlingResource.decrement() @@ -332,7 +335,7 @@ class OnboardingViewModel @Inject constructor( TestIdlingResource.increment() categoryCreator.createCategory(data) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! } TestIdlingResource.decrement() diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt index 3bc73a6bef..165d264fe8 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt @@ -6,15 +6,16 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation import com.ivy.fp.viewmodel.IvyViewModel +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.transaction.TrnsWithDateDivsAct import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.PlannedPaymentsLogic -import com.ivy.wallet.domain.logic.WalletLogic -import com.ivy.wallet.domain.logic.csv.ExportCSVLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.pure.wallet.withDateDividers +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic +import com.ivy.wallet.domain.deprecated.logic.csv.ExportCSVLogic import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.RootActivity @@ -33,15 +34,17 @@ import javax.inject.Inject class ReportViewModel @Inject constructor( private val plannedPaymentsLogic: PlannedPaymentsLogic, private val settingsDao: SettingsDao, - private val walletLogic: WalletLogic, private val transactionDao: TransactionDao, private val ivyContext: IvyWalletCtx, private val nav: Navigation, private val accountDao: AccountDao, private val categoryDao: CategoryDao, - private val exchangeRatesLogic: ExchangeRatesLogic, private val exchangeRateDao: ExchangeRateDao, - private val exportCSVLogic: ExportCSVLogic + private val exportCSVLogic: ExportCSVLogic, + private val exchangeAct: ExchangeAct, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val trnsWithDateDivsAct: TrnsWithDateDivsAct ) : IvyViewModel() { override val mutableState: MutableStateFlow = MutableStateFlow( ReportScreenState() @@ -66,8 +69,8 @@ class ReportViewModel @Inject constructor( fun start() { viewModelScope.launch(Dispatchers.IO) { _baseCurrency.value = settingsDao.findFirst().currency - _accounts.value = accountDao.findAll() - _categories.value = listOf(unSpecifiedCategory) + categoryDao.findAll() + _accounts.value = accountsAct(Unit) + _categories.value = listOf(unSpecifiedCategory) + categoriesAct(Unit) updateState { it.copy( @@ -107,10 +110,11 @@ class ReportViewModel @Inject constructor( .sortedByDescending { it.dateTime } val historyWithDateDividers = scope.async { - history.withDateDividers( - exchangeRateDao = exchangeRateDao, - accountDao = accountDao, - baseCurrencyCode = _baseCurrency.value + trnsWithDateDivsAct( + TrnsWithDateDivsAct.Input( + baseCurrency = stateVal().baseCurrency, + transactions = history + ) ) } @@ -187,6 +191,7 @@ class ReportViewModel @Inject constructor( return transactionDao .findAll() + .map { it.toDomain() } .asSequence() .filter { //Filter by Transaction Type From 59893324b8e541b5c9ce204be8c59b62b821116a Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sun, 24 Apr 2022 20:12:55 +0300 Subject: [PATCH 30/40] WIP: Fix build errors --- .../transaction/CalcTrnsIncomeExpenseAct.kt | 44 +++++++ .../action/viewmodel/home/DueTrnsInfoAct.kt | 6 +- .../CalcBalanceIncomeExpenseAct.kt | 2 +- .../deprecated/logic/csv/ExportCSVLogic.kt | 12 +- .../domain/pure/exchange/ExchangeTrns.kt | 72 +++++++++-- .../pure/transaction/TrnDateDividers.kt | 6 +- .../pure/transaction/WalletValueFunctions.kt | 49 ++++++++ .../com/ivy/wallet/ui/home/HomeViewModel.kt | 2 +- .../ivy/wallet/ui/reports/ReportViewModel.kt | 118 +++++++++++------- ivy-fp/src/main/java/com/ivy/fp/Utils.kt | 8 ++ 10 files changed, 255 insertions(+), 64 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/CalcTrnsIncomeExpenseAct.kt rename app/src/main/java/com/ivy/wallet/domain/action/{viewmodel/home => wallet}/CalcBalanceIncomeExpenseAct.kt (98%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/transaction/WalletValueFunctions.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/CalcTrnsIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/CalcTrnsIncomeExpenseAct.kt new file mode 100644 index 0000000000..002b9a1ad2 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/CalcTrnsIncomeExpenseAct.kt @@ -0,0 +1,44 @@ +package com.ivy.wallet.domain.action.transaction + +import arrow.core.nonEmptyListOf +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.fp.then +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.exchange.actInput +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.WalletValueFunctions +import com.ivy.wallet.domain.pure.transaction.foldTransactionsSuspend +import javax.inject.Inject + +class CalcTrnsIncomeExpenseAct @Inject constructor( + private val exchangeAct: ExchangeAct +) : FPAction() { + override suspend fun Input.compose(): suspend () -> IncomeExpensePair = suspend { + foldTransactionsSuspend( + transactions = transactions, + valueFunctions = nonEmptyListOf( + WalletValueFunctions::income, + WalletValueFunctions::expense, + ), + arg = WalletValueFunctions.Argument( + accounts = accounts, + baseCurrency = baseCurrency, + exchange = ::actInput then exchangeAct + ) + ) + } then { values -> + IncomeExpensePair( + income = values[0], + expense = values[1] + ) + } + + data class Input( + val transactions: List, + val baseCurrency: String, + val accounts: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt index 35bbde9c46..b647569ac1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt @@ -12,7 +12,7 @@ import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.domain.pure.exchange.ExchangeTrnArgument -import com.ivy.wallet.domain.pure.exchange.exchangeInCurrency +import com.ivy.wallet.domain.pure.exchange.exchangeInBaseCurrency import com.ivy.wallet.domain.pure.transaction.expenses import com.ivy.wallet.domain.pure.transaction.incomes import com.ivy.wallet.domain.pure.transaction.sumTrns @@ -46,12 +46,12 @@ class DueTrnsInfoAct @Inject constructor( dueIncomeExpense = IncomeExpensePair( income = sumTrns( incomes(upcomingTrns), - ::exchangeInCurrency, + ::exchangeInBaseCurrency, exchangeArg ), expense = sumTrns( expenses(upcomingTrns), - ::exchangeInCurrency, + ::exchangeInBaseCurrency, exchangeArg ) ), diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcBalanceIncomeExpenseAct.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcBalanceIncomeExpenseAct.kt index 250a940fb4..af3a3295b7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncomeExpenseAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcBalanceIncomeExpenseAct.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.action.viewmodel.home +package com.ivy.wallet.domain.action.wallet import arrow.core.nonEmptyListOf import arrow.core.toOption diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt index af4b53837a..a0c366f698 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt @@ -32,7 +32,7 @@ class ExportCSVLogic( context: Context, fileUri: Uri, exportScope: () -> List = { - transactionDao.findAll() + transactionDao.findAll().map { it.toDomain() } } ) { val csv = generateCSV( @@ -66,8 +66,8 @@ class ExportCSVLogic( .joinToString("\n") { it.toCSV( baseCurrency = baseCurrency, - accountMap = accountMap, - categoryMap = categoryMap + accountMap = accountMap.mapValues { it.value.toDomain() }, + categoryMap = categoryMap.mapValues { it.value.toDomain() } ) } @@ -116,7 +116,7 @@ class ExportCSVLogic( TransactionType.INCOME -> it TransactionType.EXPENSE -> -it TransactionType.TRANSFER -> 0.0 - }.formatAmountCSV(currency) + }.toDouble().formatAmountCSV(currency) append(amountFormatted) } @@ -132,7 +132,7 @@ class ExportCSVLogic( //Transfer Amount csv.appendValue(if (type == TransactionType.TRANSFER) amount else null) { - append(it.formatAmountCSV(currency)) + append(it.toDouble().formatAmountCSV(currency)) } //Transfer Currency @@ -148,7 +148,7 @@ class ExportCSVLogic( val receiveCurrency = toAccountId?.let { accountMap[it]?.currency ?: baseCurrency } //Receive Amount csv.appendValue(toAmount) { - append(it.formatAmountCSV(receiveCurrency ?: baseCurrency)) + append(it.toDouble().formatAmountCSV(receiveCurrency ?: baseCurrency)) } //Receive Currency diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt index 35a21b48c9..1316924db7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt @@ -2,32 +2,90 @@ package com.ivy.wallet.domain.pure.exchange import arrow.core.Option import arrow.core.toOption +import com.ivy.fp.Pure import com.ivy.fp.SideEffect import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.transaction.trnCurrency import java.math.BigDecimal import java.util.* +typealias ExchangeEffect = suspend (ExchangeData, BigDecimal) -> Option data class ExchangeTrnArgument( val baseCurrency: String, @SideEffect val getAccount: suspend (accountId: UUID) -> Account?, @SideEffect - val exchange: suspend (ExchangeData, BigDecimal) -> Option + val exchange: ExchangeEffect ) -suspend fun exchangeInCurrency( +@Pure +suspend fun exchangeInBaseCurrency( transaction: Transaction, arg: ExchangeTrnArgument ): BigDecimal { - val fromCurrencyCode = arg.getAccount(transaction.accountId)?.currency.toOption() + val fromCurrency = arg.getAccount(transaction.accountId)?.currency.toOption() + + return exchangeInCurrency( + transaction = transaction, + baseCurrency = arg.baseCurrency, + trnCurrency = fromCurrency, + toCurrency = arg.baseCurrency, + exchange = arg.exchange + ) +} + +@Pure +suspend fun exchangeInBaseCurrency( + transaction: Transaction, + baseCurrency: String, + accounts: List, + + @SideEffect + exchange: ExchangeEffect +): BigDecimal = exchangeInCurrency( + transaction = transaction, + baseCurrency = baseCurrency, + accounts = accounts, + toCurrency = baseCurrency, + exchange = exchange +) + +@Pure +suspend fun exchangeInCurrency( + transaction: Transaction, + baseCurrency: String, + accounts: List, + toCurrency: String, + + @SideEffect + exchange: ExchangeEffect +): BigDecimal { + return exchange( + ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency(transaction, accounts), + toCurrency = toCurrency + ), + transaction.amount + ).orNull() ?: BigDecimal.ZERO +} - return arg.exchange( +suspend fun exchangeInCurrency( + transaction: Transaction, + baseCurrency: String, + trnCurrency: Option, + toCurrency: String, + + @SideEffect + exchange: ExchangeEffect +): BigDecimal { + return exchange( ExchangeData( - baseCurrency = arg.baseCurrency, - fromCurrency = fromCurrencyCode, - toCurrency = arg.baseCurrency + baseCurrency = baseCurrency, + fromCurrency = trnCurrency, + toCurrency = toCurrency ), transaction.amount ).orNull() ?: BigDecimal.ZERO diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt index c774c85b21..a8d65c25df 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt @@ -9,7 +9,7 @@ import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.pure.exchange.ExchangeData import com.ivy.wallet.domain.pure.exchange.ExchangeTrnArgument -import com.ivy.wallet.domain.pure.exchange.exchangeInCurrency +import com.ivy.wallet.domain.pure.exchange.exchangeInBaseCurrency import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal @@ -47,12 +47,12 @@ suspend fun transactionsWithDateDividers( date = date!!, income = sumTrns( incomes(transactionsForDate), - ::exchangeInCurrency, + ::exchangeInBaseCurrency, arg ).toDouble(), expenses = sumTrns( expenses(transactionsForDate), - ::exchangeInCurrency, + ::exchangeInBaseCurrency, arg ).toDouble() ), diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/WalletValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/WalletValueFunctions.kt new file mode 100644 index 0000000000..2af1d8b6e9 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/WalletValueFunctions.kt @@ -0,0 +1,49 @@ +package com.ivy.wallet.domain.pure.transaction + +import com.ivy.fp.SideEffect +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.exchange.ExchangeEffect +import com.ivy.wallet.domain.pure.exchange.exchangeInBaseCurrency +import java.math.BigDecimal + +object WalletValueFunctions { + data class Argument( + val accounts: List, + val baseCurrency: String, + + @SideEffect + val exchange: ExchangeEffect + ) + + suspend fun income( + transaction: Transaction, + arg: Argument + ): BigDecimal = with(transaction) { + when (type) { + TransactionType.INCOME -> exchangeInBaseCurrency( + transaction = this, + accounts = arg.accounts, + baseCurrency = arg.baseCurrency, + exchange = arg.exchange + ) + else -> BigDecimal.ZERO + } + } + + suspend fun expense( + transaction: Transaction, + arg: Argument + ): BigDecimal = with(transaction) { + when (type) { + TransactionType.EXPENSE -> exchangeInBaseCurrency( + transaction = this, + accounts = arg.accounts, + baseCurrency = arg.baseCurrency, + exchange = arg.exchange + ) + else -> BigDecimal.ZERO + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index b57b074fc5..dba0537102 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -9,10 +9,10 @@ import com.ivy.wallet.domain.action.category.CategoriesAct import com.ivy.wallet.domain.action.settings.CalcBufferDiffAct import com.ivy.wallet.domain.action.settings.SettingsAct import com.ivy.wallet.domain.action.transaction.HistoryWithDateDivsAct -import com.ivy.wallet.domain.action.viewmodel.home.CalcBalanceIncomeExpenseAct import com.ivy.wallet.domain.action.viewmodel.home.HasTrnsAct import com.ivy.wallet.domain.action.viewmodel.home.OverdueAct import com.ivy.wallet.domain.action.viewmodel.home.UpcomingAct +import com.ivy.wallet.domain.action.wallet.CalcBalanceIncomeExpenseAct import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt index 165d264fe8..f19bee7620 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt @@ -5,10 +5,14 @@ import androidx.compose.ui.graphics.toArgb import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation +import com.ivy.fp.filterSuspend +import com.ivy.fp.sumOfSuspend import com.ivy.fp.viewmodel.IvyViewModel import com.ivy.wallet.domain.action.account.AccountsAct import com.ivy.wallet.domain.action.category.CategoriesAct import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.transaction.CalcTrnsIncomeExpenseAct import com.ivy.wallet.domain.action.transaction.TrnsWithDateDivsAct import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account @@ -16,7 +20,11 @@ import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic import com.ivy.wallet.domain.deprecated.logic.csv.ExportCSVLogic -import com.ivy.wallet.io.persistence.dao.* +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.transaction.trnCurrency +import com.ivy.wallet.domain.pure.util.orZero +import com.ivy.wallet.io.persistence.dao.SettingsDao +import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.ui.onboarding.model.TimePeriod @@ -37,14 +45,13 @@ class ReportViewModel @Inject constructor( private val transactionDao: TransactionDao, private val ivyContext: IvyWalletCtx, private val nav: Navigation, - private val accountDao: AccountDao, - private val categoryDao: CategoryDao, - private val exchangeRateDao: ExchangeRateDao, private val exportCSVLogic: ExportCSVLogic, private val exchangeAct: ExchangeAct, private val accountsAct: AccountsAct, private val categoriesAct: CategoriesAct, - private val trnsWithDateDivsAct: TrnsWithDateDivsAct + private val trnsWithDateDivsAct: TrnsWithDateDivsAct, + private val calcTrnsIncomeExpenseAct: CalcTrnsIncomeExpenseAct, + private val baseCurrencyAct: BaseCurrencyAct ) : IvyViewModel() { override val mutableState: MutableStateFlow = MutableStateFlow( ReportScreenState() @@ -68,7 +75,7 @@ class ReportViewModel @Inject constructor( fun start() { viewModelScope.launch(Dispatchers.IO) { - _baseCurrency.value = settingsDao.findFirst().currency + _baseCurrency.value = baseCurrencyAct(Unit) _accounts.value = accountsAct(Unit) _categories.value = listOf(unSpecifiedCategory) + categoriesAct(Unit) @@ -118,16 +125,21 @@ class ReportViewModel @Inject constructor( ) } - val income = scope.async { walletLogic.calculateIncome(history) } - val expenses = scope.async { walletLogic.calculateExpenses(history) } + val historyIncomeExpense = calcTrnsIncomeExpenseAct( + CalcTrnsIncomeExpenseAct.Input( + transactions = history, + accounts = accounts, + baseCurrency = baseCurrency + ) + ) val balance = scope.async { calculateBalance( baseCurrency = baseCurrency, accounts = accounts, history = history, - income = income.await(), - expenses = expenses.await(), + income = historyIncomeExpense.income.toDouble(), + expenses = historyIncomeExpense.expense.toDouble(), filter = filter ) } @@ -142,27 +154,36 @@ class ReportViewModel @Inject constructor( it.dueDate != null && it.dueDate.isAfter(timeNowUTC) } .sortedBy { it.dueDate } - val upcomingIncome = scope.async { walletLogic.calculateIncome(upcomingTransactions) } - val upcomingExpenses = - scope.async { walletLogic.calculateExpenses(upcomingTransactions) } + val upcomingIncomeExpense = calcTrnsIncomeExpenseAct( + CalcTrnsIncomeExpenseAct.Input( + transactions = upcomingTransactions, + accounts = accounts, + baseCurrency = baseCurrency + ) + ) //Overdue val overdue = transactions.filter { it.dueDate != null && it.dueDate.isBefore(timeNowUTC) }.sortedByDescending { it.dueDate } - val overdueIncome = scope.async { walletLogic.calculateIncome(overdue) } - val overdueExpenses = scope.async { walletLogic.calculateExpenses(overdue) } + val overdueIncomeExpense = calcTrnsIncomeExpenseAct( + CalcTrnsIncomeExpenseAct.Input( + transactions = overdue, + accounts = accounts, + baseCurrency = baseCurrency + ) + ) updateState { it.copy( - income = income.await(), - expenses = expenses.await(), - upcomingIncome = upcomingIncome.await(), - upcomingExpenses = upcomingExpenses.await(), - overdueIncome = overdueIncome.await(), - overdueExpenses = overdueExpenses.await(), + income = historyIncomeExpense.income.toDouble(), + expenses = historyIncomeExpense.expense.toDouble(), + upcomingIncome = upcomingIncomeExpense.income.toDouble(), + upcomingExpenses = upcomingIncomeExpense.expense.toDouble(), + overdueIncome = overdueIncomeExpense.income.toDouble(), + overdueExpenses = overdueIncomeExpense.expense.toDouble(), history = historyWithDateDividers.await(), upcomingTransactions = upcomingTransactions, overdueTransactions = overdue, @@ -179,7 +200,7 @@ class ReportViewModel @Inject constructor( } } - private fun filterTransactions( + private suspend fun filterTransactions( baseCurrency: String, accounts: List, filter: ReportFilter, @@ -192,7 +213,6 @@ class ReportViewModel @Inject constructor( return transactionDao .findAll() .map { it.toDomain() } - .asSequence() .filter { //Filter by Transaction Type filter.trnTypes.contains(it.type) @@ -216,15 +236,19 @@ class ReportViewModel @Inject constructor( filterCategoryIds.contains(trn.categoryId) || (trn.type == TransactionType.TRANSFER) } - .filter { + .filterSuspend { //Filter by Amount //!NOTE: Amount must be converted to baseCurrency amount - val trnAmountBaseCurrency = exchangeRatesLogic.amountBaseCurrency( - transaction = it, - baseCurrency = baseCurrency, - accounts = accounts - ) + val trnAmountBaseCurrency = exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency(it, accounts), + ), + amount = it.amount + ) + ).orZero().toDouble() (filter.minAmount == null || trnAmountBaseCurrency >= filter.minAmount) && (filter.maxAmount == null || trnAmountBaseCurrency <= filter.maxAmount) @@ -284,7 +308,7 @@ class ReportViewModel @Inject constructor( return this.toLowerCaseLocal().contains(anotherString.toLowerCaseLocal()) } - private fun calculateBalance( + private suspend fun calculateBalance( baseCurrency: String, accounts: List, history: List, @@ -299,12 +323,16 @@ class ReportViewModel @Inject constructor( it.type == TransactionType.TRANSFER && it.toAccountId != null && includedAccountsIds.contains(it.toAccountId) } - .sumOf { trn -> - exchangeRatesLogic.toAmountBaseCurrency( - transaction = trn, - baseCurrency = baseCurrency, - accounts = accounts - ) + .sumOfSuspend { trn -> + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency(trn, accounts), + ), + amount = trn.amount + ) + ).orZero().toDouble() } //- Transfers Out (#conv to BaseCurrency) @@ -313,19 +341,23 @@ class ReportViewModel @Inject constructor( it.type == TransactionType.TRANSFER && includedAccountsIds.contains(it.accountId) } - .sumOf { trn -> - exchangeRatesLogic.amountBaseCurrency( - transaction = trn, - baseCurrency = baseCurrency, - accounts = accounts - ) + .sumOfSuspend { trn -> + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency(trn, accounts), + ), + amount = trn.amount + ) + ).orZero().toDouble() } //Income - Expenses (#conv to BaseCurrency) return income - expenses + transfersIn - transfersOut } - private fun export(context: Context) { + private suspend fun export(context: Context) { ivyContext.protectWithPaywall( paywallReason = PaywallReason.EXPORT_CSV, navigation = nav diff --git a/ivy-fp/src/main/java/com/ivy/fp/Utils.kt b/ivy-fp/src/main/java/com/ivy/fp/Utils.kt index 563d8eac57..b6fbef2c2e 100644 --- a/ivy-fp/src/main/java/com/ivy/fp/Utils.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/Utils.kt @@ -8,4 +8,12 @@ suspend fun List.sumOfSuspend( sum += selector(item) } return sum +} + +suspend fun Collection.filterSuspend( + predicate: suspend (A) -> Boolean +): Collection { + return this.filter { a -> + predicate(a) + } } \ No newline at end of file From 2939358e1a268620ae485966843759b77582527e Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sun, 24 Apr 2022 20:35:08 +0300 Subject: [PATCH 31/40] WIP: Fix build errors --- .../domain/action/transaction/AllTrnsAct.kt | 15 +++ .../domain/deprecated/logic/AccountCreator.kt | 11 +- .../domain/deprecated/logic/BudgetCreator.kt | 8 +- .../deprecated/logic/CategoryCreator.kt | 10 +- .../domain/deprecated/logic/LoanCreator.kt | 9 +- .../deprecated/logic/LoanRecordCreator.kt | 8 +- .../logic/SmartTitleSuggestionsLogic.kt | 3 + .../deprecated/logic/WalletAccountLogic.kt | 42 +++++--- .../java/com/ivy/wallet/ui/RootActivity.kt | 4 +- .../ivy/wallet/ui/paywall/PaywallViewModel.kt | 27 +++-- .../ui/planned/edit/EditPlannedViewModel.kt | 36 ++++--- .../planned/list/PlannedPaymentsViewModel.kt | 14 +-- .../ivy/wallet/ui/search/SearchViewModel.kt | 45 ++++---- .../wallet/ui/settings/SettingsViewModel.kt | 15 +-- .../level1/PieChartStatisticViewModel.kt | 101 ++++++++++-------- .../com/ivy/wallet/ui/test/TestViewModel.kt | 6 +- 16 files changed, 197 insertions(+), 157 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/AllTrnsAct.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AllTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AllTrnsAct.kt new file mode 100644 index 0000000000..0ce113479e --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AllTrnsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.io.persistence.dao.TransactionDao +import javax.inject.Inject + +class AllTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { + transactionDao.findAll() + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt index ef14a4ccc2..7791bfcc0f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt @@ -1,9 +1,10 @@ package com.ivy.wallet.domain.deprecated.logic +import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.core.Account -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.sync.item.TransactionSync -import com.ivy.wallet.domain.sync.uploader.AccountUploader +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.sync.item.TransactionSync +import com.ivy.wallet.domain.deprecated.sync.uploader.AccountUploader import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.utils.ioThread @@ -35,7 +36,7 @@ class AccountCreator( orderNum = accountDao.findMaxOrderNum() + 1, isSynced = false ) - accountDao.save(account) + accountDao.save(account.toEntity()) accountLogic.adjustBalance( account = account, @@ -64,7 +65,7 @@ class AccountCreator( ) ioThread { - accountDao.save(updatedAccount) + accountDao.save(updatedAccount.toEntity()) accountLogic.adjustBalance( account = updatedAccount, actualBalance = accountLogic.calculateAccountBalance(updatedAccount), diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt index d8fd672352..664e734120 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.core.Budget -import com.ivy.wallet.domain.logic.model.CreateBudgetData -import com.ivy.wallet.domain.sync.uploader.BudgetUploader +import com.ivy.wallet.domain.deprecated.logic.model.CreateBudgetData +import com.ivy.wallet.domain.deprecated.sync.uploader.BudgetUploader import com.ivy.wallet.io.persistence.dao.BudgetDao import com.ivy.wallet.utils.ioThread @@ -33,7 +33,7 @@ class BudgetCreator( isSynced = false ) - budgetDao.save(budget) + budgetDao.save(budget.toEntity()) budget } @@ -59,7 +59,7 @@ class BudgetCreator( try { ioThread { budgetDao.save( - updatedBudget.copy( + updatedBudget.toEntity().copy( isSynced = false ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt index fe558d25ea..e66343d983 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt @@ -1,8 +1,9 @@ package com.ivy.wallet.domain.deprecated.logic +import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.sync.uploader.CategoryUploader +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.sync.uploader.CategoryUploader import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.utils.ioThread @@ -31,8 +32,7 @@ class CategoryCreator( isSynced = false ) - categoryDao. - save(newCategory) + categoryDao.save(newCategory.toEntity()) newCategory } @@ -57,7 +57,7 @@ class CategoryCreator( try { ioThread { categoryDao.save( - updatedCategory.copy( + updatedCategory.toEntity().copy( isSynced = false ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt index 9ac205da7c..37719e297c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt @@ -1,8 +1,9 @@ package com.ivy.wallet.domain.deprecated.logic +import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.core.Loan -import com.ivy.wallet.domain.logic.model.CreateLoanData -import com.ivy.wallet.domain.sync.uploader.LoanUploader +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData +import com.ivy.wallet.domain.deprecated.sync.uploader.LoanUploader import com.ivy.wallet.io.persistence.dao.LoanDao import com.ivy.wallet.utils.ioThread import java.util.* @@ -38,7 +39,7 @@ class LoanCreator( accountId = data.account?.id ) loanId = item.id - dao.save(item) + dao.save(item.toEntity()) item } @@ -66,7 +67,7 @@ class LoanCreator( try { ioThread { dao.save( - updatedItem.copy( + updatedItem.toEntity().copy( isSynced = false ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt index 52ec399a74..29edb414bf 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.core.LoanRecord -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData -import com.ivy.wallet.domain.sync.uploader.LoanRecordUploader +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.sync.uploader.LoanRecordUploader import com.ivy.wallet.io.persistence.dao.LoanRecordDao import com.ivy.wallet.utils.ioThread import java.util.* @@ -36,7 +36,7 @@ class LoanRecordCreator( convertedAmount = data.convertedAmount ) - dao.save(item) + dao.save(item.toEntity()) item } @@ -63,7 +63,7 @@ class LoanRecordCreator( try { ioThread { dao.save( - updatedItem.copy( + updatedItem.toEntity().copy( isSynced = false ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt index c516a3bac8..875eedfeac 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt @@ -28,6 +28,7 @@ class SmartTitleSuggestionsLogic( if (title != null && title.isNotEmpty()) { //suggest by title val suggestionsByTitle = transactionDao.findAllByTitleMatchingPattern("${title}%") + .map { it.toDomain() } .extractUniqueTitles() .sortedByMostUsedFirst { transactionDao.countByTitleMatchingPattern("${it}%") @@ -45,6 +46,7 @@ class SmartTitleSuggestionsLogic( .findAllByCategory( categoryId = categoryId ) + .map { it.toDomain() } //exclude already suggested suggestions so they're ordered by priority at the end .extractUniqueTitles(excludeSuggestions = suggestions) .sortedByMostUsedFirst { @@ -67,6 +69,7 @@ class SmartTitleSuggestionsLogic( .findAllByAccount( accountId = accountId ) + .map { it.toDomain() } //exclude already suggested suggestions so they're ordered by priority at the end .extractUniqueTitles(excludeSuggestions = suggestions) .sortedByMostUsedFirst { diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt index 4aa7e2ef26..6c090c0a00 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt @@ -5,12 +5,14 @@ import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.stringRes import com.ivy.wallet.ui.onboarding.model.FromToTimeRange +import com.ivy.wallet.ui.onboarding.model.filterOverdue +import com.ivy.wallet.ui.onboarding.model.filterUpcoming import com.ivy.wallet.utils.timeNowUTC import java.time.LocalDateTime import kotlin.math.abs @@ -44,11 +46,12 @@ class WalletAccountLogic( Transaction( type = TransactionType.INCOME, title = adjustTransactionTitle, - amount = diff.absoluteValue, + amount = diff.absoluteValue.toBigDecimal(), + toAmount = diff.absoluteValue.toBigDecimal(), dateTime = timeNowUTC(), accountId = account.id, isSynced = trnIsSyncedFlag - ) + ).toEntity() ) } finalDiff > 0 -> { @@ -57,11 +60,12 @@ class WalletAccountLogic( Transaction( type = TransactionType.EXPENSE, title = adjustTransactionTitle, - amount = diff.absoluteValue, + amount = diff.absoluteValue.toBigDecimal(), + toAmount = diff.absoluteValue.toBigDecimal(), dateTime = timeNowUTC(), accountId = account.id, isSynced = trnIsSyncedFlag - ) + ).toEntity() ) } } @@ -110,17 +114,19 @@ class WalletAccountLogic( before: LocalDateTime? ): Double { return transactionDao.findAllByTypeAndAccount(TransactionType.INCOME, account.id) + .map { it.toDomain() } .filterHappenedTransactions( before = before ) - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } .plus( //transfers in transactionDao.findAllTransfersToAccount(account.id) + .map { it.toDomain() } .filterHappenedTransactions( before = before ) - .sumOf { it.toAmount ?: it.amount } + .sumOf { it.toAmount.toDouble() } ) } @@ -129,20 +135,22 @@ class WalletAccountLogic( before: LocalDateTime? ): Double { return transactionDao.findAllByTypeAndAccount(TransactionType.EXPENSE, account.id) + .map { it.toDomain() } .filterHappenedTransactions( before = before ) - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } .plus( //transfer out transactionDao.findAllByTypeAndAccount( type = TransactionType.TRANSFER, accountId = account.id ) + .map { it.toDomain() } .filterHappenedTransactions( before = before ) - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } ) } @@ -180,29 +188,31 @@ class WalletAccountLogic( fun calculateUpcomingIncome(account: Account, range: FromToTimeRange): Double = upcoming(account, range = range) .filter { it.type == TransactionType.INCOME } - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } fun calculateUpcomingExpenses(account: Account, range: FromToTimeRange): Double = upcoming(account = account, range = range) .filter { it.type == TransactionType.EXPENSE } - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } fun calculateOverdueIncome(account: Account, range: FromToTimeRange): Double = overdue(account, range = range) .filter { it.type == TransactionType.INCOME } - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } fun calculateOverdueExpenses(account: Account, range: FromToTimeRange): Double = overdue(account, range = range) .filter { it.type == TransactionType.EXPENSE } - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } fun upcoming(account: Account, range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByAccount( accountId = account.id, startDate = range.upcomingFrom(), endDate = range.to() - ).filterUpcoming() + ) + .map { it.toDomain() } + .filterUpcoming() } @@ -211,6 +221,8 @@ class WalletAccountLogic( accountId = account.id, startDate = range.from(), endDate = range.overdueTo() - ).filterOverdue() + ) + .map { it.toDomain() } + .filterOverdue() } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt b/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt index 0b0a0f927d..632c72f631 100644 --- a/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt +++ b/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt @@ -47,11 +47,10 @@ import com.ivy.wallet.BuildConfig import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.logic.CustomerJourneyLogic +import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic import com.ivy.wallet.ui.analytics.AnalyticsReport import com.ivy.wallet.ui.applocked.AppLockedScreen import com.ivy.wallet.ui.balance.BalanceScreen -import com.ivy.wallet.ui.bankintegrations.ConnectBankScreen import com.ivy.wallet.ui.budget.BudgetScreen import com.ivy.wallet.ui.category.CategoriesScreen import com.ivy.wallet.ui.charts.ChartsScreen @@ -204,7 +203,6 @@ class RootActivity : AppCompatActivity() { is Charts -> ChartsScreen(screen = screen) is AnalyticsReport -> AnalyticsReport(screen = screen) is Import -> ImportCSVScreen(screen = screen) - is ConnectBank -> ConnectBankScreen(screen = screen) is Report -> ReportScreen(screen = screen) is BudgetScreen -> BudgetScreen(screen = screen) is Loans -> LoansScreen(screen = screen) diff --git a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt index b5d0a25420..e91de323f9 100644 --- a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt @@ -7,21 +7,20 @@ import com.android.billingclient.api.Purchase import com.ivy.wallet.android.billing.IvyBilling import com.ivy.wallet.android.billing.Plan import com.ivy.wallet.android.billing.PlanType +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.budget.BudgetsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.loan.LoansAct import com.ivy.wallet.domain.data.analytics.AnalyticsEvent import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Budget import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Loan -import com.ivy.wallet.domain.logic.PaywallLogic +import com.ivy.wallet.domain.deprecated.logic.PaywallLogic import com.ivy.wallet.io.network.IvyAnalytics -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.BudgetDao -import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.io.persistence.dao.LoanDao import com.ivy.wallet.ui.Paywall import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.utils.asLiveData -import com.ivy.wallet.utils.ioThread import com.ivy.wallet.utils.sendToCrashlytics import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch @@ -33,10 +32,10 @@ class PaywallViewModel @Inject constructor( private val ivyBilling: IvyBilling, private val paywallLogic: PaywallLogic, private val ivyAnalytics: IvyAnalytics, - private val categoryDao: CategoryDao, - private val accountDao: AccountDao, - private val budgetDao: BudgetDao, - private val loanDao: LoanDao + private val categoriesAct: CategoriesAct, + private val accountsAct: AccountsAct, + private val budgetsAct: BudgetsAct, + private val loansAct: LoansAct ) : ViewModel() { private val _plans = MutableLiveData>() @@ -90,10 +89,10 @@ class PaywallViewModel @Inject constructor( ) viewModelScope.launch { - _categories.value = ioThread { categoryDao.findAll() }!! - _accounts.value = ioThread { accountDao.findAll() }!! - _budgets.value = ioThread { budgetDao.findAll() }!! - _loans.value = ioThread { loanDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! + _accounts.value = accountsAct(Unit)!! + _budgets.value = budgetsAct(Unit)!! + _loans.value = loansAct(Unit)!! ivyAnalytics.logEvent( when (screen.paywallReason) { diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt index 65be48952b..5273de8870 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt @@ -4,19 +4,21 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.logic.CategoryCreator +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsGenerator +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.sync.item.TransactionSync +import com.ivy.wallet.domain.deprecated.sync.uploader.PlannedPaymentRuleUploader import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.logic.CategoryCreator -import com.ivy.wallet.domain.logic.PlannedPaymentsGenerator -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.sync.item.TransactionSync -import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.IvyWalletCtx @@ -42,7 +44,9 @@ class EditPlannedViewModel @Inject constructor( private val plannedPaymentRuleUploader: PlannedPaymentRuleUploader, private val plannedPaymentsGenerator: PlannedPaymentsGenerator, private val categoryCreator: CategoryCreator, - private val accountCreator: AccountCreator + private val accountCreator: AccountCreator, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct ) : ViewModel() { private val _transactionType = MutableLiveData() @@ -95,19 +99,19 @@ class EditPlannedViewModel @Inject constructor( editMode = screen.plannedPaymentRuleId != null - val accounts = ioThread { accountDao.findAll() }!! + val accounts = accountsAct(Unit) if (accounts.isEmpty()) { nav.back() return@launch } _accounts.value = accounts - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! reset() loadedRule = screen.plannedPaymentRuleId?.let { - ioThread { plannedPaymentRuleDao.findById(it)!! } + ioThread { plannedPaymentRuleDao.findById(it)!!.toDomain() } } ?: PlannedPaymentRule( startDate = null, intervalN = null, @@ -137,10 +141,10 @@ class EditPlannedViewModel @Inject constructor( _intervalType.value = rule.intervalType _initialTitle.value = rule.title _description.value = rule.description - val selectedAccount = ioThread { accountDao.findById(rule.accountId)!! } + val selectedAccount = ioThread { accountDao.findById(rule.accountId)!!.toDomain() } _account.value = selectedAccount _category.value = rule.categoryId?.let { - ioThread { categoryDao.findById(rule.categoryId) } + ioThread { categoryDao.findById(rule.categoryId)?.toDomain() } } _amount.value = rule.amount @@ -262,7 +266,7 @@ class EditPlannedViewModel @Inject constructor( isSynced = false ) - plannedPaymentRuleDao.save(loadedRule()) + plannedPaymentRuleDao.save(loadedRule().toEntity()) plannedPaymentsGenerator.generate(loadedRule()) } @@ -327,7 +331,7 @@ class EditPlannedViewModel @Inject constructor( fun createCategory(data: CreateCategoryData) { viewModelScope.launch { categoryCreator.createCategory(data) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! onCategoryChanged(it) } @@ -338,7 +342,7 @@ class EditPlannedViewModel @Inject constructor( viewModelScope.launch { accountCreator.createAccount(data) { EventBus.getDefault().post(AccountsUpdatedEvent()) - _accounts.value = ioThread { accountDao.findAll() }!! + _accounts.value = accountsAct(Unit)!! } } } diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt index 60375340a5..f48a58e551 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt @@ -3,13 +3,14 @@ package com.ivy.wallet.ui.planned.list import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.PlannedPaymentRule -import com.ivy.wallet.domain.logic.PlannedPaymentsLogic +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.io.persistence.dao.PlannedPaymentRuleDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.PlannedPayments import com.ivy.wallet.utils.TestIdlingResource @@ -22,10 +23,11 @@ import javax.inject.Inject @HiltViewModel class PlannedPaymentsViewModel @Inject constructor( private val settingsDao: SettingsDao, - private val plannedPaymentRuleDao: PlannedPaymentRuleDao, private val categoryDao: CategoryDao, private val accountDao: AccountDao, - private val plannedPaymentsLogic: PlannedPaymentsLogic + private val plannedPaymentsLogic: PlannedPaymentsLogic, + private val categoriesAct: CategoriesAct, + private val accountsAct: AccountsAct ) : ViewModel() { private val _currency = MutableLiveData() @@ -65,8 +67,8 @@ class PlannedPaymentsViewModel @Inject constructor( _currency.value = settings.currency - _categories.value = ioThread { categoryDao.findAll() }!! - _accounts.value = ioThread { accountDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! + _accounts.value = accountsAct(Unit)!! _oneTime.value = ioThread { plannedPaymentsLogic.oneTime() }!! _oneTimeIncome.value = ioThread { plannedPaymentsLogic.oneTimeIncome() }!! diff --git a/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt index 95a52146c2..fda9410402 100644 --- a/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt @@ -2,15 +2,14 @@ package com.ivy.wallet.ui.search import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.transaction.AllTrnsAct +import com.ivy.wallet.domain.action.transaction.TrnsWithDateDivsAct import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.withDateDividers -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.io.persistence.dao.SettingsDao -import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.utils.TestIdlingResource import com.ivy.wallet.utils.getDefaultFIATCurrency import com.ivy.wallet.utils.ioThread @@ -22,11 +21,11 @@ import javax.inject.Inject @HiltViewModel class SearchViewModel @Inject constructor( - private val transactionDao: TransactionDao, - private val settingsDao: SettingsDao, - private val categoryDao: CategoryDao, - private val accountDao: AccountDao, - private val exchangeRatesLogic: ExchangeRatesLogic + private val trnsWithDateDivsAct: TrnsWithDateDivsAct, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val baseCurrencyAct: BaseCurrencyAct, + private val allTrnsAct: AllTrnsAct ) : ViewModel() { private val _baseCurrencyCode = MutableStateFlow(getDefaultFIATCurrency().currencyCode) @@ -47,28 +46,24 @@ class SearchViewModel @Inject constructor( viewModelScope.launch { TestIdlingResource.increment() - _baseCurrencyCode.value = ioThread { - settingsDao.findFirst().currency - } + _baseCurrencyCode.value = baseCurrencyAct(Unit) - _categories.value = ioThread { - categoryDao.findAll() - } + _categories.value = categoriesAct(Unit) - _accounts.value = ioThread { - accountDao.findAll() - } + _accounts.value = accountsAct(Unit) _transactions.value = ioThread { - transactionDao.findAll() + val trns = allTrnsAct(Unit) .filter { it.title.matchesQuery(normalizedQuery) || it.description.matchesQuery(normalizedQuery) - }.withDateDividers( - exchangeRatesLogic = exchangeRatesLogic, - accountDao = accountDao, - settingsDao = settingsDao + } + trnsWithDateDivsAct( + TrnsWithDateDivsAct.Input( + baseCurrency = baseCurrencyCode.value, + transactions = trns ) + ) } TestIdlingResource.decrement() diff --git a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt index 4110a67f91..fda25c3cd5 100644 --- a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt @@ -6,11 +6,11 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.data.analytics.AnalyticsEvent import com.ivy.wallet.domain.data.core.User -import com.ivy.wallet.domain.logic.LogoutLogic -import com.ivy.wallet.domain.logic.csv.ExportCSVLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.zip.ExportZipLogic -import com.ivy.wallet.domain.sync.IvySync +import com.ivy.wallet.domain.deprecated.logic.LogoutLogic +import com.ivy.wallet.domain.deprecated.logic.csv.ExportCSVLogic +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.zip.ExportZipLogic +import com.ivy.wallet.domain.deprecated.sync.IvySync import com.ivy.wallet.io.network.FCMClient import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.network.IvySession @@ -88,12 +88,13 @@ class SettingsViewModel @Inject constructor( _user.value = ioThread { val userId = ivySession.getUserIdSafe() - if (userId != null) userDao.findById(userId) else null + if (userId != null) userDao.findById(userId)?.toDomain() else null } _currencyCode.value = settings.currency _lockApp.value = sharedPrefs.getBoolean(SharedPrefs.APP_LOCK_ENABLED, false) - _hideCurrentBalance.value = sharedPrefs.getBoolean(SharedPrefs.HIDE_CURRENT_BALANCE, false) + _hideCurrentBalance.value = + sharedPrefs.getBoolean(SharedPrefs.HIDE_CURRENT_BALANCE, false) _showNotifications.value = sharedPrefs.getBoolean(SharedPrefs.SHOW_NOTIFICATIONS, true) diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt index 66b35583b0..8a46a42f72 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt @@ -7,13 +7,9 @@ import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency -import com.ivy.wallet.domain.pure.category.calculateCategoryExpenseWithAccountFilters -import com.ivy.wallet.domain.pure.category.calculateCategoryIncomeWithAccountFilters +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.currency.sumInBaseCurrency import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.pure.wallet.calculateWalletExpenseWithAccountFilters -import com.ivy.wallet.domain.pure.wallet.calculateWalletIncomeWithAccountFilters import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao @@ -22,7 +18,6 @@ import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.PieChartStatistic import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.ui.onboarding.model.TimePeriod -import com.ivy.wallet.ui.onboarding.model.toCloseTimeRange import com.ivy.wallet.ui.theme.IvyLight import com.ivy.wallet.utils.dateNowUTC import com.ivy.wallet.utils.ioThread @@ -76,7 +71,11 @@ class PieChartStatisticViewModel @Inject constructor( private var filterExcluded = true private val transfersCategory = - Category(stringRes(R.string.account_transfers), color = IvyLight.toArgb(), icon = "transfer") + Category( + stringRes(R.string.account_transfers), + color = IvyLight.toArgb(), + icon = "transfer" + ) fun start( screen: PieChartStatistic @@ -149,7 +148,7 @@ class PieChartStatisticViewModel @Inject constructor( accountDao = walletDAOs.accountDao ) - CategoryAmount(category, amount, trans) + CategoryAmount(category?.toDomain(), amount, trans) } }.awaitAll().sortedByDescending { it.amount } } @@ -183,7 +182,7 @@ class PieChartStatisticViewModel @Inject constructor( exchangeRatesLogic.toAmountBaseCurrency( transaction = it, baseCurrency = baseCurrencyCode.value, - accounts = walletDAOs.accountDao.findAll() + accounts = walletDAOs.accountDao.findAll().map { it.toDomain() } ) } CategoryAmount(transfersCategory, amt, trans) @@ -211,22 +210,26 @@ class PieChartStatisticViewModel @Inject constructor( _totalAmount.value = ioThread { when (type) { TransactionType.INCOME -> { - calculateWalletIncomeWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - range = range.toCloseTimeRange(), - accountIdFilterList = accountFilterList, - filterExcluded = filterExcluded - ).value.toDouble() + //TODO: Fix that +// calculateWalletIncomeWithAccountFilters( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode.value, +// range = range.toCloseTimeRange(), +// accountIdFilterList = accountFilterList, +// filterExcluded = filterExcluded +// ).value.toDouble() + 0.0 } TransactionType.EXPENSE -> { - calculateWalletExpenseWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - range = range.toCloseTimeRange(), - accountIdFilterList = accountFilterList, - filterExcluded = filterExcluded - ).value.toDouble() + //TODO: Fix that +// calculateWalletExpenseWithAccountFilters( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode.value, +// range = range.toCloseTimeRange(), +// accountIdFilterList = accountFilterList, +// filterExcluded = filterExcluded +// ).value.toDouble() + 0.0 } else -> error("not supported transactionType - $type") } @@ -247,22 +250,26 @@ class PieChartStatisticViewModel @Inject constructor( category = category, amount = when (type) { TransactionType.INCOME -> { - calculateCategoryIncomeWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - categoryId = category?.id, - accountIdFilterList = accountFilterList, - range = range.toCloseTimeRange() - ).toDouble() + //TODO: Fix that +// calculateCategoryIncomeWithAccountFilters( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode.value, +// categoryId = category?.id, +// accountIdFilterList = accountFilterList, +// range = range.toCloseTimeRange() +// ).toDouble() + 0.0 } TransactionType.EXPENSE -> { - calculateCategoryExpenseWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - categoryId = category?.id, - accountIdList = accountFilterList, - range = range.toCloseTimeRange() - ).toDouble() + //TODO: Fix that +// calculateCategoryExpenseWithAccountFilters( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode.value, +// categoryId = category?.id, +// accountIdList = accountFilterList, +// range = range.toCloseTimeRange() +// ).toDouble() + 0.0 } else -> error("not supported transactionType - $type") } @@ -329,15 +336,17 @@ class PieChartStatisticViewModel @Inject constructor( ): List { return scopedIOThread { scope -> if (fetchCategoriesFromTransactions) { - transactionDao.findAllBetween(timeRange.from(), timeRange.to()).filter { - it.categoryId != null - }.map { - scope.async { - categoryDao.findById(it.categoryId!!) - } - }.awaitAll().filterNotNull().distinctBy { it.id } + transactionDao.findAllBetween(timeRange.from(), timeRange.to()) + .map { it.toDomain() } + .filter { + it.categoryId != null + }.map { + scope.async { + categoryDao.findById(it.categoryId!!)?.toDomain() + } + }.awaitAll().filterNotNull().distinctBy { it.id } } else - categoryDao.findAll() + categoryDao.findAll().map { it.toDomain() } } } diff --git a/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt index 99c33b991a..a988e7664b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt @@ -4,8 +4,8 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.data.core.User -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic -import com.ivy.wallet.domain.sync.item.CategorySync +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.sync.item.CategorySync import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.persistence.dao.UserDao import com.ivy.wallet.utils.TestIdlingResource @@ -32,7 +32,7 @@ class TestViewModel @Inject constructor( _user.value = ioThread { val userId = ivySession.getUserIdSafe() - if (userId != null) userDao.findById(userId) else null + if (userId != null) userDao.findById(userId)?.toDomain() else null } TestIdlingResource.decrement() From 5c3abc449dfbc8435a1e6cd500236e403d3594fc Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sun, 24 Apr 2022 21:12:19 +0300 Subject: [PATCH 32/40] Make the project builds! (certainly it's unstable) --- .../wallet/domain/data/core/Transaction.kt | 2 +- .../logic/PlannedPaymentsGenerator.kt | 4 +- .../deprecated/logic/PlannedPaymentsLogic.kt | 20 +-- .../deprecated/logic/PreloadDataLogic.kt | 10 +- .../deprecated/logic/WalletAccountLogic.kt | 30 +---- .../deprecated/logic/WalletCategoryLogic.kt | 52 ++++---- .../deprecated/logic/csv/CSVImporter.kt | 24 ++-- .../domain/deprecated/logic/csv/CSVMapper.kt | 7 +- .../deprecated/logic/csv/CSVNormalizer.kt | 2 +- .../deprecated/logic/csv/ExportCSVLogic.kt | 4 +- .../logic/currency/ExchangeRatesLogic.kt | 12 +- .../logic/loantrasactions/LTLoanMapper.kt | 40 +++--- .../loantrasactions/LTLoanRecordMapper.kt | 14 +-- .../loantrasactions/LoanTransactionsCore.kt | 27 ++-- .../deprecated/logic/zip/ExportZipLogic.kt | 41 ++++--- .../wallet/domain/pure/charts/WalletCharts.kt | 14 +-- .../pure/transaction/TrnDateDividers.kt | 26 ++++ .../com/ivy/wallet/io/network/IvySession.kt | 2 +- .../com/ivy/wallet/io/network/RestClient.kt | 3 - .../service/BankIntegrationsService.kt | 26 ---- .../ivy/wallet/ui/csvimport/ImportScreen.kt | 4 +- .../wallet/ui/csvimport/flow/ImportFrom.kt | 7 +- .../ui/csvimport/flow/ImportResultUI.kt | 4 +- .../flow/instructions/ImportInstructions.kt | 3 +- .../com/ivy/wallet/ui/home/CustomerJourney.kt | 4 +- .../ui/loandetails/LoanDetailsScreen.kt | 6 +- .../java/com/ivy/wallet/ui/main/MainScreen.kt | 2 +- .../wallet/ui/onboarding/OnboardingScreen.kt | 4 +- .../ui/onboarding/components/Suggestions.kt | 4 +- .../ui/onboarding/steps/OnboardingAccounts.kt | 2 +- .../onboarding/steps/OnboardingCategories.kt | 2 +- .../onboarding/viewmodel/OnboardingRouter.kt | 16 +-- .../ui/planned/edit/EditPlannedScreen.kt | 4 +- .../level2/ItemStatisticViewModel.kt | 116 +++++++++++------- .../ivy/wallet/ui/theme/modal/BudgetModal.kt | 2 +- .../ivy/wallet/ui/theme/modal/LoanModal.kt | 4 +- .../wallet/ui/theme/modal/LoanRecordModal.kt | 6 +- .../ui/theme/transaction/TransactionCard.kt | 14 +-- 38 files changed, 280 insertions(+), 284 deletions(-) delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/service/BankIntegrationsService.kt diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt index 86d2734698..28b810756c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt @@ -14,7 +14,7 @@ data class Transaction( val type: TransactionType, val amount: BigDecimal, val toAccountId: UUID? = null, - val toAmount: BigDecimal, + val toAmount: BigDecimal = amount, val title: String? = null, val description: String? = null, val dateTime: LocalDateTime? = null, diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt index b89bc936fe..3f028b636f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt @@ -76,7 +76,7 @@ class PlannedPaymentsGenerator( accountId = rule.accountId, recurringRuleId = rule.id, categoryId = rule.categoryId, - amount = rule.amount, + amount = rule.amount.toBigDecimal(), title = rule.title, description = rule.description, dueDate = dueDate, @@ -84,7 +84,7 @@ class PlannedPaymentsGenerator( toAccountId = null, isSynced = false - ) + ).toEntity() ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt index 8ff123dabe..9be79816a1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt @@ -5,10 +5,10 @@ import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.currency.sumByDoublePlannedInBaseCurrency -import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader -import com.ivy.wallet.domain.sync.uploader.TransactionUploader +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.currency.sumByDoublePlannedInBaseCurrency +import com.ivy.wallet.domain.deprecated.sync.uploader.PlannedPaymentRuleUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.PlannedPaymentRuleDao import com.ivy.wallet.io.persistence.dao.SettingsDao @@ -40,9 +40,9 @@ class PlannedPaymentsLogic( endDate = range.to() ).sumOf { val amount = exchangeRatesLogic.amountBaseCurrency( - transaction = it, + transaction = it.toDomain(), baseCurrency = baseCurrency, - accounts = accounts + accounts = accounts.map { it.toDomain() } ) when (it.type) { @@ -54,7 +54,7 @@ class PlannedPaymentsLogic( } fun oneTime(): List { - return plannedPaymentRuleDao.findAllByOneTime(oneTime = true) + return plannedPaymentRuleDao.findAllByOneTime(oneTime = true).map { it.toDomain() } } fun oneTimeIncome(): Double { @@ -78,7 +78,7 @@ class PlannedPaymentsLogic( } fun recurring(): List = - plannedPaymentRuleDao.findAllByOneTime(oneTime = false) + plannedPaymentRuleDao.findAllByOneTime(oneTime = false).map { it.toDomain() } fun recurringIncome(): Double { return recurring() @@ -100,7 +100,7 @@ class PlannedPaymentsLogic( amountForMonthInBaseCurrency( plannedPayment = it, baseCurrency = baseCurrency, - accounts = accounts + accounts = accounts.map { it.toDomain() } ) } } @@ -166,7 +166,7 @@ class PlannedPaymentsLogic( } ioThread { - transactionDao.save(paidTransaction) + transactionDao.save(paidTransaction.toEntity()) if (plannedPaymentRule != null && plannedPaymentRule.oneTime) { //delete paid oneTime planned payment rules diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt index da2d9c289f..2ebd1831f5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt @@ -3,8 +3,8 @@ package com.ivy.wallet.domain.deprecated.logic import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.ui.onboarding.model.AccountBalance @@ -41,8 +41,8 @@ class PreloadDataLogic( isSynced = false ) - accountsDao.save(cash) - accountsDao.save(bank) + accountsDao.save(cash.toEntity()) + accountsDao.save(bank.toEntity()) } fun accountSuggestions(baseCurrency: String): List = listOf( @@ -152,7 +152,7 @@ class PreloadDataLogic( isSynced = false ) - categoryDao.save(category) + categoryDao.save(category.toEntity()) } fun categorySuggestions(): List = preloadCategoriesCreateData() diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt index 6c090c0a00..453d65b76f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt @@ -1,7 +1,5 @@ package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.R -import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction @@ -9,7 +7,6 @@ import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao -import com.ivy.wallet.stringRes import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.ui.onboarding.model.filterOverdue import com.ivy.wallet.ui.onboarding.model.filterUpcoming @@ -31,7 +28,7 @@ class WalletAccountLogic( actualBalance: Double = calculateAccountBalance(account), newBalance: Double, - adjustTransactionTitle: String = stringRes(R.string.adjust_balance), + adjustTransactionTitle: String = "Adjust balance", isFiat: Boolean? = null, trnIsSyncedFlag: Boolean = false, //TODO: Remove this once Bank Integration trn sync is properly implemented @@ -71,31 +68,6 @@ class WalletAccountLogic( } } - fun historyForAccount(account: Account, range: FromToTimeRange): List { - val startDate = range.from() - val endDate = range.to() - - return transactionDao - .findAllByAccountAndBetween( - accountId = account.id, - startDate = startDate, - endDate = endDate - ) - .plus( - transactionDao.findAllToAccountAndBetween( - toAccountId = account.id, - startDate = startDate, - endDate = endDate - ) - ) - .sortedByDescending { it.dateTime } - .withDateDividers( - exchangeRatesLogic = exchangeRatesLogic, - accountDao = accountDao, - settingsDao = settingsDao - ) - } - fun calculateAccountBalance( account: Account, before: LocalDateTime? = null diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt index 292d08698f..e17d498e3c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt @@ -4,12 +4,15 @@ import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.currency.sumInBaseCurrency +import com.ivy.wallet.domain.pure.transaction.withDateDividers import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.ui.onboarding.model.FromToTimeRange +import com.ivy.wallet.ui.onboarding.model.filterOverdue +import com.ivy.wallet.ui.onboarding.model.filterUpcoming import java.util.* @Deprecated("Migrate to FP Style") @@ -27,7 +30,7 @@ class WalletCategoryLogic( transactions: List = emptyList() ): Double { val baseCurrency = settingsDao.findFirst().currency - val accounts = accountDao.findAll() + val accounts = accountDao.findAll().map { it.toDomain() } return historyByCategory( category, @@ -61,7 +64,7 @@ class WalletCategoryLogic( type = TransactionType.INCOME, startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } .filter { accountFilterSet.isEmpty() || accountFilterSet.contains(it.accountId) } @@ -101,7 +104,7 @@ class WalletCategoryLogic( ) .filter { accountFilterSet.isEmpty() || accountFilterSet.contains(it.accountId) - } + }.map { it.toDomain() } .sumInBaseCurrency( exchangeRatesLogic = exchangeRatesLogic, settingsDao = settingsDao, @@ -135,7 +138,7 @@ class WalletCategoryLogic( type = TransactionType.INCOME, startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } .sumInBaseCurrency( exchangeRatesLogic = exchangeRatesLogic, settingsDao = settingsDao, @@ -149,7 +152,7 @@ class WalletCategoryLogic( type = TransactionType.EXPENSE, startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } .sumInBaseCurrency( exchangeRatesLogic = exchangeRatesLogic, settingsDao = settingsDao, @@ -157,19 +160,8 @@ class WalletCategoryLogic( ) } - fun historyByCategoryWithDateDividers( - category: Category, - range: FromToTimeRange - ): List { - return historyByCategory(category, range) - .withDateDividers( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ) - } - fun historyByCategoryAccountWithDateDividers( + suspend fun historyByCategoryAccountWithDateDividers( category: Category, range: FromToTimeRange, accountFilterSet: Set, @@ -199,7 +191,7 @@ class WalletCategoryLogic( categoryId = category.id, startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } } return trans.filter { @@ -207,12 +199,12 @@ class WalletCategoryLogic( } } - fun historyUnspecified(range: FromToTimeRange): List { + suspend fun historyUnspecified(range: FromToTimeRange): List { return transactionDao .findAllUnspecifiedAndBetween( startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } .withDateDividers( exchangeRatesLogic = exchangeRatesLogic, settingsDao = settingsDao, @@ -266,14 +258,18 @@ class WalletCategoryLogic( categoryId = category.id, startDate = range.upcomingFrom(), endDate = range.to() - ).filterUpcoming() + ) + .map { it.toDomain() } + .filterUpcoming() } fun upcomingUnspecified(range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByCategoryUnspecified( startDate = range.upcomingFrom(), endDate = range.to() - ).filterUpcoming() + ) + .map { it.toDomain() } + .filterUpcoming() } fun calculateOverdueIncomeByCategory(category: Category, range: FromToTimeRange): Double { @@ -322,14 +318,18 @@ class WalletCategoryLogic( categoryId = category.id, startDate = range.from(), endDate = range.overdueTo() - ).filterOverdue() + ) + .map { it.toDomain() } + .filterOverdue() } fun overdueUnspecified(range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByCategoryUnspecified( startDate = range.from(), endDate = range.overdueTo() - ).filterOverdue() + ) + .map { it.toDomain() } + .filterOverdue() } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt index 6dadc36b44..cd36a3f8e9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt @@ -6,9 +6,9 @@ import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.csv.model.CSVRow -import com.ivy.wallet.domain.logic.csv.model.ImportResult -import com.ivy.wallet.domain.logic.csv.model.RowMapping +import com.ivy.wallet.domain.deprecated.logic.csv.model.CSVRow +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.RowMapping import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao @@ -78,10 +78,10 @@ class CSVImporter( newCategoryColorIndex = 0 newAccountColorIndex = 0 - accounts = accountDao.findAll() + accounts = accountDao.findAll().map { it.toDomain() } val initialAccountsCount = accounts.size - categories = categoryDao.findAll() + categories = categoryDao.findAll().map { it.toDomain() } val initialCategoriesCount = categories.size val baseCurrency = settingsDao.findFirst().currency @@ -120,7 +120,7 @@ class CSVImporter( val progressPercent = if (rowsCount > 0) index / transactions.size.toDouble() else 0.0 onProgress(0.5 + progressPercent / 2) - transactionDao.save(transaction) + transactionDao.save(transaction.toEntity()) } return ImportResult( @@ -212,10 +212,10 @@ class CSVImporter( Transaction( id = id, type = type, - amount = amount, + amount = amount.toBigDecimal(), accountId = account.id, toAccountId = toAccount?.id, - toAmount = toAmount, + toAmount = toAmount?.toBigDecimal() ?: amount.toBigDecimal(), dateTime = dateTime, dueDate = dueDate, categoryId = category?.id, @@ -444,8 +444,8 @@ class CSVImporter( icon = icon, orderNum = orderNum ?: accountDao.findMaxOrderNum() + 1 ) - accountDao.save(newAccount) - accounts = accountDao.findAll() + accountDao.save(newAccount.toEntity()) + accounts = accountDao.findAll().map { it.toDomain() } return newAccount } @@ -493,8 +493,8 @@ class CSVImporter( icon = icon, orderNum = orderNum ?: categoryDao.findMaxOrderNum() + 1 ) - categoryDao.save(newCategory) - categories = categoryDao.findAll() + categoryDao.save(newCategory.toEntity()) + categories = categoryDao.findAll().map { it.toDomain() } return newCategory } diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt index 61ddd35155..98c35a0015 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt @@ -2,9 +2,10 @@ package com.ivy.wallet.domain.deprecated.logic.csv import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.csv.model.ImportType -import com.ivy.wallet.domain.logic.csv.model.JoinResult -import com.ivy.wallet.domain.logic.csv.model.RowMapping +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType +import com.ivy.wallet.domain.deprecated.logic.csv.model.JoinResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.RowMapping +import com.ivy.wallet.utils.toLowerCaseLocal class CSVMapper { diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt index 3b96b1a64f..4f1b4389c3 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.domain.deprecated.logic.csv -import com.ivy.wallet.domain.logic.csv.model.ImportType +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType class CSVNormalizer { diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt index a0c366f698..2c80a97bcc 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt @@ -31,7 +31,7 @@ class ExportCSVLogic( suspend fun exportToFile( context: Context, fileUri: Uri, - exportScope: () -> List = { + exportScope: suspend () -> List = { transactionDao.findAll().map { it.toDomain() } } ) { @@ -49,7 +49,7 @@ class ExportCSVLogic( } private suspend fun generateCSV( - exportScope: () -> List + exportScope: suspend () -> List ): String { return ioThread { val accountMap = accountDao diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt index 831fbc3714..374110e9bc 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt @@ -37,7 +37,7 @@ class ExchangeRatesLogic( baseCurrency = baseCurrency, currency = currency, rate = rate - ) + ).toEntity() ) } } catch (e: Exception) { @@ -65,7 +65,7 @@ class ExchangeRatesLogic( accounts: List //helper ): Double { return amountBaseCurrency( - amount = transaction.amount, + amount = transaction.amount.toDouble(), accountId = transaction.accountId, baseCurrency = baseCurrency, accounts = accounts @@ -79,10 +79,10 @@ class ExchangeRatesLogic( ): Double { val amount = transaction.toAmount ?: transaction.amount val toCurrency = accounts.find { it.id == transaction.toAccountId }?.currency - ?: return amount // no conversion + ?: return amount.toDouble() // no conversion return amountBaseCurrency( - amount = amount, + amount = amount.toDouble(), amountCurrency = toCurrency, baseCurrency = baseCurrency ) @@ -162,7 +162,7 @@ fun Iterable.sumInBaseCurrency( exchangeRatesLogic.amountBaseCurrency( transaction = it, baseCurrency = baseCurrency, - accounts = accounts + accounts = accounts.map { it.toDomain() } ) } } @@ -180,7 +180,7 @@ fun Iterable.sumByDoublePlannedInBaseCurrency( exchangeRatesLogic.amountBaseCurrency( plannedPayment = it, baseCurrency = baseCurrency, - accounts = accounts + accounts = accounts.map { it.toDomain() } ) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt index ba088576e7..170336fe36 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt @@ -6,7 +6,7 @@ import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.domain.data.core.LoanRecord import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.model.CreateLoanData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData import com.ivy.wallet.utils.computationThread import com.ivy.wallet.utils.scopedIOThread import kotlinx.coroutines.async @@ -60,7 +60,7 @@ class LTLoanMapper( newLoanAccountId: UUID?, loanId: UUID ) { - val accounts = ltCore.fetchAccounts() + val accounts = ltCore.fetchAccounts().map { it.toDomain() } computationThread { if (oldLoanAccountId == newLoanAccountId || oldLoanAccountId.fetchAssociatedCurrencyCode( @@ -100,13 +100,13 @@ class LTLoanMapper( } val modifiedLoan = loan.copy( - amount = transaction.amount, + amount = transaction.amount.toDouble(), name = if (transaction.title.isNullOrEmpty()) loan.name else transaction.title, type = if (transaction.type == TransactionType.INCOME) LoanType.BORROW else LoanType.LEND, accountId = transaction.accountId ) - ltCore.saveLoan(modifiedLoan) + ltCore.saveLoan(modifiedLoan.toDomain()) } onBackgroundProcessingEnd() } @@ -117,21 +117,23 @@ class LTLoanMapper( ): List { return scopedIOThread { scope -> val loanRecords = - ltCore.fetchAllLoanRecords(loanId = loanId).map { loanRecord -> - scope.async { - val convertedAmount: Double? = - ltCore.computeConvertedAmount( - oldLoanRecordAccountId = loanRecord.accountId, - oldLonRecordConvertedAmount = loanRecord.convertedAmount, - oldLoanRecordAmount = loanRecord.amount, - newLoanRecordAccountID = loanRecord.accountId, - newLoanRecordAmount = loanRecord.amount, - loanAccountId = newAccountId, - accounts = ltCore.fetchAccounts(), - ) - loanRecord.copy(convertedAmount = convertedAmount) - } - }.awaitAll() + ltCore.fetchAllLoanRecords(loanId = loanId) + .map { it.toDomain() } + .map { loanRecord -> + scope.async { + val convertedAmount: Double? = + ltCore.computeConvertedAmount( + oldLoanRecordAccountId = loanRecord.accountId, + oldLonRecordConvertedAmount = loanRecord.convertedAmount, + oldLoanRecordAmount = loanRecord.amount, + newLoanRecordAccountID = loanRecord.accountId, + newLoanRecordAmount = loanRecord.amount, + loanAccountId = newAccountId, + accounts = ltCore.fetchAccounts().map { it.toDomain() }, + ) + loanRecord.copy(convertedAmount = convertedAmount) + } + }.awaitAll() loanRecords } } diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt index fe7c9c25c1..88cc9ba82a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt @@ -3,7 +3,7 @@ package com.ivy.wallet.domain.deprecated.logic.loantrasactions import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.domain.data.core.LoanRecord import com.ivy.wallet.domain.data.core.Transaction -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData import com.ivy.wallet.utils.computationThread import java.util.* @@ -75,19 +75,19 @@ class LTLoanRecordMapper( oldLonRecordConvertedAmount = loanRecord.convertedAmount, oldLoanRecordAmount = loanRecord.amount, newLoanRecordAccountID = transaction.accountId, - newLoanRecordAmount = transaction.amount, + newLoanRecordAmount = transaction.amount.toDouble(), loanAccountId = loan.accountId, - accounts = ltCore.fetchAccounts() + accounts = ltCore.fetchAccounts().map { it.toDomain() } ) val modifiedLoanRecord = loanRecord.copy( - amount = transaction.amount, + amount = transaction.amount.toDouble(), note = transaction.title, dateTime = transaction.dateTime ?: loanRecord.dateTime, accountId = transaction.accountId, convertedAmount = convertedAmount ) - ltCore.saveLoanRecords(modifiedLoanRecord) + ltCore.saveLoanRecords(modifiedLoanRecord.toDomain()) } onBackgroundProcessingEnd() } @@ -105,7 +105,7 @@ class LTLoanRecordMapper( newLoanRecordAccountID = newLoanRecord.accountId, newLoanRecordAmount = newLoanRecord.amount, loanAccountId = loanAccountId, - accounts = ltCore.fetchAccounts(), + accounts = ltCore.fetchAccounts().map { it.toDomain() }, reCalculateLoanAmount = reCalculateLoanAmount ) } @@ -121,7 +121,7 @@ class LTLoanRecordMapper( newLoanRecordAccountID = data.account?.id, newLoanRecordAmount = data.amount, loanAccountId = loanAccountId, - accounts = ltCore.fetchAccounts(), + accounts = ltCore.fetchAccounts().map { it.toDomain() }, ) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt index cb89056747..82d4efe386 100644 --- a/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt @@ -5,8 +5,8 @@ import com.ivy.wallet.R import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.sync.uploader.TransactionUploader +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.stringRes import com.ivy.wallet.ui.IvyWalletCtx @@ -48,8 +48,9 @@ class LoanTransactionsCore( ioThread { val transactions: List = - if (loanId != null) transactionDao.findAllByLoanId(loanId = loanId) else - listOf(transactionDao.findLoanRecordTransaction(loanRecordId!!)) + if (loanId != null) transactionDao.findAllByLoanId(loanId = loanId) + .map { it.toDomain() } else + listOf(transactionDao.findLoanRecordTransaction(loanRecordId!!)).map { it?.toDomain() } transactions.forEach { trans -> deleteTransaction(trans) @@ -144,7 +145,7 @@ class LoanTransactionsCore( val modifiedTransaction: Transaction = transaction?.copy( loanId = loanId, loanRecordId = if (isLoanRecord) loanRecordId else null, - amount = amount, + amount = amount.toBigDecimal(), type = transType, accountId = selectedAccountId, title = title, @@ -154,7 +155,7 @@ class LoanTransactionsCore( ?: Transaction( accountId = selectedAccountId, type = transType, - amount = amount, + amount = amount.toBigDecimal(), dateTime = time, categoryId = transCategoryId, title = title, @@ -163,7 +164,7 @@ class LoanTransactionsCore( ) ioThread { - transactionDao.save(modifiedTransaction) + transactionDao.save(modifiedTransaction.toEntity()) } } @@ -184,7 +185,7 @@ class LoanTransactionsCore( return existingCategoryId val categoryList = ioThread { - categoryDao.findAll() + categoryDao.findAll().map { it.toDomain() } } var addCategoryToDb = false @@ -203,7 +204,7 @@ class LoanTransactionsCore( if (addCategoryToDb) ioThread { loanCategory?.let { - categoryDao.save(it) + categoryDao.save(it.toEntity()) } } @@ -270,15 +271,15 @@ class LoanTransactionsCore( } suspend fun saveLoanRecords(loanRecords: List) = ioThread { - loanRecordDao.save(loanRecords) + loanRecordDao.save(loanRecords.map { it.toEntity() }) } suspend fun saveLoanRecords(loanRecord: LoanRecord) = ioThread { - loanRecordDao.save(loanRecord) + loanRecordDao.save(loanRecord.toEntity()) } suspend fun saveLoan(loan: Loan) = ioThread { - loanDao.save(loan) + loanDao.save(loan.toEntity()) } suspend fun fetchLoanRecord(loanRecordId: UUID) = ioThread { @@ -296,7 +297,7 @@ class LoanTransactionsCore( suspend fun fetchLoanRecordTransaction(loanRecordId: UUID?): Transaction? { return loanRecordId?.let { ioThread { - transactionDao.findLoanRecordTransaction(it) + transactionDao.findLoanRecordTransaction(it)?.toDomain() } } } 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 9714533e2d..a692259b5e 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 @@ -6,7 +6,7 @@ import androidx.core.net.toUri import com.google.gson.* import com.google.gson.reflect.TypeToken import com.ivy.wallet.domain.data.IvyWalletCompleteData -import com.ivy.wallet.domain.logic.csv.model.ImportResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.utils.ioThread @@ -56,14 +56,15 @@ class ExportZipLogic( private suspend fun generateJsonString(): String { return scopedIOThread { - 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() } - val settings = it.async { settingsDao.findAll() } - val transactions = it.async { transactionDao.findAll() } + 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 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() } } val sharedPrefs = it.async { getSharedPrefsData() } val gson = GsonBuilder().registerTypeAdapter( @@ -216,20 +217,22 @@ class ExportZipLogic( onProgress: suspend (progressPercent: Double) -> Unit = {} ) { scopedIOThread { - transactionDao.save(completeData.transactions) + transactionDao.save(completeData.transactions.map { it.toEntity() }) onProgress(0.6) - val accounts = it.async { accountDao.save(completeData.accounts) } - val budgets = it.async { budgetDao.save(completeData.budgets) } - val categories = it.async { categoryDao.save(completeData.categories) } + val accounts = it.async { accountDao.save(completeData.accounts.map { it.toEntity() }) } + val budgets = it.async { budgetDao.save(completeData.budgets.map { it.toEntity() }) } + val categories = + it.async { categoryDao.save(completeData.categories.map { it.toEntity() }) } accounts.await() budgets.await() categories.await() onProgress(0.7) - val loans = it.async { loanDao.save(completeData.loans) } - val loanRecords = it.async { loanRecordDao.save(completeData.loanRecords) } + val loans = it.async { loanDao.save(completeData.loans.map { it.toEntity() }) } + val loanRecords = + it.async { loanRecordDao.save(completeData.loanRecords.map { it.toEntity() }) } loans.await() loanRecords.await() @@ -237,10 +240,10 @@ class ExportZipLogic( onProgress(0.8) val plannedPayments = - it.async { plannedPaymentRuleDao.save(completeData.plannedPaymentRules) } + it.async { plannedPaymentRuleDao.save(completeData.plannedPaymentRules.map { it.toEntity() }) } val settings = it.async { settingsDao.deleteAll() - settingsDao.save(completeData.settings) + settingsDao.save(completeData.settings.map { it.toEntity() }) } sharedPrefs.putBoolean( @@ -274,8 +277,8 @@ class ExportZipLogic( completeData: IvyWalletCompleteData ): List> { return scopedIOThread { scope -> - val existingAccountsList = accountDao.findAll() - val existingCategoryList = categoryDao.findAll() + val existingAccountsList = accountDao.findAll().map { it.toDomain() } + val existingCategoryList = categoryDao.findAll().map { it.toDomain() } val backupAccountsList = completeData.accounts val backupCategoryList = completeData.categories diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt b/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt index e32e1a0cda..633f0fdcc5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt @@ -5,7 +5,6 @@ import com.ivy.fp.SideEffect import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.pure.wallet.calculateWalletIncomeExpense import com.ivy.wallet.utils.beginningOfIvyTime import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal @@ -76,12 +75,13 @@ suspend fun incomeExpenseChart( return generateIncomeExpenseChart( orderedPeriod = orderedPeriod, calculateWalletIncomeExpense = { range -> - calculateWalletIncomeExpense( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - range = range, - filterExcluded = true - ).value + TODO() +// calculateWalletIncomeExpense( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode, +// range = range, +// filterExcluded = true +// ).value } ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt index a8d65c25df..2d34d59d5a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt @@ -1,20 +1,46 @@ package com.ivy.wallet.domain.pure.transaction import arrow.core.Option +import arrow.core.toOption import com.ivy.fp.Pure import com.ivy.fp.SideEffect +import com.ivy.fp.then import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.pure.exchange.ExchangeData import com.ivy.wallet.domain.pure.exchange.ExchangeTrnArgument import com.ivy.wallet.domain.pure.exchange.exchangeInBaseCurrency +import com.ivy.wallet.io.persistence.dao.AccountDao +import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.utils.convertUTCtoLocal import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal import java.util.* +@Deprecated("Migrate to actions") +suspend fun List.withDateDividers( + exchangeRatesLogic: ExchangeRatesLogic, + settingsDao: SettingsDao, + accountDao: AccountDao +): List { + return transactionsWithDateDividers( + transactions = this, + baseCurrencyCode = settingsDao.findFirst().currency, + getAccount = accountDao::findById then { it?.toDomain() }, + exchange = { data, amount -> + exchangeRatesLogic.convertAmount( + baseCurrency = data.baseCurrency, + fromCurrency = data.fromCurrency.orNull() ?: "", + toCurrency = data.toCurrency, + amount = amount.toDouble() + ).toBigDecimal().toOption() + } + ) +} + @Pure suspend fun transactionsWithDateDividers( transactions: List, diff --git a/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt b/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt index 5a4da91126..c34c322c24 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt @@ -30,7 +30,7 @@ class IvySession( fun initiate(authResponse: AuthResponse) { val user = authResponse.user - userDao.save(user) + userDao.save(user.toEntity()) sharedPrefs.putString(SharedPrefs.SESSION_USER_ID, user.id.toString()) sharedPrefs.putString(SharedPrefs.SESSION_AUTH_TOKEN, authResponse.sessionToken) diff --git a/app/src/main/java/com/ivy/wallet/io/network/RestClient.kt b/app/src/main/java/com/ivy/wallet/io/network/RestClient.kt index 60dc6236f8..5bd80f9e06 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/RestClient.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/RestClient.kt @@ -205,9 +205,6 @@ class RestClient private constructor( } val analyticsService: AnalyticsService by lazy { retrofit.create(AnalyticsService::class.java) } val coinbaseService: CoinbaseService by lazy { retrofit.create(CoinbaseService::class.java) } - val bankIntegrationsService: BankIntegrationsService by lazy { - retrofit.create(BankIntegrationsService::class.java) - } val githubService: GithubService by lazy { retrofit.create(GithubService::class.java) } val nukeService: NukeService by lazy { retrofit.create(NukeService::class.java) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/service/BankIntegrationsService.kt b/app/src/main/java/com/ivy/wallet/io/network/service/BankIntegrationsService.kt deleted file mode 100644 index b2dbcdb296..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/service/BankIntegrationsService.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.ivy.wallet.io.network.service - -import com.ivy.wallet.io.network.request.bankintegrations.BankAccountsResponse -import com.ivy.wallet.io.network.request.bankintegrations.BankConnectionSessionResponse -import com.ivy.wallet.io.network.request.bankintegrations.BankConnectionsResponse -import com.ivy.wallet.io.network.request.bankintegrations.BankTransactionsResponse -import retrofit2.http.DELETE -import retrofit2.http.GET -import retrofit2.http.POST - -interface BankIntegrationsService { - @POST("wallet/bank-integrations/connect") - suspend fun connectSession(): BankConnectionSessionResponse - - @GET("wallet/bank-integrations/connections") - suspend fun getConnections(): BankConnectionsResponse - - @GET("wallet/bank-integrations/accounts") - suspend fun getAccounts(): BankAccountsResponse - - @GET("wallet/bank-integrations/transactions") - suspend fun getTransactions(): BankTransactionsResponse - - @DELETE("wallet/bank-integrations/remove-customer") - suspend fun removeCustomer() -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt index da82d745f5..fa7a30423e 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt @@ -8,8 +8,8 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel -import com.ivy.wallet.domain.logic.csv.model.ImportResult -import com.ivy.wallet.domain.logic.csv.model.ImportType +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType import com.ivy.wallet.ui.Import import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.csvimport.flow.ImportFrom diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt index 560860a1e3..5666223427 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.ui.csvimport.flow + import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -21,12 +22,10 @@ import com.google.accompanist.insets.statusBarsPadding import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style -import com.ivy.wallet.domain.logic.csv.model.ImportType +import com.ivy.wallet.R +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.onboarding.components.OnboardingToolbar -import com.ivy.wallet.R - - import com.ivy.wallet.ui.theme.components.GradientCutBottom import com.ivy.wallet.ui.theme.components.IvyIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt index dd671f5679..8e90c0bb68 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt @@ -12,14 +12,14 @@ import com.google.accompanist.insets.systemBarsPadding import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style -import com.ivy.wallet.domain.logic.csv.model.ImportResult +import com.ivy.wallet.R +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.BackButton import com.ivy.wallet.ui.theme.components.IvyDividerLine import com.ivy.wallet.ui.theme.components.OnboardingButton import com.ivy.wallet.utils.format -import com.ivy.wallet.R @Composable fun ImportResultUI( diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/instructions/ImportInstructions.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/instructions/ImportInstructions.kt index 7c345b65ac..d17772e14d 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/instructions/ImportInstructions.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/instructions/ImportInstructions.kt @@ -26,8 +26,7 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.logic.csv.model.ImportType -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.ui.onboarding.components.OnboardingToolbar diff --git a/app/src/main/java/com/ivy/wallet/ui/home/CustomerJourney.kt b/app/src/main/java/com/ivy/wallet/ui/home/CustomerJourney.kt index 2579bb6d15..9ffc97c915 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/CustomerJourney.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/CustomerJourney.kt @@ -17,8 +17,8 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.logic.CustomerJourneyLogic -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.ui.IvyWalletComponentPreview import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.ui.ivyWalletCtx diff --git a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt index 8c80072b46..26c9b9a328 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt @@ -33,9 +33,9 @@ import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.domain.data.core.LoanRecord -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData -import com.ivy.wallet.domain.logic.model.EditLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.EditLoanRecordData import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.LoanDetails diff --git a/app/src/main/java/com/ivy/wallet/ui/main/MainScreen.kt b/app/src/main/java/com/ivy/wallet/ui/main/MainScreen.kt index beb290d435..c56d23df65 100644 --- a/app/src/main/java/com/ivy/wallet/ui/main/MainScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/main/MainScreen.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel import com.ivy.design.api.navigation import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData import com.ivy.wallet.ui.* import com.ivy.wallet.ui.accounts.AccountsTab import com.ivy.wallet.ui.home.HomeTab diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt index 458fcd6d93..05cced0598 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt @@ -11,8 +11,8 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Onboarding import com.ivy.wallet.ui.onboarding.model.AccountBalance diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt index 42bd0ace25..01239cf54b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt @@ -17,8 +17,8 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.core.Account -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletComponentPreview import com.ivy.wallet.ui.theme.components.IvyIcon import com.ivy.wallet.ui.theme.components.WrapContentRow diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt index 20b4cba285..cb68f637ad 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt @@ -23,7 +23,7 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.core.Account -import com.ivy.wallet.domain.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Paywall import com.ivy.wallet.ui.ivyWalletCtx diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt index f54d41288e..345e4ed417 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt @@ -26,7 +26,7 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.onboarding.components.OnboardingProgressSlider import com.ivy.wallet.ui.onboarding.components.OnboardingToolbar diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt index d1a1b86fb7..0c24b9a501 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt @@ -5,13 +5,13 @@ import com.ivy.design.navigation.Navigation import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.analytics.AnalyticsEvent import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.LogoutLogic -import com.ivy.wallet.domain.logic.PreloadDataLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic -import com.ivy.wallet.domain.sync.IvySync +import com.ivy.wallet.domain.deprecated.logic.LogoutLogic +import com.ivy.wallet.domain.deprecated.logic.PreloadDataLogic +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.sync.IvySync import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.AccountDao @@ -246,7 +246,7 @@ class OnboardingRouter( } private suspend fun routeToCategories() { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = ioThread { categoryDao.findAll().map { it.toDomain() } }!! _categorySuggestions.value = preloadDataLogic.categorySuggestions() _state.value = OnboardingState.CATEGORIES diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt index f4bcd457dd..5c59e1b4d1 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt @@ -21,8 +21,8 @@ import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.edit.core.* diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt index ff90c17f5d..82f18a1d65 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt @@ -4,7 +4,16 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import arrow.core.toOption import com.ivy.design.navigation.Navigation +import com.ivy.fp.action.then import com.ivy.wallet.R +import com.ivy.wallet.domain.action.account.AccTrnsAct +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.account.CalcAccBalanceAct +import com.ivy.wallet.domain.action.account.CalcAccIncomeExpenseAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.transaction.TrnsWithDateDivsAct import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType import com.ivy.wallet.domain.data.core.Account @@ -14,11 +23,8 @@ import com.ivy.wallet.domain.deprecated.logic.* import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic import com.ivy.wallet.domain.deprecated.sync.uploader.AccountUploader import com.ivy.wallet.domain.deprecated.sync.uploader.CategoryUploader -import com.ivy.wallet.domain.pure.account.calculateAccountBalance -import com.ivy.wallet.domain.pure.account.calculateAccountIncomeExpense import com.ivy.wallet.domain.pure.data.WalletDAOs -import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode -import com.ivy.wallet.domain.pure.wallet.withDateDividers +import com.ivy.wallet.domain.pure.exchange.ExchangeData import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.stringRes import com.ivy.wallet.ui.ItemStatistic @@ -51,6 +57,14 @@ class ItemStatisticViewModel @Inject constructor( private val accountCreator: AccountCreator, private val plannedPaymentsLogic: PlannedPaymentsLogic, private val exchangeRatesLogic: ExchangeRatesLogic, + private val categoriesAct: CategoriesAct, + private val accountsAct: AccountsAct, + private val accTrnsAct: AccTrnsAct, + private val trnsWithDateDivsAct: TrnsWithDateDivsAct, + private val baseCurrencyAct: BaseCurrencyAct, + private val calcAccBalanceAct: CalcAccBalanceAct, + private val calcAccIncomeExpenseAct: CalcAccIncomeExpenseAct, + private val exchangeAct: ExchangeAct ) : ViewModel() { private val _period = MutableStateFlow(ivyContext.selectedPeriod) @@ -133,12 +147,12 @@ class ItemStatisticViewModel @Inject constructor( viewModelScope.launch { _period.value = period ?: ivyContext.selectedPeriod - val baseCurrency = ioThread { baseCurrencyCode(settingsDao) } + val baseCurrency = baseCurrencyAct(Unit) _baseCurrency.value = baseCurrency _currency.value = baseCurrency - _categories.value = ioThread { categoryDao.findAll() } - _accounts.value = ioThread { accountDao.findAll() } + _categories.value = categoriesAct(Unit) + _accounts.value = accountsAct(Unit) _initWithTransactions.value = false when { @@ -176,7 +190,7 @@ class ItemStatisticViewModel @Inject constructor( private suspend fun initForAccount(accountId: UUID) { val account = ioThread { - accountDao.findById(accountId) ?: error("account not found") + accountDao.findById(accountId)?.toDomain() ?: error("account not found") } _account.value = account val range = period.value.toRange(ivyContext.startDayOfMonth) @@ -185,37 +199,46 @@ class ItemStatisticViewModel @Inject constructor( _currency.value = account.currency!! } - val balance = ioThread { - calculateAccountBalance( - transactionDao = walletDAOs.transactionDao, - accountId = accountId - ).toDouble() - } + val balance = calcAccBalanceAct( + CalcAccBalanceAct.Input( + account = account + ) + ).balance.toDouble() _balance.value = balance if (baseCurrency.value != currency.value) { - _balanceBaseCurrency.value = ioThread { - exchangeToBaseCurrency( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrency.value, - fromCurrencyCode = currency.value.toOption(), - fromAmount = balance.toBigDecimal() - ).orNull()?.toDouble() - } + _balanceBaseCurrency.value = exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency.value, + fromCurrency = currency.value.toOption() + ), + amount = balance.toBigDecimal() + ) + ).orNull()?.toDouble() } - val incomeExpensePair = ioThread { - calculateAccountIncomeExpense( - transactionDao = transactionDao, - accountId = accountId, + val incomeExpensePair = calcAccIncomeExpenseAct( + CalcAccIncomeExpenseAct.Input( + account = account, range = range.toCloseTimeRange() ) - } + ).incomeExpensePair _income.value = incomeExpensePair.income.toDouble() _expenses.value = incomeExpensePair.expense.toDouble() - _history.value = ioThread { - accountLogic.historyForAccount(account, range) - } + _history.value = (accTrnsAct then { + trnsWithDateDivsAct( + TrnsWithDateDivsAct.Input( + baseCurrency = baseCurrency.value, + transactions = it + ) + ) + })( + AccTrnsAct.Input( + accountId = account.id, + range = range.toCloseTimeRange() + ) + ) //Upcoming _upcomingIncome.value = ioThread { @@ -243,7 +266,7 @@ class ItemStatisticViewModel @Inject constructor( private suspend fun initForCategory(categoryId: UUID, accountFilterList: List) { val accountFilterSet = accountFilterList.toSet() val category = ioThread { - categoryDao.findById(categoryId) ?: error("category not found") + categoryDao.findById(categoryId)?.toDomain() ?: error("category not found") } _category.value = category val range = period.value.toRange(ivyContext.startDayOfMonth) @@ -307,7 +330,7 @@ class ItemStatisticViewModel @Inject constructor( val accountFilterSet = accountFilterList.toSet() val category = ioThread { - categoryDao.findById(categoryId) ?: error("category not found") + categoryDao.findById(categoryId)?.toDomain() ?: error("category not found") } _category.value = category val range = period.value.toRange(ivyContext.startDayOfMonth) @@ -464,22 +487,21 @@ class ItemStatisticViewModel @Inject constructor( _income.value - _expenses.value + if (accountTransferCategoryEnabled) trans.filter { it.type == TransactionType.TRANSFER } - .sumOf { - exchangeRatesLogic.toAmountBaseCurrency( - transaction = it, - baseCurrency = baseCurrency.value, - accounts = walletDAOs.accountDao.findAll() - ) - } else 0.0 - } - - _history.value = ioThread { - trans.withDateDividers( - exchangeRateDao = exchangeRateDao, - accountDao = walletDAOs.accountDao, - baseCurrencyCode = baseCurrency.value + .sumOf { + exchangeRatesLogic.toAmountBaseCurrency( + transaction = it, + baseCurrency = baseCurrency.value, + accounts = accountsAct(Unit) + ) + } else 0.0 + } + + _history.value = trnsWithDateDivsAct( + TrnsWithDateDivsAct.Input( + baseCurrency = baseCurrency.value, + transactions = transactions ) - } + ) } private fun reset() { diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt index c5e9b2d256..53dfa94db7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt @@ -26,7 +26,7 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Budget import com.ivy.wallet.domain.data.core.Category -import com.ivy.wallet.domain.logic.model.CreateBudgetData +import com.ivy.wallet.domain.deprecated.logic.model.CreateBudgetData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.reports.ListItem import com.ivy.wallet.ui.theme.Green diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt index 7427b67ad8..42e88a716b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt @@ -28,8 +28,8 @@ import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.Loan -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.ItemIconSDefaultIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt index 7b4836dee7..5c1e38fe50 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt @@ -23,9 +23,9 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.domain.data.core.LoanRecord -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData -import com.ivy.wallet.domain.logic.model.EditLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.EditLoanRecordData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.ivyWalletCtx import com.ivy.wallet.ui.theme.components.ItemIconSDefaultIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt index b5cc9acf71..ececf3fe25 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt @@ -140,13 +140,13 @@ fun LazyItemScope.TransactionCard( transactionType = transaction.type, dueDate = transaction.dueDate, currency = transactionCurrency, - amount = transaction.amount + amount = transaction.amount.toDouble() ) if (transaction.type == TransactionType.TRANSFER && transaction.toAmount != null && toAccountCurrency != transactionCurrency) { Text( modifier = Modifier.padding(start = 68.dp), - text = "${transaction.toAmount.format(2)} $toAccountCurrency", + text = "${transaction.toAmount.toDouble().format(2)} $toAccountCurrency", style = UI.typo.nB2.style( color = Gray, fontWeight = FontWeight.Normal @@ -427,7 +427,7 @@ private fun PreviewUpcomingExpense() { accountId = cash.id, title = "Lidl pazar", categoryId = food.id, - amount = 250.75, + amount = 250.75.toBigDecimal(), dueDate = timeNowUTC().plusDays(5), dateTime = null, type = TransactionType.EXPENSE, @@ -458,7 +458,7 @@ private fun PreviewOverdueExpense() { accountId = cash.id, title = "Rent", categoryId = food.id, - amount = 500.0, + amount = 500.0.toBigDecimal(), dueDate = timeNowUTC().minusDays(5), dateTime = null, type = TransactionType.EXPENSE @@ -493,7 +493,7 @@ private fun PreviewNormalExpense() { accountId = cash.id, title = "Близкия магазин", categoryId = food.id, - amount = 32.51, + amount = 32.51.toBigDecimal(), dateTime = timeNowUTC(), type = TransactionType.EXPENSE ), @@ -522,7 +522,7 @@ private fun PreviewIncome() { accountId = cash.id, title = "Qredo Salary May", categoryId = category.id, - amount = 8049.70, + amount = 8049.70.toBigDecimal(), dateTime = timeNowUTC(), type = TransactionType.INCOME ), @@ -552,7 +552,7 @@ private fun PreviewTransfer() { accountId = acc1.id, toAccountId = acc2.id, title = "Top-up revolut", - amount = 1000.0, + amount = 1000.0.toBigDecimal(), dateTime = timeNowUTC(), type = TransactionType.TRANSFER ), From 53c3c2f9d8c485cd3cc3c35507b211f7e183ae58 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sun, 24 Apr 2022 21:16:17 +0300 Subject: [PATCH 33/40] WIP: Fix DB migrations --- .../main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt | 1 + .../persistence/migration/Migration120to121_DropWishlistItem.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt index eb00ca7657..9438ce7aa4 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt @@ -67,6 +67,7 @@ abstract class IvyRoomDatabase : RoomDatabase() { Migration117to118_Budgets(), Migration118to119_Loans(), Migration119to120_LoanTransactions(), + Migration120to121_DropWishlistItem() ) .build() } diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt b/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt index dd7b0d3e99..e982ef60ac 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt @@ -3,7 +3,7 @@ package com.ivy.wallet.io.persistence.migration import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase -class Migration120to121_DropWishlistItem : Migration(119, 120) { +class Migration120to121_DropWishlistItem : Migration(120, 121) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL("DROP TABLE wishlist_items") } From a2d48d33015dbb57a9d16773da0a2cd86b731a0b Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sun, 24 Apr 2022 21:23:37 +0300 Subject: [PATCH 34/40] Fix DB migrations --- .../wallet/io/persistence/IvyRoomDatabase.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt index 9438ce7aa4..1a3c3c88b1 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt @@ -1,10 +1,8 @@ package com.ivy.wallet.io.persistence import android.content.Context -import androidx.room.Database -import androidx.room.Room -import androidx.room.RoomDatabase -import androidx.room.TypeConverters +import androidx.room.* +import androidx.room.migration.AutoMigrationSpec import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.io.persistence.data.* import com.ivy.wallet.io.persistence.migration.* @@ -17,7 +15,14 @@ import com.ivy.wallet.io.persistence.migration.* UserEntity::class, ExchangeRateEntity::class, BudgetEntity::class, LoanEntity::class, LoanRecordEntity::class ], - version = 121, + autoMigrations = [ + AutoMigration( + from = 121, + to = 122, + spec = IvyRoomDatabase.DeleteSEMigration::class + ) + ], + version = 122, exportSchema = true ) @TypeConverters(RoomTypeConverters::class) @@ -84,4 +89,10 @@ abstract class IvyRoomDatabase : RoomDatabase() { loanDao().deleteAll() loanRecordDao().deleteAll() } + + @DeleteColumn(tableName = "accounts", columnName = "seAccountId") + @DeleteColumn(tableName = "transactions", columnName = "seTransactionId") + @DeleteColumn(tableName = "transactions", columnName = "seAutoCategoryId") + @DeleteColumn(tableName = "categories", columnName = "seCategoryName") + class DeleteSEMigration : AutoMigrationSpec } \ No newline at end of file From 09974a178de04a13f210751298611944ea84e7f1 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sun, 24 Apr 2022 21:28:48 +0300 Subject: [PATCH 35/40] Fix wrongly balance --- ...eExpenseAct.kt => CalcIncomeExpenseAct.kt} | 22 +++++-------------- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 20 +++++++++++------ 2 files changed, 19 insertions(+), 23 deletions(-) rename app/src/main/java/com/ivy/wallet/domain/action/wallet/{CalcBalanceIncomeExpenseAct.kt => CalcIncomeExpenseAct.kt} (76%) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcBalanceIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt similarity index 76% rename from app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcBalanceIncomeExpenseAct.kt rename to app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt index af3a3295b7..1c1202b13c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcBalanceIncomeExpenseAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt @@ -15,15 +15,14 @@ import com.ivy.wallet.domain.pure.exchange.ExchangeData import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions import com.ivy.wallet.domain.pure.transaction.foldTransactions import com.ivy.wallet.domain.pure.util.orZero -import java.math.BigDecimal import javax.inject.Inject -class CalcBalanceIncomeExpenseAct @Inject constructor( +class CalcIncomeExpenseAct @Inject constructor( private val accTrnsAct: AccTrnsAct, private val exchangeAct: ExchangeAct -) : FPAction() { +) : FPAction() { - override suspend fun Input.compose(): suspend () -> Output = suspend { + override suspend fun Input.compose(): suspend () -> IncomeExpensePair = suspend { filterExcluded(accounts) } thenMap { acc -> Pair( @@ -41,7 +40,6 @@ class CalcBalanceIncomeExpenseAct @Inject constructor( foldTransactions( transactions = trns, valueFunctions = nonEmptyListOf( - AccountValueFunctions::balance, AccountValueFunctions::income, AccountValueFunctions::expense ), @@ -61,12 +59,9 @@ class CalcBalanceIncomeExpenseAct @Inject constructor( ).orZero() } } then { statsList -> - Output( - balance = statsList[0].sumOf { it }, - incomeExpense = IncomeExpensePair( - income = statsList[1].sumOf { it }, - expense = statsList[2].sumOf { it } - ) + IncomeExpensePair( + income = statsList[0].sumOf { it }, + expense = statsList[1].sumOf { it } ) } @@ -75,9 +70,4 @@ class CalcBalanceIncomeExpenseAct @Inject constructor( val accounts: List, val range: ClosedTimeRange, ) - - data class Output( - val balance: BigDecimal, - val incomeExpense: IncomeExpensePair, - ) } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index dba0537102..a609de10e7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -12,7 +12,8 @@ import com.ivy.wallet.domain.action.transaction.HistoryWithDateDivsAct import com.ivy.wallet.domain.action.viewmodel.home.HasTrnsAct import com.ivy.wallet.domain.action.viewmodel.home.OverdueAct import com.ivy.wallet.domain.action.viewmodel.home.UpcomingAct -import com.ivy.wallet.domain.action.wallet.CalcBalanceIncomeExpenseAct +import com.ivy.wallet.domain.action.wallet.CalcIncomeExpenseAct +import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic @@ -46,7 +47,8 @@ class HomeViewModel @Inject constructor( private val customerJourneyLogic: CustomerJourneyLogic, private val sharedPrefs: SharedPrefs, private val historyWithDateDivsAct: HistoryWithDateDivsAct, - private val calcBalanceIncomeExpenseAct: CalcBalanceIncomeExpenseAct, + private val calcIncomeExpenseAct: CalcIncomeExpenseAct, + private val calcWalletBalanceAct: CalcWalletBalanceAct, private val settingsAct: SettingsAct, private val accountsAct: AccountsAct, private val categoriesAct: CategoriesAct, @@ -111,18 +113,22 @@ class HomeViewModel @Inject constructor( val timeRange = period.toRange(ivyContext.startDayOfMonth) .toCloseTimeRange() - val monthlyStats = calcBalanceIncomeExpenseAct( - CalcBalanceIncomeExpenseAct.Input( + val monthlyIncomeExpense = calcIncomeExpenseAct( + CalcIncomeExpenseAct.Input( baseCurrency = baseCurrency, accounts = accounts, range = timeRange ) ) + val balance = calcWalletBalanceAct( + CalcWalletBalanceAct.Input(baseCurrency = baseCurrency) + ) + updateState { it.copy( - balance = monthlyStats.balance, - monthly = monthlyStats.incomeExpense + balance = balance, + monthly = monthlyIncomeExpense ) } @@ -174,7 +180,7 @@ class HomeViewModel @Inject constructor( buffer = settings.bufferAmount, bufferDiff = calcBufferDiffAct( CalcBufferDiffAct.Input( - balance = monthlyStats.balance, + balance = balance, buffer = settings.bufferAmount ) ) From 676f529bf7bd583af35a2215e790ff19d4a6aab2 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sun, 24 Apr 2022 21:33:46 +0300 Subject: [PATCH 36/40] Add Room DB files --- .../121.json | 707 ++++++++++++++++++ .../122.json | 707 ++++++++++++++++++ 2 files changed, 1414 insertions(+) create mode 100644 app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/121.json create mode 100644 app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/122.json diff --git a/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/121.json b/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/121.json new file mode 100644 index 0000000000..83dd1a6fb9 --- /dev/null +++ b/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/121.json @@ -0,0 +1,707 @@ +{ + "formatVersion": 1, + "database": { + "version": 121, + "identityHash": "319b13332051b3e936a5902b2b7a2ad5", + "entities": [ + { + "tableName": "accounts", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `currency` TEXT, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `includeInBalance` INTEGER NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "includeInBalance", + "columnName": "includeInBalance", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "transactions", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountId` TEXT NOT NULL, `type` TEXT NOT NULL, `amount` REAL NOT NULL, `toAccountId` TEXT, `toAmount` REAL, `title` TEXT, `description` TEXT, `dateTime` INTEGER, `categoryId` TEXT, `dueDate` INTEGER, `recurringRuleId` TEXT, `attachmentUrl` TEXT, `loanId` TEXT, `loanRecordId` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "toAccountId", + "columnName": "toAccountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "toAmount", + "columnName": "toAmount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dateTime", + "columnName": "dateTime", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "categoryId", + "columnName": "categoryId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dueDate", + "columnName": "dueDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "recurringRuleId", + "columnName": "recurringRuleId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "attachmentUrl", + "columnName": "attachmentUrl", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "loanId", + "columnName": "loanId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "loanRecordId", + "columnName": "loanRecordId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "categories", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "settings", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`theme` TEXT NOT NULL, `currency` TEXT NOT NULL, `bufferAmount` REAL NOT NULL, `name` TEXT NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "theme", + "columnName": "theme", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "bufferAmount", + "columnName": "bufferAmount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "planned_payment_rules", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`startDate` INTEGER, `intervalN` INTEGER, `intervalType` TEXT, `oneTime` INTEGER NOT NULL, `type` TEXT NOT NULL, `accountId` TEXT NOT NULL, `amount` REAL NOT NULL, `categoryId` TEXT, `title` TEXT, `description` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "startDate", + "columnName": "startDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "intervalN", + "columnName": "intervalN", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "intervalType", + "columnName": "intervalType", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "oneTime", + "columnName": "oneTime", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "categoryId", + "columnName": "categoryId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "users", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`email` TEXT NOT NULL, `authProviderType` TEXT NOT NULL, `firstName` TEXT NOT NULL, `lastName` TEXT, `profilePicture` TEXT, `color` INTEGER NOT NULL, `testUser` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "email", + "columnName": "email", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "authProviderType", + "columnName": "authProviderType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "firstName", + "columnName": "firstName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastName", + "columnName": "lastName", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "profilePicture", + "columnName": "profilePicture", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "testUser", + "columnName": "testUser", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "exchange_rates", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`baseCurrency` TEXT NOT NULL, `currency` TEXT NOT NULL, `rate` REAL NOT NULL, PRIMARY KEY(`baseCurrency`, `currency`))", + "fields": [ + { + "fieldPath": "baseCurrency", + "columnName": "baseCurrency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "rate", + "columnName": "rate", + "affinity": "REAL", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "baseCurrency", + "currency" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "budgets", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `categoryIdsSerialized` TEXT, `accountIdsSerialized` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `orderId` REAL NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "categoryIdsSerialized", + "columnName": "categoryIdsSerialized", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "accountIdsSerialized", + "columnName": "accountIdsSerialized", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "orderId", + "columnName": "orderId", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "loans", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `type` TEXT NOT NULL, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `accountId` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "loan_records", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`loanId` TEXT NOT NULL, `amount` REAL NOT NULL, `note` TEXT, `dateTime` INTEGER NOT NULL, `interest` INTEGER NOT NULL, `accountId` TEXT, `convertedAmount` REAL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "loanId", + "columnName": "loanId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "note", + "columnName": "note", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dateTime", + "columnName": "dateTime", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "interest", + "columnName": "interest", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "convertedAmount", + "columnName": "convertedAmount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '319b13332051b3e936a5902b2b7a2ad5')" + ] + } +} \ No newline at end of file diff --git a/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/122.json b/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/122.json new file mode 100644 index 0000000000..295aa84e59 --- /dev/null +++ b/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/122.json @@ -0,0 +1,707 @@ +{ + "formatVersion": 1, + "database": { + "version": 122, + "identityHash": "319b13332051b3e936a5902b2b7a2ad5", + "entities": [ + { + "tableName": "accounts", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `currency` TEXT, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `includeInBalance` INTEGER NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "includeInBalance", + "columnName": "includeInBalance", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "transactions", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountId` TEXT NOT NULL, `type` TEXT NOT NULL, `amount` REAL NOT NULL, `toAccountId` TEXT, `toAmount` REAL, `title` TEXT, `description` TEXT, `dateTime` INTEGER, `categoryId` TEXT, `dueDate` INTEGER, `recurringRuleId` TEXT, `attachmentUrl` TEXT, `loanId` TEXT, `loanRecordId` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "toAccountId", + "columnName": "toAccountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "toAmount", + "columnName": "toAmount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dateTime", + "columnName": "dateTime", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "categoryId", + "columnName": "categoryId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dueDate", + "columnName": "dueDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "recurringRuleId", + "columnName": "recurringRuleId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "attachmentUrl", + "columnName": "attachmentUrl", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "loanId", + "columnName": "loanId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "loanRecordId", + "columnName": "loanRecordId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "categories", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "settings", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`theme` TEXT NOT NULL, `currency` TEXT NOT NULL, `bufferAmount` REAL NOT NULL, `name` TEXT NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "theme", + "columnName": "theme", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "bufferAmount", + "columnName": "bufferAmount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "planned_payment_rules", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`startDate` INTEGER, `intervalN` INTEGER, `intervalType` TEXT, `oneTime` INTEGER NOT NULL, `type` TEXT NOT NULL, `accountId` TEXT NOT NULL, `amount` REAL NOT NULL, `categoryId` TEXT, `title` TEXT, `description` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "startDate", + "columnName": "startDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "intervalN", + "columnName": "intervalN", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "intervalType", + "columnName": "intervalType", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "oneTime", + "columnName": "oneTime", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "categoryId", + "columnName": "categoryId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "users", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`email` TEXT NOT NULL, `authProviderType` TEXT NOT NULL, `firstName` TEXT NOT NULL, `lastName` TEXT, `profilePicture` TEXT, `color` INTEGER NOT NULL, `testUser` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "email", + "columnName": "email", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "authProviderType", + "columnName": "authProviderType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "firstName", + "columnName": "firstName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastName", + "columnName": "lastName", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "profilePicture", + "columnName": "profilePicture", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "testUser", + "columnName": "testUser", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "exchange_rates", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`baseCurrency` TEXT NOT NULL, `currency` TEXT NOT NULL, `rate` REAL NOT NULL, PRIMARY KEY(`baseCurrency`, `currency`))", + "fields": [ + { + "fieldPath": "baseCurrency", + "columnName": "baseCurrency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "rate", + "columnName": "rate", + "affinity": "REAL", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "baseCurrency", + "currency" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "budgets", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `categoryIdsSerialized` TEXT, `accountIdsSerialized` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `orderId` REAL NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "categoryIdsSerialized", + "columnName": "categoryIdsSerialized", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "accountIdsSerialized", + "columnName": "accountIdsSerialized", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "orderId", + "columnName": "orderId", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "loans", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `type` TEXT NOT NULL, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `accountId` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "loan_records", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`loanId` TEXT NOT NULL, `amount` REAL NOT NULL, `note` TEXT, `dateTime` INTEGER NOT NULL, `interest` INTEGER NOT NULL, `accountId` TEXT, `convertedAmount` REAL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "loanId", + "columnName": "loanId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "note", + "columnName": "note", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dateTime", + "columnName": "dateTime", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "interest", + "columnName": "interest", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "convertedAmount", + "columnName": "convertedAmount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '319b13332051b3e936a5902b2b7a2ad5')" + ] + } +} \ No newline at end of file From 3130270575c7212c1a4241d8554c1a4bca6a5634 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Mon, 25 Apr 2022 00:05:35 +0300 Subject: [PATCH 37/40] Fix wrong CalcIncomeExpenseAct.kt --- .../wallet/domain/action/wallet/CalcIncomeExpenseAct.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt index 1c1202b13c..589568cfc0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt @@ -15,6 +15,7 @@ import com.ivy.wallet.domain.pure.exchange.ExchangeData import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions import com.ivy.wallet.domain.pure.transaction.foldTransactions import com.ivy.wallet.domain.pure.util.orZero +import timber.log.Timber import javax.inject.Inject class CalcIncomeExpenseAct @Inject constructor( @@ -35,6 +36,7 @@ class CalcIncomeExpenseAct @Inject constructor( ) ) } thenMap { (acc, trns) -> + Timber.i("acc: $acc, trns = ${trns.size}") Pair( acc, foldTransactions( @@ -47,6 +49,7 @@ class CalcIncomeExpenseAct @Inject constructor( ) ) } thenMap { (acc, stats) -> + Timber.i("acc_stats: $acc - $stats") stats.map { exchangeAct( ExchangeAct.Input( @@ -60,8 +63,8 @@ class CalcIncomeExpenseAct @Inject constructor( } } then { statsList -> IncomeExpensePair( - income = statsList[0].sumOf { it }, - expense = statsList[1].sumOf { it } + income = statsList.sumOf { it[0] }, + expense = statsList.sumOf { it[1] } ) } From ace1fd99a43e9ff9fd316b4c75e9c31e92b2486f Mon Sep 17 00:00:00 2001 From: code-a1 <68858676+code-a1@users.noreply.github.com> Date: Sun, 24 Apr 2022 23:36:55 +0200 Subject: [PATCH 38/40] Resolved conflicts --- app/proguard-rules.pro | 2 + .../121.json | 707 ++++++++++++++++++ .../122.json | 707 ++++++++++++++++++ .../main/java/com/ivy/wallet/AppModuleDI.kt | 95 +-- .../com/ivy/wallet/domain/action/Action.kt | 45 -- .../domain/action/account/AccTrnsAct.kt | 35 + .../domain/action/account/AccountByIdAct.kt | 18 + .../domain/action/account/AccountsAct.kt | 15 + .../action/account/CalcAccBalanceAct.kt | 44 ++ .../action/account/CalcAccIncomeExpenseAct.kt | 50 ++ .../wallet/domain/action/budget/BudgetsAct.kt | 15 + .../domain/action/category/CategoriesAct.kt | 17 + .../domain/action/category/CategoryByIdAct.kt | 15 + .../action/category/CategoryTrnsBetweenAct.kt | 37 + .../domain/action/charts/BalanceChartAct.kt | 34 + .../domain/action/exchange/ExchangeAct.kt | 39 + .../wallet/domain/action/loan/LoanByIdAct.kt | 15 + .../ivy/wallet/domain/action/loan/LoansAct.kt | 15 + .../domain/action/settings/BaseCurrencyAct.kt | 13 + .../action/settings/CalcBufferDiffAct.kt | 17 + .../action/settings/GetBaseCurrencyAct.kt | 14 - .../domain/action/settings/SettingsAct.kt | 15 + .../domain/action/transaction/AllTrnsAct.kt | 15 + .../transaction/CalcTrnsIncomeExpenseAct.kt | 44 ++ .../domain/action/transaction/DueTrnsAct.kt | 22 + .../action/transaction/HistoryTrnsAct.kt | 22 + .../transaction/HistoryWithDateDivsAct.kt | 27 + .../domain/action/transaction/TrnByIdAct.kt | 18 + .../action/transaction/TrnsWithDateDivsAct.kt | 32 + .../viewmodel/account/AccountDataAct.kt | 65 ++ .../action/viewmodel/home/DueTrnsInfoAct.kt | 73 ++ .../action/viewmodel/home/HasTrnsAct.kt | 15 + .../action/viewmodel/home/OverdueAct.kt | 37 + .../action/viewmodel/home/UpcomingAct.kt | 37 + .../action/wallet/CalcIncomeExpenseAct.kt | 76 ++ .../domain/action/wallet/CalcOverdueAct.kt | 29 - .../domain/action/wallet/CalcUpcomingAct.kt | 29 - .../action/wallet/CalcWalletBalanceAct.kt | 59 +- .../action/wallet/HistoryWithDateDivAct.kt | 26 - .../domain/data/IvyWalletCompleteData.kt | 2 +- .../domain/data/bankintegrations/SEAccount.kt | 23 - .../bankintegrations/SEAccountConnection.kt | 10 - .../data/bankintegrations/SEConnection.kt | 30 - .../data/bankintegrations/SECustomer.kt | 14 - .../data/bankintegrations/SETransaction.kt | 44 -- .../ivy/wallet/domain/data/core/Account.kt | 43 ++ .../com/ivy/wallet/domain/data/core/Budget.kt | 81 ++ .../ivy/wallet/domain/data/core/Category.kt | 37 + .../wallet/domain/data/core/ExchangeRate.kt | 22 + .../com/ivy/wallet/domain/data/core/Loan.kt | 52 ++ .../ivy/wallet/domain/data/core/LoanRecord.kt | 46 ++ .../domain/data/core/PlannedPaymentRule.kt | 57 ++ .../ivy/wallet/domain/data/core/Settings.kt | 32 + .../wallet/domain/data/core/Transaction.kt | 77 ++ .../com/ivy/wallet/domain/data/core/User.kt | 42 ++ .../wallet/domain/data/entity/ExchangeRate.kt | 10 - .../wallet/domain/data/entity/LoanRecord.kt | 24 - .../wallet/domain/data/entity/WishlistItem.kt | 19 - .../{ => deprecated}/logic/AccountCreator.kt | 14 +- .../{ => deprecated}/logic/BudgetCreator.kt | 12 +- .../{ => deprecated}/logic/CategoryCreator.kt | 13 +- .../logic/CustomerJourneyLogic.kt | 4 +- .../{ => deprecated}/logic/LoanCreator.kt | 12 +- .../logic/LoanRecordCreator.kt | 12 +- .../{ => deprecated}/logic/LogoutLogic.kt | 2 +- .../{ => deprecated}/logic/PaywallLogic.kt | 2 +- .../logic/PlannedPaymentsGenerator.kt | 10 +- .../logic/PlannedPaymentsLogic.kt | 28 +- .../logic/PreloadDataLogic.kt | 78 +- .../logic/SmartTitleSuggestionsLogic.kt | 7 +- .../logic/WalletAccountLogic.kt | 76 +- .../logic/WalletCategoryLogic.kt | 56 +- .../{ => deprecated}/logic/csv/CSVImporter.kt | 32 +- .../{ => deprecated}/logic/csv/CSVMapper.kt | 10 +- .../logic/csv/CSVNormalizer.kt | 4 +- .../logic/csv/ExportCSVLogic.kt | 24 +- .../logic/csv/IvyFileReader.kt | 2 +- .../logic/csv/model/CSVRow.kt | 2 +- .../logic/csv/model/ImportResult.kt | 2 +- .../logic/csv/model/ImportType.kt | 2 +- .../logic/csv/model/RowMapping.kt | 6 +- .../logic/currency/ExchangeRatesLogic.kt | 22 +- .../logic/loantrasactions/LTLoanMapper.kt | 50 +- .../loantrasactions/LTLoanRecordMapper.kt | 22 +- .../loantrasactions/LoanTransactionsCore.kt | 31 +- .../loantrasactions/LoanTransactionsLogic.kt | 4 +- .../logic/model/CreateAccountData.kt | 2 +- .../logic/model/CreateBudgetData.kt | 2 +- .../logic/model/CreateCategoryData.kt | 2 +- .../logic/model/CreateLoanData.kt | 4 +- .../logic/model/CreateLoanRecordData.kt | 4 +- .../logic/model/CustomerJourneyCardData.kt | 2 +- .../logic/model/EditLoanRecordData.kt | 4 +- .../notification/TransactionReminderLogic.kt | 2 +- .../notification/TransactionReminderWorker.kt | 2 +- .../logic/zip/ExportZipLogic.kt | 43 +- .../{ => deprecated}/logic/zip/ZipUtils.kt | 2 +- .../domain/{ => deprecated}/sync/IvySync.kt | 4 +- .../{ => deprecated}/sync/item/AccountSync.kt | 8 +- .../{ => deprecated}/sync/item/BudgetSync.kt | 8 +- .../sync/item/CategorySync.kt | 8 +- .../sync/item/LoanRecordSync.kt | 8 +- .../{ => deprecated}/sync/item/LoanSync.kt | 8 +- .../sync/item/PlannedPaymentSync.kt | 8 +- .../sync/item/TransactionSync.kt | 8 +- .../sync/uploader/AccountUploader.kt | 8 +- .../sync/uploader/BudgetUploader.kt | 8 +- .../sync/uploader/CategoryUploader.kt | 8 +- .../sync/uploader/LoanRecordUploader.kt | 8 +- .../sync/uploader/LoanUploader.kt | 8 +- .../uploader/PlannedPaymentRuleUploader.kt | 8 +- .../sync/uploader/TransactionUploader.kt | 8 +- .../wallet/domain/fp/account/AccountCore.kt | 56 -- .../domain/fp/account/AccountFunctions.kt | 82 -- .../wallet/domain/fp/category/CategoryCore.kt | 101 --- .../domain/fp/category/CategoryFunctions.kt | 135 ---- .../domain/fp/core/CoreValueFunctions.kt | 28 - .../java/com/ivy/wallet/domain/fp/core/FP.kt | 29 - .../domain/fp/core/TransactionFunctions.kt | 33 - .../ivy/wallet/domain/fp/core/Uncertain.kt | 10 - .../wallet/domain/fp/core/ValueFunction.kt | 48 -- .../domain/fp/data/CurrencyConvError.kt | 3 - .../ivy/wallet/domain/fp/data/FPAccount.kt | 29 - .../wallet/domain/fp/data/FPTransaction.kt | 46 -- .../ivy/wallet/domain/fp/wallet/WalletCore.kt | 148 ---- .../domain/fp/wallet/WalletFunctions.kt | 194 ----- .../domain/fp/wallet/WalletTransactions.kt | 83 -- .../ivy/wallet/domain/logic/WalletLogic.kt | 135 ---- .../bankintegrations/BankIntegrationsLogic.kt | 64 -- .../bankintegrations/SaltEdgeAccountMapper.kt | 67 -- .../SaltEdgeCategoryMapper.kt | 371 --------- .../SaltEdgeTransactionMapper.kt | 165 ---- .../domain/pure/account/AccountFunctions.kt | 6 + .../domain/{fp => pure}/charts/ChartPeriod.kt | 14 +- .../domain/{fp => pure}/charts/ChartsCore.kt | 6 +- .../{fp => pure}/charts/WalletCharts.kt | 69 +- .../{fp => pure}/data/ClosedTimeRange.kt | 2 +- .../{fp => pure}/data/IncomeExpensePair.kt | 2 +- .../domain/{fp => pure}/data/WalletDAOs.kt | 2 +- .../exchange/Exchange.kt} | 96 +-- .../domain/pure/exchange/ExchangeTrns.kt | 92 +++ .../transaction/AccValueFunctions.kt} | 29 +- .../transaction/CatValueFunctions.kt} | 63 +- .../pure/transaction/FoldTransactions.kt | 89 +++ .../pure/transaction/TrnDateDividers.kt | 87 +++ .../domain/pure/transaction/TrnFunctions.kt | 38 + .../pure/transaction/WalletValueFunctions.kt | 49 ++ .../domain/{fp/core => pure/util}/Utils.kt | 7 +- .../com/ivy/wallet/io/network/IvySession.kt | 2 +- .../com/ivy/wallet/io/network/RestClient.kt | 3 - .../ivy/wallet/io/network/data/AccountDTO.kt | 30 + .../ivy/wallet/io/network/data/BudgetDTO.kt | 66 ++ .../ivy/wallet/io/network/data/CategoryDTO.kt | 24 + .../wallet/io/network/data/ExchangeRateDTO.kt | 13 + .../com/ivy/wallet/io/network/data/LoanDTO.kt | 35 + .../wallet/io/network/data/LoanRecordDTO.kt | 32 + .../io/network/data/PlannedPaymentRuleDTO.kt | 39 + .../ivy/wallet/io/network/data/SettingsDTO.kt | 25 + .../wallet/io/network/data/TransactionDTO.kt | 52 ++ .../com/ivy/wallet/io/network/data/UserDTO.kt | 30 + .../request/account/AccountsResponse.kt | 4 +- .../request/account/UpdateAccountRequest.kt | 4 +- .../io/network/request/auth/AuthResponse.kt | 2 +- .../request/auth/UpdateUserInfoResponse.kt | 2 +- .../bankintegrations/BankAccountsResponse.kt | 9 - .../BankConnectionSessionResponse.kt | 8 - .../BankConnectionsResponse.kt | 9 - .../BankTransactionsResponse.kt | 9 - .../network/request/budget/BudgetsResponse.kt | 4 +- .../request/budget/CrupdateBudgetRequest.kt | 4 +- .../category/UpdateWalletCategoryRequest.kt | 4 +- .../category/WalletCategoriesResponse.kt | 4 +- .../request/loan/LoanRecordsResponse.kt | 4 +- .../io/network/request/loan/LoansResponse.kt | 4 +- .../request/loan/UpdateLoanRecordRequest.kt | 4 +- .../network/request/loan/UpdateLoanRequest.kt | 4 +- .../planned/PlannedPaymentRulesResponse.kt | 4 +- .../UpdatePlannedPaymentRuleRequest.kt | 4 +- .../transaction/TransactionsResponse.kt | 4 +- .../transaction/UpdateTransactionRequest.kt | 4 +- .../service/BankIntegrationsService.kt | 26 - .../wallet/io/persistence/IvyRoomDatabase.kt | 35 +- .../wallet/io/persistence/dao/AccountDao.kt | 15 +- .../wallet/io/persistence/dao/BudgetDao.kt | 12 +- .../wallet/io/persistence/dao/CategoryDao.kt | 15 +- .../io/persistence/dao/ExchangeRateDao.kt | 9 +- .../ivy/wallet/io/persistence/dao/LoanDao.kt | 12 +- .../io/persistence/dao/LoanRecordDao.kt | 17 +- .../persistence/dao/PlannedPaymentRuleDao.kt | 14 +- .../wallet/io/persistence/dao/SettingsDao.kt | 12 +- .../io/persistence/dao/TransactionDao.kt | 87 +-- .../ivy/wallet/io/persistence/dao/UserDao.kt | 6 +- .../io/persistence/dao/WishlistItemDao.kt | 26 - .../persistence/data/AccountEntity.kt} | 23 +- .../persistence/data/BudgetEntity.kt} | 24 +- .../persistence/data/CategoryEntity.kt} | 21 +- .../io/persistence/data/ExchangeRateEntity.kt | 17 + .../persistence/data/LoanEntity.kt} | 23 +- .../io/persistence/data/LoanRecordEntity.kt | 38 + .../data/PlannedPaymentRuleEntity.kt} | 23 +- .../persistence/data/SettingsEntity.kt} | 15 +- .../persistence/data/TransactionEntity.kt} | 38 +- .../persistence/data/UserEntity.kt} | 26 +- .../Migration120to121_DropWishlistItem.kt | 10 + .../java/com/ivy/wallet/ui/RootActivity.kt | 4 +- .../java/com/ivy/wallet/ui/RootViewModel.kt | 4 +- .../main/java/com/ivy/wallet/ui/Screens.kt | 2 +- .../com/ivy/wallet/ui/accounts/AccountData.kt | 2 +- .../com/ivy/wallet/ui/accounts/AccountsTab.kt | 2 +- .../wallet/ui/accounts/AccountsViewModel.kt | 78 +- .../ivy/wallet/ui/balance/BalanceViewModel.kt | 26 +- .../ui/bankintegrations/ConnectBankScreen.kt | 133 ---- .../bankintegrations/ConnectBankViewModel.kt | 93 --- .../com/ivy/wallet/ui/budget/BudgetScreen.kt | 45 +- .../ivy/wallet/ui/budget/BudgetViewModel.kt | 114 +-- .../wallet/ui/budget/model/DisplayBudget.kt | 2 +- .../wallet/ui/category/CategoriesScreen.kt | 9 +- .../wallet/ui/category/CategoriesViewModel.kt | 33 +- .../ivy/wallet/ui/category/CategoryData.kt | 2 +- .../ivy/wallet/ui/charts/CategoryValues.kt | 2 +- .../com/ivy/wallet/ui/charts/ChartsScreen.kt | 8 +- .../ivy/wallet/ui/charts/ChartsViewModel.kt | 58 +- .../com/ivy/wallet/ui/charts/TimeValue.kt | 4 +- .../wallet/ui/charts/charts/AccountCharts.kt | 2 +- .../wallet/ui/charts/charts/CategoryCharts.kt | 4 +- .../wallet/ui/charts/charts/WalletCharts.kt | 4 +- .../ivy/wallet/ui/csvimport/ImportScreen.kt | 4 +- .../wallet/ui/csvimport/ImportViewModel.kt | 14 +- .../wallet/ui/csvimport/flow/ImportFrom.kt | 7 +- .../ui/csvimport/flow/ImportResultUI.kt | 4 +- .../flow/instructions/ImportInstructions.kt | 3 +- .../wallet/ui/edit/EditTransactionScreen.kt | 38 +- .../ui/edit/EditTransactionViewModel.kt | 144 ++-- .../com/ivy/wallet/ui/edit/core/Category.kt | 2 +- .../wallet/ui/edit/core/EditBottomSheet.kt | 2 +- .../com/ivy/wallet/ui/home/CustomerJourney.kt | 4 +- .../java/com/ivy/wallet/ui/home/HomeState.kt | 21 +- .../java/com/ivy/wallet/ui/home/HomeTab.kt | 13 +- .../com/ivy/wallet/ui/home/HomeViewModel.kt | 130 ++-- .../com/ivy/wallet/ui/loan/LoanViewModel.kt | 32 +- .../com/ivy/wallet/ui/loan/LoansScreen.kt | 2 +- .../ivy/wallet/ui/loan/data/DisplayLoan.kt | 2 +- .../wallet/ui/loan/data/DisplayLoanRecord.kt | 4 +- .../ui/loandetails/LoanDetailsScreen.kt | 12 +- .../ui/loandetails/LoanDetailsViewModel.kt | 42 +- .../java/com/ivy/wallet/ui/main/MainScreen.kt | 2 +- .../com/ivy/wallet/ui/main/MainViewModel.kt | 8 +- .../wallet/ui/onboarding/OnboardingScreen.kt | 8 +- .../ui/onboarding/components/Suggestions.kt | 6 +- .../ui/onboarding/model/AccountBalance.kt | 2 +- .../ui/onboarding/model/FromToTimeRange.kt | 12 +- .../ui/onboarding/steps/OnboardingAccounts.kt | 4 +- .../onboarding/steps/OnboardingCategories.kt | 4 +- .../onboarding/viewmodel/OnboardingRouter.kt | 18 +- .../viewmodel/OnboardingViewModel.kt | 49 +- .../ivy/wallet/ui/paywall/PaywallScreen.kt | 8 +- .../ivy/wallet/ui/paywall/PaywallViewModel.kt | 35 +- .../ui/planned/edit/EditPlannedScreen.kt | 8 +- .../ui/planned/edit/EditPlannedViewModel.kt | 42 +- .../ui/planned/list/PlannedPaymentCard.kt | 6 +- .../planned/list/PlannedPaymentsLazyColumn.kt | 16 +- .../ui/planned/list/PlannedPaymentsScreen.kt | 6 +- .../planned/list/PlannedPaymentsViewModel.kt | 20 +- .../ivy/wallet/ui/reports/FilterOverlay.kt | 4 +- .../com/ivy/wallet/ui/reports/ReportFilter.kt | 4 +- .../com/ivy/wallet/ui/reports/ReportScreen.kt | 20 +- .../wallet/ui/reports/ReportScreenEvent.kt | 2 +- .../wallet/ui/reports/ReportScreenState.kt | 6 +- .../ivy/wallet/ui/reports/ReportViewModel.kt | 159 ++-- .../com/ivy/wallet/ui/search/SearchScreen.kt | 12 +- .../ivy/wallet/ui/search/SearchViewModel.kt | 49 +- .../ivy/wallet/ui/settings/SettingsScreen.kt | 2 +- .../wallet/ui/settings/SettingsViewModel.kt | 17 +- .../ui/statistic/level1/CategoryAmount.kt | 4 +- .../wallet/ui/statistic/level1/PieChart.kt | 2 +- .../level1/PieChartStatisticScreen.kt | 4 +- .../level1/PieChartStatisticViewModel.kt | 107 +-- .../ui/statistic/level1/SelectedCategory.kt | 2 +- .../statistic/level2/ItemStatisticScreen.kt | 6 +- .../level2/ItemStatisticViewModel.kt | 133 ++-- .../java/com/ivy/wallet/ui/test/TestScreen.kt | 2 +- .../com/ivy/wallet/ui/test/TestViewModel.kt | 8 +- .../ui/theme/components/WrapContentRow.kt | 2 +- .../ivy/wallet/ui/theme/modal/BudgetModal.kt | 21 +- .../ivy/wallet/ui/theme/modal/LoanModal.kt | 8 +- .../wallet/ui/theme/modal/LoanRecordModal.kt | 10 +- .../ui/theme/modal/edit/AccountModal.kt | 4 +- .../wallet/ui/theme/modal/edit/AmountModal.kt | 12 +- .../ui/theme/modal/edit/CategoryModal.kt | 4 +- .../theme/modal/edit/ChooseCategoryModal.kt | 2 +- .../ui/theme/transaction/TransactionCard.kt | 22 +- .../ui/theme/transaction/Transactions.kt | 14 +- .../com/ivy/wallet/buildsrc/dependencies.kt | 16 + ivy-fp/.gitignore | 1 + ivy-fp/build.gradle.kts | 52 ++ ivy-fp/consumer-rules.pro | 0 ivy-fp/proguard-rules.pro | 21 + .../com/ivy/design/ExampleInstrumentedTest.kt | 22 + ivy-fp/src/main/AndroidManifest.xml | 4 + .../src/main/java/com/ivy/fp/Composition.kt | 55 ++ ivy-fp/src/main/java/com/ivy/fp/Utils.kt | 19 + .../src/main/java/com/ivy/fp/action/Action.kt | 26 + .../java/com/ivy/fp/action/Composition.kt | 58 ++ .../com/ivy/fp/action/CompositionFilter.kt | 28 + .../java/com/ivy/fp/action/CompositionMap.kt | 51 ++ .../java/com/ivy/fp/action/CompositionSum.kt | 29 + .../main/java/com/ivy/fp/action/FPAction.kt | 17 + .../com/ivy/fp}/viewmodel/IvyViewModel.kt | 2 +- .../com/ivy/fp}/viewmodel/ViewmodelUtils.kt | 2 +- .../java/com/ivy/design/ExampleUnitTest.kt | 16 + settings.gradle.kts | 6 +- 311 files changed, 5740 insertions(+), 4139 deletions(-) create mode 100644 app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/121.json create mode 100644 app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/122.json delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/Action.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccIncomeExpenseAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/budget/BudgetsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/category/CategoriesAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/category/CategoryByIdAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/category/CategoryTrnsBetweenAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/exchange/ExchangeAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/settings/GetBaseCurrencyAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/AllTrnsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/CalcTrnsIncomeExpenseAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnByIdAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/account/AccountDataAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/action/wallet/HistoryWithDateDivAct.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccount.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccountConnection.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEConnection.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SECustomer.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SETransaction.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/data/core/User.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/entity/ExchangeRate.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/entity/LoanRecord.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/data/entity/WishlistItem.kt rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/AccountCreator.kt (83%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/BudgetCreator.kt (87%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/CategoryCreator.kt (83%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/CustomerJourneyLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/LoanCreator.kt (88%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/LoanRecordCreator.kt (87%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/LogoutLogic.kt (93%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/PaywallLogic.kt (99%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/PlannedPaymentsGenerator.kt (91%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/PlannedPaymentsLogic.kt (86%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/PreloadDataLogic.kt (72%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/SmartTitleSuggestionsLogic.kt (94%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/WalletAccountLogic.kt (77%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/WalletCategoryLogic.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/CSVImporter.kt (94%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/CSVMapper.kt (95%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/CSVNormalizer.kt (77%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/ExportCSVLogic.kt (89%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/IvyFileReader.kt (88%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/model/CSVRow.kt (55%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/model/ImportResult.kt (76%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/model/ImportType.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/csv/model/RowMapping.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/currency/ExchangeRatesLogic.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/loantrasactions/LTLoanMapper.kt (71%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/loantrasactions/LTLoanRecordMapper.kt (85%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/loantrasactions/LoanTransactionsCore.kt (91%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/loantrasactions/LoanTransactionsLogic.kt (91%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateAccountData.kt (81%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateBudgetData.kt (74%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateCategoryData.kt (72%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateLoanData.kt (75%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CreateLoanRecordData.kt (75%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/CustomerJourneyCardData.kt (91%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/model/EditLoanRecordData.kt (67%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/notification/TransactionReminderLogic.kt (97%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/notification/TransactionReminderWorker.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/zip/ExportZipLogic.kt (88%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/logic/zip/ZipUtils.kt (98%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/IvySync.kt (92%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/AccountSync.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/BudgetSync.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/CategorySync.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/LoanRecordSync.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/LoanSync.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/PlannedPaymentSync.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/item/TransactionSync.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/AccountUploader.kt (91%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/BudgetUploader.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/CategoryUploader.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/LoanRecordUploader.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/LoanUploader.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/PlannedPaymentRuleUploader.kt (90%) rename app/src/main/java/com/ivy/wallet/domain/{ => deprecated}/sync/uploader/TransactionUploader.kt (90%) delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryCore.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryFunctions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/core/CoreValueFunctions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/core/TransactionFunctions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/core/Uncertain.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/core/ValueFunction.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/data/CurrencyConvError.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/data/FPAccount.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/data/FPTransaction.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/logic/WalletLogic.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/BankIntegrationsLogic.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeAccountMapper.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeCategoryMapper.kt delete mode 100644 app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeTransactionMapper.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/charts/ChartPeriod.kt (89%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/charts/ChartsCore.kt (65%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/charts/WalletCharts.kt (71%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/ClosedTimeRange.kt (94%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/IncomeExpensePair.kt (85%) rename app/src/main/java/com/ivy/wallet/domain/{fp => pure}/data/WalletDAOs.kt (88%) rename app/src/main/java/com/ivy/wallet/domain/{fp/ExchangeRates.kt => pure/exchange/Exchange.kt} (51%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt rename app/src/main/java/com/ivy/wallet/domain/{fp/account/AccountValueFunctions.kt => pure/transaction/AccValueFunctions.kt} (68%) rename app/src/main/java/com/ivy/wallet/domain/{fp/category/CategoryValueFunctions.kt => pure/transaction/CatValueFunctions.kt} (58%) create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt create mode 100644 app/src/main/java/com/ivy/wallet/domain/pure/transaction/WalletValueFunctions.kt rename app/src/main/java/com/ivy/wallet/domain/{fp/core => pure/util}/Utils.kt (78%) create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/AccountDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/BudgetDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/CategoryDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/ExchangeRateDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/LoanDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/LoanRecordDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/PlannedPaymentRuleDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/SettingsDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/TransactionDTO.kt create mode 100644 app/src/main/java/com/ivy/wallet/io/network/data/UserDTO.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankAccountsResponse.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionSessionResponse.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionsResponse.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankTransactionsResponse.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/network/service/BankIntegrationsService.kt delete mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/dao/WishlistItemDao.kt rename app/src/main/java/com/ivy/wallet/{domain/data/entity/Account.kt => io/persistence/data/AccountEntity.kt} (55%) rename app/src/main/java/com/ivy/wallet/{domain/data/entity/Budget.kt => io/persistence/data/BudgetEntity.kt} (69%) rename app/src/main/java/com/ivy/wallet/{domain/data/entity/Category.kt => io/persistence/data/CategoryEntity.kt} (56%) create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/ExchangeRateEntity.kt rename app/src/main/java/com/ivy/wallet/{domain/data/entity/Loan.kt => io/persistence/data/LoanEntity.kt} (52%) create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/data/LoanRecordEntity.kt rename app/src/main/java/com/ivy/wallet/{domain/data/entity/PlannedPaymentRule.kt => io/persistence/data/PlannedPaymentRuleEntity.kt} (54%) rename app/src/main/java/com/ivy/wallet/{domain/data/entity/Settings.kt => io/persistence/data/SettingsEntity.kt} (54%) rename app/src/main/java/com/ivy/wallet/{domain/data/entity/Transaction.kt => io/persistence/data/TransactionEntity.kt} (61%) rename app/src/main/java/com/ivy/wallet/{domain/data/entity/User.kt => io/persistence/data/UserEntity.kt} (63%) create mode 100644 app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt delete mode 100644 app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankScreen.kt delete mode 100644 app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankViewModel.kt create mode 100644 ivy-fp/.gitignore create mode 100644 ivy-fp/build.gradle.kts create mode 100644 ivy-fp/consumer-rules.pro create mode 100644 ivy-fp/proguard-rules.pro create mode 100644 ivy-fp/src/androidTest/java/com/ivy/design/ExampleInstrumentedTest.kt create mode 100644 ivy-fp/src/main/AndroidManifest.xml create mode 100644 ivy-fp/src/main/java/com/ivy/fp/Composition.kt create mode 100644 ivy-fp/src/main/java/com/ivy/fp/Utils.kt create mode 100644 ivy-fp/src/main/java/com/ivy/fp/action/Action.kt create mode 100644 ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt create mode 100644 ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt create mode 100644 ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt create mode 100644 ivy-fp/src/main/java/com/ivy/fp/action/CompositionSum.kt create mode 100644 ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt rename {ivy-design/src/main/java/com/ivy/design => ivy-fp/src/main/java/com/ivy/fp}/viewmodel/IvyViewModel.kt (94%) rename {ivy-design/src/main/java/com/ivy/design => ivy-fp/src/main/java/com/ivy/fp}/viewmodel/ViewmodelUtils.kt (83%) create mode 100644 ivy-fp/src/test/java/com/ivy/design/ExampleUnitTest.kt diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 7f1f804381..d0b810ad20 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -140,6 +140,8 @@ -keep class com.ivy.wallet.domain.data.** { *; } -keep class com.ivy.wallet.ui.widget.** { *; } -keep class com.ivy.wallet.io.network.** { *; } +-keep class com.ivy.wallet.io.persistence.data.** { *; } +-keep class com.ivy.wallet.io.network.data.** { *; } -keep class com.ivy.wallet.domain.event.** { *; } # Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory, diff --git a/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/121.json b/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/121.json new file mode 100644 index 0000000000..83dd1a6fb9 --- /dev/null +++ b/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/121.json @@ -0,0 +1,707 @@ +{ + "formatVersion": 1, + "database": { + "version": 121, + "identityHash": "319b13332051b3e936a5902b2b7a2ad5", + "entities": [ + { + "tableName": "accounts", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `currency` TEXT, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `includeInBalance` INTEGER NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "includeInBalance", + "columnName": "includeInBalance", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "transactions", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountId` TEXT NOT NULL, `type` TEXT NOT NULL, `amount` REAL NOT NULL, `toAccountId` TEXT, `toAmount` REAL, `title` TEXT, `description` TEXT, `dateTime` INTEGER, `categoryId` TEXT, `dueDate` INTEGER, `recurringRuleId` TEXT, `attachmentUrl` TEXT, `loanId` TEXT, `loanRecordId` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "toAccountId", + "columnName": "toAccountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "toAmount", + "columnName": "toAmount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dateTime", + "columnName": "dateTime", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "categoryId", + "columnName": "categoryId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dueDate", + "columnName": "dueDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "recurringRuleId", + "columnName": "recurringRuleId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "attachmentUrl", + "columnName": "attachmentUrl", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "loanId", + "columnName": "loanId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "loanRecordId", + "columnName": "loanRecordId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "categories", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "settings", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`theme` TEXT NOT NULL, `currency` TEXT NOT NULL, `bufferAmount` REAL NOT NULL, `name` TEXT NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "theme", + "columnName": "theme", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "bufferAmount", + "columnName": "bufferAmount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "planned_payment_rules", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`startDate` INTEGER, `intervalN` INTEGER, `intervalType` TEXT, `oneTime` INTEGER NOT NULL, `type` TEXT NOT NULL, `accountId` TEXT NOT NULL, `amount` REAL NOT NULL, `categoryId` TEXT, `title` TEXT, `description` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "startDate", + "columnName": "startDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "intervalN", + "columnName": "intervalN", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "intervalType", + "columnName": "intervalType", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "oneTime", + "columnName": "oneTime", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "categoryId", + "columnName": "categoryId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "users", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`email` TEXT NOT NULL, `authProviderType` TEXT NOT NULL, `firstName` TEXT NOT NULL, `lastName` TEXT, `profilePicture` TEXT, `color` INTEGER NOT NULL, `testUser` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "email", + "columnName": "email", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "authProviderType", + "columnName": "authProviderType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "firstName", + "columnName": "firstName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastName", + "columnName": "lastName", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "profilePicture", + "columnName": "profilePicture", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "testUser", + "columnName": "testUser", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "exchange_rates", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`baseCurrency` TEXT NOT NULL, `currency` TEXT NOT NULL, `rate` REAL NOT NULL, PRIMARY KEY(`baseCurrency`, `currency`))", + "fields": [ + { + "fieldPath": "baseCurrency", + "columnName": "baseCurrency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "rate", + "columnName": "rate", + "affinity": "REAL", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "baseCurrency", + "currency" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "budgets", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `categoryIdsSerialized` TEXT, `accountIdsSerialized` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `orderId` REAL NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "categoryIdsSerialized", + "columnName": "categoryIdsSerialized", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "accountIdsSerialized", + "columnName": "accountIdsSerialized", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "orderId", + "columnName": "orderId", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "loans", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `type` TEXT NOT NULL, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `accountId` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "loan_records", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`loanId` TEXT NOT NULL, `amount` REAL NOT NULL, `note` TEXT, `dateTime` INTEGER NOT NULL, `interest` INTEGER NOT NULL, `accountId` TEXT, `convertedAmount` REAL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "loanId", + "columnName": "loanId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "note", + "columnName": "note", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dateTime", + "columnName": "dateTime", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "interest", + "columnName": "interest", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "convertedAmount", + "columnName": "convertedAmount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '319b13332051b3e936a5902b2b7a2ad5')" + ] + } +} \ No newline at end of file diff --git a/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/122.json b/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/122.json new file mode 100644 index 0000000000..295aa84e59 --- /dev/null +++ b/app/schemas/com.ivy.wallet.io.persistence.IvyRoomDatabase/122.json @@ -0,0 +1,707 @@ +{ + "formatVersion": 1, + "database": { + "version": 122, + "identityHash": "319b13332051b3e936a5902b2b7a2ad5", + "entities": [ + { + "tableName": "accounts", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `currency` TEXT, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `includeInBalance` INTEGER NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "includeInBalance", + "columnName": "includeInBalance", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "transactions", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountId` TEXT NOT NULL, `type` TEXT NOT NULL, `amount` REAL NOT NULL, `toAccountId` TEXT, `toAmount` REAL, `title` TEXT, `description` TEXT, `dateTime` INTEGER, `categoryId` TEXT, `dueDate` INTEGER, `recurringRuleId` TEXT, `attachmentUrl` TEXT, `loanId` TEXT, `loanRecordId` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "toAccountId", + "columnName": "toAccountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "toAmount", + "columnName": "toAmount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dateTime", + "columnName": "dateTime", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "categoryId", + "columnName": "categoryId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dueDate", + "columnName": "dueDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "recurringRuleId", + "columnName": "recurringRuleId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "attachmentUrl", + "columnName": "attachmentUrl", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "loanId", + "columnName": "loanId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "loanRecordId", + "columnName": "loanRecordId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "categories", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "settings", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`theme` TEXT NOT NULL, `currency` TEXT NOT NULL, `bufferAmount` REAL NOT NULL, `name` TEXT NOT NULL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "theme", + "columnName": "theme", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "bufferAmount", + "columnName": "bufferAmount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "planned_payment_rules", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`startDate` INTEGER, `intervalN` INTEGER, `intervalType` TEXT, `oneTime` INTEGER NOT NULL, `type` TEXT NOT NULL, `accountId` TEXT NOT NULL, `amount` REAL NOT NULL, `categoryId` TEXT, `title` TEXT, `description` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "startDate", + "columnName": "startDate", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "intervalN", + "columnName": "intervalN", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "intervalType", + "columnName": "intervalType", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "oneTime", + "columnName": "oneTime", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "categoryId", + "columnName": "categoryId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "users", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`email` TEXT NOT NULL, `authProviderType` TEXT NOT NULL, `firstName` TEXT NOT NULL, `lastName` TEXT, `profilePicture` TEXT, `color` INTEGER NOT NULL, `testUser` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "email", + "columnName": "email", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "authProviderType", + "columnName": "authProviderType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "firstName", + "columnName": "firstName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastName", + "columnName": "lastName", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "profilePicture", + "columnName": "profilePicture", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "testUser", + "columnName": "testUser", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "exchange_rates", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`baseCurrency` TEXT NOT NULL, `currency` TEXT NOT NULL, `rate` REAL NOT NULL, PRIMARY KEY(`baseCurrency`, `currency`))", + "fields": [ + { + "fieldPath": "baseCurrency", + "columnName": "baseCurrency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "currency", + "columnName": "currency", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "rate", + "columnName": "rate", + "affinity": "REAL", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "baseCurrency", + "currency" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "budgets", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `categoryIdsSerialized` TEXT, `accountIdsSerialized` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `orderId` REAL NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "categoryIdsSerialized", + "columnName": "categoryIdsSerialized", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "accountIdsSerialized", + "columnName": "accountIdsSerialized", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "orderId", + "columnName": "orderId", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "loans", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `amount` REAL NOT NULL, `type` TEXT NOT NULL, `color` INTEGER NOT NULL, `icon` TEXT, `orderNum` REAL NOT NULL, `accountId` TEXT, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "type", + "columnName": "type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "orderNum", + "columnName": "orderNum", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "loan_records", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`loanId` TEXT NOT NULL, `amount` REAL NOT NULL, `note` TEXT, `dateTime` INTEGER NOT NULL, `interest` INTEGER NOT NULL, `accountId` TEXT, `convertedAmount` REAL, `isSynced` INTEGER NOT NULL, `isDeleted` INTEGER NOT NULL, `id` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "loanId", + "columnName": "loanId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "amount", + "columnName": "amount", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "note", + "columnName": "note", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "dateTime", + "columnName": "dateTime", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "interest", + "columnName": "interest", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "accountId", + "columnName": "accountId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "convertedAmount", + "columnName": "convertedAmount", + "affinity": "REAL", + "notNull": false + }, + { + "fieldPath": "isSynced", + "columnName": "isSynced", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDeleted", + "columnName": "isDeleted", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '319b13332051b3e936a5902b2b7a2ad5')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/AppModuleDI.kt b/app/src/main/java/com/ivy/wallet/AppModuleDI.kt index 502a42c43d..d204a1baf9 100644 --- a/app/src/main/java/com/ivy/wallet/AppModuleDI.kt +++ b/app/src/main/java/com/ivy/wallet/AppModuleDI.kt @@ -6,23 +6,19 @@ import com.google.gson.GsonBuilder import com.ivy.design.navigation.Navigation import com.ivy.wallet.android.billing.IvyBilling import com.ivy.wallet.android.notification.NotificationService -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.logic.* -import com.ivy.wallet.domain.logic.bankintegrations.BankIntegrationsLogic -import com.ivy.wallet.domain.logic.bankintegrations.SaltEdgeAccountMapper -import com.ivy.wallet.domain.logic.bankintegrations.SaltEdgeCategoryMapper -import com.ivy.wallet.domain.logic.bankintegrations.SaltEdgeTransactionMapper -import com.ivy.wallet.domain.logic.csv.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.loantrasactions.LTLoanMapper -import com.ivy.wallet.domain.logic.loantrasactions.LTLoanRecordMapper -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsCore -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic -import com.ivy.wallet.domain.logic.zip.ExportZipLogic -import com.ivy.wallet.domain.sync.IvySync -import com.ivy.wallet.domain.sync.item.* -import com.ivy.wallet.domain.sync.uploader.* +import com.ivy.wallet.domain.deprecated.logic.* +import com.ivy.wallet.domain.deprecated.logic.csv.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LTLoanMapper +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LTLoanRecordMapper +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsCore +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.logic.zip.ExportZipLogic +import com.ivy.wallet.domain.deprecated.sync.IvySync +import com.ivy.wallet.domain.deprecated.sync.item.* +import com.ivy.wallet.domain.deprecated.sync.uploader.* +import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.io.network.* import com.ivy.wallet.io.network.error.ErrorCode import com.ivy.wallet.io.persistence.IvyRoomDatabase @@ -117,9 +113,6 @@ object AppModuleDI { @Provides fun provideBudgetDao(db: IvyRoomDatabase): BudgetDao = db.budgetDao() - @Provides - fun provideWishlistItemDao(db: IvyRoomDatabase): WishlistItemDao = db.wishlistItemDao() - @Provides fun provideSettingsDao(db: IvyRoomDatabase): SettingsDao = db.settingsDao() @@ -133,18 +126,6 @@ object AppModuleDI { fun provideTrnRecurringRuleDao(db: IvyRoomDatabase): PlannedPaymentRuleDao = db.plannedPaymentRuleDao() - @Provides - fun provideWalletLogic( - accountDao: AccountDao, - transactionDao: TransactionDao, - settingsDao: SettingsDao, - exchangeRatesLogic: ExchangeRatesLogic, - ): WalletLogic = WalletLogic( - accountDao = accountDao, - transactionDao = transactionDao, - settingsDao = settingsDao, - exchangeRatesLogic = exchangeRatesLogic, - ) @Provides fun provideWalletAccountLogic( @@ -658,56 +639,6 @@ object AppModuleDI { ) } - @Provides - fun provideSaltEdgeLogic( - restClient: RestClient, - seTransactionsMapper: SaltEdgeTransactionMapper, - ivySession: IvySession, - sharedPrefs: SharedPrefs - ): BankIntegrationsLogic { - return BankIntegrationsLogic( - restClient = restClient, - seTransactionMapper = seTransactionsMapper, - ivySession = ivySession, - sharedPrefs = sharedPrefs - ) - } - - @Provides - fun provideSeTransactionMapper( - transactionDao: TransactionDao, - seAccountMapper: SaltEdgeAccountMapper, - seCategoryMapper: SaltEdgeCategoryMapper, - accountDao: AccountDao, - walletAccountLogic: WalletAccountLogic - ): SaltEdgeTransactionMapper { - return SaltEdgeTransactionMapper( - transactionDao = transactionDao, - seAccountMapper = seAccountMapper, - seCategoryMapper = seCategoryMapper, - accountDao = accountDao, - walletAccountLogic = walletAccountLogic - ) - } - - @Provides - fun provideSeAccountMapper( - accountDao: AccountDao - ): SaltEdgeAccountMapper { - return SaltEdgeAccountMapper( - accountDao = accountDao - ) - } - - @Provides - fun provideSeCategoryMapper( - categoryDao: CategoryDao - ): SaltEdgeCategoryMapper { - return SaltEdgeCategoryMapper( - categoryDao = categoryDao - ) - } - @Provides fun provideCustomerJourneyLogic( transactionDao: TransactionDao, diff --git a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt b/app/src/main/java/com/ivy/wallet/domain/action/Action.kt deleted file mode 100644 index 4c46662198..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/Action.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.ivy.wallet.domain.action - -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext - -abstract class Action { - abstract suspend fun I.willDo(): O - - suspend operator fun invoke(input: I): O { - return input.willDo() - } - - protected suspend fun io(action: suspend () -> T): T = withContext(Dispatchers.IO) { - return@withContext action() - } - - protected suspend fun computation(action: suspend () -> T): T = - withContext(Dispatchers.Main) { - return@withContext action() - } -} - -infix fun Action.after(act1: Action): Action = object : Action() { - override suspend fun A.willDo(): C { - val b = act1(this@willDo) //A -> B - return this@after(b) //B -> C - } -} - -infix fun Action.then(act2: Action): Action = object : Action() { - override suspend fun A.willDo(): C { - val b = this@then(this) - return act2(b) - } -} - -///** -// * Action composition example -// */ -//suspend fun example( -// calcWalletBalance: CalcWalletBalanceAct, -// getBaseCurrency: GetBaseCurrencyAct -//): BigDecimal { -// return (calcWalletBalance after getBaseCurrency)(Unit) -//} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt new file mode 100644 index 0000000000..97c86a0972 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccTrnsAct.kt @@ -0,0 +1,35 @@ +package com.ivy.wallet.domain.action.account + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.io.persistence.dao.TransactionDao +import java.util.* +import javax.inject.Inject + +class AccTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + override suspend fun Input.compose(): suspend () -> List = suspend { + io { + transactionDao.findAllByAccountAndBetween( + accountId = accountId, + startDate = range.from, + endDate = range.to + ) + transactionDao.findAllToAccountAndBetween( + toAccountId = accountId, + startDate = range.from, + endDate = range.to + ) + } + } thenMap { + it.toDomain() + } + + class Input( + val accountId: UUID, + val range: ClosedTimeRange + ) +} + diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.kt new file mode 100644 index 0000000000..da343e503a --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.kt @@ -0,0 +1,18 @@ +package com.ivy.wallet.domain.action.account + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.io.persistence.dao.AccountDao +import java.util.* +import javax.inject.Inject + +class AccountByIdAct @Inject constructor( + private val accountDao: AccountDao +) : FPAction() { + override suspend fun UUID.compose(): suspend () -> Account? = suspend { + this //accountId + } then accountDao::findById then { + it?.toDomain() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt new file mode 100644 index 0000000000..f199a896ba --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/AccountsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.account + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.io.persistence.dao.AccountDao +import javax.inject.Inject + +class AccountsAct @Inject constructor( + private val accountDao: AccountDao +) : FPAction>() { + + override suspend fun Unit.compose(): suspend () -> List = suspend { + io { accountDao.findAll().map { it.toDomain() } } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt new file mode 100644 index 0000000000..04dc6c1112 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccBalanceAct.kt @@ -0,0 +1,44 @@ +package com.ivy.wallet.domain.action.account + +import arrow.core.nonEmptyListOf +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions +import com.ivy.wallet.domain.pure.transaction.foldTransactions +import java.math.BigDecimal +import javax.inject.Inject + +class CalcAccBalanceAct @Inject constructor( + private val accTrnsAct: AccTrnsAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + AccTrnsAct.Input( + accountId = account.id, + range = range + ) + } then accTrnsAct then { accTrns -> + foldTransactions( + transactions = accTrns, + arg = account.id, + valueFunctions = nonEmptyListOf(AccountValueFunctions::balance) + ).head + } then { balance -> + Output( + account = account, + balance = balance + ) + } + + data class Input( + val account: Account, + val range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() + ) + + data class Output( + val account: Account, + val balance: BigDecimal, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccIncomeExpenseAct.kt new file mode 100644 index 0000000000..2538904d02 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/account/CalcAccIncomeExpenseAct.kt @@ -0,0 +1,50 @@ +package com.ivy.wallet.domain.action.account + +import arrow.core.nonEmptyListOf +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions +import com.ivy.wallet.domain.pure.transaction.foldTransactions +import javax.inject.Inject + +class CalcAccIncomeExpenseAct @Inject constructor( + private val accTrnsAct: AccTrnsAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + AccTrnsAct.Input( + accountId = account.id, + range = range + ) + } then accTrnsAct then { accTrns -> + foldTransactions( + transactions = accTrns, + arg = account.id, + valueFunctions = nonEmptyListOf( + AccountValueFunctions::income, + AccountValueFunctions::expense + ) + ) + } then { values -> + Output( + account = account, + incomeExpensePair = IncomeExpensePair( + income = values[0], + expense = values[1] + ) + ) + } + + data class Input( + val account: Account, + val range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() + ) + + data class Output( + val account: Account, + val incomeExpensePair: IncomeExpensePair + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/budget/BudgetsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/budget/BudgetsAct.kt new file mode 100644 index 0000000000..46c713f841 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/budget/BudgetsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.budget + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.io.persistence.dao.BudgetDao +import javax.inject.Inject + +class BudgetsAct @Inject constructor( + private val budgetDao: BudgetDao +) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { + budgetDao.findAll() + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/category/CategoriesAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoriesAct.kt new file mode 100644 index 0000000000..f0c5869cdd --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoriesAct.kt @@ -0,0 +1,17 @@ +package com.ivy.wallet.domain.action.category + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.io.persistence.dao.CategoryDao +import javax.inject.Inject + +class CategoriesAct @Inject constructor( + private val categoryDao: CategoryDao +) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { + io { + categoryDao.findAll() + } + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryByIdAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryByIdAct.kt new file mode 100644 index 0000000000..00beafbf43 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryByIdAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.category + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.io.persistence.dao.CategoryDao +import java.util.* +import javax.inject.Inject + +class CategoryByIdAct @Inject constructor( + private val categoryDao: CategoryDao +) : FPAction() { + override suspend fun UUID.compose(): suspend () -> Category? = suspend { + categoryDao.findById(this)?.toDomain() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryTrnsBetweenAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryTrnsBetweenAct.kt new file mode 100644 index 0000000000..1303090ac9 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/category/CategoryTrnsBetweenAct.kt @@ -0,0 +1,37 @@ +package com.ivy.wallet.domain.action.category + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.io.persistence.dao.TransactionDao +import java.util.* +import javax.inject.Inject + +class CategoryTrnsBetweenAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + io { + transactionDao.findAllByCategoryAndBetween( + startDate = between.from, + endDate = between.to, + categoryId = categoryId + ) + } + } thenMap { it.toDomain() } + + data class Input( + val categoryId: UUID, + val between: ClosedTimeRange + ) +} + +fun actInput( + categoryId: UUID, + between: ClosedTimeRange +) = CategoryTrnsBetweenAct.Input( + categoryId = categoryId, + between = between +) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt new file mode 100644 index 0000000000..9f5a570121 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/charts/BalanceChartAct.kt @@ -0,0 +1,34 @@ +package com.ivy.wallet.domain.action.charts + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.balanceChart +import javax.inject.Inject + +class BalanceChartAct @Inject constructor( + private val calcWalletBalanceAct: CalcWalletBalanceAct +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + io { + balanceChart( + period = period, + calcWalletBalance = { range -> + calcWalletBalanceAct( + CalcWalletBalanceAct.Input( + baseCurrency = baseCurrency, + range = range + ) + ) + } + ) + } + } + + data class Input( + val baseCurrency: String, + val period: ChartPeriod + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/exchange/ExchangeAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/exchange/ExchangeAct.kt new file mode 100644 index 0000000000..7906d11a7b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/exchange/ExchangeAct.kt @@ -0,0 +1,39 @@ +package com.ivy.wallet.domain.action.exchange + +import arrow.core.Option +import com.ivy.fp.action.FPAction +import com.ivy.fp.then +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.exchange.exchange +import com.ivy.wallet.io.persistence.dao.ExchangeRateDao +import java.math.BigDecimal +import javax.inject.Inject + +class ExchangeAct @Inject constructor( + private val exchangeRateDao: ExchangeRateDao, +) : FPAction>() { + override suspend fun Input.compose(): suspend () -> Option = suspend { + io { + exchange( + data = data, + amount = amount, + getExchangeRate = exchangeRateDao::findByBaseCurrencyAndCurrency then { + it?.toDomain() + } + ) + } + } + + data class Input( + val data: ExchangeData, + val amount: BigDecimal + ) +} + +fun actInput( + data: ExchangeData, + amount: BigDecimal +): ExchangeAct.Input = ExchangeAct.Input( + data = data, + amount = amount +) diff --git a/app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt new file mode 100644 index 0000000000..9e771cc9cd --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/loan/LoanByIdAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.loan + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.io.persistence.dao.LoanDao +import java.util.* +import javax.inject.Inject + +class LoanByIdAct @Inject constructor( + private val loanDao: LoanDao +) : FPAction() { + override suspend fun UUID.compose(): suspend () -> Loan? = suspend { + loanDao.findById(this)?.toDomain() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt new file mode 100644 index 0000000000..86c2c8fc23 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/loan/LoansAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.loan + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.io.persistence.dao.LoanDao +import javax.inject.Inject + +class LoansAct @Inject constructor( + private val loanDao: LoanDao +) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { + loanDao.findAll() + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt new file mode 100644 index 0000000000..6d989e8ff4 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/BaseCurrencyAct.kt @@ -0,0 +1,13 @@ +package com.ivy.wallet.domain.action.settings + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.io.persistence.dao.SettingsDao +import javax.inject.Inject + +class BaseCurrencyAct @Inject constructor( + private val settingsDao: SettingsDao +) : FPAction() { + override suspend fun Unit.compose(): suspend () -> String = suspend { + io { settingsDao.findFirst().currency } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.kt new file mode 100644 index 0000000000..845362449d --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.kt @@ -0,0 +1,17 @@ +package com.ivy.wallet.domain.action.settings + +import com.ivy.fp.action.FPAction +import java.math.BigDecimal +import javax.inject.Inject + +class CalcBufferDiffAct @Inject constructor() : FPAction() { + + override suspend fun Input.compose(): suspend () -> BigDecimal = { + balance - buffer + } + + data class Input( + val balance: BigDecimal, + val buffer: BigDecimal + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/GetBaseCurrencyAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/GetBaseCurrencyAct.kt deleted file mode 100644 index f3cfe73457..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/settings/GetBaseCurrencyAct.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.ivy.wallet.domain.action.settings - -import com.ivy.wallet.domain.action.Action -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.io.persistence.dao.SettingsDao -import javax.inject.Inject - -class GetBaseCurrencyAct @Inject constructor( - private val settingsDao: SettingsDao -) : Action() { - override suspend fun Unit.willDo(): String = io { - baseCurrencyCode(settingsDao) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.kt new file mode 100644 index 0000000000..e354ffb166 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.settings + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Settings +import com.ivy.wallet.io.persistence.dao.SettingsDao +import javax.inject.Inject + +class SettingsAct @Inject constructor( + private val settingsDao: SettingsDao +) : FPAction() { + override suspend fun Unit.compose(): suspend () -> Settings = suspend { + io { settingsDao.findFirst() } + } then { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/AllTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AllTrnsAct.kt new file mode 100644 index 0000000000..0ce113479e --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/AllTrnsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.io.persistence.dao.TransactionDao +import javax.inject.Inject + +class AllTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + override suspend fun Unit.compose(): suspend () -> List = suspend { + transactionDao.findAll() + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/CalcTrnsIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/CalcTrnsIncomeExpenseAct.kt new file mode 100644 index 0000000000..002b9a1ad2 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/CalcTrnsIncomeExpenseAct.kt @@ -0,0 +1,44 @@ +package com.ivy.wallet.domain.action.transaction + +import arrow.core.nonEmptyListOf +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.fp.then +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.exchange.actInput +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.WalletValueFunctions +import com.ivy.wallet.domain.pure.transaction.foldTransactionsSuspend +import javax.inject.Inject + +class CalcTrnsIncomeExpenseAct @Inject constructor( + private val exchangeAct: ExchangeAct +) : FPAction() { + override suspend fun Input.compose(): suspend () -> IncomeExpensePair = suspend { + foldTransactionsSuspend( + transactions = transactions, + valueFunctions = nonEmptyListOf( + WalletValueFunctions::income, + WalletValueFunctions::expense, + ), + arg = WalletValueFunctions.Argument( + accounts = accounts, + baseCurrency = baseCurrency, + exchange = ::actInput then exchangeAct + ) + ) + } then { values -> + IncomeExpensePair( + income = values[0], + expense = values[1] + ) + } + + data class Input( + val transactions: List, + val baseCurrency: String, + val accounts: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.kt new file mode 100644 index 0000000000..f61f349354 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.kt @@ -0,0 +1,22 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.io.persistence.dao.TransactionDao +import javax.inject.Inject + +class DueTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + + override suspend fun ClosedTimeRange.compose(): suspend () -> List = suspend { + io { + transactionDao.findAllDueToBetween( + startDate = from, + endDate = to + ) + } + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt new file mode 100644 index 0000000000..66442f80f3 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryTrnsAct.kt @@ -0,0 +1,22 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.io.persistence.dao.TransactionDao +import javax.inject.Inject + +class HistoryTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction>() { + + override suspend fun ClosedTimeRange.compose(): suspend () -> List = suspend { + io { + transactionDao.findAllBetween( + startDate = from, + endDate = to + ) + } + } thenMap { it.toDomain() } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt new file mode 100644 index 0000000000..2449faf0fc --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.kt @@ -0,0 +1,27 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.TransactionHistoryItem +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import javax.inject.Inject + +class HistoryWithDateDivsAct @Inject constructor( + private val historyTrnsAct: HistoryTrnsAct, + private val trnsWithDateDivsAct: TrnsWithDateDivsAct +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + range + } then historyTrnsAct then { trns -> + TrnsWithDateDivsAct.Input( + baseCurrency = baseCurrency, + transactions = trns + ) + } then trnsWithDateDivsAct + + data class Input( + val range: ClosedTimeRange, + val baseCurrency: String + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnByIdAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnByIdAct.kt new file mode 100644 index 0000000000..d075b66dd6 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnByIdAct.kt @@ -0,0 +1,18 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.io.persistence.dao.TransactionDao +import java.util.* +import javax.inject.Inject + +class TrnByIdAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction() { + override suspend fun UUID.compose(): suspend () -> Transaction? = suspend { + this //transactionId + } then transactionDao::findById then { + it?.toDomain() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt new file mode 100644 index 0000000000..08d09ad07c --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/transaction/TrnsWithDateDivsAct.kt @@ -0,0 +1,32 @@ +package com.ivy.wallet.domain.action.transaction + +import com.ivy.fp.action.FPAction +import com.ivy.fp.then +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.exchange.actInput +import com.ivy.wallet.domain.data.TransactionHistoryItem +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.transaction.transactionsWithDateDividers +import com.ivy.wallet.io.persistence.dao.AccountDao +import javax.inject.Inject + +class TrnsWithDateDivsAct @Inject constructor( + private val accountDao: AccountDao, + private val exchangeAct: ExchangeAct +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + transactionsWithDateDividers( + transactions = transactions, + baseCurrencyCode = baseCurrency, + + getAccount = accountDao::findById then { it?.toDomain() }, + exchange = ::actInput then exchangeAct + ) + } + + data class Input( + val baseCurrency: String, + val transactions: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/account/AccountDataAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/account/AccountDataAct.kt new file mode 100644 index 0000000000..68265aeddd --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/account/AccountDataAct.kt @@ -0,0 +1,65 @@ +package com.ivy.wallet.domain.action.viewmodel.account + +import arrow.core.toOption +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.action.account.CalcAccBalanceAct +import com.ivy.wallet.domain.action.account.CalcAccIncomeExpenseAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.ui.accounts.AccountData +import javax.inject.Inject + +class AccountDataAct @Inject constructor( + private val exchangeAct: ExchangeAct, + private val calcAccBalanceAct: CalcAccBalanceAct, + private val calcAccIncomeExpenseAct: CalcAccIncomeExpenseAct +) : FPAction>() { + + override suspend fun Input.compose(): suspend () -> List = suspend { + accounts + } thenMap { acc -> + val balance = calcAccBalanceAct( + CalcAccBalanceAct.Input( + account = acc + ) + ).balance + + val balanceBaseCurrency = if (acc.currency != baseCurrency) { + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = acc.currency.toOption() + ), + amount = balance + ) + ).orNull() + } else { + null + } + + val incomeExpensePair = calcAccIncomeExpenseAct( + CalcAccIncomeExpenseAct.Input( + account = acc, + range = range + ) + ).incomeExpensePair + + AccountData( + account = acc, + balance = balance.toDouble(), + balanceBaseCurrency = balanceBaseCurrency?.toDouble(), + monthlyIncome = incomeExpensePair.income.toDouble(), + monthlyExpenses = incomeExpensePair.expense.toDouble(), + ) + } + + data class Input( + val accounts: List, + val baseCurrency: String, + val range: ClosedTimeRange + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt new file mode 100644 index 0000000000..b647569ac1 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.kt @@ -0,0 +1,73 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.lambda +import com.ivy.fp.action.then +import com.ivy.fp.then +import com.ivy.wallet.domain.action.account.AccountByIdAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.exchange.actInput +import com.ivy.wallet.domain.action.transaction.DueTrnsAct +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.exchange.ExchangeTrnArgument +import com.ivy.wallet.domain.pure.exchange.exchangeInBaseCurrency +import com.ivy.wallet.domain.pure.transaction.expenses +import com.ivy.wallet.domain.pure.transaction.incomes +import com.ivy.wallet.domain.pure.transaction.sumTrns +import com.ivy.wallet.utils.timeNowUTC +import java.time.LocalDateTime +import javax.inject.Inject + +class DueTrnsInfoAct @Inject constructor( + private val dueTrnsAct: DueTrnsAct, + private val accountByIdAct: AccountByIdAct, + private val exchangeAct: ExchangeAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + range + } then dueTrnsAct then { trns -> + val timeNow = timeNowUTC() + trns.filter { + this.dueFilter(it, timeNow) + } + } then { upcomingTrns -> + //We have due transactions in different currencies + val exchangeArg = ExchangeTrnArgument( + baseCurrency = baseCurrency, + exchange = ::actInput then exchangeAct, + getAccount = accountByIdAct.lambda() + ) + + io { + Output( + dueIncomeExpense = IncomeExpensePair( + income = sumTrns( + incomes(upcomingTrns), + ::exchangeInBaseCurrency, + exchangeArg + ), + expense = sumTrns( + expenses(upcomingTrns), + ::exchangeInBaseCurrency, + exchangeArg + ) + ), + dueTrns = upcomingTrns + ) + } + } + + data class Input( + val range: ClosedTimeRange, + val baseCurrency: String, + val dueFilter: (Transaction, LocalDateTime) -> Boolean + ) + + data class Output( + val dueIncomeExpense: IncomeExpensePair, + val dueTrns: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.kt new file mode 100644 index 0000000000..9f11f4911c --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.kt @@ -0,0 +1,15 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import com.ivy.fp.action.FPAction +import com.ivy.wallet.io.persistence.dao.TransactionDao +import javax.inject.Inject + +class HasTrnsAct @Inject constructor( + private val transactionDao: TransactionDao +) : FPAction() { + override suspend fun Unit.compose(): suspend () -> Boolean = suspend { + io { + transactionDao.findAll_LIMIT_1().isNotEmpty() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.kt new file mode 100644 index 0000000000..b1f5075d57 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.kt @@ -0,0 +1,37 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.isOverdue +import javax.inject.Inject + +class OverdueAct @Inject constructor( + private val dueTrnsInfoAct: DueTrnsInfoAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + DueTrnsInfoAct.Input( + range = range, + baseCurrency = baseCurrency, + dueFilter = ::isOverdue + ) + } then dueTrnsInfoAct then { + Output( + overdue = it.dueIncomeExpense, + overdueTrns = it.dueTrns + ) + } + + data class Input( + val range: ClosedTimeRange, + val baseCurrency: String + ) + + data class Output( + val overdue: IncomeExpensePair, + val overdueTrns: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.kt new file mode 100644 index 0000000000..35536be366 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.kt @@ -0,0 +1,37 @@ +package com.ivy.wallet.domain.action.viewmodel.home + +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.transaction.isUpcoming +import javax.inject.Inject + +class UpcomingAct @Inject constructor( + private val dueTrnsInfoAct: DueTrnsInfoAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> Output = suspend { + DueTrnsInfoAct.Input( + range = range, + baseCurrency = baseCurrency, + dueFilter = ::isUpcoming + ) + } then dueTrnsInfoAct then { + Output( + upcoming = it.dueIncomeExpense, + upcomingTrns = it.dueTrns + ) + } + + data class Input( + val range: ClosedTimeRange, + val baseCurrency: String + ) + + data class Output( + val upcoming: IncomeExpensePair, + val upcomingTrns: List + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt new file mode 100644 index 0000000000..589568cfc0 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcIncomeExpenseAct.kt @@ -0,0 +1,76 @@ +package com.ivy.wallet.domain.action.wallet + +import arrow.core.nonEmptyListOf +import arrow.core.toOption +import com.ivy.fp.action.FPAction +import com.ivy.fp.action.then +import com.ivy.fp.action.thenMap +import com.ivy.wallet.domain.action.account.AccTrnsAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.pure.account.filterExcluded +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions +import com.ivy.wallet.domain.pure.transaction.foldTransactions +import com.ivy.wallet.domain.pure.util.orZero +import timber.log.Timber +import javax.inject.Inject + +class CalcIncomeExpenseAct @Inject constructor( + private val accTrnsAct: AccTrnsAct, + private val exchangeAct: ExchangeAct +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> IncomeExpensePair = suspend { + filterExcluded(accounts) + } thenMap { acc -> + Pair( + acc, + accTrnsAct( + AccTrnsAct.Input( + accountId = acc.id, + range = range + ) + ) + ) + } thenMap { (acc, trns) -> + Timber.i("acc: $acc, trns = ${trns.size}") + Pair( + acc, + foldTransactions( + transactions = trns, + valueFunctions = nonEmptyListOf( + AccountValueFunctions::income, + AccountValueFunctions::expense + ), + arg = acc.id + ) + ) + } thenMap { (acc, stats) -> + Timber.i("acc_stats: $acc - $stats") + stats.map { + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = acc.currency.toOption() + ), + amount = it + ), + ).orZero() + } + } then { statsList -> + IncomeExpensePair( + income = statsList.sumOf { it[0] }, + expense = statsList.sumOf { it[1] } + ) + } + + data class Input( + val baseCurrency: String, + val accounts: List, + val range: ClosedTimeRange, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt deleted file mode 100644 index 0de83c8845..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.ivy.wallet.domain.action.wallet - -import com.ivy.wallet.domain.action.Action -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.IncomeExpensePair -import com.ivy.wallet.domain.logic.WalletLogic -import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import javax.inject.Inject - -class CalcOverdueAct @Inject constructor( - private val walletLogic: WalletLogic -) : Action() { - - override suspend fun FromToTimeRange.willDo(): Output = io { - //TODO: Rework & optimize this - Output( - overdue = IncomeExpensePair( - income = walletLogic.calculateOverdueIncome(this).toBigDecimal(), - expense = walletLogic.calculateOverdueExpenses(this).toBigDecimal() - ), - overdueTrns = walletLogic.overdueTransactions(this) - ) - } - - data class Output( - val overdue: IncomeExpensePair, - val overdueTrns: List - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt deleted file mode 100644 index 0b82883c9a..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.ivy.wallet.domain.action.wallet - -import com.ivy.wallet.domain.action.Action -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.IncomeExpensePair -import com.ivy.wallet.domain.logic.WalletLogic -import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import javax.inject.Inject - -class CalcUpcomingAct @Inject constructor( - private val walletLogic: WalletLogic -) : Action() { - - override suspend fun FromToTimeRange.willDo(): Output = io { - //TODO: Rework & optimize this - Output( - upcoming = IncomeExpensePair( - income = walletLogic.calculateUpcomingIncome(this).toBigDecimal(), - expense = walletLogic.calculateUpcomingExpenses(this).toBigDecimal() - ), - upcomingTrns = walletLogic.upcomingTransactions(this) - ) - } - - data class Output( - val upcoming: IncomeExpensePair, - val upcomingTrns: List - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt index 1b35c54806..67e18f12d5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt +++ b/app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcWalletBalanceAct.kt @@ -1,19 +1,52 @@ package com.ivy.wallet.domain.action.wallet -import com.ivy.wallet.domain.action.Action -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletBalance +import arrow.core.toOption +import com.ivy.fp.action.* +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.account.CalcAccBalanceAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.exchange.ExchangeData import java.math.BigDecimal import javax.inject.Inject class CalcWalletBalanceAct @Inject constructor( - private val walletDAOs: WalletDAOs, -) : Action() { - override suspend fun String.willDo(): BigDecimal = io { - val baseCurrency = this - calculateWalletBalance( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrency - ).value - } -} \ No newline at end of file + private val accountsAct: AccountsAct, + private val calcAccBalanceAct: CalcAccBalanceAct, + private val exchangeAct: ExchangeAct, +) : FPAction() { + + override suspend fun Input.compose(): suspend () -> BigDecimal = recipe().fixUnit() + + private suspend fun Input.recipe(): suspend (Unit) -> BigDecimal = + accountsAct thenFilter { + withExcluded || it.includeInBalance + } thenMap { + calcAccBalanceAct( + CalcAccBalanceAct.Input( + account = it, + range = range + ) + ) + } thenMap { + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = it.account.currency.toOption(), + toCurrency = balanceCurrency + ), + amount = it.balance + ) + ) + } thenSum { + it.orNull() ?: BigDecimal.ZERO + } + + data class Input( + val baseCurrency: String, + val balanceCurrency: String = baseCurrency, + val range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), + val withExcluded: Boolean = false + ) +} diff --git a/app/src/main/java/com/ivy/wallet/domain/action/wallet/HistoryWithDateDivAct.kt b/app/src/main/java/com/ivy/wallet/domain/action/wallet/HistoryWithDateDivAct.kt deleted file mode 100644 index 43b92e8ea4..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/action/wallet/HistoryWithDateDivAct.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.ivy.wallet.domain.action.wallet - -import com.ivy.wallet.domain.action.Action -import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.historyWithDateDividers -import javax.inject.Inject - -class HistoryWithDateDivAct @Inject constructor( - private val walletDAOs: WalletDAOs -) : Action>() { - - override suspend fun Input.willDo(): List = io { - historyWithDateDividers( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - range = timeRange - ) - } - - data class Input( - val timeRange: ClosedTimeRange, - val baseCurrencyCode: String - ) -} \ No newline at end of file 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 31b50cdb7d..143680c392 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,6 +1,6 @@ package com.ivy.wallet.domain.data -import com.ivy.wallet.domain.data.entity.* +import com.ivy.wallet.domain.data.core.* data class IvyWalletCompleteData( val accounts: List = emptyList(), diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccount.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccount.kt deleted file mode 100644 index 08c68fc6bd..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccount.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class SEAccount( - @SerializedName("id") - val id: String, - - @SerializedName("name") - val name: String, - - @SerializedName("nature") - val nature: String, - - @SerializedName("balance") - val balance: Double, - - @SerializedName("currency_code") - val currency_code: String, - - @SerializedName("connection_id") - val connection_id: String, -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccountConnection.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccountConnection.kt deleted file mode 100644 index 48f50e5552..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEAccountConnection.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class SEAccountConnection( - @SerializedName("account") - val account: SEAccount, - @SerializedName("connection") - val connection: SEConnection -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEConnection.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEConnection.kt deleted file mode 100644 index f47ddcf08d..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SEConnection.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.PrimaryKey -import com.google.gson.annotations.SerializedName -import java.time.LocalDateTime - -@Entity(tableName = "se_connections") -data class SEConnection( - @SerializedName("id") - @PrimaryKey @ColumnInfo(name = "id") - val id: String = "", - - @SerializedName("provider_code") - @ColumnInfo(name = "provider_code") - val provider_code: String = "", - - @SerializedName("provider_name") - @ColumnInfo(name = "provider_name") - val provider_name: String = "", - - @SerializedName("customer_id") - @ColumnInfo(name = "customer_id") - val customer_id: String = "", - - @SerializedName("next_refresh_possible_at") - @ColumnInfo(name = "next_refresh_possible_at") - var next_refresh_possible_at: LocalDateTime? = null, -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SECustomer.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SECustomer.kt deleted file mode 100644 index c67c98136a..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SECustomer.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class SECustomer( - @SerializedName("id") - val id: String = "", - - @SerializedName("identifier") - val identifier: String = "", - - @SerializedName("secret") - val secret: String = "" -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SETransaction.kt b/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SETransaction.kt deleted file mode 100644 index 480f1e821f..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/bankintegrations/SETransaction.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.ivy.wallet.domain.data.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class SETransaction( - @SerializedName("id") - val id: String, - - @SerializedName("duplicated") - val duplicated: Boolean, - - @SerializedName("mode") - val mode: String, - - @SerializedName("status") - val status: String, - - @SerializedName("made_on") - val made_on: String, - - @SerializedName("amount") - val amount: Double, - - @SerializedName("currency_code") - val currency_code: String, - - @SerializedName("description") - val description: String, - - @SerializedName("category") - val category: String, - - @SerializedName("account_id") - val account_id: String, - - @SerializedName("created_at") - val created_at: String, - - @SerializedName("updated_at") - val updated_at: String, - - @SerializedName("extra") - val extra: Map? -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt new file mode 100644 index 0000000000..e11d51d9b5 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Account.kt @@ -0,0 +1,43 @@ +package com.ivy.wallet.domain.data.core + +import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.network.data.AccountDTO +import com.ivy.wallet.io.persistence.data.AccountEntity +import com.ivy.wallet.ui.theme.Green +import java.util.* + +data class Account( + val name: String, + val currency: String? = null, + val color: Int = Green.toArgb(), + val icon: String? = null, + val orderNum: Double = 0.0, + val includeInBalance: Boolean = true, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): AccountEntity = AccountEntity( + name = name, + currency = currency, + color = color, + icon = icon, + orderNum = orderNum, + includeInBalance = includeInBalance, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + + fun toDTO(): AccountDTO = AccountDTO( + name = name, + currency = currency, + color = color, + icon = icon, + orderNum = orderNum, + includeInBalance = includeInBalance, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt new file mode 100644 index 0000000000..1f96b2c06c --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt @@ -0,0 +1,81 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.wallet.io.network.data.BudgetDTO +import com.ivy.wallet.io.persistence.data.BudgetEntity +import com.ivy.wallet.R +import com.ivy.wallet.stringRes +import java.util.* + +data class Budget( + val name: String, + val amount: Double, + + val categoryIdsSerialized: String?, + val accountIdsSerialized: String?, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + val orderId: Double, + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): BudgetEntity = BudgetEntity( + name = name, + amount = amount, + categoryIdsSerialized = categoryIdsSerialized, + accountIdsSerialized = accountIdsSerialized, + isSynced = isSynced, + isDeleted = isDeleted, + orderId = orderId, + id = id, + ) + + fun toDTO(): BudgetDTO = BudgetDTO( + name = name, + amount = amount, + categoryIdsSerialized = categoryIdsSerialized, + accountIdsSerialized = accountIdsSerialized, + orderId = orderId, + id = id + ) + + companion object { + fun serialize(ids: List): String { + return ids.joinToString(separator = ",") + } + + fun type(categoriesCount: Int): String { + return when (categoriesCount) { + 0 -> stringRes(R.string.total_budget) + 1 -> stringRes(R.string.category_budget) + else -> stringRes(R.string.multi_category_budget, categoriesCount.toString()) + } + } + } + + fun parseCategoryIds(): List { + return parseIdsString(categoryIdsSerialized) + } + + fun parseAccountIds(): List { + return parseIdsString(accountIdsSerialized) + } + + private fun parseIdsString(idsString: String?): List { + return try { + if (idsString == null) return emptyList() + + idsString + .split(",") + .map { UUID.fromString(it) } + } catch (e: Exception) { + e.printStackTrace() + emptyList() + } + } + + + fun validate(): Boolean { + return name.isNotEmpty() && amount > 0.0 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt new file mode 100644 index 0000000000..49ad3a650b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Category.kt @@ -0,0 +1,37 @@ +package com.ivy.wallet.domain.data.core + +import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.network.data.CategoryDTO +import com.ivy.wallet.io.persistence.data.CategoryEntity +import com.ivy.wallet.ui.theme.Ivy +import java.util.* + +data class Category( + val name: String, + val color: Int = Ivy.toArgb(), + val icon: String? = null, + val orderNum: Double = 0.0, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): CategoryEntity = CategoryEntity( + name = name, + color = color, + icon = icon, + orderNum = orderNum, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + + fun toDTO(): CategoryDTO = CategoryDTO( + name = name, + color = color, + icon = icon, + orderNum = orderNum, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt new file mode 100644 index 0000000000..7f2240e66b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/ExchangeRate.kt @@ -0,0 +1,22 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.wallet.io.network.data.ExchangeRateDTO +import com.ivy.wallet.io.persistence.data.ExchangeRateEntity + +data class ExchangeRate( + val baseCurrency: String, + val currency: String, + val rate: Double, +) { + fun toEntity(): ExchangeRateEntity = ExchangeRateEntity( + baseCurrency = baseCurrency, + currency = currency, + rate = rate + ) + + fun toDTO(): ExchangeRateDTO = ExchangeRateDTO( + baseCurrency = baseCurrency, + currency = currency, + rate = rate + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt new file mode 100644 index 0000000000..c7b61efca6 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt @@ -0,0 +1,52 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.wallet.R +import com.ivy.wallet.domain.data.LoanType +import com.ivy.wallet.io.network.data.LoanDTO +import com.ivy.wallet.io.persistence.data.LoanEntity +import com.ivy.wallet.stringRes +import java.util.* + +data class Loan( + val name: String, + val amount: Double, + val type: LoanType, + val color: Int = 0, + val icon: String? = null, + val orderNum: Double = 0.0, + val accountId: UUID? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): LoanEntity = LoanEntity( + name = name, + amount = amount, + type = type, + color = color, + icon = icon, + orderNum = orderNum, + accountId = accountId, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + + fun toDTO(): LoanDTO = LoanDTO( + name = name, + amount = amount, + type = type, + color = color, + icon = icon, + orderNum = orderNum, + accountId = accountId, + id = id + ) + + fun humanReadableType(): String { + return if (type == LoanType.BORROW) stringRes(R.string.borrowed_uppercase) else stringRes( + R.string.lent_uppercase) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt new file mode 100644 index 0000000000..c0b72b7e4f --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/LoanRecord.kt @@ -0,0 +1,46 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.wallet.io.network.data.LoanRecordDTO +import com.ivy.wallet.io.persistence.data.LoanRecordEntity +import java.time.LocalDateTime +import java.util.* + +data class LoanRecord( + val loanId: UUID, + val amount: Double, + val note: String? = null, + val dateTime: LocalDateTime, + val interest: Boolean = false, + val accountId: UUID? = null, + //This is used store the converted amount for currencies which are different from the loan account currency + val convertedAmount: Double? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): LoanRecordEntity = LoanRecordEntity( + loanId = loanId, + amount = amount, + note = note, + dateTime = dateTime, + interest = interest, + accountId = accountId, + convertedAmount = convertedAmount, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + + fun toDTO(): LoanRecordDTO = LoanRecordDTO( + loanId = loanId, + amount = amount, + note = note, + dateTime = dateTime, + interest = interest, + accountId = accountId, + convertedAmount = convertedAmount, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt new file mode 100644 index 0000000000..dceb2a3a59 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/PlannedPaymentRule.kt @@ -0,0 +1,57 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.wallet.domain.data.IntervalType +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.network.data.PlannedPaymentRuleDTO +import com.ivy.wallet.io.persistence.data.PlannedPaymentRuleEntity +import java.time.LocalDateTime +import java.util.* + +data class PlannedPaymentRule( + val startDate: LocalDateTime?, + val intervalN: Int?, + val intervalType: IntervalType?, + val oneTime: Boolean, + + val type: TransactionType, + val accountId: UUID, + val amount: Double = 0.0, + val categoryId: UUID? = null, + val title: String? = null, + val description: String? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): PlannedPaymentRuleEntity = PlannedPaymentRuleEntity( + startDate = startDate, + intervalN = intervalN, + intervalType = intervalType, + oneTime = oneTime, + type = type, + accountId = accountId, + amount = amount, + categoryId = categoryId, + title = title, + description = description, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + + fun toDTO(): PlannedPaymentRuleDTO = PlannedPaymentRuleDTO( + startDate = startDate, + intervalN = intervalN, + intervalType = intervalType, + oneTime = oneTime, + type = type, + accountId = accountId, + amount = amount, + categoryId = categoryId, + title = title, + description = description, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt new file mode 100644 index 0000000000..3970eadd55 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Settings.kt @@ -0,0 +1,32 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.design.l0_system.Theme +import com.ivy.wallet.io.network.data.SettingsDTO +import com.ivy.wallet.io.persistence.data.SettingsEntity +import java.math.BigDecimal +import java.util.* + +data class Settings( + val theme: Theme, + val baseCurrency: String, + val bufferAmount: BigDecimal, + val name: String, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): SettingsEntity = SettingsEntity( + theme = theme, + currency = baseCurrency, + bufferAmount = bufferAmount.toDouble(), + name = name, + id = id + ) + + fun toDTO(): SettingsDTO = SettingsDTO( + theme = theme, + currency = baseCurrency, + bufferAmount = bufferAmount.toDouble(), + name = name, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt new file mode 100644 index 0000000000..28b810756c --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Transaction.kt @@ -0,0 +1,77 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.wallet.domain.data.TransactionHistoryItem +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.network.data.TransactionDTO +import com.ivy.wallet.io.persistence.data.TransactionEntity +import java.math.BigDecimal +import java.time.LocalDateTime +import java.util.* + +data class Transaction( + //TODO: Remove default values & introduce Transaction#dummy() method + val accountId: UUID, + val type: TransactionType, + val amount: BigDecimal, + val toAccountId: UUID? = null, + val toAmount: BigDecimal = amount, + val title: String? = null, + val description: String? = null, + val dateTime: LocalDateTime? = null, + val categoryId: UUID? = null, + val dueDate: LocalDateTime? = null, + + val recurringRuleId: UUID? = null, + + val attachmentUrl: String? = null, + + //This refers to the loan id that is linked with a transaction + val loanId: UUID? = null, + + //This refers to the loan record id that is linked with a transaction + val loanRecordId: UUID? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + + val id: UUID = UUID.randomUUID() +) : TransactionHistoryItem { + fun toEntity(): TransactionEntity = TransactionEntity( + accountId = accountId, + type = type, + amount = amount.toDouble(), + toAccountId = toAccountId, + toAmount = toAmount.toDouble(), + title = title, + description = description, + dateTime = dateTime, + categoryId = categoryId, + dueDate = dueDate, + recurringRuleId = recurringRuleId, + attachmentUrl = attachmentUrl, + loanId = loanId, + loanRecordId = loanRecordId, + id = id, + isSynced = isSynced, + isDeleted = isDeleted + ) + + fun toDTO(): TransactionDTO = TransactionDTO( + accountId = accountId, + type = type, + amount = amount.toDouble(), + toAccountId = toAccountId, + toAmount = toAmount.toDouble(), + title = title, + description = description, + dateTime = dateTime, + categoryId = categoryId, + dueDate = dueDate, + recurringRuleId = recurringRuleId, + attachmentUrl = attachmentUrl, + loanId = loanId, + loanRecordId = loanRecordId, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt new file mode 100644 index 0000000000..031b6ca12d --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/User.kt @@ -0,0 +1,42 @@ +package com.ivy.wallet.domain.data.core + +import com.ivy.wallet.domain.data.AuthProviderType +import com.ivy.wallet.io.network.data.UserDTO +import com.ivy.wallet.io.persistence.data.UserEntity +import java.util.* + +data class User( + val email: String, + val authProviderType: AuthProviderType, + var firstName: String, + val lastName: String?, + val profilePicture: String?, + val color: Int, + + val testUser: Boolean = false, + var id: UUID +) { + fun toEntity(): UserEntity = UserEntity( + email = email, + authProviderType = authProviderType, + firstName = firstName, + lastName = lastName, + profilePicture = profilePicture, + color = color, + testUser = testUser, + id = id + ) + + fun toDTO(): UserDTO = UserDTO( + email = email, + authProviderType = authProviderType, + firstName = firstName, + lastName = lastName, + profilePicture = profilePicture, + color = color, + testUser = testUser, + id = id + ) + + fun names(): String = firstName + if (lastName != null) " $lastName" else "" +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/ExchangeRate.kt b/app/src/main/java/com/ivy/wallet/domain/data/entity/ExchangeRate.kt deleted file mode 100644 index d8689b9e4f..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/ExchangeRate.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ivy.wallet.domain.data.entity - -import androidx.room.Entity - -@Entity(tableName = "exchange_rates", primaryKeys = ["baseCurrency", "currency"]) -data class ExchangeRate( - val baseCurrency: String, - val currency: String, - val rate: Double, -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/LoanRecord.kt b/app/src/main/java/com/ivy/wallet/domain/data/entity/LoanRecord.kt deleted file mode 100644 index f30df981f5..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/LoanRecord.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.ivy.wallet.domain.data.entity - -import androidx.room.Entity -import androidx.room.PrimaryKey -import java.time.LocalDateTime -import java.util.* - -@Entity(tableName = "loan_records") -data class LoanRecord( - val loanId: UUID, - val amount: Double, - val note: String? = null, - val dateTime: LocalDateTime, - val interest:Boolean = false, - val accountId : UUID? = null, - //This is used store the converted amount for currencies which are different from the loan account currency - val convertedAmount :Double? = null, - - val isSynced: Boolean = false, - val isDeleted: Boolean = false, - - @PrimaryKey - val id: UUID = UUID.randomUUID() -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/WishlistItem.kt b/app/src/main/java/com/ivy/wallet/domain/data/entity/WishlistItem.kt deleted file mode 100644 index 9eb6b6cba5..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/WishlistItem.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.ivy.wallet.domain.data.entity - -import androidx.room.Entity -import androidx.room.PrimaryKey -import java.time.LocalDateTime -import java.util.* - -@Entity(tableName = "wishlist_items") -data class WishlistItem( - val name: String, - val price: Double, - val accountId: UUID, - val categoryId: UUID? = null, - val description: String?, - val plannedDateTime: LocalDateTime? = null, - val orderNum: Double = 0.0, - @PrimaryKey - val id: UUID = UUID.randomUUID() -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/AccountCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt similarity index 83% rename from app/src/main/java/com/ivy/wallet/domain/logic/AccountCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt index 87e84bd58f..7791bfcc0f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/AccountCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/AccountCreator.kt @@ -1,10 +1,10 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.sync.item.TransactionSync -import com.ivy.wallet.domain.sync.uploader.AccountUploader +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.sync.item.TransactionSync +import com.ivy.wallet.domain.deprecated.sync.uploader.AccountUploader import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.utils.ioThread @@ -36,7 +36,7 @@ class AccountCreator( orderNum = accountDao.findMaxOrderNum() + 1, isSynced = false ) - accountDao.save(account) + accountDao.save(account.toEntity()) accountLogic.adjustBalance( account = account, @@ -65,7 +65,7 @@ class AccountCreator( ) ioThread { - accountDao.save(updatedAccount) + accountDao.save(updatedAccount.toEntity()) accountLogic.adjustBalance( account = updatedAccount, actualBalance = accountLogic.calculateAccountBalance(updatedAccount), diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/BudgetCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt similarity index 87% rename from app/src/main/java/com/ivy/wallet/domain/logic/BudgetCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt index 0042a802bb..664e734120 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/BudgetCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/BudgetCreator.kt @@ -1,8 +1,8 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.logic.model.CreateBudgetData -import com.ivy.wallet.domain.sync.uploader.BudgetUploader +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.deprecated.logic.model.CreateBudgetData +import com.ivy.wallet.domain.deprecated.sync.uploader.BudgetUploader import com.ivy.wallet.io.persistence.dao.BudgetDao import com.ivy.wallet.utils.ioThread @@ -33,7 +33,7 @@ class BudgetCreator( isSynced = false ) - budgetDao.save(budget) + budgetDao.save(budget.toEntity()) budget } @@ -59,7 +59,7 @@ class BudgetCreator( try { ioThread { budgetDao.save( - updatedBudget.copy( + updatedBudget.toEntity().copy( isSynced = false ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/CategoryCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt similarity index 83% rename from app/src/main/java/com/ivy/wallet/domain/logic/CategoryCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt index 0f74897ada..e66343d983 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/CategoryCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CategoryCreator.kt @@ -1,9 +1,9 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.sync.uploader.CategoryUploader +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.sync.uploader.CategoryUploader import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.utils.ioThread @@ -32,8 +32,7 @@ class CategoryCreator( isSynced = false ) - categoryDao. - save(newCategory) + categoryDao.save(newCategory.toEntity()) newCategory } @@ -58,7 +57,7 @@ class CategoryCreator( try { ioThread { categoryDao.save( - updatedCategory.copy( + updatedCategory.toEntity().copy( isSynced = false ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/CustomerJourneyLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/CustomerJourneyLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt index ccad0b54a4..2f45174949 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/CustomerJourneyLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/CustomerJourneyLogic.kt @@ -1,11 +1,11 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.PlannedPaymentRuleDao import com.ivy.wallet.io.persistence.dao.TransactionDao diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/LoanCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt similarity index 88% rename from app/src/main/java/com/ivy/wallet/domain/logic/LoanCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt index 23b6c4ee08..37719e297c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/LoanCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanCreator.kt @@ -1,9 +1,9 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.logic.model.CreateLoanData -import com.ivy.wallet.domain.sync.uploader.LoanUploader +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData +import com.ivy.wallet.domain.deprecated.sync.uploader.LoanUploader import com.ivy.wallet.io.persistence.dao.LoanDao import com.ivy.wallet.utils.ioThread import java.util.* @@ -39,7 +39,7 @@ class LoanCreator( accountId = data.account?.id ) loanId = item.id - dao.save(item) + dao.save(item.toEntity()) item } @@ -67,7 +67,7 @@ class LoanCreator( try { ioThread { dao.save( - updatedItem.copy( + updatedItem.toEntity().copy( isSynced = false ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/LoanRecordCreator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt similarity index 87% rename from app/src/main/java/com/ivy/wallet/domain/logic/LoanRecordCreator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt index 3789a4fc25..29edb414bf 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/LoanRecordCreator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LoanRecordCreator.kt @@ -1,8 +1,8 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData -import com.ivy.wallet.domain.sync.uploader.LoanRecordUploader +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.sync.uploader.LoanRecordUploader import com.ivy.wallet.io.persistence.dao.LoanRecordDao import com.ivy.wallet.utils.ioThread import java.util.* @@ -36,7 +36,7 @@ class LoanRecordCreator( convertedAmount = data.convertedAmount ) - dao.save(item) + dao.save(item.toEntity()) item } @@ -63,7 +63,7 @@ class LoanRecordCreator( try { ioThread { dao.save( - updatedItem.copy( + updatedItem.toEntity().copy( isSynced = false ) ) diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/LogoutLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LogoutLogic.kt similarity index 93% rename from app/src/main/java/com/ivy/wallet/domain/logic/LogoutLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LogoutLogic.kt index 8a83a3804f..92fa95f17d 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/LogoutLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/LogoutLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.design.navigation.Navigation import com.ivy.wallet.io.network.IvySession diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/PaywallLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PaywallLogic.kt similarity index 99% rename from app/src/main/java/com/ivy/wallet/domain/logic/PaywallLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PaywallLogic.kt index e0b3e82126..fbbeaaecf4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/PaywallLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PaywallLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.android.billingclient.api.Purchase import com.ivy.design.navigation.Navigation diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsGenerator.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt similarity index 91% rename from app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsGenerator.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt index 918341158d..3f028b636f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsGenerator.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsGenerator.kt @@ -1,7 +1,7 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.persistence.dao.TransactionDao import java.time.LocalDateTime @@ -76,7 +76,7 @@ class PlannedPaymentsGenerator( accountId = rule.accountId, recurringRuleId = rule.id, categoryId = rule.categoryId, - amount = rule.amount, + amount = rule.amount.toBigDecimal(), title = rule.title, description = rule.description, dueDate = dueDate, @@ -84,7 +84,7 @@ class PlannedPaymentsGenerator( toAccountId = null, isSynced = false - ) + ).toEntity() ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt similarity index 86% rename from app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt index 80ae5301f9..9be79816a1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/PlannedPaymentsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PlannedPaymentsLogic.kt @@ -1,14 +1,14 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.currency.sumByDoublePlannedInBaseCurrency -import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader -import com.ivy.wallet.domain.sync.uploader.TransactionUploader +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.currency.sumByDoublePlannedInBaseCurrency +import com.ivy.wallet.domain.deprecated.sync.uploader.PlannedPaymentRuleUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.PlannedPaymentRuleDao import com.ivy.wallet.io.persistence.dao.SettingsDao @@ -40,9 +40,9 @@ class PlannedPaymentsLogic( endDate = range.to() ).sumOf { val amount = exchangeRatesLogic.amountBaseCurrency( - transaction = it, + transaction = it.toDomain(), baseCurrency = baseCurrency, - accounts = accounts + accounts = accounts.map { it.toDomain() } ) when (it.type) { @@ -54,7 +54,7 @@ class PlannedPaymentsLogic( } fun oneTime(): List { - return plannedPaymentRuleDao.findAllByOneTime(oneTime = true) + return plannedPaymentRuleDao.findAllByOneTime(oneTime = true).map { it.toDomain() } } fun oneTimeIncome(): Double { @@ -78,7 +78,7 @@ class PlannedPaymentsLogic( } fun recurring(): List = - plannedPaymentRuleDao.findAllByOneTime(oneTime = false) + plannedPaymentRuleDao.findAllByOneTime(oneTime = false).map { it.toDomain() } fun recurringIncome(): Double { return recurring() @@ -100,7 +100,7 @@ class PlannedPaymentsLogic( amountForMonthInBaseCurrency( plannedPayment = it, baseCurrency = baseCurrency, - accounts = accounts + accounts = accounts.map { it.toDomain() } ) } } @@ -166,7 +166,7 @@ class PlannedPaymentsLogic( } ioThread { - transactionDao.save(paidTransaction) + transactionDao.save(paidTransaction.toEntity()) if (plannedPaymentRule != null && plannedPaymentRule.oneTime) { //delete paid oneTime planned payment rules diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/PreloadDataLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt similarity index 72% rename from app/src/main/java/com/ivy/wallet/domain/logic/PreloadDataLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt index 06b7ac2620..2ebd1831f5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/PreloadDataLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/PreloadDataLogic.kt @@ -1,14 +1,12 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.stringRes import com.ivy.wallet.ui.onboarding.model.AccountBalance import com.ivy.wallet.ui.theme.* @@ -26,7 +24,7 @@ class PreloadDataLogic( fun preloadAccounts() { val cash = Account( - name = stringRes(R.string.cash), + name = "Cash", currency = null, color = Green.toArgb(), icon = "cash", @@ -35,7 +33,7 @@ class PreloadDataLogic( ) val bank = Account( - name = stringRes(R.string.bank), + name = "Bank", currency = null, color = IvyDark.toArgb(), icon = "bank", @@ -43,27 +41,27 @@ class PreloadDataLogic( isSynced = false ) - accountsDao.save(cash) - accountsDao.save(bank) + accountsDao.save(cash.toEntity()) + accountsDao.save(bank.toEntity()) } fun accountSuggestions(baseCurrency: String): List = listOf( CreateAccountData( - name = stringRes(R.string.cash), + name = "Cash", currency = baseCurrency, color = Green, icon = "cash", balance = 0.0 ), CreateAccountData( - name = stringRes(R.string.bank), + name = "Bank", currency = baseCurrency, color = IvyDark, icon = "bank", balance = 0.0 ), CreateAccountData( - name = stringRes(R.string.revoult), + name = "Revolut", currency = baseCurrency, color = Blue, icon = "revolut", @@ -83,61 +81,61 @@ class PreloadDataLogic( private fun preloadCategoriesCreateData() = listOf( CreateCategoryData( - name = stringRes(R.string.food_drinks), + name = "Food & Drinks", color = Green, icon = "fooddrink" ), CreateCategoryData( - name = stringRes(R.string.bills_fees), + name = "Bills & Fees", color = Red, icon = "bills" ), CreateCategoryData( - name = stringRes(R.string.transport), + name = "Transport", color = YellowLight, icon = "transport" ), CreateCategoryData( - name = stringRes(R.string.groceries), + name = "Groceries", color = GreenLight, icon = "groceries" ), CreateCategoryData( - name = stringRes(R.string.entertainment), + name = "Entertainment", color = Orange, icon = "game" ), CreateCategoryData( - name = stringRes(R.string.shopping), + name = "Shopping", color = Ivy, icon = "shopping" ), CreateCategoryData( - name = stringRes(R.string.gifts), + name = "Gifts", color = RedLight, icon = "gift" ), CreateCategoryData( - name = stringRes(R.string.health), + name = "Health", color = IvyLight, icon = "health" ), CreateCategoryData( - name = stringRes(R.string.investments), + name = "Investments", color = IvyDark, icon = "leaf" ), CreateCategoryData( - name = stringRes(R.string.loans), + name = "Loans", color = BlueDark, icon = "loan" ), @@ -154,98 +152,98 @@ class PreloadDataLogic( isSynced = false ) - categoryDao.save(category) + categoryDao.save(category.toEntity()) } fun categorySuggestions(): List = preloadCategoriesCreateData() .plus( listOf( CreateCategoryData( - name = stringRes(R.string.car), + name = "Car", color = Blue3, icon = "vehicle" ), CreateCategoryData( - name = stringRes(R.string.work), + name = "Work", color = Blue2Light, icon = "work" ), CreateCategoryData( - name = stringRes(R.string.home), + name = "Home", color = Green2, icon = "house" ), CreateCategoryData( - name = stringRes(R.string.restaurant), + name = "Restaurant", color = Orange3, icon = "restaurant" ), CreateCategoryData( - name = stringRes(R.string.family), + name = "Family", color = Red3Light, icon = "family" ), CreateCategoryData( - name = stringRes(R.string.social_life), + name = "Social Life", color = Blue2, icon = "people" ), CreateCategoryData( - name = stringRes(R.string.order_food), + name = "Order food", color = Orange2, icon = "orderfood2" ), CreateCategoryData( - name = stringRes(R.string.travel), + name = "Travel", color = BlueLight, icon = "travel" ), CreateCategoryData( - name = stringRes(R.string.fitness), + name = "Fitness", color = Purple2, icon = "fitness" ), CreateCategoryData( - name = stringRes(R.string.self_development), + name = "Self-development", color = Yellow, icon = "selfdevelopment" ), CreateCategoryData( - name = stringRes(R.string.clothes), + name = "Clothes", color = Green2Light, icon = "clothes2" ), CreateCategoryData( - name = stringRes(R.string.beauty), + name = "Beauty", color = Red3, icon = "makeup" ), CreateCategoryData( - name = stringRes(R.string.education), + name = "Education", color = Blue, icon = "education" ), CreateCategoryData( - name = stringRes(R.string.pet), + name = "Pet", color = Orange3Light, icon = "pet" ), CreateCategoryData( - name = stringRes(R.string.sports), + name = "Sports", color = Purple1, icon = "sports" ), diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/SmartTitleSuggestionsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt similarity index 94% rename from app/src/main/java/com/ivy/wallet/domain/logic/SmartTitleSuggestionsLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt index c313425e15..875eedfeac 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/SmartTitleSuggestionsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/SmartTitleSuggestionsLogic.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.ui.edit.core.SUGGESTIONS_LIMIT import com.ivy.wallet.utils.capitalizeWords @@ -28,6 +28,7 @@ class SmartTitleSuggestionsLogic( if (title != null && title.isNotEmpty()) { //suggest by title val suggestionsByTitle = transactionDao.findAllByTitleMatchingPattern("${title}%") + .map { it.toDomain() } .extractUniqueTitles() .sortedByMostUsedFirst { transactionDao.countByTitleMatchingPattern("${it}%") @@ -45,6 +46,7 @@ class SmartTitleSuggestionsLogic( .findAllByCategory( categoryId = categoryId ) + .map { it.toDomain() } //exclude already suggested suggestions so they're ordered by priority at the end .extractUniqueTitles(excludeSuggestions = suggestions) .sortedByMostUsedFirst { @@ -67,6 +69,7 @@ class SmartTitleSuggestionsLogic( .findAllByAccount( accountId = accountId ) + .map { it.toDomain() } //exclude already suggested suggestions so they're ordered by priority at the end .extractUniqueTitles(excludeSuggestions = suggestions) .sortedByMostUsedFirst { diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/WalletAccountLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt similarity index 77% rename from app/src/main/java/com/ivy/wallet/domain/logic/WalletAccountLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt index 493cedf7b2..453d65b76f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/WalletAccountLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletAccountLogic.kt @@ -1,15 +1,12 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic -import com.ivy.wallet.R -import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao -import com.ivy.wallet.stringRes import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.ui.onboarding.model.filterOverdue import com.ivy.wallet.ui.onboarding.model.filterUpcoming @@ -31,7 +28,7 @@ class WalletAccountLogic( actualBalance: Double = calculateAccountBalance(account), newBalance: Double, - adjustTransactionTitle: String = stringRes(R.string.adjust_balance), + adjustTransactionTitle: String = "Adjust balance", isFiat: Boolean? = null, trnIsSyncedFlag: Boolean = false, //TODO: Remove this once Bank Integration trn sync is properly implemented @@ -46,11 +43,12 @@ class WalletAccountLogic( Transaction( type = TransactionType.INCOME, title = adjustTransactionTitle, - amount = diff.absoluteValue, + amount = diff.absoluteValue.toBigDecimal(), + toAmount = diff.absoluteValue.toBigDecimal(), dateTime = timeNowUTC(), accountId = account.id, isSynced = trnIsSyncedFlag - ) + ).toEntity() ) } finalDiff > 0 -> { @@ -59,41 +57,17 @@ class WalletAccountLogic( Transaction( type = TransactionType.EXPENSE, title = adjustTransactionTitle, - amount = diff.absoluteValue, + amount = diff.absoluteValue.toBigDecimal(), + toAmount = diff.absoluteValue.toBigDecimal(), dateTime = timeNowUTC(), accountId = account.id, isSynced = trnIsSyncedFlag - ) + ).toEntity() ) } } } - fun historyForAccount(account: Account, range: FromToTimeRange): List { - val startDate = range.from() - val endDate = range.to() - - return transactionDao - .findAllByAccountAndBetween( - accountId = account.id, - startDate = startDate, - endDate = endDate - ) - .plus( - transactionDao.findAllToAccountAndBetween( - toAccountId = account.id, - startDate = startDate, - endDate = endDate - ) - ) - .sortedByDescending { it.dateTime } - .withDateDividers( - exchangeRatesLogic = exchangeRatesLogic, - accountDao = accountDao, - settingsDao = settingsDao - ) - } - fun calculateAccountBalance( account: Account, before: LocalDateTime? = null @@ -112,17 +86,19 @@ class WalletAccountLogic( before: LocalDateTime? ): Double { return transactionDao.findAllByTypeAndAccount(TransactionType.INCOME, account.id) + .map { it.toDomain() } .filterHappenedTransactions( before = before ) - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } .plus( //transfers in transactionDao.findAllTransfersToAccount(account.id) + .map { it.toDomain() } .filterHappenedTransactions( before = before ) - .sumOf { it.toAmount ?: it.amount } + .sumOf { it.toAmount.toDouble() } ) } @@ -131,20 +107,22 @@ class WalletAccountLogic( before: LocalDateTime? ): Double { return transactionDao.findAllByTypeAndAccount(TransactionType.EXPENSE, account.id) + .map { it.toDomain() } .filterHappenedTransactions( before = before ) - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } .plus( //transfer out transactionDao.findAllByTypeAndAccount( type = TransactionType.TRANSFER, accountId = account.id ) + .map { it.toDomain() } .filterHappenedTransactions( before = before ) - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } ) } @@ -182,29 +160,31 @@ class WalletAccountLogic( fun calculateUpcomingIncome(account: Account, range: FromToTimeRange): Double = upcoming(account, range = range) .filter { it.type == TransactionType.INCOME } - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } fun calculateUpcomingExpenses(account: Account, range: FromToTimeRange): Double = upcoming(account = account, range = range) .filter { it.type == TransactionType.EXPENSE } - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } fun calculateOverdueIncome(account: Account, range: FromToTimeRange): Double = overdue(account, range = range) .filter { it.type == TransactionType.INCOME } - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } fun calculateOverdueExpenses(account: Account, range: FromToTimeRange): Double = overdue(account, range = range) .filter { it.type == TransactionType.EXPENSE } - .sumOf { it.amount } + .sumOf { it.amount.toDouble() } fun upcoming(account: Account, range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByAccount( accountId = account.id, startDate = range.upcomingFrom(), endDate = range.to() - ).filterUpcoming() + ) + .map { it.toDomain() } + .filterUpcoming() } @@ -213,6 +193,8 @@ class WalletAccountLogic( accountId = account.id, startDate = range.from(), endDate = range.overdueTo() - ).filterOverdue() + ) + .map { it.toDomain() } + .filterOverdue() } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/WalletCategoryLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/logic/WalletCategoryLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt index 86eb786913..e17d498e3c 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/WalletCategoryLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/WalletCategoryLogic.kt @@ -1,11 +1,12 @@ -package com.ivy.wallet.domain.logic +package com.ivy.wallet.domain.deprecated.logic import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.currency.sumInBaseCurrency +import com.ivy.wallet.domain.pure.transaction.withDateDividers import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao @@ -29,7 +30,7 @@ class WalletCategoryLogic( transactions: List = emptyList() ): Double { val baseCurrency = settingsDao.findFirst().currency - val accounts = accountDao.findAll() + val accounts = accountDao.findAll().map { it.toDomain() } return historyByCategory( category, @@ -63,7 +64,7 @@ class WalletCategoryLogic( type = TransactionType.INCOME, startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } .filter { accountFilterSet.isEmpty() || accountFilterSet.contains(it.accountId) } @@ -103,7 +104,7 @@ class WalletCategoryLogic( ) .filter { accountFilterSet.isEmpty() || accountFilterSet.contains(it.accountId) - } + }.map { it.toDomain() } .sumInBaseCurrency( exchangeRatesLogic = exchangeRatesLogic, settingsDao = settingsDao, @@ -137,7 +138,7 @@ class WalletCategoryLogic( type = TransactionType.INCOME, startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } .sumInBaseCurrency( exchangeRatesLogic = exchangeRatesLogic, settingsDao = settingsDao, @@ -151,7 +152,7 @@ class WalletCategoryLogic( type = TransactionType.EXPENSE, startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } .sumInBaseCurrency( exchangeRatesLogic = exchangeRatesLogic, settingsDao = settingsDao, @@ -159,19 +160,8 @@ class WalletCategoryLogic( ) } - fun historyByCategoryWithDateDividers( - category: Category, - range: FromToTimeRange - ): List { - return historyByCategory(category, range) - .withDateDividers( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ) - } - fun historyByCategoryAccountWithDateDividers( + suspend fun historyByCategoryAccountWithDateDividers( category: Category, range: FromToTimeRange, accountFilterSet: Set, @@ -201,7 +191,7 @@ class WalletCategoryLogic( categoryId = category.id, startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } } return trans.filter { @@ -209,12 +199,12 @@ class WalletCategoryLogic( } } - fun historyUnspecified(range: FromToTimeRange): List { + suspend fun historyUnspecified(range: FromToTimeRange): List { return transactionDao .findAllUnspecifiedAndBetween( startDate = range.from(), endDate = range.to() - ) + ).map { it.toDomain() } .withDateDividers( exchangeRatesLogic = exchangeRatesLogic, settingsDao = settingsDao, @@ -268,14 +258,18 @@ class WalletCategoryLogic( categoryId = category.id, startDate = range.upcomingFrom(), endDate = range.to() - ).filterUpcoming() + ) + .map { it.toDomain() } + .filterUpcoming() } fun upcomingUnspecified(range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByCategoryUnspecified( startDate = range.upcomingFrom(), endDate = range.to() - ).filterUpcoming() + ) + .map { it.toDomain() } + .filterUpcoming() } fun calculateOverdueIncomeByCategory(category: Category, range: FromToTimeRange): Double { @@ -324,14 +318,18 @@ class WalletCategoryLogic( categoryId = category.id, startDate = range.from(), endDate = range.overdueTo() - ).filterOverdue() + ) + .map { it.toDomain() } + .filterOverdue() } fun overdueUnspecified(range: FromToTimeRange): List { return transactionDao.findAllDueToBetweenByCategoryUnspecified( startDate = range.from(), endDate = range.overdueTo() - ).filterOverdue() + ) + .map { it.toDomain() } + .filterOverdue() } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVImporter.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt similarity index 94% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVImporter.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt index edc55bb848..cd36a3f8e9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVImporter.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVImporter.kt @@ -1,14 +1,14 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.csv.model.CSVRow -import com.ivy.wallet.domain.logic.csv.model.ImportResult -import com.ivy.wallet.domain.logic.csv.model.RowMapping +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.csv.model.CSVRow +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.RowMapping import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao @@ -78,10 +78,10 @@ class CSVImporter( newCategoryColorIndex = 0 newAccountColorIndex = 0 - accounts = accountDao.findAll() + accounts = accountDao.findAll().map { it.toDomain() } val initialAccountsCount = accounts.size - categories = categoryDao.findAll() + categories = categoryDao.findAll().map { it.toDomain() } val initialCategoriesCount = categories.size val baseCurrency = settingsDao.findFirst().currency @@ -120,7 +120,7 @@ class CSVImporter( val progressPercent = if (rowsCount > 0) index / transactions.size.toDouble() else 0.0 onProgress(0.5 + progressPercent / 2) - transactionDao.save(transaction) + transactionDao.save(transaction.toEntity()) } return ImportResult( @@ -212,10 +212,10 @@ class CSVImporter( Transaction( id = id, type = type, - amount = amount, + amount = amount.toBigDecimal(), accountId = account.id, toAccountId = toAccount?.id, - toAmount = toAmount, + toAmount = toAmount?.toBigDecimal() ?: amount.toBigDecimal(), dateTime = dateTime, dueDate = dueDate, categoryId = category?.id, @@ -444,8 +444,8 @@ class CSVImporter( icon = icon, orderNum = orderNum ?: accountDao.findMaxOrderNum() + 1 ) - accountDao.save(newAccount) - accounts = accountDao.findAll() + accountDao.save(newAccount.toEntity()) + accounts = accountDao.findAll().map { it.toDomain() } return newAccount } @@ -493,8 +493,8 @@ class CSVImporter( icon = icon, orderNum = orderNum ?: categoryDao.findMaxOrderNum() + 1 ) - categoryDao.save(newCategory) - categories = categoryDao.findAll() + categoryDao.save(newCategory.toEntity()) + categories = categoryDao.findAll().map { it.toDomain() } return newCategory } diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt similarity index 95% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt index 7101669908..98c35a0015 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVMapper.kt @@ -1,10 +1,10 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.csv.model.ImportType -import com.ivy.wallet.domain.logic.csv.model.JoinResult -import com.ivy.wallet.domain.logic.csv.model.RowMapping +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType +import com.ivy.wallet.domain.deprecated.logic.csv.model.JoinResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.RowMapping import com.ivy.wallet.utils.toLowerCaseLocal class CSVMapper { diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVNormalizer.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt similarity index 77% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVNormalizer.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt index 29d19d1a8e..4f1b4389c3 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/CSVNormalizer.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/CSVNormalizer.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv -import com.ivy.wallet.domain.logic.csv.model.ImportType +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType class CSVNormalizer { diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/ExportCSVLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt similarity index 89% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/ExportCSVLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt index 6df704811f..2c80a97bcc 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/ExportCSVLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/ExportCSVLogic.kt @@ -1,11 +1,11 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import android.content.Context import android.net.Uri import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao @@ -31,8 +31,8 @@ class ExportCSVLogic( suspend fun exportToFile( context: Context, fileUri: Uri, - exportScope: () -> List = { - transactionDao.findAll() + exportScope: suspend () -> List = { + transactionDao.findAll().map { it.toDomain() } } ) { val csv = generateCSV( @@ -49,7 +49,7 @@ class ExportCSVLogic( } private suspend fun generateCSV( - exportScope: () -> List + exportScope: suspend () -> List ): String { return ioThread { val accountMap = accountDao @@ -66,8 +66,8 @@ class ExportCSVLogic( .joinToString("\n") { it.toCSV( baseCurrency = baseCurrency, - accountMap = accountMap, - categoryMap = categoryMap + accountMap = accountMap.mapValues { it.value.toDomain() }, + categoryMap = categoryMap.mapValues { it.value.toDomain() } ) } @@ -116,7 +116,7 @@ class ExportCSVLogic( TransactionType.INCOME -> it TransactionType.EXPENSE -> -it TransactionType.TRANSFER -> 0.0 - }.formatAmountCSV(currency) + }.toDouble().formatAmountCSV(currency) append(amountFormatted) } @@ -132,7 +132,7 @@ class ExportCSVLogic( //Transfer Amount csv.appendValue(if (type == TransactionType.TRANSFER) amount else null) { - append(it.formatAmountCSV(currency)) + append(it.toDouble().formatAmountCSV(currency)) } //Transfer Currency @@ -148,7 +148,7 @@ class ExportCSVLogic( val receiveCurrency = toAccountId?.let { accountMap[it]?.currency ?: baseCurrency } //Receive Amount csv.appendValue(toAmount) { - append(it.formatAmountCSV(receiveCurrency ?: baseCurrency)) + append(it.toDouble().formatAmountCSV(receiveCurrency ?: baseCurrency)) } //Receive Currency diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/IvyFileReader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/IvyFileReader.kt similarity index 88% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/IvyFileReader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/IvyFileReader.kt index 24734883cb..0ad0b9c05a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/IvyFileReader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/IvyFileReader.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv +package com.ivy.wallet.domain.deprecated.logic.csv import android.content.Context import android.net.Uri diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/CSVRow.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/CSVRow.kt similarity index 55% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/model/CSVRow.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/CSVRow.kt index 3fa61d3aea..1b926a8f93 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/CSVRow.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/CSVRow.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv.model +package com.ivy.wallet.domain.deprecated.logic.csv.model data class CSVRow( val index: Int, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportResult.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportResult.kt similarity index 76% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportResult.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportResult.kt index 833026c420..681e3a2f37 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportResult.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportResult.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv.model +package com.ivy.wallet.domain.deprecated.logic.csv.model data class ImportResult( val rowsFound: Int, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportType.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportType.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportType.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportType.kt index d9028d0287..ebfb836b06 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/ImportType.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/ImportType.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.csv.model +package com.ivy.wallet.domain.deprecated.logic.csv.model import androidx.annotation.DrawableRes import androidx.compose.runtime.Composable diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/RowMapping.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/logic/csv/model/RowMapping.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt index 03c67fbdca..5bd01acb35 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/csv/model/RowMapping.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/csv/model/RowMapping.kt @@ -1,7 +1,7 @@ -package com.ivy.wallet.domain.logic.csv.model +package com.ivy.wallet.domain.deprecated.logic.csv.model -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction data class RowMapping( val type: Int? = null, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/currency/ExchangeRatesLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/logic/currency/ExchangeRatesLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt index 5b34df0b28..374110e9bc 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/currency/ExchangeRatesLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/currency/ExchangeRatesLogic.kt @@ -1,9 +1,9 @@ -package com.ivy.wallet.domain.logic.currency +package com.ivy.wallet.domain.deprecated.logic.currency -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.ExchangeRate -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.ExchangeRate +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.service.CoinbaseService import com.ivy.wallet.io.persistence.dao.AccountDao @@ -37,7 +37,7 @@ class ExchangeRatesLogic( baseCurrency = baseCurrency, currency = currency, rate = rate - ) + ).toEntity() ) } } catch (e: Exception) { @@ -65,7 +65,7 @@ class ExchangeRatesLogic( accounts: List //helper ): Double { return amountBaseCurrency( - amount = transaction.amount, + amount = transaction.amount.toDouble(), accountId = transaction.accountId, baseCurrency = baseCurrency, accounts = accounts @@ -79,10 +79,10 @@ class ExchangeRatesLogic( ): Double { val amount = transaction.toAmount ?: transaction.amount val toCurrency = accounts.find { it.id == transaction.toAccountId }?.currency - ?: return amount // no conversion + ?: return amount.toDouble() // no conversion return amountBaseCurrency( - amount = amount, + amount = amount.toDouble(), amountCurrency = toCurrency, baseCurrency = baseCurrency ) @@ -162,7 +162,7 @@ fun Iterable.sumInBaseCurrency( exchangeRatesLogic.amountBaseCurrency( transaction = it, baseCurrency = baseCurrency, - accounts = accounts + accounts = accounts.map { it.toDomain() } ) } } @@ -180,7 +180,7 @@ fun Iterable.sumByDoublePlannedInBaseCurrency( exchangeRatesLogic.amountBaseCurrency( plannedPayment = it, baseCurrency = baseCurrency, - accounts = accounts + accounts = accounts.map { it.toDomain() } ) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt similarity index 71% rename from app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt index dbf9afe159..170336fe36 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanMapper.kt @@ -1,12 +1,12 @@ -package com.ivy.wallet.domain.logic.loantrasactions +package com.ivy.wallet.domain.deprecated.logic.loantrasactions import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.model.CreateLoanData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData import com.ivy.wallet.utils.computationThread import com.ivy.wallet.utils.scopedIOThread import kotlinx.coroutines.async @@ -60,7 +60,7 @@ class LTLoanMapper( newLoanAccountId: UUID?, loanId: UUID ) { - val accounts = ltCore.fetchAccounts() + val accounts = ltCore.fetchAccounts().map { it.toDomain() } computationThread { if (oldLoanAccountId == newLoanAccountId || oldLoanAccountId.fetchAssociatedCurrencyCode( @@ -100,13 +100,13 @@ class LTLoanMapper( } val modifiedLoan = loan.copy( - amount = transaction.amount, + amount = transaction.amount.toDouble(), name = if (transaction.title.isNullOrEmpty()) loan.name else transaction.title, type = if (transaction.type == TransactionType.INCOME) LoanType.BORROW else LoanType.LEND, accountId = transaction.accountId ) - ltCore.saveLoan(modifiedLoan) + ltCore.saveLoan(modifiedLoan.toDomain()) } onBackgroundProcessingEnd() } @@ -117,21 +117,23 @@ class LTLoanMapper( ): List { return scopedIOThread { scope -> val loanRecords = - ltCore.fetchAllLoanRecords(loanId = loanId).map { loanRecord -> - scope.async { - val convertedAmount: Double? = - ltCore.computeConvertedAmount( - oldLoanRecordAccountId = loanRecord.accountId, - oldLonRecordConvertedAmount = loanRecord.convertedAmount, - oldLoanRecordAmount = loanRecord.amount, - newLoanRecordAccountID = loanRecord.accountId, - newLoanRecordAmount = loanRecord.amount, - loanAccountId = newAccountId, - accounts = ltCore.fetchAccounts(), - ) - loanRecord.copy(convertedAmount = convertedAmount) - } - }.awaitAll() + ltCore.fetchAllLoanRecords(loanId = loanId) + .map { it.toDomain() } + .map { loanRecord -> + scope.async { + val convertedAmount: Double? = + ltCore.computeConvertedAmount( + oldLoanRecordAccountId = loanRecord.accountId, + oldLonRecordConvertedAmount = loanRecord.convertedAmount, + oldLoanRecordAmount = loanRecord.amount, + newLoanRecordAccountID = loanRecord.accountId, + newLoanRecordAmount = loanRecord.amount, + loanAccountId = newAccountId, + accounts = ltCore.fetchAccounts().map { it.toDomain() }, + ) + loanRecord.copy(convertedAmount = convertedAmount) + } + }.awaitAll() loanRecords } } diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanRecordMapper.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt similarity index 85% rename from app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanRecordMapper.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt index 78e443409e..88cc9ba82a 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LTLoanRecordMapper.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LTLoanRecordMapper.kt @@ -1,9 +1,9 @@ -package com.ivy.wallet.domain.logic.loantrasactions +package com.ivy.wallet.domain.deprecated.logic.loantrasactions -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData import com.ivy.wallet.utils.computationThread import java.util.* @@ -75,19 +75,19 @@ class LTLoanRecordMapper( oldLonRecordConvertedAmount = loanRecord.convertedAmount, oldLoanRecordAmount = loanRecord.amount, newLoanRecordAccountID = transaction.accountId, - newLoanRecordAmount = transaction.amount, + newLoanRecordAmount = transaction.amount.toDouble(), loanAccountId = loan.accountId, - accounts = ltCore.fetchAccounts() + accounts = ltCore.fetchAccounts().map { it.toDomain() } ) val modifiedLoanRecord = loanRecord.copy( - amount = transaction.amount, + amount = transaction.amount.toDouble(), note = transaction.title, dateTime = transaction.dateTime ?: loanRecord.dateTime, accountId = transaction.accountId, convertedAmount = convertedAmount ) - ltCore.saveLoanRecords(modifiedLoanRecord) + ltCore.saveLoanRecords(modifiedLoanRecord.toDomain()) } onBackgroundProcessingEnd() } @@ -105,7 +105,7 @@ class LTLoanRecordMapper( newLoanRecordAccountID = newLoanRecord.accountId, newLoanRecordAmount = newLoanRecord.amount, loanAccountId = loanAccountId, - accounts = ltCore.fetchAccounts(), + accounts = ltCore.fetchAccounts().map { it.toDomain() }, reCalculateLoanAmount = reCalculateLoanAmount ) } @@ -121,7 +121,7 @@ class LTLoanRecordMapper( newLoanRecordAccountID = data.account?.id, newLoanRecordAmount = data.amount, loanAccountId = loanAccountId, - accounts = ltCore.fetchAccounts(), + accounts = ltCore.fetchAccounts().map { it.toDomain() }, ) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsCore.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt similarity index 91% rename from app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsCore.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt index 4d0b3e2caa..82d4efe386 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsCore.kt @@ -1,12 +1,12 @@ -package com.ivy.wallet.domain.logic.loantrasactions +package com.ivy.wallet.domain.deprecated.logic.loantrasactions import androidx.compose.ui.graphics.toArgb import com.ivy.wallet.R import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.sync.uploader.TransactionUploader +import com.ivy.wallet.domain.data.core.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.stringRes import com.ivy.wallet.ui.IvyWalletCtx @@ -48,8 +48,9 @@ class LoanTransactionsCore( ioThread { val transactions: List = - if (loanId != null) transactionDao.findAllByLoanId(loanId = loanId) else - listOf(transactionDao.findLoanRecordTransaction(loanRecordId!!)) + if (loanId != null) transactionDao.findAllByLoanId(loanId = loanId) + .map { it.toDomain() } else + listOf(transactionDao.findLoanRecordTransaction(loanRecordId!!)).map { it?.toDomain() } transactions.forEach { trans -> deleteTransaction(trans) @@ -144,7 +145,7 @@ class LoanTransactionsCore( val modifiedTransaction: Transaction = transaction?.copy( loanId = loanId, loanRecordId = if (isLoanRecord) loanRecordId else null, - amount = amount, + amount = amount.toBigDecimal(), type = transType, accountId = selectedAccountId, title = title, @@ -154,7 +155,7 @@ class LoanTransactionsCore( ?: Transaction( accountId = selectedAccountId, type = transType, - amount = amount, + amount = amount.toBigDecimal(), dateTime = time, categoryId = transCategoryId, title = title, @@ -163,7 +164,7 @@ class LoanTransactionsCore( ) ioThread { - transactionDao.save(modifiedTransaction) + transactionDao.save(modifiedTransaction.toEntity()) } } @@ -184,7 +185,7 @@ class LoanTransactionsCore( return existingCategoryId val categoryList = ioThread { - categoryDao.findAll() + categoryDao.findAll().map { it.toDomain() } } var addCategoryToDb = false @@ -203,7 +204,7 @@ class LoanTransactionsCore( if (addCategoryToDb) ioThread { loanCategory?.let { - categoryDao.save(it) + categoryDao.save(it.toEntity()) } } @@ -270,15 +271,15 @@ class LoanTransactionsCore( } suspend fun saveLoanRecords(loanRecords: List) = ioThread { - loanRecordDao.save(loanRecords) + loanRecordDao.save(loanRecords.map { it.toEntity() }) } suspend fun saveLoanRecords(loanRecord: LoanRecord) = ioThread { - loanRecordDao.save(loanRecord) + loanRecordDao.save(loanRecord.toEntity()) } suspend fun saveLoan(loan: Loan) = ioThread { - loanDao.save(loan) + loanDao.save(loan.toEntity()) } suspend fun fetchLoanRecord(loanRecordId: UUID) = ioThread { @@ -296,7 +297,7 @@ class LoanTransactionsCore( suspend fun fetchLoanRecordTransaction(loanRecordId: UUID?): Transaction? { return loanRecordId?.let { ioThread { - transactionDao.findLoanRecordTransaction(it) + transactionDao.findLoanRecordTransaction(it)?.toDomain() } } } diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt similarity index 91% rename from app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt index 0ea34c1056..20c431e0a6 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/loantrasactions/LoanTransactionsLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/loantrasactions/LoanTransactionsLogic.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.logic.loantrasactions +package com.ivy.wallet.domain.deprecated.logic.loantrasactions -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.utils.computationThread data class LoanTransactionsLogic( diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateAccountData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateAccountData.kt similarity index 81% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateAccountData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateAccountData.kt index afd0854982..2def1f6323 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateAccountData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateAccountData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import androidx.compose.ui.graphics.Color diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateBudgetData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateBudgetData.kt similarity index 74% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateBudgetData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateBudgetData.kt index 99a6ef502b..db29ec3812 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateBudgetData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateBudgetData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model data class CreateBudgetData( val name: String, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateCategoryData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateCategoryData.kt similarity index 72% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateCategoryData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateCategoryData.kt index b9913ba77f..95be242474 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateCategoryData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateCategoryData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import androidx.compose.ui.graphics.Color diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt similarity index 75% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt index 6bd69df44e..826613c6e8 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanData.kt @@ -1,8 +1,8 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import androidx.compose.ui.graphics.Color import com.ivy.wallet.domain.data.LoanType -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account data class CreateLoanData( val name: String, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanRecordData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt similarity index 75% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanRecordData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt index 7392dfde34..df578879ea 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CreateLoanRecordData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CreateLoanRecordData.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import java.time.LocalDateTime data class CreateLoanRecordData( diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/CustomerJourneyCardData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CustomerJourneyCardData.kt similarity index 91% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/CustomerJourneyCardData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CustomerJourneyCardData.kt index 0609932a1b..543c9c739f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/CustomerJourneyCardData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/CustomerJourneyCardData.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model import androidx.annotation.DrawableRes import androidx.compose.ui.graphics.Color diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/model/EditLoanRecordData.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt similarity index 67% rename from app/src/main/java/com/ivy/wallet/domain/logic/model/EditLoanRecordData.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt index 93460dad76..542db83cc9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/model/EditLoanRecordData.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/model/EditLoanRecordData.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.logic.model +package com.ivy.wallet.domain.deprecated.logic.model -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.LoanRecord data class EditLoanRecordData( val newLoanRecord: LoanRecord, diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderLogic.kt similarity index 97% rename from app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderLogic.kt index 11c2db7c86..79b6a5e742 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.notification +package com.ivy.wallet.domain.deprecated.logic.notification import android.content.Context import androidx.work.ExistingPeriodicWorkPolicy diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderWorker.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderWorker.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderWorker.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderWorker.kt index 71964bbf66..8b9c854d37 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/notification/TransactionReminderWorker.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/notification/TransactionReminderWorker.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.notification +package com.ivy.wallet.domain.deprecated.logic.notification import android.app.PendingIntent import android.content.Context diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/zip/ExportZipLogic.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt similarity index 88% rename from app/src/main/java/com/ivy/wallet/domain/logic/zip/ExportZipLogic.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt index 9ccd5a0cd8..a692259b5e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/zip/ExportZipLogic.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ExportZipLogic.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.zip +package com.ivy.wallet.domain.deprecated.logic.zip import android.content.Context import android.net.Uri @@ -6,7 +6,7 @@ import androidx.core.net.toUri import com.google.gson.* import com.google.gson.reflect.TypeToken import com.ivy.wallet.domain.data.IvyWalletCompleteData -import com.ivy.wallet.domain.logic.csv.model.ImportResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.utils.ioThread @@ -56,14 +56,15 @@ class ExportZipLogic( private suspend fun generateJsonString(): String { return scopedIOThread { - 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() } - val settings = it.async { settingsDao.findAll() } - val transactions = it.async { transactionDao.findAll() } + 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 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() } } val sharedPrefs = it.async { getSharedPrefsData() } val gson = GsonBuilder().registerTypeAdapter( @@ -216,20 +217,22 @@ class ExportZipLogic( onProgress: suspend (progressPercent: Double) -> Unit = {} ) { scopedIOThread { - transactionDao.save(completeData.transactions) + transactionDao.save(completeData.transactions.map { it.toEntity() }) onProgress(0.6) - val accounts = it.async { accountDao.save(completeData.accounts) } - val budgets = it.async { budgetDao.save(completeData.budgets) } - val categories = it.async { categoryDao.save(completeData.categories) } + val accounts = it.async { accountDao.save(completeData.accounts.map { it.toEntity() }) } + val budgets = it.async { budgetDao.save(completeData.budgets.map { it.toEntity() }) } + val categories = + it.async { categoryDao.save(completeData.categories.map { it.toEntity() }) } accounts.await() budgets.await() categories.await() onProgress(0.7) - val loans = it.async { loanDao.save(completeData.loans) } - val loanRecords = it.async { loanRecordDao.save(completeData.loanRecords) } + val loans = it.async { loanDao.save(completeData.loans.map { it.toEntity() }) } + val loanRecords = + it.async { loanRecordDao.save(completeData.loanRecords.map { it.toEntity() }) } loans.await() loanRecords.await() @@ -237,10 +240,10 @@ class ExportZipLogic( onProgress(0.8) val plannedPayments = - it.async { plannedPaymentRuleDao.save(completeData.plannedPaymentRules) } + it.async { plannedPaymentRuleDao.save(completeData.plannedPaymentRules.map { it.toEntity() }) } val settings = it.async { settingsDao.deleteAll() - settingsDao.save(completeData.settings) + settingsDao.save(completeData.settings.map { it.toEntity() }) } sharedPrefs.putBoolean( @@ -274,8 +277,8 @@ class ExportZipLogic( completeData: IvyWalletCompleteData ): List> { return scopedIOThread { scope -> - val existingAccountsList = accountDao.findAll() - val existingCategoryList = categoryDao.findAll() + val existingAccountsList = accountDao.findAll().map { it.toDomain() } + val existingCategoryList = categoryDao.findAll().map { it.toDomain() } val backupAccountsList = completeData.accounts val backupCategoryList = completeData.categories diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/zip/ZipUtils.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ZipUtils.kt similarity index 98% rename from app/src/main/java/com/ivy/wallet/domain/logic/zip/ZipUtils.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ZipUtils.kt index 8139069415..8b35ba1015 100644 --- a/app/src/main/java/com/ivy/wallet/domain/logic/zip/ZipUtils.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/logic/zip/ZipUtils.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.logic.zip +package com.ivy.wallet.domain.deprecated.logic.zip import android.content.Context import android.net.Uri diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/IvySync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt similarity index 92% rename from app/src/main/java/com/ivy/wallet/domain/sync/IvySync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt index d2791015d8..41cb2a9941 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/IvySync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/IvySync.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync +package com.ivy.wallet.domain.deprecated.sync -import com.ivy.wallet.domain.sync.item.* +import com.ivy.wallet.domain.deprecated.sync.item.* import com.ivy.wallet.io.network.IvySession class IvySync( diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/AccountSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/AccountSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt index bf0a4d6dad..6181a6d4c7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/AccountSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/AccountSync.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.AccountUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.AccountUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class AccountSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -63,7 +63,7 @@ class AccountSync( response.accounts.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/BudgetSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/BudgetSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt index ed5158164b..022c54b2bf 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/BudgetSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/BudgetSync.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.BudgetUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.BudgetUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class BudgetSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -63,7 +63,7 @@ class BudgetSync( response.budgets.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/CategorySync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/CategorySync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt index 26e7553aa2..b3327ddfa7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/CategorySync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/CategorySync.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.CategoryUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.CategoryUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class CategorySync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -63,7 +63,7 @@ class CategorySync( response.categories.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/LoanRecordSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/LoanRecordSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt index b3209ad56a..cb0ece3006 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/LoanRecordSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanRecordSync.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.LoanRecordUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.LoanRecordUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class LoanRecordSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -64,7 +64,7 @@ class LoanRecordSync( response.loanRecords.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/LoanSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/LoanSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt index c6889ac7fd..f4e6e634ae 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/LoanSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/LoanSync.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.LoanUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.LoanUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class LoanSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -63,7 +63,7 @@ class LoanSync( response.loans.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/PlannedPaymentSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/PlannedPaymentSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt index 5d1e49823b..46e80e4a1e 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/PlannedPaymentSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/PlannedPaymentSync.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.PlannedPaymentRuleUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -41,7 +41,7 @@ class PlannedPaymentSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -65,7 +65,7 @@ class PlannedPaymentSync( response.rules.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/item/TransactionSync.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/item/TransactionSync.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt index 08924bf2a5..1b97b9df6f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/item/TransactionSync.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/item/TransactionSync.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.item +package com.ivy.wallet.domain.deprecated.sync.item -import com.ivy.wallet.domain.sync.uploader.TransactionUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.persistence.SharedPrefs @@ -40,7 +40,7 @@ class TransactionSync( ) for (item in toSync) { - uploader.sync(item) + uploader.sync(item.toDomain()) } } @@ -64,7 +64,7 @@ class TransactionSync( response.transactions.forEach { item -> dao.save( - item.copy( + item.toEntity().copy( isSynced = true, isDeleted = false ) diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/AccountUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt similarity index 91% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/AccountUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt index 9d0db4a07b..a71735cab2 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/AccountUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/AccountUploader.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.account.DeleteAccountRequest @@ -25,7 +25,7 @@ class AccountUploader( //update service.update( UpdateAccountRequest( - account = item + account = item.toDTO() ) ) @@ -33,7 +33,7 @@ class AccountUploader( accountDao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Account updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/BudgetUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/BudgetUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt index 91a0b8b552..17d609d890 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/BudgetUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/BudgetUploader.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.domain.data.core.Budget import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.budget.CrupdateBudgetRequest @@ -23,7 +23,7 @@ class BudgetUploader( //update service.update( CrupdateBudgetRequest( - budget = item + budget = item.toDTO() ) ) @@ -31,7 +31,7 @@ class BudgetUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Budget updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/CategoryUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/CategoryUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt index 43dab1c576..c0d452bdd1 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/CategoryUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/CategoryUploader.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.category.DeleteWalletCategoryRequest @@ -23,7 +23,7 @@ class CategoryUploader( //update service.update( UpdateWalletCategoryRequest( - category = item + category = item.toDTO() ) ) @@ -31,7 +31,7 @@ class CategoryUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Category updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanRecordUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanRecordUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt index 61bbb13ff5..14809c41ff 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanRecordUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanRecordUploader.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.LoanRecord import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.loan.DeleteLoanRecordRequest @@ -23,7 +23,7 @@ class LoanRecordUploader( //update service.updateRecord( UpdateLoanRecordRequest( - loanRecord = item + loanRecord = item.toDTO() ) ) @@ -31,7 +31,7 @@ class LoanRecordUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Loan record updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt index 8107b16f04..5ddb17d2af 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/LoanUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/LoanUploader.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.loan.DeleteLoanRequest @@ -23,7 +23,7 @@ class LoanUploader( //update service.update( UpdateLoanRequest( - loan = item + loan = item.toDTO() ) ) @@ -31,7 +31,7 @@ class LoanUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Loan updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/PlannedPaymentRuleUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/PlannedPaymentRuleUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt index e6965922ed..a4d264f6dc 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/PlannedPaymentRuleUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/PlannedPaymentRuleUploader.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.planned.DeletePlannedPaymentRuleRequest @@ -23,7 +23,7 @@ class PlannedPaymentRuleUploader( //update service.update( UpdatePlannedPaymentRuleRequest( - rule = item + rule = item.toDTO() ) ) @@ -31,7 +31,7 @@ class PlannedPaymentRuleUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("PlannedPaymentRule updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/TransactionUploader.kt b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt similarity index 90% rename from app/src/main/java/com/ivy/wallet/domain/sync/uploader/TransactionUploader.kt rename to app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt index f0c3008d4b..78cdabd6d5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/sync/uploader/TransactionUploader.kt +++ b/app/src/main/java/com/ivy/wallet/domain/deprecated/sync/uploader/TransactionUploader.kt @@ -1,6 +1,6 @@ -package com.ivy.wallet.domain.sync.uploader +package com.ivy.wallet.domain.deprecated.sync.uploader -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.network.RestClient import com.ivy.wallet.io.network.request.transaction.DeleteTransactionRequest @@ -23,7 +23,7 @@ class TransactionUploader( //update service.update( UpdateTransactionRequest( - transaction = item + transaction = item.toDTO() ) ) @@ -31,7 +31,7 @@ class TransactionUploader( dao.save( item.copy( isSynced = true - ) + ).toEntity() ) Timber.d("Transaction updated: $item.") } catch (e: Exception) { diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt b/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt deleted file mode 100644 index 493efeb1b4..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountCore.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.ivy.wallet.domain.fp.account - -import arrow.core.NonEmptyList -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.core.Total -import com.ivy.wallet.domain.fp.core.calculateValueFunctionsSum -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.toFPTransaction -import com.ivy.wallet.io.persistence.dao.TransactionDao -import java.math.BigDecimal -import java.util.* - -@Total -suspend fun calculateAccountValues( - transactionDao: TransactionDao, - accountId: UUID, - range: ClosedTimeRange, - valueFunctions: NonEmptyList -): NonEmptyList { - return calculateAccountValues( - accountId = accountId, - retrieveAccountTransactions = { - transactionDao.findAllByAccountAndBetween( - accountId = accountId, - startDate = range.from, - endDate = range.to - ) - }, - retrieveToAccountTransfers = { - transactionDao.findAllToAccountAndBetween( - toAccountId = accountId, - startDate = range.from, - endDate = range.to - ) - }, - valueFunctions = valueFunctions - ) -} - -@Total -suspend fun calculateAccountValues( - accountId: UUID, - retrieveAccountTransactions: suspend (UUID) -> List, - retrieveToAccountTransfers: suspend (UUID) -> List, - valueFunctions: NonEmptyList -): NonEmptyList { - val accountTrns = retrieveAccountTransactions(accountId) - .plus(retrieveToAccountTransfers(accountId)) - .map { it.toFPTransaction() } - - return calculateValueFunctionsSum( - valueFunctionArgument = accountId, - transactions = accountTrns, - valueFunctions = valueFunctions - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt deleted file mode 100644 index 20e99c8902..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountFunctions.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.ivy.wallet.domain.fp.account - -import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.IncomeExpensePair -import com.ivy.wallet.io.persistence.dao.TransactionDao -import java.math.BigDecimal -import java.util.* - - -suspend fun calculateAccountBalance( - transactionDao: TransactionDao, - accountId: UUID, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() -): BigDecimal { - return calculateAccountValues( - transactionDao = transactionDao, - accountId = accountId, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::balance - ) - ).head -} - -data class AccountStats( - val balance: BigDecimal, - val income: BigDecimal, - val expense: BigDecimal, - val incomeCount: Int, - val expenseCount: Int -) - -suspend fun calculateAccountStats( - transactionDao: TransactionDao, - accountId: UUID, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() -): AccountStats { - val values = calculateAccountValues( - transactionDao = transactionDao, - accountId = accountId, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::balance, - AccountValueFunctions::income, - AccountValueFunctions::expense, - AccountValueFunctions::incomeCount, - AccountValueFunctions::expenseCount - ) - ) - - return AccountStats( - balance = values[0], - income = values[1], - expense = values[2], - incomeCount = values[3].toInt(), - expenseCount = values[4].toInt() - ) -} - -suspend fun calculateAccountIncomeExpense( - transactionDao: TransactionDao, - accountId: UUID, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy() -): IncomeExpensePair { - val values = calculateAccountValues( - transactionDao = transactionDao, - accountId = accountId, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::income, - AccountValueFunctions::expense, - ) - ) - - return IncomeExpensePair( - income = values[0], - expense = values[1], - ) -} - - diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryCore.kt b/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryCore.kt deleted file mode 100644 index 4ce2586dbb..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryCore.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.ivy.wallet.domain.fp.category - -import arrow.core.NonEmptyList -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.core.calculateValueFunctionsSumSuspend -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.data.toFPTransaction -import java.math.BigDecimal -import java.util.* - -suspend fun calculateCategoryValues( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, - valueFunctions: NonEmptyList -): NonEmptyList { - return calculateCategoryValues( - argument = CategoryValueFunctions.Argument( - categoryId = categoryId, - accounts = walletDAOs.accountDao.findAll(), - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode - ), - retrieveCategoryTransactions = { forCategoryId -> - if (forCategoryId == null) { - walletDAOs.transactionDao.findAllUnspecifiedAndBetween( - startDate = range.from, - endDate = range.to - ) - } else { - walletDAOs.transactionDao.findAllByCategoryAndBetween( - categoryId = forCategoryId, - startDate = range.from, - endDate = range.to - ) - } - - }, - valueFunctions = valueFunctions - ) -} - -suspend fun calculateCategoryValuesWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, - accountIdFilterSet: Set, - valueFunctions: NonEmptyList -): NonEmptyList { - return calculateCategoryValues( - argument = CategoryValueFunctions.Argument( - categoryId = categoryId, - accounts = walletDAOs.accountDao.findAll(), - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode - ), - retrieveCategoryTransactions = { forCategoryId -> - if (forCategoryId == null) { - walletDAOs.transactionDao.findAllUnspecifiedAndBetween( - startDate = range.from, - endDate = range.to - ).filter { - if (accountIdFilterSet.isNotEmpty()) - accountIdFilterSet.contains(it.accountId) - else - true - } - } else { - walletDAOs.transactionDao.findAllByCategoryAndBetween( - categoryId = forCategoryId, - startDate = range.from, - endDate = range.to - ).filter { - if (accountIdFilterSet.isNotEmpty()) - accountIdFilterSet.contains(it.accountId) - else - true - } - } - }, - valueFunctions = valueFunctions - ) -} - -suspend fun calculateCategoryValues( - argument: CategoryValueFunctions.Argument, - retrieveCategoryTransactions: suspend (UUID?) -> List, - valueFunctions: NonEmptyList -): NonEmptyList { - val categoryTrns = retrieveCategoryTransactions(argument.categoryId) - .map { it.toFPTransaction() } - - return calculateValueFunctionsSumSuspend( - valueFunctionArgument = argument, - transactions = categoryTrns, - valueFunctions = valueFunctions - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryFunctions.kt deleted file mode 100644 index 2c17284b6f..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryFunctions.kt +++ /dev/null @@ -1,135 +0,0 @@ -package com.ivy.wallet.domain.fp.category - -import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.WalletDAOs -import java.math.BigDecimal -import java.util.* - -suspend fun calculateCategoryBalance( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::balance - ) - ).head -} - -data class CategoryStats( - val balance: BigDecimal, - val income: BigDecimal, - val expense: BigDecimal, - val incomeCount: BigDecimal, - val expenseCount: BigDecimal -) - -suspend fun calculateCategoryStats( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, -): CategoryStats { - val values = calculateCategoryValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::income, - CategoryValueFunctions::expense, - CategoryValueFunctions::incomeCount, - CategoryValueFunctions::expenseCount - ) - ) - - val income = values[0] - val expense = values[1] - - return CategoryStats( - balance = income - expense, - income = income, - expense = expense, - incomeCount = values[2], - expenseCount = values[3] - ) -} - -suspend fun calculateCategoryIncome( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::income - ) - ).head -} - -suspend fun calculateCategoryIncomeWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - accountIdFilterList: List, - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValuesWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - accountIdFilterSet = accountIdFilterList.toHashSet(), - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::income - ) - ).head -} - -suspend fun calculateCategoryExpense( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::expense - ) - ).head -} - -suspend fun calculateCategoryExpenseWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - categoryId: UUID?, - accountIdList: List = emptyList(), - range: ClosedTimeRange, -): BigDecimal { - return calculateCategoryValuesWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - categoryId = categoryId, - range = range, - accountIdFilterSet = accountIdList.toHashSet(), - valueFunctions = nonEmptyListOf( - CategoryValueFunctions::expense - ) - ).head -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/CoreValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/core/CoreValueFunctions.kt deleted file mode 100644 index ce1d113b37..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/CoreValueFunctions.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.ivy.wallet.domain.fp.core - -import arrow.core.toOption -import com.ivy.wallet.domain.fp.data.FPTransaction -import com.ivy.wallet.domain.fp.exchange -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao -import java.math.BigDecimal - -data class ExchangeData( - val exchangeRateDao: ExchangeRateDao, - val accountDao: AccountDao, - val baseCurrencyCode: String, - val toCurrency: String, -) - -suspend fun amountInCurrency(fpTransaction: FPTransaction, data: ExchangeData): BigDecimal { - val fromCurrencyCode = - data.accountDao.findById(fpTransaction.accountId)?.currency.toOption() - - return exchange( - exchangeRateDao = data.exchangeRateDao, - baseCurrencyCode = data.baseCurrencyCode, - fromCurrencyCode = fromCurrencyCode, - fromAmount = fpTransaction.amount, - toCurrencyCode = data.toCurrency - ).orNull() ?: BigDecimal.ZERO -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt b/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt deleted file mode 100644 index f5d7feb972..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/FP.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.ivy.wallet.domain.fp.core - -@Target(AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -annotation class Pure - -@Target(AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -annotation class Total - -@Target(AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -annotation class Partial(val inCaseOf: String = "") - - -infix fun ((A) -> B).compose(fn2: (B) -> C): (A) -> C = { a -> - val b = this(a) - val c = fn2(b) - c -} - -infix fun ((B) -> C).after(fn1: (A) -> B): (A) -> C = { a -> - val b = fn1(a) - val c = this(b) - c -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/TransactionFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/core/TransactionFunctions.kt deleted file mode 100644 index a48b38a31a..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/TransactionFunctions.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.ivy.wallet.domain.fp.core - -import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.FPTransaction -import com.ivy.wallet.domain.fp.data.toFPTransaction -import java.math.BigDecimal - -suspend fun sum( - transactions: List, - valueFunction: SuspendValueFunction, - argument: A -): BigDecimal { - return transactions.sumOf { - valueFunction(it, argument) - } -} - -fun expenses(transactions: List): List { - return transactions.filter { it.type == TransactionType.EXPENSE } -} - -fun incomes(transactions: List): List { - return transactions.filter { it.type == TransactionType.INCOME } -} - -fun transfers(transactions: List): List { - return transactions.filter { it.type == TransactionType.TRANSFER } -} - -fun List.toFPTransactions(): List { - return this.map { it.toFPTransaction() } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/Uncertain.kt b/app/src/main/java/com/ivy/wallet/domain/fp/core/Uncertain.kt deleted file mode 100644 index 024501df1d..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/Uncertain.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ivy.wallet.domain.fp.core - -data class Uncertain, V>( - val error: E, - val value: V -) { - fun isCertain(): Boolean { - return error.isEmpty() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/ValueFunction.kt b/app/src/main/java/com/ivy/wallet/domain/fp/core/ValueFunction.kt deleted file mode 100644 index 7dde3b18e5..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/ValueFunction.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.ivy.wallet.domain.fp.core - -import arrow.core.NonEmptyList -import com.ivy.wallet.domain.fp.data.FPTransaction -import java.math.BigDecimal - -typealias ValueFunction = (FPTransaction, A) -> BigDecimal -typealias SuspendValueFunction = suspend (FPTransaction, A) -> BigDecimal - -internal tailrec fun calculateValueFunctionsSum( - valueFunctionArgument: A, - transactions: List, - valueFunctions: NonEmptyList>, - sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) -): NonEmptyList { - return if (transactions.isEmpty()) - sum - else - calculateValueFunctionsSum( - valueFunctionArgument = valueFunctionArgument, - transactions = transactions.drop(1), - valueFunctions = valueFunctions, - sum = sum.mapIndexedNel { index, sumValue -> - val valueFunction = valueFunctions[index] - sumValue + valueFunction(transactions.first(), valueFunctionArgument) - } - ) -} - -internal tailrec suspend fun calculateValueFunctionsSumSuspend( - valueFunctionArgument: A, - transactions: List, - valueFunctions: NonEmptyList>, - sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) -): NonEmptyList { - return if (transactions.isEmpty()) - sum - else - calculateValueFunctionsSumSuspend( - valueFunctionArgument = valueFunctionArgument, - transactions = transactions.drop(1), - valueFunctions = valueFunctions, - sum = sum.mapIndexedNelSuspend { index, sumValue -> - val valueFunction = valueFunctions[index] - sumValue + valueFunction(transactions.first(), valueFunctionArgument) - } - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/CurrencyConvError.kt b/app/src/main/java/com/ivy/wallet/domain/fp/data/CurrencyConvError.kt deleted file mode 100644 index fde5cdb0ae..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/CurrencyConvError.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.ivy.wallet.domain.fp.data - -data class CurrencyConvError(val account: FPAccount) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/FPAccount.kt b/app/src/main/java/com/ivy/wallet/domain/fp/data/FPAccount.kt deleted file mode 100644 index 0e5d8e3758..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/FPAccount.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.ivy.wallet.domain.fp.data - -import arrow.core.Option -import arrow.core.toOption -import com.ivy.wallet.domain.data.entity.Account -import java.util.* - -data class FPAccount( - val id: UUID, - val name: String, - val currencyCode: String, - val color: Int, - val icon: Option, - val orderNum: Double, - val includeInBalance: Boolean, -) - -fun Account.toFPAccount( - baseCurrencyCode: String -): FPAccount = - FPAccount( - id = id, - name = name, - currencyCode = currency ?: baseCurrencyCode, - color = color, - icon = icon.toOption(), - orderNum = orderNum, - includeInBalance = includeInBalance - ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/FPTransaction.kt b/app/src/main/java/com/ivy/wallet/domain/fp/data/FPTransaction.kt deleted file mode 100644 index ce220b9627..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/FPTransaction.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.ivy.wallet.domain.fp.data - -import arrow.core.Option -import arrow.core.toOption -import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction -import java.math.BigDecimal -import java.time.LocalDateTime -import java.util.* - -data class FPTransaction( - val id: UUID, - val type: TransactionType, - val accountId: UUID, - val categoryId: Option, - val amount: BigDecimal, - val toAccountId: Option, - val toAmount: BigDecimal, - val dateTime: Option, - - val loanId: Option, - val loanRecordId:Option, - - val title: Option, - val description: Option, - val dueDate: Option, - val recurringRuleId: Option -) - -fun Transaction.toFPTransaction(): FPTransaction = - FPTransaction( - id = id, - accountId = accountId, - type = type, - amount = amount.toBigDecimal(), - toAccountId = toAccountId.toOption(), - toAmount = toAmount?.toBigDecimal() ?: amount.toBigDecimal(), - title = title.toOption(), - description = description.toOption(), - dateTime = dateTime.toOption(), - categoryId = categoryId.toOption(), - dueDate = dueDate.toOption(), - recurringRuleId = recurringRuleId.toOption(), - loanId = loanId.toOption(), - loanRecordId = loanRecordId.toOption() - ) diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt deleted file mode 100644 index 7f4b431dbe..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletCore.kt +++ /dev/null @@ -1,148 +0,0 @@ -package com.ivy.wallet.domain.fp.wallet - -import arrow.core.NonEmptyList -import arrow.core.Some -import com.ivy.wallet.domain.fp.account.AccountValueFunction -import com.ivy.wallet.domain.fp.account.calculateAccountValues -import com.ivy.wallet.domain.fp.core.Uncertain -import com.ivy.wallet.domain.fp.core.mapIndexedNel -import com.ivy.wallet.domain.fp.core.nonEmptyListOfZeros -import com.ivy.wallet.domain.fp.data.* -import com.ivy.wallet.domain.fp.exchangeToBaseCurrency -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao -import com.ivy.wallet.utils.scopedIOThread -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import java.math.BigDecimal -import java.util.* - -typealias UncertainWalletValues = Uncertain, NonEmptyList> -typealias AccountValuesPair = Pair> - -suspend fun calculateWalletValues( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), - valueFunctions: NonEmptyList -): UncertainWalletValues { - val uncertainWalletValues = walletDAOs.accountDao.findAll() - .filter { !filterExcluded || it.includeInBalance } - .map { account -> - Pair( - first = account.toFPAccount(baseCurrencyCode), - second = calculateAccountValues( - transactionDao = walletDAOs.transactionDao, - accountId = account.id, - range = range, - valueFunctions = valueFunctions - ) - ) - } - .convertValuesInBaseCurrency( - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode - ) - - return sumUncertainWalletValues( - valueN = valueFunctions.size, - uncertainWalletValues = uncertainWalletValues - ) -} - -suspend fun calculateWalletValuesWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - accountIdFilterList: List, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), - valueFunctions: NonEmptyList -): UncertainWalletValues { - - val accounts = scopedIOThread { scope -> - if (accountIdFilterList.isNotEmpty()) - accountIdFilterList.map { accId -> - scope.async { - walletDAOs.accountDao.findById(accId) - } - }.awaitAll().filterNotNull() - else { - walletDAOs.accountDao.findAll() - } - } - - val uncertainWalletValues = accounts - .filter { !filterExcluded || it.includeInBalance } - .map { account -> - Pair( - first = account.toFPAccount(baseCurrencyCode), - second = calculateAccountValues( - transactionDao = walletDAOs.transactionDao, - accountId = account.id, - range = range, - valueFunctions = valueFunctions - ) - ) - } - .convertValuesInBaseCurrency( - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode - ) - - return sumUncertainWalletValues( - valueN = valueFunctions.size, - uncertainWalletValues = uncertainWalletValues - ) -} - -private suspend fun Iterable.convertValuesInBaseCurrency( - exchangeRateDao: ExchangeRateDao, - baseCurrencyCode: String, -): List { - return this.map { (account, values) -> - val valuesInBaseCurrency = values.map { - exchangeToBaseCurrency( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = account.currencyCode, - fromAmount = it - ) - } - val hasError = valuesInBaseCurrency.any { !it.isDefined() } - - Uncertain( - error = if (hasError) - listOf(CurrencyConvError(account = account)) else emptyList(), - value = if (!hasError) { - //if there is no error all values must be Some() - valuesInBaseCurrency.map { (it as Some).value } - } else nonEmptyListOfZeros(values.size) - ) - } -} - -private tailrec fun sumUncertainWalletValues( - valueN: Int, - uncertainWalletValues: List, - sum: UncertainWalletValues = Uncertain( - error = emptyList(), - value = nonEmptyListOfZeros(n = valueN) - ) -): UncertainWalletValues { - return if (uncertainWalletValues.isEmpty()) sum else { - val uncertainValues = uncertainWalletValues.first() - - sumUncertainWalletValues( - valueN = valueN, - uncertainWalletValues = uncertainWalletValues.drop(1), - sum = Uncertain( - error = sum.error.plus(uncertainValues.error), - value = if (uncertainValues.isCertain()) { - sum.value.mapIndexedNel { index, value -> - value.plus(uncertainValues.value[index]) - } - } else sum.value //no need to sum it, if it's uncertain (it'll be all ZEROs) - ) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt deleted file mode 100644 index 2e1b844447..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletFunctions.kt +++ /dev/null @@ -1,194 +0,0 @@ -package com.ivy.wallet.domain.fp.wallet - -import arrow.core.nonEmptyListOf -import com.ivy.wallet.domain.data.entity.Settings -import com.ivy.wallet.domain.fp.account.AccountValueFunctions -import com.ivy.wallet.domain.fp.core.Uncertain -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.CurrencyConvError -import com.ivy.wallet.domain.fp.data.IncomeExpensePair -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.io.persistence.dao.SettingsDao -import java.math.BigDecimal -import java.util.* - -fun walletBufferDiff( - settings: Settings, - balance: BigDecimal -): BigDecimal { - return balance - settings.bufferAmount.toBigDecimal() -} - -suspend fun baseCurrencyCode( - settingsDao: SettingsDao -): String { - return settingsDao.findFirst().currency -} - -suspend fun calculateWalletBalance( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::balance - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - -suspend fun calculateWalletIncome( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::income - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - -suspend fun calculateWalletIncomeWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - accountIdFilterList: List, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValuesWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - accountIdFilterList = accountIdFilterList, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::income - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - -suspend fun calculateWalletExpense( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::expense - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - -suspend fun calculateWalletExpenseWithAccountFilters( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - accountIdFilterList: List, - range: ClosedTimeRange = ClosedTimeRange.allTimeIvy(), -): Uncertain, BigDecimal> { - val uncertainValues = calculateWalletValuesWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - accountIdFilterList = accountIdFilterList, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::expense - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = uncertainValues.value.head - ) -} - -suspend fun calculateWalletIncomeExpense( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange, -): Uncertain, IncomeExpensePair> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::income, - AccountValueFunctions::expense - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = IncomeExpensePair( - income = uncertainValues.value[0], - expense = uncertainValues.value[1] - ) - ) -} - -suspend fun calculateWalletIncomeExpenseCount( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - filterExcluded: Boolean = true, - range: ClosedTimeRange, -): Uncertain, Pair> { - val uncertainValues = calculateWalletValues( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = filterExcluded, - range = range, - valueFunctions = nonEmptyListOf( - AccountValueFunctions::incomeCount, - AccountValueFunctions::expenseCount - ) - ) - - return Uncertain( - error = uncertainValues.error, - value = Pair( - uncertainValues.value[0], uncertainValues.value[1] - ) - ) -} - -//TODO: upcomingIncomeExpense -//TODO: overdueIncomeExpense diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt b/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt deleted file mode 100644 index 6742e592b3..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/fp/wallet/WalletTransactions.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.ivy.wallet.domain.fp.wallet - -import com.ivy.wallet.domain.data.TransactionHistoryDateDivider -import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.core.* -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao -import com.ivy.wallet.io.persistence.dao.TransactionDao -import com.ivy.wallet.utils.convertUTCtoLocal -import com.ivy.wallet.utils.toEpochSeconds - -//TODO: overdue(range) -//TODO: upcoming(range) - -suspend fun historyWithDateDividers( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - range: ClosedTimeRange -): List { - return history( - transactionDao = walletDAOs.transactionDao, - range = range - ).withDateDividers( - exchangeRateDao = walletDAOs.exchangeRateDao, - accountDao = walletDAOs.accountDao, - baseCurrencyCode = baseCurrencyCode - ) -} - -suspend fun history( - transactionDao: TransactionDao, - range: ClosedTimeRange -): List { - return transactionDao.findAllBetween( - startDate = range.from, - endDate = range.to - ) -} - -suspend fun List.withDateDividers( - exchangeRateDao: ExchangeRateDao, - accountDao: AccountDao, - baseCurrencyCode: String, -): List { - val history = this - if (history.isEmpty()) return emptyList() - - return history - .groupBy { it.dateTime?.convertUTCtoLocal()?.toLocalDate() } - .filterKeys { it != null } - .toSortedMap { date1, date2 -> - if (date1 == null || date2 == null) return@toSortedMap 0 //this case shouldn't happen - (date2.atStartOfDay().toEpochSeconds() - date1.atStartOfDay().toEpochSeconds()).toInt() - } - .flatMap { (date, transactionsForDate) -> - val baseCurrencyExchangeData = ExchangeData( - exchangeRateDao = exchangeRateDao, - accountDao = accountDao, - baseCurrencyCode = baseCurrencyCode, - toCurrency = baseCurrencyCode - ) - val fpTransactions = transactionsForDate.toFPTransactions() - - listOf( - TransactionHistoryDateDivider( - date = date!!, - income = sum( - incomes(fpTransactions), - ::amountInCurrency, - baseCurrencyExchangeData - ).toDouble(), - expenses = sum( - expenses(fpTransactions), - ::amountInCurrency, - baseCurrencyExchangeData - ).toDouble() - ), - ).plus(transactionsForDate) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/WalletLogic.kt b/app/src/main/java/com/ivy/wallet/domain/logic/WalletLogic.kt deleted file mode 100644 index c3570fd371..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/logic/WalletLogic.kt +++ /dev/null @@ -1,135 +0,0 @@ -package com.ivy.wallet.domain.logic - -import com.ivy.wallet.domain.data.TransactionHistoryDateDivider -import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.SettingsDao -import com.ivy.wallet.io.persistence.dao.TransactionDao -import com.ivy.wallet.ui.onboarding.model.FromToTimeRange -import com.ivy.wallet.ui.onboarding.model.filterOverdue -import com.ivy.wallet.ui.onboarding.model.filterUpcoming -import com.ivy.wallet.utils.beginningOfIvyTime -import com.ivy.wallet.utils.convertUTCtoLocal -import com.ivy.wallet.utils.toEpochSeconds -import java.time.LocalDate - -@Deprecated("Migrate to FP Style") -class WalletLogic( - private val accountDao: AccountDao, - private val transactionDao: TransactionDao, - private val settingsDao: SettingsDao, - private val exchangeRatesLogic: ExchangeRatesLogic, -) { - fun history(range: FromToTimeRange): List { - return transactionDao.findAllBetween( - startDate = range.from(), - endDate = range.to() - ).withDateDividers( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ) - } - - fun calculateUpcomingIncome(range: FromToTimeRange): Double { - return calculateIncome(upcomingTransactions(range)) - } - - fun calculateUpcomingExpenses(range: FromToTimeRange): Double { - return calculateExpenses(upcomingTransactions(range)) - } - - fun calculateOverdueIncome(range: FromToTimeRange): Double { - return calculateIncome(overdueTransactions(range)) - } - - fun calculateOverdueExpenses(range: FromToTimeRange): Double { - return calculateExpenses(overdueTransactions(range)) - } - - fun calculateIncome(transactions: List): Double { - return calculate(transactions, TransactionType.INCOME) - } - - fun calculateExpenses(transactions: List): Double { - return calculate(transactions, TransactionType.EXPENSE) - } - - private fun calculate(transactions: List, trnType: TransactionType): Double { - return transactions - .filter { it.type == trnType } - .sumInBaseCurrency( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ) - } - - fun upcomingTransactions(range: FromToTimeRange): List { - return transactionDao.findAllDueToBetween( - startDate = range.upcomingFrom(), - endDate = range.to() - ).filterUpcoming() - } - - fun overdueTransactions(range: FromToTimeRange): List { - return transactionDao.findAllDueToBetween( - startDate = beginningOfIvyTime(), - endDate = range.overdueTo() - ).filterOverdue() - } -} - -@Deprecated("Migrate to FP Style") -fun List.withDateDividers( - exchangeRatesLogic: ExchangeRatesLogic, - settingsDao: SettingsDao, - accountDao: AccountDao -): List { - val trns = this - if (trns.isEmpty()) return trns - - val historyWithDividers = mutableListOf() - - val dateTransactionsMap = mutableMapOf>() - for (transaction in trns) { - if (transaction.dateTime != null) { - val date = transaction.dateTime.convertUTCtoLocal().toLocalDate() - dateTransactionsMap[date]?.add(transaction) ?: run { - dateTransactionsMap[date] = mutableListOf(transaction) - } - } - } - - dateTransactionsMap.toSortedMap { date1, date2 -> - (date2.atStartOfDay().toEpochSeconds() - date1.atStartOfDay().toEpochSeconds()).toInt() - }.forEach { (date, trns) -> - historyWithDividers.add( - TransactionHistoryDateDivider( - date = date, - income = trns - .filter { it.type == TransactionType.INCOME } - .sumInBaseCurrency( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ), - expenses = trns - .filter { it.type == TransactionType.EXPENSE } - .sumInBaseCurrency( - exchangeRatesLogic = exchangeRatesLogic, - settingsDao = settingsDao, - accountDao = accountDao - ) - ) - ) - - historyWithDividers.addAll(trns) - } - - return historyWithDividers -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/BankIntegrationsLogic.kt b/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/BankIntegrationsLogic.kt deleted file mode 100644 index 97f5c4624b..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/BankIntegrationsLogic.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.ivy.wallet.domain.logic.bankintegrations - -import com.ivy.wallet.domain.data.bankintegrations.SEAccount -import com.ivy.wallet.domain.data.bankintegrations.SEConnection -import com.ivy.wallet.domain.data.bankintegrations.SETransaction -import com.ivy.wallet.io.network.IvySession -import com.ivy.wallet.io.network.RestClient -import com.ivy.wallet.io.persistence.SharedPrefs -import com.ivy.wallet.ui.RootActivity - -@Deprecated("Use FP style, look into `domain.fp` package") -class BankIntegrationsLogic( - restClient: RestClient, - private val seTransactionMapper: SaltEdgeTransactionMapper, - private val ivySession: IvySession, - private val sharedPrefs: SharedPrefs -) { - private val bankIntegrationsService = restClient.bankIntegrationsService - - suspend fun connect( - rootActivity: RootActivity - ) { - val response = bankIntegrationsService.connectSession() - rootActivity.openUrlInBrowser(response.connectUrl) - } - - suspend fun fetchConnections(): List { - if (!hasBankConnection()) return emptyList() //do nothing if the user isn't logged in - - return bankIntegrationsService.getConnections().connections - } - - suspend fun sync() { - if (!hasBankConnection()) return //do nothing if the user isn't logged in - - val seAccounts = fetchAccounts() - val seTransactions = fetchTransactions() - - seTransactionMapper.save( - seAccounts = seAccounts, - seTransactions = seTransactions - ) - } - - private suspend fun hasBankConnection(): Boolean { - //TODO: Check for SEConnections in table - return ivySession.isLoggedIn() && sharedPrefs.getBoolean( - SharedPrefs.ENABLE_BANK_SYNC, - false - ) - } - - private suspend fun fetchAccounts(): List { - return bankIntegrationsService.getAccounts().accounts - } - - private suspend fun fetchTransactions(): List { - return bankIntegrationsService.getTransactions().transactions - } - - suspend fun removeCustomer() { - bankIntegrationsService.removeCustomer() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeAccountMapper.kt b/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeAccountMapper.kt deleted file mode 100644 index 4dcc598632..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeAccountMapper.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.ivy.wallet.domain.logic.bankintegrations - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.bankintegrations.SEAccount -import com.ivy.wallet.domain.data.bankintegrations.SETransaction -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.ui.theme.components.IVY_COLOR_PICKER_COLORS_FREE -import com.ivy.wallet.utils.toLowerCaseLocal -import java.util.* - -@Deprecated("Use FP style, look into `domain.fp` package") -class SaltEdgeAccountMapper( - private val accountDao: AccountDao -) { - - fun mapAccount( - seAccounts: List, - seTransaction: SETransaction - ): UUID? { - val existingAccount = accountDao.findBySeAccountId( - seAccountId = seTransaction.account_id - ) - - val account = if (existingAccount == null) { - //create account - val seAccount = seAccounts.find { it.id == seTransaction.account_id } ?: return null - - val account = Account( - seAccountId = seAccount.id, - - name = seAccount.name, - color = mapColor(seAccount).toArgb(), - icon = mapIcon(seAccount), - - currency = IvyCurrency.fromCode(seAccount.currency_code)?.code, - orderNum = accountDao.findMaxOrderNum(), - - isSynced = false, - isDeleted = false - ) - - accountDao.save(account) - - account - } else existingAccount - - return account.id - } - - private fun mapColor(seAccount: SEAccount): Color { - //TODO: Create better mapping - return IVY_COLOR_PICKER_COLORS_FREE.shuffled().first() - } - - private fun mapIcon(seAccount: SEAccount): String? { - //TODO: Create better mapping - return when { - seAccount.name.toLowerCaseLocal().contains("revolut") -> { - "revolut" - } - else -> null - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeCategoryMapper.kt b/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeCategoryMapper.kt deleted file mode 100644 index e87ceecb43..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeCategoryMapper.kt +++ /dev/null @@ -1,371 +0,0 @@ -package com.ivy.wallet.domain.logic.bankintegrations - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.toArgb -import com.ivy.wallet.domain.data.bankintegrations.SETransaction -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.ui.theme.* -import com.ivy.wallet.ui.theme.components.IVY_COLOR_PICKER_COLORS_FREE -import com.ivy.wallet.utils.capitalizeLocal -import java.util.* - -/* -{ - "data": { - "business": { - "equipment_and_materials": [ - "electronics", - "software", - "supplies_and_furniture", - "raw_materials", - "consumer_goods" - ], - "financials": [ - "dividends", - "donations", - "interest", - "fees", - "fines", - "loans" - ], - "human_resources": [ - "wages", - "bonus", - "employee_benefits", - "education_and_trainings", - "staff_outsourcing", - "travel", - "entertainment", - "meals" - ], - "income": [ - "investments", - "sales", - "returns", - "prepayments" - ], - "insurance": [ - "business_insurance", - "liability_insurance", - "health_insurance", - "equipment_insurance", - "vehicle_insurance", - "professional_insurance" - ], - "real_estate": [ - "office_rent", - "mortgage", - "construction_and_repair" - ], - "services": [ - "contractors", - "accounting_and_auditing", - "legal", - "consulting", - "storage", - "marketing_and_media", - "online_subscriptions", - "it_services", - "cleaning" - ], - "taxes": [ - "vat", - "federal_taxes", - "property_taxes", - "income_taxes", - "duty_taxes", - "tax_return", - "payroll_taxes" - ], - "transport": [ - "shipping", - "leasing", - "gas_and_fuel", - "taxi", - "service_and_parts" - ], - "uncategorized": [], - "utilities": [ - "internet", - "phone", - "water", - "gas", - "electricity" - ] - }, - "personal": { - "auto_and_transport": [ - "car_rental", - "gas_and_fuel", - "parking", - "public_transportation", - "service_and_parts", - "taxi" - ], - "bills_and_utilities": [ - "internet", - "phone", - "television", - "utilities" - ], - "business_services": [ - "advertising", - "office_supplies", - "shipping" - ], - "education": [ - "books_and_supplies", - "student_loan", - "tuition" - ], - "entertainment": [ - "amusement", - "arts", - "games", - "movies_and_music", - "newspapers_and_magazines" - ], - "fees_and_charges": [ - "provider_fee", - "loans", - "service_fee", - "taxes" - ], - "food_and_dining": [ - "alcohol_and_bars", - "cafes_and_restaurants", - "groceries" - ], - "gifts_and_donations": [ - "charity", - "gifts" - ], - "health_and_fitness": [ - "doctor", - "personal_care", - "pharmacy", - "sports", - "wellness" - ], - "home": [ - "home_improvement", - "home_services", - "home_supplies", - "mortgage", - "rent" - ], - "income": [ - "bonus", - "investment_income", - "paycheck" - ], - "insurance": [ - "car_insurance", - "health_insurance", - "life_insurance", - "property_insurance" - ], - "kids": [ - "allowance", - "babysitter_and_daycare", - "baby_supplies", - "child_support", - "kids_activities", - "toys" - ], - "pets": [ - "pet_food_and_supplies", - "pet_grooming", - "veterinary" - ], - "shopping": [ - "clothing", - "electronics_and_software", - "sporting_goods" - ], - "transfer": [], - "travel": [ - "hotel", - "transportation", - "vacation" - ], - "uncategorized": [] - } - } -} - */ - -@Deprecated("Use FP style, look into `domain.fp` package") -class SaltEdgeCategoryMapper( - private val categoryDao: CategoryDao -) { - - fun mapSeAutoCategoryId( - seTransaction: SETransaction - ): UUID? { - val existingCategory = categoryDao.findBySeCategoryName( - seCategoryName = seTransaction.category - ) - - val seAutoCategory = if (existingCategory == null) { - //Try to map and create category - val seAutoCategory = mapSeCategoryName(seTransaction.category)?.copy( - orderNum = categoryDao.findMaxOrderNum(), - - isSynced = false, - isDeleted = false - ) - - if (seAutoCategory != null) { - categoryDao.save( - seAutoCategory - ) - } - - seAutoCategory - } else existingCategory - - return seAutoCategory?.id - } - - private fun mapSeCategoryName(seCategoryName: String): Category? { - if (seCategoryName == "uncategorized") return null - - val colorIcon = mapCategoryColorIcon(seCategoryName = seCategoryName) - - return Category( - name = seCategoryName - .replace("_", " ") - .capitalizeLocal(), - seCategoryName = seCategoryName, - color = (colorIcon?.first ?: IVY_COLOR_PICKER_COLORS_FREE.shuffled().first()).toArgb(), - icon = colorIcon?.second - ) - } - - private fun mapCategoryColorIcon(seCategoryName: String): Pair? { - return when (seCategoryName) { - "electronics" -> Pair(Blue, "atom") - "software" -> Pair(Blue3, "programming") - "supplies_and_furniture" -> Pair(Orange2Dark, "label") - "raw_materials" -> Pair(Green2Dark, "hike") - "consumer_goods" -> Pair(Blue3Light, "shopping") - "dividends" -> Pair(Orange3, "calculator") - "donations" -> Pair(Yellow, "relationship") - "interest" -> Pair(Purple1Light, "selfdevelopment") - "fees" -> Pair(Orange, "document") - "fines" -> Pair(Orange2Dark, "loan") - "loans" -> Pair(Blue2Dark, "loan") - "wages" -> Pair(IvyDark, "work") - "bonus" -> Pair(YellowLight, "diamond") - "employee_benefits" -> Pair(Blue2, "people") - "education_and_trainings" -> Pair(Blue, "education") - "staff_outsourcing" -> Pair(Green3, "people") - "travel" -> Pair(BlueLight, "travel") - "entertainment" -> Pair(Orange, "game") - "meals" -> Pair(Green2, "restaurant") - "investments" -> Pair(Green2Light, "document") - "sales" -> Pair(Yellow, "label") - "returns" -> Pair(OrangeLight, "category") - "prepayments" -> Pair(GreenLight, "bills") - "business_insurance" -> Pair(Blue2, "insurance") - "liability_insurance" -> Pair(Blue2, "insurance") - "health_insurance," -> Pair(Green2Light, "insurance") - "equipment_insurance" -> Pair(Blue2, "insurance") - "vehicle_insurance" -> Pair(Blue2, "insurance") - "professional_insurance" -> Pair(Blue2, "insurance") - "office_rent" -> Pair(BlueDark, "work") - "mortgage" -> Pair(Orange2Dark, "house") - "construction_and_repair" -> Pair(OrangeDark, "tools") - "contractors" -> Pair(Blue3Dark, "document") - "accounting_and_auditing" -> Pair(Blue3, "document") - "legal" -> Pair(Blue3Dark, "document") - "consulting" -> Pair(Blue2Light, "people") - "storage" -> Pair(Orange2Dark, "furniture") - "marketing_and_media" -> Pair(Orange, "rocket") - "online_subscriptions" -> Pair(Orange3, "connect") - "it_services" -> Pair(Blue, "programming") - "cleaning" -> Pair(Blue2Light, "house") - "vat" -> Pair(OrangeLight, "loan") - "federal_taxes" -> Pair(RedDark, "loan") - "property_taxes" -> Pair(RedDark, "loan") - "income_taxes" -> Pair(RedDark, "loan") - "duty_taxes" -> Pair(RedDark, "loan") - "tax_return" -> Pair(GreenDark, "loan") - "payroll_taxes" -> Pair(RedDark, "loan") - "shipping" -> Pair(Yellow, "shopping2") - "leasing" -> Pair(Green4, "house") - "gas_and_fuel" -> Pair(Green3Dark, "vehicle") - "taxi" -> Pair(YellowLight, "vehicle") - "service_and_parts" -> Pair(Green2, "tools") - "internet" -> Pair(BlueLight, "connect") - "phone" -> Pair(BlueLight, "bills") - "water" -> Pair(BlueLight, "bills") - "gas" -> Pair(Orange3Light, "bills") - "electricity" -> Pair(Blue2Light, "bills") - "car_rental" -> Pair(BlueDark, "vehicle") - "parking" -> Pair(GreenDark, "vehicle") - "public_transportation" -> Pair(Purple1, "transport") - "television" -> Pair(Green3Dark, "bills") - "utilities" -> Pair(Blue, "bills") - "advertising" -> Pair(Orange2, "rocket") - "office_supplies" -> Pair(BlueLight, "work") - "books_and_supplies" -> Pair(BlueLight, "document") - "student_loan" -> Pair(Blue2Dark, "loan") - "tuition" -> Pair(Blue2Dark, "education") - "education" -> Pair(Blue2Dark, "education") - "amusement" -> Pair(Orange, "rocket") - "arts" -> Pair(Red, "palette") - "games" -> Pair(Orange, "game") - "movies_and_music" -> Pair(Red, "music") - "newspapers_and_magazines" -> Pair(Orange, "document") - "provider_fee" -> Pair(RedLight, "loan") - "service_fee" -> Pair(RedDark, "loan") - "taxes" -> Pair(RedDark, "bills") - "alcohol_and_bars" -> Pair(Purple2Dark, "fooddrink") - "cafes_and_restaurants" -> Pair(Green, "coffee") - "groceries" -> Pair(Green4, "groceries") - "charity" -> Pair(GreenLight, "selfdevelopment") - "gifts" -> Pair(Red, "gift") - "doctor" -> Pair(Blue2Light, "health") - "personal_care" -> Pair(Blue2Light, "hairdresser") - "pharmacy" -> Pair(Blue2Light, "farmacy") - "sports" -> Pair(IvyLight, "sports") - "wellness" -> Pair(GreenLight, "fitness") - "home_improvement" -> Pair(Blue2Light, "house") - "home_services" -> Pair(Blue2Light, "house") - "home_supplies" -> Pair(Blue2Light, "house") - "rent" -> Pair(BlueDark, "house") - "investment_income" -> Pair(Green2Light, "leaf") - "paycheck" -> Pair(Green, "work") - "car_insurance" -> Pair(Blue2, "insurance") - "health_insurance" -> Pair(Blue2, "insurance") - "life_insurance" -> Pair(Green2Light, "insurance") - "property_insurance" -> Pair(Blue2, "insurance") - "allowance" -> Pair(GreenLight, "loan") - "babysitter_and_daycare" -> Pair(BlueLight, "family") - "baby_supplies" -> Pair(BlueLight, "shopping2") - "child_support" -> Pair(BlueLight, "family") - "kids_activities" -> Pair(Blue, "sports") - "toys" -> Pair(Yellow, "rocket") - "pet_food_and_supplies" -> Pair(Orange3Light, "pet") - "pet_grooming" -> Pair(Orange3Light, "pet") - "veterinary" -> Pair(Purple1, "pet") - "clothing" -> Pair(Red3, "clothes2") - "electronics_and_software" -> Pair(Blue, "atom") - "sporting_goods" -> Pair(Blue, "sports") - "hotel" -> Pair(Orange2Dark, "location") - "transportation" -> Pair(Yellow, "transport") - "vacation" -> Pair(Blue2Light, "travel") - - //Extra not documented categories - "bills_and_utilities" -> Pair(Red, "bills") - "business_services" -> Pair(BlueDark, "groceries") - "shopping" -> Pair(BlueLight, "shopping") - "income" -> Pair(Green, "work") - "transfer" -> Pair(Ivy, "bank") - else -> null - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeTransactionMapper.kt b/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeTransactionMapper.kt deleted file mode 100644 index 256829d9b3..0000000000 --- a/app/src/main/java/com/ivy/wallet/domain/logic/bankintegrations/SaltEdgeTransactionMapper.kt +++ /dev/null @@ -1,165 +0,0 @@ -package com.ivy.wallet.domain.logic.bankintegrations - -import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.bankintegrations.SEAccount -import com.ivy.wallet.domain.data.bankintegrations.SETransaction -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.WalletAccountLogic -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.TransactionDao -import com.ivy.wallet.utils.ioThread -import timber.log.Timber -import java.time.LocalDate -import java.time.LocalDateTime -import java.time.LocalTime -import java.time.format.DateTimeFormatter -import java.util.* -import kotlin.math.absoluteValue - -@Deprecated("Use FP style, look into `domain.fp` package") -class SaltEdgeTransactionMapper( - private val transactionDao: TransactionDao, - private val seAccountMapper: SaltEdgeAccountMapper, - private val seCategoryMapper: SaltEdgeCategoryMapper, - private val accountDao: AccountDao, - private val walletAccountLogic: WalletAccountLogic -) { - - suspend fun save(seAccounts: List, seTransactions: List) { - ioThread { - syncTransactions( - seTransactions = seTransactions, - seAccounts = seAccounts - ) - - syncBalances( - seAccounts = seAccounts - ) - } - } - - private fun syncTransactions( - seTransactions: List, - seAccounts: List - ) { - seTransactions.mapNotNull { - mapSeTransaction( - seAccounts = seAccounts, - seTransaction = it - ) - }.forEach { - transactionDao.save(it) - } - } - - private fun syncBalances( - seAccounts: List - ) { - val seAccountToAccount = seAccounts.map { seAccount -> - seAccount to accountDao.findBySeAccountId(seAccount.id) - }.toMap() - - seAccountToAccount.forEach { (seAccount, account) -> - if (account != null) { - walletAccountLogic.adjustBalance( - account = account, - newBalance = seAccount.balance, - adjustTransactionTitle = "Auto-adjust bank account balance", - isFiat = true, - trnIsSyncedFlag = false - ) - } - } - } - - private fun mapSeTransaction( - seAccounts: List, - seTransaction: SETransaction - ): Transaction? { - val existingIvyTransaction = transactionDao.findBySeTransactionId( - seTransactionId = seTransaction.id - ) - - //Persist ---------------------------------------------------------------------- - val ivyTrnId = existingIvyTransaction?.id ?: UUID.randomUUID() - val categoryId = existingIvyTransaction?.categoryId - val title = existingIvyTransaction?.title ?: seTransaction.description - val description = existingIvyTransaction?.description - //Persist ---------------------------------------------------------------------- - - //Map -------------------------------------------------------------------------- - val accountId = seAccountMapper.mapAccount( - seAccounts = seAccounts, - seTransaction = seTransaction - ) ?: return null - - val seAutoCategoryId = seCategoryMapper.mapSeAutoCategoryId( - seTransaction = seTransaction - ) - - val type = if (seTransaction.amount > 0) - TransactionType.INCOME else TransactionType.EXPENSE - val amount = seTransaction.amount.absoluteValue - - val dateTime = mapDateTime(seTransaction = seTransaction) - //Map -------------------------------------------------------------------------- - - val finalTransaction = Transaction( - id = ivyTrnId, - type = type, - amount = amount, - accountId = accountId, - dateTime = dateTime, - - categoryId = categoryId, - seTransactionId = seTransaction.id, - seAutoCategoryId = seAutoCategoryId, - description = description, - title = title, - ) - val shouldUploadToSerer = !finalTransaction.isIdenticalWith(existingIvyTransaction) || - existingIvyTransaction?.isSynced == false - Timber.i("Should upload to server: $shouldUploadToSerer") - - return finalTransaction.copy( - isSynced = !shouldUploadToSerer, - isDeleted = false - ) - } - - private fun mapDateTime(seTransaction: SETransaction): LocalDateTime? { - val time = (seTransaction.extra?.get("time") as? String?) - ?.parseSaltEdgeTime() ?: LocalTime.of(12, 0, 0) - - return seTransaction.made_on - .parseSaltEdgeDate() - ?.atTime(time) ?: return null - } - - private fun String.parseSaltEdgeTime(): LocalTime? { - return try { - LocalTime.parse(this) - } catch (e: Exception) { - e.printStackTrace() - null - } - } - - private fun String.parseSaltEdgeDate(): LocalDate? { - return try { - return LocalDate.parse(this, DateTimeFormatter.ofPattern("yyyy-MM-dd")) - } catch (e: Exception) { - e.printStackTrace() - null - } - } - - private fun String.parseSaltEdgeDateTime(): LocalDateTime? { - return try { - return LocalDateTime.parse(this, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssz")) - } catch (e: Exception) { - e.printStackTrace() - null - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt new file mode 100644 index 0000000000..8ce07dff3b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.kt @@ -0,0 +1,6 @@ +package com.ivy.wallet.domain.pure.account + +import com.ivy.wallet.domain.data.core.Account + +fun filterExcluded(accounts: List): List = + accounts.filter { it.includeInBalance } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartPeriod.kt b/app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartPeriod.kt similarity index 89% rename from app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartPeriod.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartPeriod.kt index 60019d8211..40c1ec1ea0 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartPeriod.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartPeriod.kt @@ -1,8 +1,6 @@ -package com.ivy.wallet.domain.fp.charts +package com.ivy.wallet.domain.pure.charts -import com.ivy.wallet.R -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.utils.dateNowUTC import com.ivy.wallet.utils.endOfDayNowUTC import com.ivy.wallet.utils.endOfMonth @@ -17,10 +15,10 @@ enum class ChartPeriod { fun display(): String { return when (this) { - LAST_12_MONTHS -> stringRes(R.string.last_12_months) - LAST_6_MONTHS -> stringRes(R.string.last_6_months) - LAST_4_WEEKS -> stringRes(R.string.last_4_weeks) - LAST_7_DAYS -> stringRes(R.string.last_7_days) + LAST_12_MONTHS -> "Last 12 months" + LAST_6_MONTHS -> "Last 6 months" + LAST_4_WEEKS -> "Last 4 weeks" + LAST_7_DAYS -> "Last 7 days" } } diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartsCore.kt b/app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartsCore.kt similarity index 65% rename from app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartsCore.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartsCore.kt index 32cd162b2b..a8baaaf298 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/charts/ChartsCore.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/charts/ChartsCore.kt @@ -1,7 +1,7 @@ -package com.ivy.wallet.domain.fp.charts +package com.ivy.wallet.domain.pure.charts -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair import java.math.BigDecimal data class ChartPoint( diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt b/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt similarity index 71% rename from app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt index 6411414586..633f0fdcc5 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/charts/WalletCharts.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/charts/WalletCharts.kt @@ -1,11 +1,10 @@ -package com.ivy.wallet.domain.fp.charts - -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.domain.fp.data.IncomeExpensePair -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletBalance -import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpense -import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpenseCount +package com.ivy.wallet.domain.pure.charts + +import com.ivy.fp.Pure +import com.ivy.fp.SideEffect +import com.ivy.wallet.domain.pure.data.ClosedTimeRange +import com.ivy.wallet.domain.pure.data.IncomeExpensePair +import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.utils.beginningOfIvyTime import com.ivy.wallet.utils.toEpochSeconds import java.math.BigDecimal @@ -15,10 +14,12 @@ data class ToRange( val to: LocalDateTime ) +@Pure suspend fun balanceChart( - walletDAOs: WalletDAOs, - baseCurrencyCode: String, - period: ChartPeriod + period: ChartPeriod, + + @SideEffect + calcWalletBalance: suspend (ClosedTimeRange) -> BigDecimal ): List { val orderedPeriod = period.toRangesList().sortedBy { it.to.toEpochSeconds() @@ -26,21 +27,17 @@ suspend fun balanceChart( return generateBalanceChart( orderedPeriod = orderedPeriod.map { ToRange(it.to) }, - calculateWalletBalance = { range -> - calculateWalletBalance( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = true, - range = range - ).value - } + calcWalletBalance = calcWalletBalance ) } +@Pure tailrec suspend fun generateBalanceChart( orderedPeriod: List, - calculateWalletBalance: suspend (range: ClosedTimeRange) -> BigDecimal, - accumulator: List = emptyList() + accumulator: List = emptyList(), + + @SideEffect + calcWalletBalance: suspend (ClosedTimeRange) -> BigDecimal ): List { return if (orderedPeriod.isEmpty()) accumulator else { //recurse @@ -49,7 +46,7 @@ tailrec suspend fun generateBalanceChart( val chartPoint = ChartPoint( range = ClosedTimeRange.to(to = toDateTime), - value = calculateWalletBalance( + value = calcWalletBalance( ClosedTimeRange( from = previousChartPoint?.range?.to?.plusSeconds(1) ?: beginningOfIvyTime(), to = toDateTime @@ -59,7 +56,7 @@ tailrec suspend fun generateBalanceChart( generateBalanceChart( orderedPeriod = orderedPeriod.drop(1), - calculateWalletBalance = calculateWalletBalance, + calcWalletBalance = calcWalletBalance, accumulator = accumulator.plus(chartPoint) ) } @@ -78,12 +75,13 @@ suspend fun incomeExpenseChart( return generateIncomeExpenseChart( orderedPeriod = orderedPeriod, calculateWalletIncomeExpense = { range -> - calculateWalletIncomeExpense( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - range = range, - filterExcluded = true - ).value + TODO() +// calculateWalletIncomeExpense( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode, +// range = range, +// filterExcluded = true +// ).value } ) } @@ -123,12 +121,13 @@ suspend fun incomeExpenseCountChart( return generateIncomeExpenseCountChart( orderedPeriod = orderedPeriod, calculateWalletIncomeExpenseCount = { range -> - calculateWalletIncomeExpenseCount( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - range = range, - filterExcluded = true - ).value + TODO() +// calculateWalletIncomeExpenseCount( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode, +// range = range, +// filterExcluded = true +// ).value } ) } diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/ClosedTimeRange.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/ClosedTimeRange.kt similarity index 94% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/ClosedTimeRange.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/ClosedTimeRange.kt index a89ce785d0..b9859b7340 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/ClosedTimeRange.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/ClosedTimeRange.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.utils.beginningOfIvyTime diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/IncomeExpensePair.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/IncomeExpensePair.kt similarity index 85% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/IncomeExpensePair.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/IncomeExpensePair.kt index acfa28deb6..e42f1bce9f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/IncomeExpensePair.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/IncomeExpensePair.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data import java.math.BigDecimal diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/data/WalletDAOs.kt b/app/src/main/java/com/ivy/wallet/domain/pure/data/WalletDAOs.kt similarity index 88% rename from app/src/main/java/com/ivy/wallet/domain/fp/data/WalletDAOs.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/data/WalletDAOs.kt index 69c8c44e3a..450ed0ea77 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/data/WalletDAOs.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/data/WalletDAOs.kt @@ -1,4 +1,4 @@ -package com.ivy.wallet.domain.fp.data +package com.ivy.wallet.domain.pure.data import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.ExchangeRateDao diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/ExchangeRates.kt b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/Exchange.kt similarity index 51% rename from app/src/main/java/com/ivy/wallet/domain/fp/ExchangeRates.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/exchange/Exchange.kt index 5899266a35..f2927168af 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/ExchangeRates.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/Exchange.kt @@ -1,96 +1,54 @@ -package com.ivy.wallet.domain.fp +package com.ivy.wallet.domain.pure.exchange import arrow.core.None import arrow.core.Option import arrow.core.Some import arrow.core.computations.option import arrow.core.toOption -import com.ivy.wallet.domain.data.entity.ExchangeRate -import com.ivy.wallet.domain.fp.core.Pure -import com.ivy.wallet.domain.fp.core.Total -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao +import com.ivy.fp.Pure +import com.ivy.fp.SideEffect +import com.ivy.wallet.domain.data.core.ExchangeRate import com.ivy.wallet.utils.isNotNullOrBlank import java.math.BigDecimal -@Total -suspend fun exchangeToBaseCurrency( - exchangeRateDao: ExchangeRateDao, - baseCurrencyCode: String, - fromCurrencyCode: String, - fromAmount: BigDecimal, -): Option { - return exchangeToBaseCurrency( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = fromCurrencyCode.toOption(), - fromAmount = fromAmount - ) -} +data class ExchangeData( + val baseCurrency: String, + val fromCurrency: Option, + val toCurrency: String = baseCurrency, +) -@Total -suspend fun exchangeToBaseCurrency( - exchangeRateDao: ExchangeRateDao, - baseCurrencyCode: String, - fromCurrencyCode: Option, - fromAmount: BigDecimal, -): Option { - return exchange( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = fromCurrencyCode, - fromAmount = fromAmount, - toCurrencyCode = baseCurrencyCode, - ) -} -@Total +@Pure suspend fun exchange( - exchangeRateDao: ExchangeRateDao, - baseCurrencyCode: String, - fromCurrencyCode: Option, - fromAmount: BigDecimal, - toCurrencyCode: String, -): Option { - return exchange( - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = fromCurrencyCode, - fromAmount = fromAmount, - toCurrencyCode = toCurrencyCode, - retrieveExchangeRate = exchangeRateDao::findByBaseCurrencyAndCurrency - ) -} + data: ExchangeData, + amount: BigDecimal, -@Total -suspend fun exchange( - baseCurrencyCode: String, - fromCurrencyCode: Option, - fromAmount: BigDecimal, - toCurrencyCode: String, - retrieveExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, + @SideEffect + getExchangeRate: suspend (baseCurrency: String, toCurrency: String) -> ExchangeRate?, ): Option = option { - if (fromAmount == BigDecimal.ZERO) { + if (amount == BigDecimal.ZERO) { return@option BigDecimal.ZERO } - val fromCurrency = fromCurrencyCode.bind().validateCurrency().bind() - val toCurrency = toCurrencyCode.validateCurrency().bind() + val fromCurrency = data.fromCurrency.bind().validateCurrency().bind() + val toCurrency = data.toCurrency.validateCurrency().bind() if (fromCurrency == toCurrency) { - return@option fromAmount + return@option amount } - when (val baseCurrency = baseCurrencyCode.validateCurrency().bind()) { + when (val baseCurrency = data.baseCurrency.validateCurrency().bind()) { fromCurrency -> { //exchange from base currency to other currency //we need the rate from baseCurrency to toCurrency val rateFromTo = validExchangeRate( baseCurrency = fromCurrency, //fromCurrency = baseCurrency toCurrency = toCurrency, - retrieveExchangeRate = retrieveExchangeRate + retrieveExchangeRate = getExchangeRate ).bind() //toAmount = fromAmount * rateFromTo - fromAmount * rateFromTo + amount * rateFromTo } toCurrency -> { //exchange from other currency to base currency @@ -99,7 +57,7 @@ suspend fun exchange( val rateToFrom = validExchangeRate( baseCurrency = toCurrency, //toCurrency = baseCurrency toCurrency = fromCurrency, - retrieveExchangeRate = retrieveExchangeRate + retrieveExchangeRate = getExchangeRate ).bind() /* @@ -111,7 +69,7 @@ suspend fun exchange( EXPECTED: 10 EUR ~= 19.67 BGN */ - fromAmount / rateToFrom + amount / rateToFrom } else -> { //exchange from other currency to other currency @@ -120,17 +78,17 @@ suspend fun exchange( val rateBaseFrom = validExchangeRate( baseCurrency = baseCurrency, toCurrency = fromCurrency, - retrieveExchangeRate = retrieveExchangeRate + retrieveExchangeRate = getExchangeRate ).bind() val rateBaseTo = validExchangeRate( baseCurrency = baseCurrency, toCurrency = toCurrency, - retrieveExchangeRate = retrieveExchangeRate + retrieveExchangeRate = getExchangeRate ).bind() //Convert: toBaseCurrency -> toToCurrency - val amountBaseCurrency = fromAmount / rateBaseFrom + val amountBaseCurrency = amount / rateBaseFrom amountBaseCurrency * rateBaseTo } } @@ -141,7 +99,7 @@ private fun String.validateCurrency(): Option { return if (this.isNotNullOrBlank()) return Some(this) else None } -@Total +@Pure suspend fun validExchangeRate( baseCurrency: String, toCurrency: String, diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt new file mode 100644 index 0000000000..1316924db7 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/exchange/ExchangeTrns.kt @@ -0,0 +1,92 @@ +package com.ivy.wallet.domain.pure.exchange + +import arrow.core.Option +import arrow.core.toOption +import com.ivy.fp.Pure +import com.ivy.fp.SideEffect +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.transaction.trnCurrency +import java.math.BigDecimal +import java.util.* + +typealias ExchangeEffect = suspend (ExchangeData, BigDecimal) -> Option + +data class ExchangeTrnArgument( + val baseCurrency: String, + @SideEffect + val getAccount: suspend (accountId: UUID) -> Account?, + @SideEffect + val exchange: ExchangeEffect +) + +@Pure +suspend fun exchangeInBaseCurrency( + transaction: Transaction, + arg: ExchangeTrnArgument +): BigDecimal { + val fromCurrency = arg.getAccount(transaction.accountId)?.currency.toOption() + + return exchangeInCurrency( + transaction = transaction, + baseCurrency = arg.baseCurrency, + trnCurrency = fromCurrency, + toCurrency = arg.baseCurrency, + exchange = arg.exchange + ) +} + +@Pure +suspend fun exchangeInBaseCurrency( + transaction: Transaction, + baseCurrency: String, + accounts: List, + + @SideEffect + exchange: ExchangeEffect +): BigDecimal = exchangeInCurrency( + transaction = transaction, + baseCurrency = baseCurrency, + accounts = accounts, + toCurrency = baseCurrency, + exchange = exchange +) + +@Pure +suspend fun exchangeInCurrency( + transaction: Transaction, + baseCurrency: String, + accounts: List, + toCurrency: String, + + @SideEffect + exchange: ExchangeEffect +): BigDecimal { + return exchange( + ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency(transaction, accounts), + toCurrency = toCurrency + ), + transaction.amount + ).orNull() ?: BigDecimal.ZERO +} + +suspend fun exchangeInCurrency( + transaction: Transaction, + baseCurrency: String, + trnCurrency: Option, + toCurrency: String, + + @SideEffect + exchange: ExchangeEffect +): BigDecimal { + return exchange( + ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency, + toCurrency = toCurrency + ), + transaction.amount + ).orNull() ?: BigDecimal.ZERO +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/AccValueFunctions.kt similarity index 68% rename from app/src/main/java/com/ivy/wallet/domain/fp/account/AccountValueFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/transaction/AccValueFunctions.kt index c804134621..0d1e4391be 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/account/AccountValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/AccValueFunctions.kt @@ -1,8 +1,7 @@ -package com.ivy.wallet.domain.fp.account +package com.ivy.wallet.domain.pure.transaction import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.fp.core.ValueFunction -import com.ivy.wallet.domain.fp.data.FPTransaction +import com.ivy.wallet.domain.data.core.Transaction import java.math.BigDecimal import java.util.* @@ -10,16 +9,16 @@ typealias AccountValueFunction = ValueFunction object AccountValueFunctions { fun balance( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId) { //Account's transactions when (type) { TransactionType.INCOME -> amount TransactionType.EXPENSE -> amount.negate() TransactionType.TRANSFER -> { - if (toAccountId.orNull() != accountId) { + if (toAccountId != accountId) { //transfer to another account amount.negate() } else { @@ -30,39 +29,39 @@ object AccountValueFunctions { } } else { //potential transfer to account? - toAccountId.orNull()?.takeIf { it == accountId } ?: return BigDecimal.ZERO + toAccountId?.takeIf { it == accountId } ?: return BigDecimal.ZERO toAmount } } fun income( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId && type == TransactionType.INCOME) amount else BigDecimal.ZERO } fun expense( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId && type == TransactionType.EXPENSE) amount else BigDecimal.ZERO } fun incomeCount( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId && type == TransactionType.INCOME) BigDecimal.ONE else BigDecimal.ZERO } fun expenseCount( - fpTransaction: FPTransaction, + transaction: Transaction, accountId: UUID - ): BigDecimal = with(fpTransaction) { + ): BigDecimal = with(transaction) { if (this.accountId == accountId && type == TransactionType.EXPENSE) BigDecimal.ONE else BigDecimal.ZERO } diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt similarity index 58% rename from app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryValueFunctions.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt index bce496e14f..217d4d2fd9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/category/CategoryValueFunctions.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/CatValueFunctions.kt @@ -1,13 +1,11 @@ -package com.ivy.wallet.domain.fp.category +package com.ivy.wallet.domain.pure.transaction import arrow.core.Option import arrow.core.toOption +import com.ivy.fp.SideEffect import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.fp.core.SuspendValueFunction -import com.ivy.wallet.domain.fp.data.FPTransaction -import com.ivy.wallet.domain.fp.exchangeToBaseCurrency -import com.ivy.wallet.io.persistence.dao.ExchangeRateDao +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction import java.math.BigDecimal import java.util.* @@ -16,17 +14,20 @@ typealias CategoryValueFunction = SuspendValueFunction, - val exchangeRateDao: ExchangeRateDao, - val baseCurrencyCode: String, + + @SideEffect + val exchangeToBaseCurrency: suspend ( + fromCurrency: Option, + amount: BigDecimal + ) -> Option ) suspend fun balance( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.INCOME -> amount.toBaseCurrencyOrZero(arg, accountId) TransactionType.EXPENSE -> amount.toBaseCurrencyOrZero(arg, accountId).negate() @@ -36,10 +37,10 @@ object CategoryValueFunctions { } suspend fun income( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.INCOME -> amount.toBaseCurrencyOrZero(arg, accountId) else -> BigDecimal.ZERO @@ -48,10 +49,10 @@ object CategoryValueFunctions { } suspend fun expense( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.EXPENSE -> amount.toBaseCurrencyOrZero(arg, accountId) else -> BigDecimal.ZERO @@ -60,10 +61,10 @@ object CategoryValueFunctions { } suspend fun incomeCount( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.INCOME -> BigDecimal.ONE else -> BigDecimal.ZERO @@ -72,10 +73,10 @@ object CategoryValueFunctions { } suspend fun expenseCount( - fpTransaction: FPTransaction, + transaction: Transaction, arg: Argument, - ): BigDecimal = with(fpTransaction) { - if (this.categoryId.orNull() == arg.categoryId) { + ): BigDecimal = with(transaction) { + if (this.categoryId == arg.categoryId) { when (type) { TransactionType.EXPENSE -> BigDecimal.ONE else -> BigDecimal.ZERO @@ -84,24 +85,20 @@ object CategoryValueFunctions { } private suspend fun BigDecimal.toBaseCurrencyOrZero( - argument: Argument, + arg: Argument, accountId: UUID ): BigDecimal { return this.convertToBaseCurrency( - argument = argument, + arg = arg, accountId = accountId ).orNull() ?: BigDecimal.ZERO } private suspend fun BigDecimal.convertToBaseCurrency( accountId: UUID, - argument: Argument + arg: Argument ): Option { - return exchangeToBaseCurrency( - exchangeRateDao = argument.exchangeRateDao, - baseCurrencyCode = argument.baseCurrencyCode, - fromAmount = this, - fromCurrencyCode = argument.accounts.find { it.id == accountId }?.currency.toOption() - ) + val trnCurrency = arg.accounts.find { it.id == accountId }?.currency.toOption() + return arg.exchangeToBaseCurrency(trnCurrency, this) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt new file mode 100644 index 0000000000..54dc741231 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/FoldTransactions.kt @@ -0,0 +1,89 @@ +package com.ivy.wallet.domain.pure.transaction + +import arrow.core.NonEmptyList +import arrow.core.nonEmptyListOf +import com.ivy.fp.Pure +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.util.mapIndexedNel +import com.ivy.wallet.domain.pure.util.mapIndexedNelSuspend +import com.ivy.wallet.domain.pure.util.nonEmptyListOfZeros +import java.math.BigDecimal + +typealias ValueFunction = (Transaction, A) -> BigDecimal +typealias SuspendValueFunction = suspend (Transaction, A) -> BigDecimal + +@Pure +fun foldTransactions( + transactions: List, + valueFunctions: NonEmptyList>, + arg: Arg +): NonEmptyList = sumTransactionsInternal( + valueFunctionArgument = arg, + transactions = transactions, + valueFunctions = valueFunctions +) + +@Pure +internal tailrec fun sumTransactionsInternal( + transactions: List, + valueFunctionArgument: A, + valueFunctions: NonEmptyList>, + sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) +): NonEmptyList { + return if (transactions.isEmpty()) + sum + else + sumTransactionsInternal( + valueFunctionArgument = valueFunctionArgument, + transactions = transactions.drop(1), + valueFunctions = valueFunctions, + sum = sum.mapIndexedNel { index, sumValue -> + val valueFunction = valueFunctions[index] + sumValue + valueFunction(transactions.first(), valueFunctionArgument) + } + ) +} + +@Pure +suspend fun foldTransactionsSuspend( + transactions: List, + valueFunctions: NonEmptyList>, + arg: Arg +): NonEmptyList = sumTransactionsSuspendInternal( + transactions = transactions, + valueFunctions = valueFunctions, + valueFunctionArgument = arg +) + +@Pure +internal tailrec suspend fun sumTransactionsSuspendInternal( + transactions: List, + valueFunctionArgument: A, + valueFunctions: NonEmptyList>, + sum: NonEmptyList = nonEmptyListOfZeros(n = valueFunctions.size) +): NonEmptyList { + return if (transactions.isEmpty()) + sum + else + sumTransactionsSuspendInternal( + valueFunctionArgument = valueFunctionArgument, + transactions = transactions.drop(1), + valueFunctions = valueFunctions, + sum = sum.mapIndexedNelSuspend { index, sumValue -> + val valueFunction = valueFunctions[index] + sumValue + valueFunction(transactions.first(), valueFunctionArgument) + } + ) +} + +suspend fun sumTrns( + transactions: List, + valueFunction: SuspendValueFunction, + argument: A +): BigDecimal { + return sumTransactionsSuspendInternal( + transactions = transactions, + valueFunctionArgument = argument, + valueFunctions = nonEmptyListOf(valueFunction) + ).head +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt new file mode 100644 index 0000000000..2d34d59d5a --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnDateDividers.kt @@ -0,0 +1,87 @@ +package com.ivy.wallet.domain.pure.transaction + +import arrow.core.Option +import arrow.core.toOption +import com.ivy.fp.Pure +import com.ivy.fp.SideEffect +import com.ivy.fp.then +import com.ivy.wallet.domain.data.TransactionHistoryDateDivider +import com.ivy.wallet.domain.data.TransactionHistoryItem +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.exchange.ExchangeTrnArgument +import com.ivy.wallet.domain.pure.exchange.exchangeInBaseCurrency +import com.ivy.wallet.io.persistence.dao.AccountDao +import com.ivy.wallet.io.persistence.dao.SettingsDao +import com.ivy.wallet.utils.convertUTCtoLocal +import com.ivy.wallet.utils.toEpochSeconds +import java.math.BigDecimal +import java.util.* + +@Deprecated("Migrate to actions") +suspend fun List.withDateDividers( + exchangeRatesLogic: ExchangeRatesLogic, + settingsDao: SettingsDao, + accountDao: AccountDao +): List { + return transactionsWithDateDividers( + transactions = this, + baseCurrencyCode = settingsDao.findFirst().currency, + getAccount = accountDao::findById then { it?.toDomain() }, + exchange = { data, amount -> + exchangeRatesLogic.convertAmount( + baseCurrency = data.baseCurrency, + fromCurrency = data.fromCurrency.orNull() ?: "", + toCurrency = data.toCurrency, + amount = amount.toDouble() + ).toBigDecimal().toOption() + } + ) +} + +@Pure +suspend fun transactionsWithDateDividers( + transactions: List, + baseCurrencyCode: String, + + @SideEffect + getAccount: suspend (accountId: UUID) -> Account?, + @SideEffect + exchange: suspend (ExchangeData, BigDecimal) -> Option +): List { + if (transactions.isEmpty()) return emptyList() + + return transactions + .groupBy { it.dateTime?.convertUTCtoLocal()?.toLocalDate() } + .filterKeys { it != null } + .toSortedMap { date1, date2 -> + if (date1 == null || date2 == null) return@toSortedMap 0 //this case shouldn't happen + (date2.atStartOfDay().toEpochSeconds() - date1.atStartOfDay().toEpochSeconds()).toInt() + } + .flatMap { (date, transactionsForDate) -> + val arg = ExchangeTrnArgument( + baseCurrency = baseCurrencyCode, + getAccount = getAccount, + exchange = exchange + ) + + + listOf( + TransactionHistoryDateDivider( + date = date!!, + income = sumTrns( + incomes(transactionsForDate), + ::exchangeInBaseCurrency, + arg + ).toDouble(), + expenses = sumTrns( + expenses(transactionsForDate), + ::exchangeInBaseCurrency, + arg + ).toDouble() + ), + ).plus(transactionsForDate) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt new file mode 100644 index 0000000000..331ac45bc0 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/TrnFunctions.kt @@ -0,0 +1,38 @@ +package com.ivy.wallet.domain.pure.transaction + +import arrow.core.Option +import arrow.core.toOption +import com.ivy.fp.Pure +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import java.time.LocalDateTime + +@Pure +fun expenses(transactions: List): List { + return transactions.filter { it.type == TransactionType.EXPENSE } +} + +@Pure +fun incomes(transactions: List): List { + return transactions.filter { it.type == TransactionType.INCOME } +} + +@Pure +fun transfers(transactions: List): List { + return transactions.filter { it.type == TransactionType.TRANSFER } +} + +@Pure +fun isUpcoming(transaction: Transaction, timeNowUTC: LocalDateTime): Boolean = + timeNowUTC.isBefore(transaction.dueDate) + +@Pure +fun isOverdue(transaction: Transaction, timeNowUTC: LocalDateTime): Boolean = + timeNowUTC.isAfter(transaction.dueDate) + +@Pure +fun trnCurrency( + transaction: Transaction, + accounts: List +): Option = accounts.find { it.id == transaction.accountId }?.currency.toOption() \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/pure/transaction/WalletValueFunctions.kt b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/WalletValueFunctions.kt new file mode 100644 index 0000000000..2af1d8b6e9 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/domain/pure/transaction/WalletValueFunctions.kt @@ -0,0 +1,49 @@ +package com.ivy.wallet.domain.pure.transaction + +import com.ivy.fp.SideEffect +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.exchange.ExchangeEffect +import com.ivy.wallet.domain.pure.exchange.exchangeInBaseCurrency +import java.math.BigDecimal + +object WalletValueFunctions { + data class Argument( + val accounts: List, + val baseCurrency: String, + + @SideEffect + val exchange: ExchangeEffect + ) + + suspend fun income( + transaction: Transaction, + arg: Argument + ): BigDecimal = with(transaction) { + when (type) { + TransactionType.INCOME -> exchangeInBaseCurrency( + transaction = this, + accounts = arg.accounts, + baseCurrency = arg.baseCurrency, + exchange = arg.exchange + ) + else -> BigDecimal.ZERO + } + } + + suspend fun expense( + transaction: Transaction, + arg: Argument + ): BigDecimal = with(transaction) { + when (type) { + TransactionType.EXPENSE -> exchangeInBaseCurrency( + transaction = this, + accounts = arg.accounts, + baseCurrency = arg.baseCurrency, + exchange = arg.exchange + ) + else -> BigDecimal.ZERO + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/fp/core/Utils.kt b/app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt similarity index 78% rename from app/src/main/java/com/ivy/wallet/domain/fp/core/Utils.kt rename to app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt index dc953e5044..71c53d3627 100644 --- a/app/src/main/java/com/ivy/wallet/domain/fp/core/Utils.kt +++ b/app/src/main/java/com/ivy/wallet/domain/pure/util/Utils.kt @@ -1,6 +1,7 @@ -package com.ivy.wallet.domain.fp.core +package com.ivy.wallet.domain.pure.util import arrow.core.NonEmptyList +import arrow.core.Option import java.math.BigDecimal fun NonEmptyList.mapIndexedNel( @@ -25,4 +26,8 @@ fun nonEmptyListOfZeros(n: Int): NonEmptyList { return NonEmptyList.fromListUnsafe( List(n) { BigDecimal.ZERO } ) +} + +fun Option.orZero(): BigDecimal { + return this.orNull() ?: BigDecimal.ZERO } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt b/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt index 5a4da91126..c34c322c24 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/IvySession.kt @@ -30,7 +30,7 @@ class IvySession( fun initiate(authResponse: AuthResponse) { val user = authResponse.user - userDao.save(user) + userDao.save(user.toEntity()) sharedPrefs.putString(SharedPrefs.SESSION_USER_ID, user.id.toString()) sharedPrefs.putString(SharedPrefs.SESSION_AUTH_TOKEN, authResponse.sessionToken) diff --git a/app/src/main/java/com/ivy/wallet/io/network/RestClient.kt b/app/src/main/java/com/ivy/wallet/io/network/RestClient.kt index 60dc6236f8..5bd80f9e06 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/RestClient.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/RestClient.kt @@ -205,9 +205,6 @@ class RestClient private constructor( } val analyticsService: AnalyticsService by lazy { retrofit.create(AnalyticsService::class.java) } val coinbaseService: CoinbaseService by lazy { retrofit.create(CoinbaseService::class.java) } - val bankIntegrationsService: BankIntegrationsService by lazy { - retrofit.create(BankIntegrationsService::class.java) - } val githubService: GithubService by lazy { retrofit.create(GithubService::class.java) } val nukeService: NukeService by lazy { retrofit.create(NukeService::class.java) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/AccountDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/AccountDTO.kt new file mode 100644 index 0000000000..37f758c248 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/AccountDTO.kt @@ -0,0 +1,30 @@ +package com.ivy.wallet.io.network.data + +import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.persistence.data.AccountEntity +import com.ivy.wallet.ui.theme.Green +import java.util.* + +data class AccountDTO( + val name: String, + val currency: String? = null, + val color: Int = Green.toArgb(), + val icon: String? = null, + val orderNum: Double = 0.0, + val includeInBalance: Boolean = true, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): AccountEntity = AccountEntity( + name = name, + currency = currency, + color = color, + icon = icon, + orderNum = orderNum, + includeInBalance = includeInBalance, + id = id, + isSynced = true, + isDeleted = false + ) +} + diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/BudgetDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/BudgetDTO.kt new file mode 100644 index 0000000000..c3e395afc8 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/BudgetDTO.kt @@ -0,0 +1,66 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.io.persistence.data.BudgetEntity +import java.util.* + +data class BudgetDTO( + val name: String, + val amount: Double, + + val categoryIdsSerialized: String?, + val accountIdsSerialized: String?, + + val orderId: Double, + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): BudgetEntity = BudgetEntity( + name = name, + amount = amount, + categoryIdsSerialized = categoryIdsSerialized, + accountIdsSerialized = accountIdsSerialized, + orderId = orderId, + id = id, + isSynced = true, + isDeleted = false + ) + + companion object { + fun serialize(ids: List): String { + return ids.joinToString(separator = ",") + } + + fun type(categoriesCount: Int): String { + return when (categoriesCount) { + 0 -> "Total Budget" + 1 -> "Category Budget" + else -> "Multi-Category ($categoriesCount) Budget" + } + } + } + + fun parseCategoryIds(): List { + return parseIdsString(categoryIdsSerialized) + } + + fun parseAccountIds(): List { + return parseIdsString(accountIdsSerialized) + } + + private fun parseIdsString(idsString: String?): List { + return try { + if (idsString == null) return emptyList() + + idsString + .split(",") + .map { UUID.fromString(it) } + } catch (e: Exception) { + e.printStackTrace() + emptyList() + } + } + + + fun validate(): Boolean { + return name.isNotEmpty() && amount > 0.0 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/CategoryDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/CategoryDTO.kt new file mode 100644 index 0000000000..a013b9de29 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/CategoryDTO.kt @@ -0,0 +1,24 @@ +package com.ivy.wallet.io.network.data + +import androidx.compose.ui.graphics.toArgb +import com.ivy.wallet.io.persistence.data.CategoryEntity +import com.ivy.wallet.ui.theme.Ivy +import java.util.* + +data class CategoryDTO( + val name: String, + val color: Int = Ivy.toArgb(), + val icon: String? = null, + val orderNum: Double = 0.0, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): CategoryEntity = CategoryEntity( + name = name, + color = color, + icon = icon, + orderNum = orderNum, + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/ExchangeRateDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/ExchangeRateDTO.kt new file mode 100644 index 0000000000..0dc2b63ee9 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/ExchangeRateDTO.kt @@ -0,0 +1,13 @@ +package com.ivy.wallet.io.network.data + +data class ExchangeRateDTO( + val baseCurrency: String, + val currency: String, + val rate: Double, +) { + fun toEntity(): ExchangeRateDTO = ExchangeRateDTO( + baseCurrency = baseCurrency, + currency = currency, + rate = rate + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/LoanDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/LoanDTO.kt new file mode 100644 index 0000000000..bccc945f43 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/LoanDTO.kt @@ -0,0 +1,35 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.domain.data.LoanType +import com.ivy.wallet.io.persistence.data.LoanEntity +import java.util.* + +data class LoanDTO( + val name: String, + val amount: Double, + val type: LoanType, + val color: Int = 0, + val icon: String? = null, + val orderNum: Double = 0.0, + val accountId: UUID? = null, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): LoanEntity = LoanEntity( + name = name, + amount = amount, + type = type, + color = color, + icon = icon, + orderNum = orderNum, + accountId = accountId, + id = id, + + isSynced = true, + isDeleted = false + ) + + fun humanReadableType(): String { + return if (type == LoanType.BORROW) "BORROWED" else "LENT" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/LoanRecordDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/LoanRecordDTO.kt new file mode 100644 index 0000000000..9062cec26f --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/LoanRecordDTO.kt @@ -0,0 +1,32 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.io.persistence.data.LoanRecordEntity +import java.time.LocalDateTime +import java.util.* + +data class LoanRecordDTO( + val loanId: UUID, + val amount: Double, + val note: String? = null, + val dateTime: LocalDateTime, + val interest: Boolean = false, + val accountId: UUID? = null, + //This is used store the converted amount for currencies which are different from the loan account currency + val convertedAmount: Double? = null, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): LoanRecordEntity = LoanRecordEntity( + loanId = loanId, + amount = amount, + note = note, + dateTime = dateTime, + interest = interest, + accountId = accountId, + convertedAmount = convertedAmount, + id = id, + + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/PlannedPaymentRuleDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/PlannedPaymentRuleDTO.kt new file mode 100644 index 0000000000..f9310370d3 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/PlannedPaymentRuleDTO.kt @@ -0,0 +1,39 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.domain.data.IntervalType +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.persistence.data.PlannedPaymentRuleEntity +import java.time.LocalDateTime +import java.util.* + +data class PlannedPaymentRuleDTO( + val startDate: LocalDateTime?, + val intervalN: Int?, + val intervalType: IntervalType?, + val oneTime: Boolean, + + val type: TransactionType, + val accountId: UUID, + val amount: Double = 0.0, + val categoryId: UUID? = null, + val title: String? = null, + val description: String? = null, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): PlannedPaymentRuleEntity = PlannedPaymentRuleEntity( + startDate = startDate, + intervalN = intervalN, + intervalType = intervalType, + oneTime = oneTime, + type = type, + accountId = accountId, + amount = amount, + categoryId = categoryId, + title = title, + id = id, + + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/SettingsDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/SettingsDTO.kt new file mode 100644 index 0000000000..49b0d54695 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/SettingsDTO.kt @@ -0,0 +1,25 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.design.l0_system.Theme +import com.ivy.wallet.io.persistence.data.SettingsEntity +import java.util.* + +data class SettingsDTO( + val theme: Theme, + val currency: String, + val bufferAmount: Double, + val name: String, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): SettingsEntity = SettingsEntity( + theme = theme, + currency = currency, + bufferAmount = bufferAmount, + name = name, + id = id, + + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/TransactionDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/TransactionDTO.kt new file mode 100644 index 0000000000..fa7c7f5f54 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/TransactionDTO.kt @@ -0,0 +1,52 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.io.persistence.data.TransactionEntity +import java.time.LocalDateTime +import java.util.* + +data class TransactionDTO( + val accountId: UUID, + val type: TransactionType, + val amount: Double, + val toAccountId: UUID? = null, + val toAmount: Double? = null, + val title: String? = null, + val description: String? = null, + val dateTime: LocalDateTime? = null, + val categoryId: UUID? = null, + val dueDate: LocalDateTime? = null, + + val recurringRuleId: UUID? = null, + + val attachmentUrl: String? = null, + + //This refers to the loan id that is linked with a transaction + val loanId: UUID? = null, + + //This refers to the loan record id that is linked with a transaction + val loanRecordId: UUID? = null, + + val id: UUID = UUID.randomUUID() +) { + fun toEntity(): TransactionEntity = TransactionEntity( + accountId = accountId, + type = type, + amount = amount, + toAccountId = toAccountId, + toAmount = toAmount, + title = title, + description = description, + dateTime = dateTime, + categoryId = categoryId, + dueDate = dueDate, + recurringRuleId = recurringRuleId, + attachmentUrl = attachmentUrl, + loanId = loanId, + loanRecordId = loanRecordId, + id = id, + + isSynced = true, + isDeleted = false + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/data/UserDTO.kt b/app/src/main/java/com/ivy/wallet/io/network/data/UserDTO.kt new file mode 100644 index 0000000000..fcb34ae15a --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/network/data/UserDTO.kt @@ -0,0 +1,30 @@ +package com.ivy.wallet.io.network.data + +import com.ivy.wallet.domain.data.AuthProviderType +import com.ivy.wallet.io.persistence.data.UserEntity +import java.util.* + +data class UserDTO( + val email: String, + val authProviderType: AuthProviderType, + var firstName: String, + val lastName: String?, + val profilePicture: String?, + val color: Int, + + val testUser: Boolean = false, + var id: UUID +) { + fun toEntity(): UserEntity = UserEntity( + email = email, + authProviderType = authProviderType, + firstName = firstName, + lastName = lastName, + profilePicture = profilePicture, + color = color, + testUser = testUser, + id = id, + ) + + fun names(): String = firstName + if (lastName != null) " $lastName" else "" +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/account/AccountsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/account/AccountsResponse.kt index 31ae7b1250..fd0d885d68 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/account/AccountsResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/account/AccountsResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.account -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.io.network.data.AccountDTO data class AccountsResponse( - val accounts: List + val accounts: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/account/UpdateAccountRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/account/UpdateAccountRequest.kt index 9e3bca215e..d2136e8a6d 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/account/UpdateAccountRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/account/UpdateAccountRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.account -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.io.network.data.AccountDTO data class UpdateAccountRequest( - val account: Account? = null + val account: AccountDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/auth/AuthResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/auth/AuthResponse.kt index 674a7cf43e..62eddc5051 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/auth/AuthResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/auth/AuthResponse.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.auth import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User data class AuthResponse( @SerializedName("user") diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/auth/UpdateUserInfoResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/auth/UpdateUserInfoResponse.kt index 6570cfbdd6..d37241f64f 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/auth/UpdateUserInfoResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/auth/UpdateUserInfoResponse.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.auth import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User data class UpdateUserInfoResponse( @SerializedName("user") diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankAccountsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankAccountsResponse.kt deleted file mode 100644 index efa3904b45..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankAccountsResponse.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ivy.wallet.io.network.request.bankintegrations - -import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.bankintegrations.SEAccount - -data class BankAccountsResponse( - @SerializedName("accounts") - val accounts: List -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionSessionResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionSessionResponse.kt deleted file mode 100644 index db67cf0dc5..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionSessionResponse.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.ivy.wallet.io.network.request.bankintegrations - -import com.google.gson.annotations.SerializedName - -data class BankConnectionSessionResponse( - @SerializedName("connectUrl") - val connectUrl: String -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionsResponse.kt deleted file mode 100644 index 1dae8bb2ca..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankConnectionsResponse.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ivy.wallet.io.network.request.bankintegrations - -import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.bankintegrations.SEConnection - -data class BankConnectionsResponse( - @SerializedName("connections") - val connections: List -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankTransactionsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankTransactionsResponse.kt deleted file mode 100644 index 2869ede286..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/request/bankintegrations/BankTransactionsResponse.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ivy.wallet.io.network.request.bankintegrations - -import com.google.gson.annotations.SerializedName -import com.ivy.wallet.domain.data.bankintegrations.SETransaction - -data class BankTransactionsResponse( - @SerializedName("transactions") - val transactions: List -) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/budget/BudgetsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/budget/BudgetsResponse.kt index 3f3eb0c2ef..0a390092f8 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/budget/BudgetsResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/budget/BudgetsResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.budget -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.io.network.data.BudgetDTO data class BudgetsResponse( - val budgets: List + val budgets: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/budget/CrupdateBudgetRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/budget/CrupdateBudgetRequest.kt index 78f90f8af5..4273e5efb4 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/budget/CrupdateBudgetRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/budget/CrupdateBudgetRequest.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.budget -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.io.network.data.BudgetDTO data class CrupdateBudgetRequest( - val budget: Budget? = null + val budget: BudgetDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/category/UpdateWalletCategoryRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/category/UpdateWalletCategoryRequest.kt index 3fd9b1e4e8..5642bce39d 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/category/UpdateWalletCategoryRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/category/UpdateWalletCategoryRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.category -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.io.network.data.CategoryDTO data class UpdateWalletCategoryRequest( - val category: Category? = null + val category: CategoryDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/category/WalletCategoriesResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/category/WalletCategoriesResponse.kt index 1dd6db5340..41ff386004 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/category/WalletCategoriesResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/category/WalletCategoriesResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.category -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.io.network.data.CategoryDTO data class WalletCategoriesResponse( - val categories: List + val categories: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoanRecordsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoanRecordsResponse.kt index 9ab03665de..be6a3e030a 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoanRecordsResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoanRecordsResponse.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.loan -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.io.network.data.LoanRecordDTO data class LoanRecordsResponse( - val loanRecords: List + val loanRecords: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoansResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoansResponse.kt index 8acae599be..6397632fa8 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoansResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/loan/LoansResponse.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.loan -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.io.network.data.LoanDTO data class LoansResponse( - val loans: List + val loans: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRecordRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRecordRequest.kt index 6b7f5bb300..b35a489089 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRecordRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRecordRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.loan -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.io.network.data.LoanRecordDTO data class UpdateLoanRecordRequest( - val loanRecord: LoanRecord? = null + val loanRecord: LoanRecordDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRequest.kt index 2a5eb75061..7b3f48408a 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/loan/UpdateLoanRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.loan -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.io.network.data.LoanDTO data class UpdateLoanRequest( - val loan: Loan? = null + val loan: LoanDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/planned/PlannedPaymentRulesResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/planned/PlannedPaymentRulesResponse.kt index 7beb4bd362..5009e0cbaa 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/planned/PlannedPaymentRulesResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/planned/PlannedPaymentRulesResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.planned -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.io.network.data.PlannedPaymentRuleDTO data class PlannedPaymentRulesResponse( - val rules: List + val rules: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/planned/UpdatePlannedPaymentRuleRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/planned/UpdatePlannedPaymentRuleRequest.kt index d0e22444d3..f0e53df538 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/planned/UpdatePlannedPaymentRuleRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/planned/UpdatePlannedPaymentRuleRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.planned -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.io.network.data.PlannedPaymentRuleDTO data class UpdatePlannedPaymentRuleRequest( - val rule: PlannedPaymentRule? = null + val rule: PlannedPaymentRuleDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/transaction/TransactionsResponse.kt b/app/src/main/java/com/ivy/wallet/io/network/request/transaction/TransactionsResponse.kt index 7abf78d9a5..e09e65b88f 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/transaction/TransactionsResponse.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/transaction/TransactionsResponse.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.io.network.request.transaction -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.io.network.data.TransactionDTO data class TransactionsResponse( - val transactions: List + val transactions: List ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/request/transaction/UpdateTransactionRequest.kt b/app/src/main/java/com/ivy/wallet/io/network/request/transaction/UpdateTransactionRequest.kt index 54a1258ac2..d0c26b57a0 100644 --- a/app/src/main/java/com/ivy/wallet/io/network/request/transaction/UpdateTransactionRequest.kt +++ b/app/src/main/java/com/ivy/wallet/io/network/request/transaction/UpdateTransactionRequest.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.io.network.request.transaction -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.io.network.data.TransactionDTO data class UpdateTransactionRequest( - val transaction: Transaction? = null + val transaction: TransactionDTO? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/network/service/BankIntegrationsService.kt b/app/src/main/java/com/ivy/wallet/io/network/service/BankIntegrationsService.kt deleted file mode 100644 index b2dbcdb296..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/network/service/BankIntegrationsService.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.ivy.wallet.io.network.service - -import com.ivy.wallet.io.network.request.bankintegrations.BankAccountsResponse -import com.ivy.wallet.io.network.request.bankintegrations.BankConnectionSessionResponse -import com.ivy.wallet.io.network.request.bankintegrations.BankConnectionsResponse -import com.ivy.wallet.io.network.request.bankintegrations.BankTransactionsResponse -import retrofit2.http.DELETE -import retrofit2.http.GET -import retrofit2.http.POST - -interface BankIntegrationsService { - @POST("wallet/bank-integrations/connect") - suspend fun connectSession(): BankConnectionSessionResponse - - @GET("wallet/bank-integrations/connections") - suspend fun getConnections(): BankConnectionsResponse - - @GET("wallet/bank-integrations/accounts") - suspend fun getAccounts(): BankAccountsResponse - - @GET("wallet/bank-integrations/transactions") - suspend fun getTransactions(): BankTransactionsResponse - - @DELETE("wallet/bank-integrations/remove-customer") - suspend fun removeCustomer() -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt index c103b00085..1a3c3c88b1 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/IvyRoomDatabase.kt @@ -1,23 +1,28 @@ package com.ivy.wallet.io.persistence import android.content.Context -import androidx.room.Database -import androidx.room.Room -import androidx.room.RoomDatabase -import androidx.room.TypeConverters -import com.ivy.wallet.domain.data.entity.* +import androidx.room.* +import androidx.room.migration.AutoMigrationSpec import com.ivy.wallet.io.persistence.dao.* +import com.ivy.wallet.io.persistence.data.* import com.ivy.wallet.io.persistence.migration.* @Database( entities = [ - Account::class, Transaction::class, Category::class, - WishlistItem::class, Settings::class, PlannedPaymentRule::class, - User::class, ExchangeRate::class, Budget::class, Loan::class, - LoanRecord::class + AccountEntity::class, TransactionEntity::class, CategoryEntity::class, + SettingsEntity::class, PlannedPaymentRuleEntity::class, + UserEntity::class, ExchangeRateEntity::class, BudgetEntity::class, + LoanEntity::class, LoanRecordEntity::class ], - version = 120, + autoMigrations = [ + AutoMigration( + from = 121, + to = 122, + spec = IvyRoomDatabase.DeleteSEMigration::class + ) + ], + version = 122, exportSchema = true ) @TypeConverters(RoomTypeConverters::class) @@ -30,8 +35,6 @@ abstract class IvyRoomDatabase : RoomDatabase() { abstract fun budgetDao(): BudgetDao - abstract fun wishlistItemDao(): WishlistItemDao - abstract fun plannedPaymentRuleDao(): PlannedPaymentRuleDao abstract fun settingsDao(): SettingsDao @@ -69,6 +72,7 @@ abstract class IvyRoomDatabase : RoomDatabase() { Migration117to118_Budgets(), Migration118to119_Loans(), Migration119to120_LoanTransactions(), + Migration120to121_DropWishlistItem() ) .build() } @@ -78,7 +82,6 @@ abstract class IvyRoomDatabase : RoomDatabase() { accountDao().deleteAll() transactionDao().deleteAll() categoryDao().deleteAll() - wishlistItemDao().deleteAll() settingsDao().deleteAll() plannedPaymentRuleDao().deleteAll() userDao().deleteAll() @@ -86,4 +89,10 @@ abstract class IvyRoomDatabase : RoomDatabase() { loanDao().deleteAll() loanRecordDao().deleteAll() } + + @DeleteColumn(tableName = "accounts", columnName = "seAccountId") + @DeleteColumn(tableName = "transactions", columnName = "seTransactionId") + @DeleteColumn(tableName = "transactions", columnName = "seAutoCategoryId") + @DeleteColumn(tableName = "categories", columnName = "seCategoryName") + class DeleteSEMigration : AutoMigrationSpec } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt index f3bb21fbce..c7b4a7248e 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/AccountDao.kt @@ -4,28 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.io.persistence.data.AccountEntity import java.util.* @Dao interface AccountDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Account) + fun save(value: AccountEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM accounts WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM accounts WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM accounts WHERE id = :id") - fun findById(id: UUID): Account? - - @Query("SELECT * FROM accounts WHERE seAccountId = :seAccountId") - fun findBySeAccountId(seAccountId: String): Account? + fun findById(id: UUID): AccountEntity? @Query("UPDATE accounts SET isDeleted = 1, isSynced = 0 WHERE id = :id") fun flagDeleted(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt index bfc0e5b6d6..5644bcc8db 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/BudgetDao.kt @@ -4,25 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.io.persistence.data.BudgetEntity import java.util.* @Dao interface BudgetDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Budget) + fun save(value: BudgetEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM budgets WHERE isDeleted = 0 ORDER BY orderId ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM budgets WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM budgets WHERE id = :id") - fun findById(id: UUID): Budget? + fun findById(id: UUID): BudgetEntity? @Query("DELETE FROM budgets WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt index 22f86856e4..609e7f3e5f 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/CategoryDao.kt @@ -4,28 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.io.persistence.data.CategoryEntity import java.util.* @Dao interface CategoryDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Category) + fun save(value: CategoryEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM categories WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM categories WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM categories WHERE id = :id") - fun findById(id: UUID): Category? - - @Query("SELECT * FROM categories WHERE seCategoryName = :seCategoryName") - fun findBySeCategoryName(seCategoryName: String): Category? + fun findById(id: UUID): CategoryEntity? @Query("DELETE FROM categories WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt index 3d3c921f11..a85007ee8a 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/ExchangeRateDao.kt @@ -4,20 +4,19 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.ExchangeRate +import com.ivy.wallet.io.persistence.data.ExchangeRateEntity @Dao interface ExchangeRateDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: ExchangeRate) + fun save(value: ExchangeRateEntity) @Query("SELECT * FROM exchange_rates WHERE baseCurrency = :baseCurrency AND currency = :currency") fun findByBaseCurrencyAndCurrency( baseCurrency: String, currency: String - ): ExchangeRate? + ): ExchangeRateEntity? @Query("DELETE FROM exchange_rates") - fun deleteALl() { - } + fun deleteALl() } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt index 83c12e6d8e..349a3d28dd 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanDao.kt @@ -4,25 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.io.persistence.data.LoanEntity import java.util.* @Dao interface LoanDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Loan) + fun save(value: LoanEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM loans WHERE isDeleted = 0 ORDER BY orderNum ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM loans WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List @Query("SELECT * FROM loans WHERE id = :id") - fun findById(id: UUID): Loan? + fun findById(id: UUID): LoanEntity? @Query("DELETE FROM loans WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt index 058ccfa0df..fedc62336b 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/LoanRecordDao.kt @@ -4,28 +4,31 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.io.persistence.data.LoanRecordEntity import java.util.* @Dao interface LoanRecordDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: LoanRecord) + fun save(value: LoanRecordEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM loan_records WHERE isDeleted = 0 ORDER BY dateTime DESC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM loan_records WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted( + synced: Boolean, + deleted: Boolean = false + ): List @Query("SELECT * FROM loan_records WHERE id = :id") - fun findById(id: UUID): LoanRecord? + fun findById(id: UUID): LoanRecordEntity? @Query("SELECT * FROM loan_records WHERE loanId = :loanId AND isDeleted = 0 ORDER BY dateTime DESC") - fun findAllByLoanId(loanId: UUID): List + fun findAllByLoanId(loanId: UUID): List @Query("DELETE FROM loan_records WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt index 458c4cd3fe..9986b3c2d6 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/PlannedPaymentRuleDao.kt @@ -4,31 +4,31 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.io.persistence.data.PlannedPaymentRuleEntity import java.util.* @Dao interface PlannedPaymentRuleDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: PlannedPaymentRule) + fun save(value: PlannedPaymentRuleEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM planned_payment_rules WHERE isDeleted = 0 ORDER BY amount DESC, startDate ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM planned_payment_rules WHERE isSynced = :synced AND isDeleted = :deleted") fun findByIsSyncedAndIsDeleted( synced: Boolean, deleted: Boolean = false - ): List + ): List @Query("SELECT * FROM planned_payment_rules WHERE isDeleted = 0 AND oneTime = :oneTime ORDER BY amount DESC, startDate ASC") - fun findAllByOneTime(oneTime: Boolean): List + fun findAllByOneTime(oneTime: Boolean): List @Query("SELECT * FROM planned_payment_rules WHERE id = :id AND isDeleted = 0") - fun findById(id: UUID): PlannedPaymentRule? + fun findById(id: UUID): PlannedPaymentRuleEntity? @Query("UPDATE planned_payment_rules SET isDeleted = 1, isSynced = 0 WHERE id = :id") fun flagDeleted(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt index b921cc578d..a77a89f405 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/SettingsDao.kt @@ -4,25 +4,25 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.Settings +import com.ivy.wallet.io.persistence.data.SettingsEntity import java.util.* @Dao interface SettingsDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Settings) + fun save(value: SettingsEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM settings LIMIT 1") - fun findFirst(): Settings + fun findFirst(): SettingsEntity @Query("SELECT * FROM settings") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM settings WHERE id = :id") - fun findById(id: UUID): Settings? + fun findById(id: UUID): SettingsEntity? @Query("DELETE FROM settings WHERE id = :id") fun deleteById(id: UUID) diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt index 92cbc96bc4..b89d721f8a 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/TransactionDao.kt @@ -5,30 +5,30 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.io.persistence.data.TransactionEntity import java.time.LocalDateTime import java.util.* @Dao interface TransactionDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: Transaction) + fun save(value: TransactionEntity) @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: List) + fun save(value: List) @Query("SELECT * FROM transactions WHERE isDeleted = 0 ORDER BY dateTime DESC, dueDate ASC") - fun findAll(): List + fun findAll(): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 LIMIT 1") - fun findAll_LIMIT_1(): List + fun findAll_LIMIT_1(): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type ORDER BY dateTime DESC") - fun findAllByType(type: TransactionType): List + fun findAllByType(type: TransactionType): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and accountId = :accountId ORDER BY dateTime DESC") - fun findAllByTypeAndAccount(type: TransactionType, accountId: UUID): List + fun findAllByTypeAndAccount(type: TransactionType, accountId: UUID): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and accountId = :accountId and dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByTypeAndAccountBetween( @@ -36,13 +36,13 @@ interface TransactionDao { accountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and toAccountId = :toAccountId ORDER BY dateTime DESC") fun findAllTransfersToAccount( toAccountId: UUID, type: TransactionType = TransactionType.TRANSFER - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND type = :type and toAccountId = :toAccountId and dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllTransfersToAccountBetween( @@ -50,101 +50,104 @@ interface TransactionDao { startDate: LocalDateTime, endDate: LocalDateTime, type: TransactionType = TransactionType.TRANSFER - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") - fun findAllBetween(startDate: LocalDateTime, endDate: LocalDateTime): List + fun findAllBetween(startDate: LocalDateTime, endDate: LocalDateTime): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND accountId = :accountId AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByAccountAndBetween( accountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByCategoryAndBetween( categoryId: UUID, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL AND seAutoCategoryId IS NULL) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL) AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllUnspecifiedAndBetween( startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllByCategoryAndTypeAndBetween( categoryId: UUID, type: TransactionType, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL AND seAutoCategoryId IS NULL) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId IS NULL) AND type = :type AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllUnspecifiedAndTypeAndBetween( type: TransactionType, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND toAccountId = :toAccountId AND dateTime >= :startDate AND dateTime <= :endDate ORDER BY dateTime DESC") fun findAllToAccountAndBetween( toAccountId: UUID, startDate: LocalDateTime, endDate: LocalDateTime - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate ORDER BY dueDate ASC") - fun findAllDueToBetween(startDate: LocalDateTime, endDate: LocalDateTime): List + fun findAllDueToBetween( + startDate: LocalDateTime, + endDate: LocalDateTime + ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) ORDER BY dateTime DESC, dueDate ASC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId = :categoryId) ORDER BY dateTime DESC, dueDate ASC") fun findAllDueToBetweenByCategory( startDate: LocalDateTime, endDate: LocalDateTime, categoryId: UUID - ): List + ): List - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId IS NULL AND seAutoCategoryId IS NULL) ORDER BY dateTime DESC, dueDate ASC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND (categoryId IS NULL) ORDER BY dateTime DESC, dueDate ASC") fun findAllDueToBetweenByCategoryUnspecified( startDate: LocalDateTime, endDate: LocalDateTime, - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dueDate >= :startDate AND dueDate <= :endDate AND accountId = :accountId ORDER BY dateTime DESC, dueDate ASC") fun findAllDueToBetweenByAccount( startDate: LocalDateTime, endDate: LocalDateTime, accountId: UUID - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND recurringRuleId = :recurringRuleId ORDER BY dateTime DESC") - fun findAllByRecurringRuleId(recurringRuleId: UUID): List + fun findAllByRecurringRuleId(recurringRuleId: UUID): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate AND type = :type ORDER BY dateTime DESC") fun findAllBetweenAndType( startDate: LocalDateTime, endDate: LocalDateTime, type: TransactionType - ): List + ): List @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND dateTime >= :startDate AND dateTime <= :endDate AND recurringRuleId = :recurringRuleId ORDER BY dateTime DESC") fun findAllBetweenAndRecurringRuleId( startDate: LocalDateTime, endDate: LocalDateTime, recurringRuleId: UUID - ): List + ): List @Query("SELECT * FROM transactions WHERE id = :id") - fun findById(id: UUID): Transaction? - - @Query("SELECT * FROM transactions WHERE seTransactionId = :seTransactionId") - fun findBySeTransactionId(seTransactionId: String): Transaction? + fun findById(id: UUID): TransactionEntity? @Query("SELECT * FROM transactions WHERE isSynced = :synced AND isDeleted = :deleted") - fun findByIsSyncedAndIsDeleted(synced: Boolean, deleted: Boolean = false): List + fun findByIsSyncedAndIsDeleted( + synced: Boolean, + deleted: Boolean = false + ): List @Query("UPDATE transactions SET isDeleted = 1, isSynced = 0 WHERE id = :id") fun flagDeleted(id: UUID) @@ -169,17 +172,17 @@ interface TransactionDao { //Smart Title Suggestions @Query("SELECT * FROM transactions WHERE title LIKE :pattern AND isDeleted = 0") - fun findAllByTitleMatchingPattern(pattern: String): List + fun findAllByTitleMatchingPattern(pattern: String): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND isDeleted = 0") fun countByTitleMatchingPattern( pattern: String, ): Long - @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId OR seAutoCategoryId = :categoryId) ORDER BY dateTime DESC") + @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND (categoryId = :categoryId) ORDER BY dateTime DESC") fun findAllByCategory( categoryId: UUID, - ): List + ): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND categoryId = :categoryId AND isDeleted = 0") fun countByTitleMatchingPatternAndCategoryId( @@ -190,7 +193,7 @@ interface TransactionDao { @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND accountId = :accountId ORDER BY dateTime DESC") fun findAllByAccount( accountId: UUID - ): List + ): List @Query("SELECT COUNT(*) FROM transactions WHERE title LIKE :pattern AND accountId = :accountId AND isDeleted = 0") fun countByTitleMatchingPatternAndAccountId( @@ -201,15 +204,15 @@ interface TransactionDao { @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanId = :loanId AND loanRecordId IS NULL") fun findLoanTransaction( loanId: UUID - ): Transaction? + ): TransactionEntity? @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanRecordId = :loanRecordId") fun findLoanRecordTransaction( loanRecordId: UUID - ): Transaction? + ): TransactionEntity? @Query("SELECT * FROM transactions WHERE isDeleted = 0 AND loanId = :loanId") fun findAllByLoanId( loanId: UUID - ): List + ): List } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt index 74e1cf61af..d76364d46f 100644 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/dao/UserDao.kt @@ -4,16 +4,16 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.io.persistence.data.UserEntity import java.util.* @Dao interface UserDao { @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(user: User) + fun save(user: UserEntity) @Query("SELECT * FROM users WHERE id = :userId") - fun findById(userId: UUID): User? + fun findById(userId: UUID): UserEntity? @Query("DELETE FROM users") fun deleteAll() diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/dao/WishlistItemDao.kt b/app/src/main/java/com/ivy/wallet/io/persistence/dao/WishlistItemDao.kt deleted file mode 100644 index 714375ddd2..0000000000 --- a/app/src/main/java/com/ivy/wallet/io/persistence/dao/WishlistItemDao.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.ivy.wallet.io.persistence.dao - -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy -import androidx.room.Query -import com.ivy.wallet.domain.data.entity.WishlistItem -import java.util.* - -@Dao -interface WishlistItemDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - fun save(value: WishlistItem) - - @Query("SELECT * FROM wishlist_items ORDER BY orderNum ASC") - fun findAll(): List - - @Query("SELECT * FROM wishlist_items WHERE id = :id") - fun findById(id: UUID): WishlistItem? - - @Query("DELETE FROM wishlist_items WHERE id = :id") - fun deleteById(id: UUID) - - @Query("DELETE FROM wishlist_items") - fun deleteAll() -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Account.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/AccountEntity.kt similarity index 55% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Account.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/AccountEntity.kt index 12abeb68c1..e4d4d8faf7 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Account.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/AccountEntity.kt @@ -1,13 +1,14 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.compose.ui.graphics.toArgb import androidx.room.Entity import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.ui.theme.Green import java.util.* @Entity(tableName = "accounts") -data class Account( +data class AccountEntity( val name: String, val currency: String? = null, val color: Int = Green.toArgb(), @@ -15,13 +16,21 @@ data class Account( val orderNum: Double = 0.0, val includeInBalance: Boolean = true, - //SaltEdge integration ------- - val seAccountId: String? = null, - //SaltEdge integration ------- - val isSynced: Boolean = false, val isDeleted: Boolean = false, @PrimaryKey val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toDomain(): Account = Account( + name = name, + currency = currency, + color = color, + icon = icon, + orderNum = orderNum, + includeInBalance = includeInBalance, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/BudgetEntity.kt similarity index 69% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/BudgetEntity.kt index 48969cebd7..7446b1ea6f 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Budget.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/BudgetEntity.kt @@ -1,13 +1,12 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.room.Entity import androidx.room.PrimaryKey -import com.ivy.wallet.R -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Budget import java.util.* @Entity(tableName = "budgets") -data class Budget( +data class BudgetEntity( val name: String, val amount: Double, @@ -21,6 +20,17 @@ data class Budget( @PrimaryKey val id: UUID = UUID.randomUUID() ) { + fun toDomain(): Budget = Budget( + name = name, + amount = amount, + categoryIdsSerialized = categoryIdsSerialized, + accountIdsSerialized = accountIdsSerialized, + isSynced = isSynced, + isDeleted = isDeleted, + orderId = orderId, + id = id + ) + companion object { fun serialize(ids: List): String { return ids.joinToString(separator = ",") @@ -28,9 +38,9 @@ data class Budget( fun type(categoriesCount: Int): String { return when (categoriesCount) { - 0 -> stringRes(R.string.total_budget) - 1 -> stringRes(R.string.category_budget) - else -> stringRes(R.string.multi_category_budget, categoriesCount.toString()) + 0 -> "Total Budget" + 1 -> "Category Budget" + else -> "Multi-Category ($categoriesCount) Budget" } } } diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Category.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/CategoryEntity.kt similarity index 56% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Category.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/CategoryEntity.kt index 231722b953..b6ebf86c68 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Category.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/CategoryEntity.kt @@ -1,25 +1,32 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.compose.ui.graphics.toArgb import androidx.room.Entity import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.theme.Ivy import java.util.* @Entity(tableName = "categories") -data class Category( +data class CategoryEntity( val name: String, val color: Int = Ivy.toArgb(), val icon: String? = null, val orderNum: Double = 0.0, - //SaltEdge integration ------- - val seCategoryName: String? = null, - //SaltEdge integration ------- - val isSynced: Boolean = false, val isDeleted: Boolean = false, @PrimaryKey val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toDomain(): Category = Category( + name = name, + color = color, + icon = icon, + orderNum = orderNum, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/ExchangeRateEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/ExchangeRateEntity.kt new file mode 100644 index 0000000000..873dc767bf --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/ExchangeRateEntity.kt @@ -0,0 +1,17 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.room.Entity +import com.ivy.wallet.domain.data.core.ExchangeRate + +@Entity(tableName = "exchange_rates", primaryKeys = ["baseCurrency", "currency"]) +data class ExchangeRateEntity( + val baseCurrency: String, + val currency: String, + val rate: Double, +) { + fun toDomain(): ExchangeRate = ExchangeRate( + baseCurrency = baseCurrency, + currency = currency, + rate = rate + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanEntity.kt similarity index 52% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/LoanEntity.kt index 9acd2d6c84..fe5a447cfe 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Loan.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanEntity.kt @@ -1,14 +1,13 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.room.Entity import androidx.room.PrimaryKey -import com.ivy.wallet.R import com.ivy.wallet.domain.data.LoanType -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Loan import java.util.* @Entity(tableName = "loans") -data class Loan( +data class LoanEntity( val name: String, val amount: Double, val type: LoanType, @@ -23,8 +22,20 @@ data class Loan( @PrimaryKey val id: UUID = UUID.randomUUID() ) { + fun toDomain(): Loan = Loan( + name = name, + amount = amount, + type = type, + color = color, + icon = icon, + orderNum = orderNum, + accountId = accountId, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) + fun humanReadableType(): String { - return if (type == LoanType.BORROW) stringRes(R.string.borrowed_uppercase) else stringRes( - R.string.lent_uppercase) + return if (type == LoanType.BORROW) "BORROWED" else "LENT" } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanRecordEntity.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanRecordEntity.kt new file mode 100644 index 0000000000..af6487f78b --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/LoanRecordEntity.kt @@ -0,0 +1,38 @@ +package com.ivy.wallet.io.persistence.data + +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.ivy.wallet.domain.data.core.LoanRecord +import java.time.LocalDateTime +import java.util.* + +@Entity(tableName = "loan_records") +data class LoanRecordEntity( + val loanId: UUID, + val amount: Double, + val note: String? = null, + val dateTime: LocalDateTime, + val interest: Boolean = false, + val accountId: UUID? = null, + //This is used store the converted amount for currencies which are different from the loan account currency + val convertedAmount: Double? = null, + + val isSynced: Boolean = false, + val isDeleted: Boolean = false, + + @PrimaryKey + val id: UUID = UUID.randomUUID() +) { + fun toDomain(): LoanRecord = LoanRecord( + loanId = loanId, + amount = amount, + note = note, + dateTime = dateTime, + interest = interest, + accountId = accountId, + convertedAmount = convertedAmount, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/PlannedPaymentRule.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/PlannedPaymentRuleEntity.kt similarity index 54% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/PlannedPaymentRule.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/PlannedPaymentRuleEntity.kt index bdac3aa3aa..e38fa3c151 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/PlannedPaymentRule.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/PlannedPaymentRuleEntity.kt @@ -1,14 +1,15 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.room.Entity import androidx.room.PrimaryKey import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import java.time.LocalDateTime import java.util.* @Entity(tableName = "planned_payment_rules") -data class PlannedPaymentRule( +data class PlannedPaymentRuleEntity( val startDate: LocalDateTime?, val intervalN: Int?, val intervalType: IntervalType?, @@ -26,4 +27,20 @@ data class PlannedPaymentRule( @PrimaryKey val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toDomain(): PlannedPaymentRule = PlannedPaymentRule( + startDate = startDate, + intervalN = intervalN, + intervalType = intervalType, + oneTime = oneTime, + type = type, + accountId = accountId, + amount = amount, + categoryId = categoryId, + title = title, + description = description, + isSynced = isSynced, + isDeleted = isDeleted, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Settings.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt similarity index 54% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Settings.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt index f352a3ee5f..f153edabde 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Settings.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/SettingsEntity.kt @@ -1,12 +1,13 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.room.Entity import androidx.room.PrimaryKey import com.ivy.design.l0_system.Theme +import com.ivy.wallet.domain.data.core.Settings import java.util.* @Entity(tableName = "settings") -data class Settings( +data class SettingsEntity( val theme: Theme, val currency: String, val bufferAmount: Double, @@ -17,4 +18,12 @@ data class Settings( @PrimaryKey val id: UUID = UUID.randomUUID() -) \ No newline at end of file +) { + fun toDomain(): Settings = Settings( + theme = theme, + baseCurrency = currency, + bufferAmount = bufferAmount.toBigDecimal(), + name = name, + id = id + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/Transaction.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt similarity index 61% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/Transaction.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt index 8d4107ffa4..749a803622 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/Transaction.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/TransactionEntity.kt @@ -1,14 +1,14 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.room.Entity import androidx.room.PrimaryKey -import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType +import com.ivy.wallet.domain.data.core.Transaction import java.time.LocalDateTime import java.util.* @Entity(tableName = "transactions") -data class Transaction( +data class TransactionEntity( val accountId: UUID, val type: TransactionType, val amount: Double, @@ -28,25 +28,33 @@ data class Transaction( val loanId: UUID? = null, //This refers to the loan record id that is linked with a transaction - val loanRecordId:UUID? = null, - - //SaltEdge integration ------- - val seTransactionId: String? = null, - val seAutoCategoryId: UUID? = null, - //SaltEdge integration ------- + val loanRecordId: UUID? = null, val isSynced: Boolean = false, val isDeleted: Boolean = false, @PrimaryKey val id: UUID = UUID.randomUUID() -) : TransactionHistoryItem { - - fun smartCategoryId(): UUID? { - return categoryId ?: seAutoCategoryId - } +) { + fun toDomain(): Transaction = Transaction( + accountId = accountId, + type = type, + amount = amount.toBigDecimal(), + toAccountId = toAccountId, + toAmount = toAmount?.toBigDecimal() ?: amount.toBigDecimal(), + title = title, + description = description, + dateTime = dateTime, + categoryId = categoryId, + dueDate = dueDate, + recurringRuleId = recurringRuleId, + attachmentUrl = attachmentUrl, + loanId = loanId, + loanRecordId = loanRecordId, + id = id + ) - fun isIdenticalWith(transaction: Transaction?): Boolean { + fun isIdenticalWith(transaction: TransactionEntity?): Boolean { if (transaction == null) return false //Set isSynced && isDeleted to false so they aren't accounted in the equals check diff --git a/app/src/main/java/com/ivy/wallet/domain/data/entity/User.kt b/app/src/main/java/com/ivy/wallet/io/persistence/data/UserEntity.kt similarity index 63% rename from app/src/main/java/com/ivy/wallet/domain/data/entity/User.kt rename to app/src/main/java/com/ivy/wallet/io/persistence/data/UserEntity.kt index e6712cf52a..55f48c6ab9 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/entity/User.kt +++ b/app/src/main/java/com/ivy/wallet/io/persistence/data/UserEntity.kt @@ -1,39 +1,43 @@ -package com.ivy.wallet.domain.data.entity +package com.ivy.wallet.io.persistence.data import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey -import com.google.gson.annotations.SerializedName import com.ivy.wallet.domain.data.AuthProviderType +import com.ivy.wallet.domain.data.core.User import java.util.* @Entity(tableName = "users") -data class User( - @SerializedName("email") +data class UserEntity( @ColumnInfo(name = "email") val email: String, - @SerializedName("authProviderType") + @ColumnInfo(name = "authProviderType") val authProviderType: AuthProviderType, - @SerializedName("firstName") @ColumnInfo(name = "firstName") var firstName: String, - @SerializedName("lastName") @ColumnInfo(name = "lastName") val lastName: String?, - @SerializedName("profilePictureUrl") @ColumnInfo(name = "profilePicture") val profilePicture: String?, - @SerializedName("color") @ColumnInfo(name = "color") val color: Int, - @SerializedName("testUser") @ColumnInfo(name = "testUser") val testUser: Boolean = false, - @SerializedName("id") @PrimaryKey @ColumnInfo(name = "id") var id: UUID ) { + fun toDomain(): User = User( + email = email, + authProviderType = authProviderType, + firstName = firstName, + lastName = lastName, + profilePicture = profilePicture, + color = color, + testUser = testUser, + id = id + ) + fun names(): String = firstName + if (lastName != null) " $lastName" else "" } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt b/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt new file mode 100644 index 0000000000..e982ef60ac --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/io/persistence/migration/Migration120to121_DropWishlistItem.kt @@ -0,0 +1,10 @@ +package com.ivy.wallet.io.persistence.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration120to121_DropWishlistItem : Migration(120, 121) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE wishlist_items") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt b/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt index 0b0a0f927d..632c72f631 100644 --- a/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt +++ b/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt @@ -47,11 +47,10 @@ import com.ivy.wallet.BuildConfig import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.logic.CustomerJourneyLogic +import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic import com.ivy.wallet.ui.analytics.AnalyticsReport import com.ivy.wallet.ui.applocked.AppLockedScreen import com.ivy.wallet.ui.balance.BalanceScreen -import com.ivy.wallet.ui.bankintegrations.ConnectBankScreen import com.ivy.wallet.ui.budget.BudgetScreen import com.ivy.wallet.ui.category.CategoriesScreen import com.ivy.wallet.ui.charts.ChartsScreen @@ -204,7 +203,6 @@ class RootActivity : AppCompatActivity() { is Charts -> ChartsScreen(screen = screen) is AnalyticsReport -> AnalyticsReport(screen = screen) is Import -> ImportCSVScreen(screen = screen) - is ConnectBank -> ConnectBankScreen(screen = screen) is Report -> ReportScreen(screen = screen) is BudgetScreen -> BudgetScreen(screen = screen) is Loans -> LoansScreen(screen = screen) diff --git a/app/src/main/java/com/ivy/wallet/ui/RootViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/RootViewModel.kt index edaa1b9c89..a55ef7c9a5 100644 --- a/app/src/main/java/com/ivy/wallet/ui/RootViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/RootViewModel.kt @@ -11,8 +11,8 @@ import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.android.billing.IvyBilling import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.logic.PaywallLogic -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.logic.PaywallLogic +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.persistence.SharedPrefs diff --git a/app/src/main/java/com/ivy/wallet/ui/Screens.kt b/app/src/main/java/com/ivy/wallet/ui/Screens.kt index 2aa1f881f1..d5f5be4a6f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/Screens.kt +++ b/app/src/main/java/com/ivy/wallet/ui/Screens.kt @@ -2,7 +2,7 @@ package com.ivy.wallet.ui import com.ivy.design.navigation.Screen import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.ui.paywall.PaywallReason import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountData.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountData.kt index 58ffb4cc36..62336b06e1 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountData.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountData.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.accounts import com.ivy.wallet.domain.data.Reorderable -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account data class AccountData( val account: Account, diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsTab.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsTab.kt index e47cc15cd8..7b6d4af7db 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsTab.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsTab.kt @@ -22,7 +22,7 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Main diff --git a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt index b074d3f52f..3b69257b77 100644 --- a/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/accounts/AccountsViewModel.kt @@ -2,16 +2,15 @@ package com.ivy.wallet.ui.accounts import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.viewmodel.account.AccountDataAct +import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.sync.item.AccountSync import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.fp.account.calculateAccountBalance -import com.ivy.wallet.domain.fp.account.calculateAccountIncomeExpense -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.exchangeToBaseCurrency -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.domain.fp.wallet.calculateWalletBalance -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.sync.item.AccountSync +import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx @@ -35,6 +34,10 @@ class AccountsViewModel @Inject constructor( private val accountSync: AccountSync, private val accountCreator: AccountCreator, private val ivyContext: IvyWalletCtx, + private val accountsAct: AccountsAct, + private val calcWalletBalanceAct: CalcWalletBalanceAct, + private val baseCurrencyAct: BaseCurrencyAct, + private val accountDataAct: AccountDataAct ) : ViewModel() { @Subscribe @@ -64,50 +67,25 @@ class AccountsViewModel @Inject constructor( ) //this must be monthly val range = period.toRange(ivyContext.startDayOfMonth) - val baseCurrencyCode = ioThread { baseCurrencyCode(settingsDao) } + val baseCurrencyCode = baseCurrencyAct(Unit) _baseCurrencyCode.value = baseCurrencyCode - _accounts.value = ioThread { - accountDao.findAll() - .map { - val balance = calculateAccountBalance( - transactionDao = walletDAOs.transactionDao, - accountId = it.id - ) - val balanceBaseCurrency = if (it.currency != baseCurrencyCode) { - exchangeToBaseCurrency( - exchangeRateDao = walletDAOs.exchangeRateDao, - baseCurrencyCode = baseCurrencyCode, - fromCurrencyCode = it.currency ?: baseCurrencyCode, - fromAmount = balance - ).orNull()?.toDouble() - } else { - null - } - - val incomeExpensePair = calculateAccountIncomeExpense( - transactionDao = walletDAOs.transactionDao, - accountId = it.id, - range = range.toCloseTimeRange() - ) + val accs = accountsAct(Unit) - AccountData( - account = it, - balance = balance.toDouble(), - balanceBaseCurrency = balanceBaseCurrency, - monthlyIncome = incomeExpensePair.income.toDouble(), - monthlyExpenses = incomeExpensePair.expense.toDouble(), - ) - } - } + _accounts.value = accountDataAct( + AccountDataAct.Input( + accounts = accs, + range = range.toCloseTimeRange(), + baseCurrency = baseCurrencyCode + ) + ) - _totalBalanceWithExcluded.value = ioThread { - calculateWalletBalance( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode, - filterExcluded = false - ).value.toDouble() - } + _totalBalanceWithExcluded.value = calcWalletBalanceAct( + CalcWalletBalanceAct.Input( + baseCurrency = baseCurrencyCode, + withExcluded = true + ) + ).toDouble() TestIdlingResource.decrement() } @@ -120,7 +98,7 @@ class AccountsViewModel @Inject constructor( ioThread { newOrder.mapIndexed { index, accountData -> accountDao.save( - accountData.account.copy( + accountData.account.toEntity().copy( orderNum = index.toDouble(), isSynced = false ) diff --git a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt index e521918d3b..974f06022b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/balance/BalanceViewModel.kt @@ -2,11 +2,9 @@ package com.ivy.wallet.ui.balance import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.domain.fp.wallet.calculateWalletBalance -import com.ivy.wallet.domain.logic.PlannedPaymentsLogic -import com.ivy.wallet.io.persistence.dao.SettingsDao +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod import com.ivy.wallet.utils.dateNowUTC @@ -19,10 +17,10 @@ import javax.inject.Inject @HiltViewModel class BalanceViewModel @Inject constructor( - private val walletDAOs: WalletDAOs, - private val settingsDao: SettingsDao, private val plannedPaymentsLogic: PlannedPaymentsLogic, - private val ivyContext: IvyWalletCtx + private val ivyContext: IvyWalletCtx, + private val baseCurrencyAct: BaseCurrencyAct, + private val calcWalletBalanceAct: CalcWalletBalanceAct ) : ViewModel() { private val _period = MutableStateFlow(ivyContext.selectedPeriod) @@ -42,16 +40,14 @@ class BalanceViewModel @Inject constructor( fun start(period: TimePeriod = ivyContext.selectedPeriod) { viewModelScope.launch { - _baseCurrencyCode.value = ioThread { baseCurrencyCode(settingsDao) } + _baseCurrencyCode.value = baseCurrencyAct(Unit) _period.value = period - val currentBalance = ioThread { - calculateWalletBalance( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value - ).value.toDouble() - } + val currentBalance = calcWalletBalanceAct( + CalcWalletBalanceAct.Input(baseCurrencyCode.value) + ).toDouble() + _currentBalance.value = currentBalance val plannedPaymentsAmount = ioThread { diff --git a/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankScreen.kt b/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankScreen.kt deleted file mode 100644 index 1723dd09ca..0000000000 --- a/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankScreen.kt +++ /dev/null @@ -1,133 +0,0 @@ -package com.ivy.wallet.ui.bankintegrations - -import androidx.compose.foundation.layout.* -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.lifecycle.viewmodel.compose.viewModel -import com.google.accompanist.insets.systemBarsPadding -import com.ivy.wallet.R -import com.ivy.design.l0_system.UI -import com.ivy.design.l0_system.style -import com.ivy.wallet.ui.ConnectBank -import com.ivy.wallet.ui.IvyWalletPreview -import com.ivy.wallet.ui.RootActivity -import com.ivy.wallet.ui.theme.Orange -import com.ivy.wallet.ui.theme.components.IvyButton -import com.ivy.wallet.ui.theme.components.IvySwitch -import com.ivy.wallet.utils.OpResult -import com.ivy.wallet.utils.onScreenStart - -@Composable -fun BoxWithConstraintsScope.ConnectBankScreen(screen: ConnectBank) { - val viewModel: ConnectBankViewModel = viewModel() - - val opSyncTransactions by viewModel.opSyncTransactions.observeAsState() - val bankSyncEnabled by viewModel.bankSyncEnabled.observeAsState(false) - - onScreenStart { - viewModel.start() - } - - val ivyActivity = LocalContext.current as RootActivity - UI( - opSyncTransactions = opSyncTransactions, - bankSyncEnabled = bankSyncEnabled, - - onConnect = { - viewModel.connectBank( - rootActivity = ivyActivity - ) - }, - onFetchTransactions = viewModel::syncTransactions, - onRemoveCustomer = viewModel::removeCustomer, - onSetBankSyncEnabled = viewModel::setBankSyncEnabled - ) -} - -@Composable -private fun UI( - opSyncTransactions: OpResult?, - bankSyncEnabled: Boolean, - - onConnect: () -> Unit = {}, - onFetchTransactions: () -> Unit = {}, - onRemoveCustomer: () -> Unit = {}, - - onSetBankSyncEnabled: (Boolean) -> Unit = {} -) { - Column( - modifier = Modifier - .fillMaxSize() - .systemBarsPadding(), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center - ) { - IvyButton(text = stringResource(R.string.connect)) { - onConnect() - } - - Spacer(Modifier.height(24.dp)) - - IvyButton(text = stringResource(R.string.sync_transactions)) { - onFetchTransactions() - } - - if (opSyncTransactions is OpResult.Loading) { - Spacer(Modifier.height(24.dp)) - - Text( - text = stringResource(R.string.syncing_transactions), - style = UI.typo.b2.style( - color = Orange, - fontWeight = FontWeight.ExtraBold - ) - ) - } - - Spacer(Modifier.height(24.dp)) - - Row( - verticalAlignment = Alignment.CenterVertically - ) { - Text( - stringResource(R.string.bank_sync_enabled) - ) - - Spacer(Modifier.width(16.dp)) - - IvySwitch( - enabled = bankSyncEnabled - ) { - onSetBankSyncEnabled(it) - } - } - - Spacer(Modifier.height(24.dp)) - - IvyButton(text = stringResource(R.string.remove_customer)) { - onRemoveCustomer() - } - } -} - -@Preview -@Composable -private fun Preview() { - IvyWalletPreview { - UI( - opSyncTransactions = null, - bankSyncEnabled = true, - - onConnect = {} - ) - } -} diff --git a/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankViewModel.kt deleted file mode 100644 index 36a5860c40..0000000000 --- a/app/src/main/java/com/ivy/wallet/ui/bankintegrations/ConnectBankViewModel.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.ivy.wallet.ui.bankintegrations - -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.logic.bankintegrations.BankIntegrationsLogic -import com.ivy.wallet.domain.sync.IvySync -import com.ivy.wallet.io.network.IvySession -import com.ivy.wallet.io.persistence.SharedPrefs -import com.ivy.wallet.io.persistence.dao.UserDao -import com.ivy.wallet.ui.RootActivity -import com.ivy.wallet.utils.OpResult -import com.ivy.wallet.utils.TestIdlingResource -import com.ivy.wallet.utils.asLiveData -import com.ivy.wallet.utils.ioThread -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.launch -import javax.inject.Inject - -@HiltViewModel -class ConnectBankViewModel @Inject constructor( - private val bankIntegrationsLogic: BankIntegrationsLogic, - private val ivySession: IvySession, - private val userDao: UserDao, - private val ivySync: IvySync, - private val sharedPrefs: SharedPrefs -) : ViewModel() { - - private val _opSyncTransactions = MutableLiveData>() - val opSyncTransactions = _opSyncTransactions.asLiveData() - - private val _bankSyncEnabled = MutableLiveData(false) - val bankSyncEnabled = _bankSyncEnabled.asLiveData() - - fun start() { - _bankSyncEnabled.value = sharedPrefs.getBoolean(SharedPrefs.ENABLE_BANK_SYNC, false) - } - - fun connectBank(rootActivity: RootActivity) { - viewModelScope.launch { - TestIdlingResource.increment() - - try { - val user = ivySession.getUserIdSafe()?.let { - ioThread { userDao.findById(it) } - } - - if (user != null) { - bankIntegrationsLogic.connect(rootActivity) - } - } catch (e: Exception) { - e.printStackTrace() - } - - TestIdlingResource.decrement() - } - } - - fun syncTransactions() { - viewModelScope.launch { - TestIdlingResource.increment() - - _opSyncTransactions.value = OpResult.loading() - - try { - bankIntegrationsLogic.sync() - ioThread { - ivySync.sync() - } - - _opSyncTransactions.value = OpResult.success(Unit) - } catch (e: Exception) { - e.printStackTrace() - _opSyncTransactions.value = OpResult.failure(e) - } - - TestIdlingResource.decrement() - } - } - - fun setBankSyncEnabled(enabled: Boolean) { - sharedPrefs.putBoolean(SharedPrefs.ENABLE_BANK_SYNC, enabled) - _bankSyncEnabled.value = enabled - } - - fun removeCustomer() { - viewModelScope.launch { - TestIdlingResource.increment() - bankIntegrationsLogic.removeCustomer() - TestIdlingResource.decrement() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt index 08916b5347..640478ce20 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetScreen.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.Text import androidx.compose.runtime.* -import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag @@ -20,10 +19,10 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateBudgetData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateBudgetData import com.ivy.wallet.ui.BudgetScreen import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.budget.model.DisplayBudget @@ -45,13 +44,13 @@ import com.ivy.wallet.utils.onScreenStart fun BoxWithConstraintsScope.BudgetScreen(screen: BudgetScreen) { val viewModel: BudgetViewModel = viewModel() - val timeRange by viewModel.timeRange.observeAsState() - val baseCurrency by viewModel.baseCurrencyCode.observeAsState("") - val categories by viewModel.categories.observeAsState(emptyList()) - val accounts by viewModel.accounts.observeAsState(emptyList()) - val budgets by viewModel.budgets.observeAsState(emptyList()) - val appBudgetMax by viewModel.appBudgetMax.observeAsState(0.0) - val categoryBudgetsTotal by viewModel.categoryBudgetsTotal.observeAsState(0.0) + val timeRange by viewModel.timeRange.collectAsState() + val baseCurrency by viewModel.baseCurrencyCode.collectAsState() + val categories by viewModel.categories.collectAsState() + val accounts by viewModel.accounts.collectAsState() + val budgets by viewModel.budgets.collectAsState() + val appBudgetMax by viewModel.appBudgetMax.collectAsState() + val categoryBudgetsTotal by viewModel.categoryBudgetsTotal.collectAsState() onScreenStart { viewModel.start() @@ -133,7 +132,7 @@ private fun BoxWithConstraintsScope.UI( NoBudgetsEmptyState( emptyStateTitle = stringResource(R.string.no_budgets), - emptyStateText = stringResource(R.string.no_budgets) + emptyStateText = stringResource(R.string.no_budgets_text) ) Spacer(Modifier.weight(1f)) @@ -231,11 +230,19 @@ private fun Toolbar( Spacer(Modifier.height(4.dp)) val categoryBudgetText = if (categoryBudgetsTotal > 0) { - stringResource(R.string.for_categories, categoryBudgetsTotal.format(baseCurrency), baseCurrency) + stringResource( + R.string.for_categories, + categoryBudgetsTotal.format(baseCurrency), + baseCurrency + ) } else "" val appBudgetMaxText = if (appBudgetMax > 0) { - stringResource(R.string.app_budget, appBudgetMax.format(baseCurrency), baseCurrency) + stringResource( + R.string.app_budget, + appBudgetMax.format(baseCurrency), + baseCurrency + ) } else "" val hasBothBudgetTypes = @@ -243,8 +250,12 @@ private fun Toolbar( Text( modifier = Modifier.testTag("budgets_info_text"), text = if (hasBothBudgetTypes) - stringResource(R.string.budget_info_both, categoryBudgetText, appBudgetMaxText) - else stringResource(R.string.budget_info, categoryBudgetText, appBudgetMaxText), + stringResource( + R.string.budget_info_both, + categoryBudgetText, + appBudgetMaxText + ) + else stringResource(R.string.budget_info, categoryBudgetText, appBudgetMaxText), style = UI.typo.nC.style( color = Gray, fontWeight = FontWeight.ExtraBold diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt index 247831cb9d..820b2749ec 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt @@ -1,18 +1,24 @@ package com.ivy.wallet.ui.budget -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.fp.sumOfSuspend +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.budget.BudgetsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.transaction.HistoryTrnsAct import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.BudgetCreator -import com.ivy.wallet.domain.logic.WalletLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CreateBudgetData -import com.ivy.wallet.domain.sync.item.BudgetSync +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.BudgetCreator +import com.ivy.wallet.domain.deprecated.logic.model.CreateBudgetData +import com.ivy.wallet.domain.deprecated.sync.item.BudgetSync +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.transaction.trnCurrency import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.BudgetDao @@ -20,10 +26,11 @@ import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.budget.model.DisplayBudget -import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.ui.onboarding.model.TimePeriod +import com.ivy.wallet.ui.onboarding.model.toCloseTimeRange import com.ivy.wallet.utils.* import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -32,54 +39,50 @@ class BudgetViewModel @Inject constructor( private val sharedPrefs: SharedPrefs, private val settingsDao: SettingsDao, private val budgetDao: BudgetDao, - private val walletLogic: WalletLogic, private val categoryDao: CategoryDao, private val accountDao: AccountDao, - private val exchangeRatesLogic: ExchangeRatesLogic, private val budgetCreator: BudgetCreator, private val budgetSync: BudgetSync, - private val ivyContext: IvyWalletCtx + private val ivyContext: IvyWalletCtx, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val budgetsAct: BudgetsAct, + private val baseCurrencyAct: BaseCurrencyAct, + private val historyTrnsAct: HistoryTrnsAct, + private val exchangeAct: ExchangeAct ) : ViewModel() { - private val _timeRange = MutableLiveData() - val timeRange = _timeRange.asLiveData() + private val _timeRange = MutableStateFlow(ivyContext.selectedPeriod.toRange(1)) + val timeRange = _timeRange.readOnly() - private val _baseCurrencyCode = MutableLiveData(getDefaultFIATCurrency().currencyCode) - val baseCurrencyCode = _baseCurrencyCode.asLiveData() + private val _baseCurrencyCode = MutableStateFlow(getDefaultFIATCurrency().currencyCode) + val baseCurrencyCode = _baseCurrencyCode.readOnly() - private val _budgets = MutableLiveData>() - val budgets = _budgets.asLiveData() + private val _budgets = MutableStateFlow>(emptyList()) + val budgets = _budgets.readOnly() - private val _categories = MutableLiveData>() - val categories = _categories.asLiveData() + private val _categories = MutableStateFlow>(emptyList()) + val categories = _categories.readOnly() - private val _accounts = MutableLiveData>() - val accounts = _accounts.asLiveData() + private val _accounts = MutableStateFlow>(emptyList()) + val accounts = _accounts.readOnly() - private val _categoryBudgetsTotal = MutableLiveData() - val categoryBudgetsTotal = _categoryBudgetsTotal.asLiveData() + private val _categoryBudgetsTotal = MutableStateFlow(0.0) + val categoryBudgetsTotal = _categoryBudgetsTotal.readOnly() - private val _appBudgetMax = MutableLiveData() - val appBudgetMax = _appBudgetMax.asLiveData() + private val _appBudgetMax = MutableStateFlow(0.0) + val appBudgetMax = _appBudgetMax.readOnly() fun start() { viewModelScope.launch { TestIdlingResource.increment() - _categories.value = ioThread { - categoryDao.findAll() - }!! + _categories.value = categoriesAct(Unit) - val accounts = ioThread { - accountDao.findAll() - } + val accounts = accountsAct(Unit) _accounts.value = accounts - val settings = ioThread { - settingsDao.findFirst() - } - - val baseCurrency = settings.currency + val baseCurrency = baseCurrencyAct(Unit) _baseCurrencyCode.value = baseCurrency val startDateOfMonth = ivyContext.initStartDayOfMonthInMemory(sharedPrefs = sharedPrefs) @@ -88,13 +91,7 @@ class BudgetViewModel @Inject constructor( ).toRange(startDateOfMonth = startDateOfMonth) _timeRange.value = timeRange - val transactions = ioThread { - walletLogic.history(range = timeRange) - }.filterIsInstance(Transaction::class.java) - - val budgets = ioThread { - budgetDao.findAll() - } + val budgets = budgetsAct(Unit) _appBudgetMax.value = budgets .filter { it.categoryIdsSerialized.isNullOrBlank() } @@ -110,7 +107,7 @@ class BudgetViewModel @Inject constructor( budget = it, spentAmount = calculateSpentAmount( budget = it, - transactions = transactions, + transactions = historyTrnsAct(timeRange.toCloseTimeRange()), accounts = accounts, baseCurrencyCode = baseCurrency ) @@ -122,25 +119,20 @@ class BudgetViewModel @Inject constructor( } } - private fun calculateSpentAmount( + private suspend fun calculateSpentAmount( budget: Budget, transactions: List, baseCurrencyCode: String, accounts: List ): Double { + //TODO: Re-work this by creating an FPAction for it val accountsFilter = budget.parseAccountIds() val categoryFilter = budget.parseCategoryIds() return transactions .filter { accountsFilter.isEmpty() || accountsFilter.contains(it.accountId) } .filter { categoryFilter.isEmpty() || categoryFilter.contains(it.categoryId) } - .sumOf { - val amountBaseCurrency = exchangeRatesLogic.amountBaseCurrency( - transaction = it, - baseCurrency = baseCurrencyCode, - accounts = accounts - ) - + .sumOfSuspend { when (it.type) { TransactionType.INCOME -> { //decrement spent amount if it's not global budget @@ -149,7 +141,15 @@ class BudgetViewModel @Inject constructor( } TransactionType.EXPENSE -> { //increment spent amount - amountBaseCurrency + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrencyCode, + fromCurrency = trnCurrency(it, accounts) + ), + amount = it.amount + ) + ).orNull()?.toDouble() ?: 0.0 } TransactionType.TRANSFER -> { //ignore transfers for simplicity @@ -203,7 +203,7 @@ class BudgetViewModel @Inject constructor( ioThread { newOrder.forEachIndexed { index, item -> budgetDao.save( - item.budget.copy( + item.budget.toEntity().copy( orderId = index.toDouble(), isSynced = false ) diff --git a/app/src/main/java/com/ivy/wallet/ui/budget/model/DisplayBudget.kt b/app/src/main/java/com/ivy/wallet/ui/budget/model/DisplayBudget.kt index 89cfec2c6a..c7a69d18a3 100644 --- a/app/src/main/java/com/ivy/wallet/ui/budget/model/DisplayBudget.kt +++ b/app/src/main/java/com/ivy/wallet/ui/budget/model/DisplayBudget.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.budget.model import com.ivy.wallet.domain.data.Reorderable -import com.ivy.wallet.domain.data.entity.Budget +import com.ivy.wallet.domain.data.core.Budget data class DisplayBudget( val budget: Budget, diff --git a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt index a1335b9766..2de0618bd3 100644 --- a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesScreen.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.* import androidx.compose.foundation.layout.* import androidx.compose.material.Text import androidx.compose.runtime.* -import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -23,8 +22,8 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.Categories import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview @@ -43,8 +42,8 @@ import com.ivy.wallet.utils.onScreenStart fun BoxWithConstraintsScope.CategoriesScreen(screen: Categories) { val viewModel: CategoriesViewModel = viewModel() - val currency by viewModel.currency.observeAsState("") - val categories by viewModel.categories.observeAsState(emptyList()) + val currency by viewModel.currency.collectAsState() + val categories by viewModel.categories.collectAsState() onScreenStart { viewModel.start() diff --git a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt index 1ec260669d..e50e62ef6f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/category/CategoriesViewModel.kt @@ -1,20 +1,22 @@ package com.ivy.wallet.ui.category -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.logic.CategoryCreator -import com.ivy.wallet.domain.logic.WalletCategoryLogic -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.sync.item.CategorySync +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.deprecated.logic.CategoryCreator +import com.ivy.wallet.domain.deprecated.logic.WalletCategoryLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.sync.item.CategorySync import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod import com.ivy.wallet.utils.TestIdlingResource -import com.ivy.wallet.utils.asLiveData import com.ivy.wallet.utils.ioThread +import com.ivy.wallet.utils.readOnly import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -25,14 +27,16 @@ class CategoriesViewModel @Inject constructor( private val categoryLogic: WalletCategoryLogic, private val categorySync: CategorySync, private val categoryCreator: CategoryCreator, - private val ivyContext: IvyWalletCtx + private val categoriesAct: CategoriesAct, + private val ivyContext: IvyWalletCtx, + private val baseCurrencyAct: BaseCurrencyAct ) : ViewModel() { - private val _currency = MutableLiveData() - val currency = _currency.asLiveData() + private val _currency = MutableStateFlow("") + val currency = _currency.readOnly() - private val _categories = MutableLiveData>() - val categories = _categories.asLiveData() + private val _categories = MutableStateFlow>(emptyList()) + val categories = _categories.readOnly() fun start() { viewModelScope.launch { @@ -42,11 +46,10 @@ class CategoriesViewModel @Inject constructor( startDayOfMonth = ivyContext.startDayOfMonth ).toRange(ivyContext.startDayOfMonth) //this must be monthly - _currency.value = ioThread { settingsDao.findFirst().currency }!! + _currency.value = baseCurrencyAct(Unit) _categories.value = ioThread { - categoryDao - .findAll() + categoriesAct(Unit) .map { CategoryData( category = it, @@ -77,7 +80,7 @@ class CategoriesViewModel @Inject constructor( ioThread { newOrder.forEachIndexed { index, categoryData -> categoryDao.save( - categoryData.category.copy( + categoryData.category.toEntity().copy( orderNum = index.toDouble(), isSynced = false ) diff --git a/app/src/main/java/com/ivy/wallet/ui/category/CategoryData.kt b/app/src/main/java/com/ivy/wallet/ui/category/CategoryData.kt index 0bfc6f6aa5..5e0b3900f1 100644 --- a/app/src/main/java/com/ivy/wallet/ui/category/CategoryData.kt +++ b/app/src/main/java/com/ivy/wallet/ui/category/CategoryData.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.category import com.ivy.wallet.domain.data.Reorderable -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category data class CategoryData( val category: Category, diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/CategoryValues.kt b/app/src/main/java/com/ivy/wallet/ui/charts/CategoryValues.kt index a93a489b03..500d318587 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/CategoryValues.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/CategoryValues.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.ui.charts -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category class CategoryValues( val category: Category, diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt index bd4751e839..2c6b781c01 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsScreen.kt @@ -21,10 +21,10 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.fp.charts.ChartPeriod -import com.ivy.wallet.domain.fp.charts.IncomeExpenseChartPoint -import com.ivy.wallet.domain.fp.charts.SingleChartPoint +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.IncomeExpenseChartPoint +import com.ivy.wallet.domain.pure.charts.SingleChartPoint import com.ivy.wallet.ui.Charts import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.charts.charts.accountCharts diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt index f8374fd98a..b18cc06f0f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/ChartsViewModel.kt @@ -2,12 +2,17 @@ package com.ivy.wallet.ui.charts import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.fp.action.then +import com.ivy.wallet.domain.action.charts.BalanceChartAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.fp.charts.* -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.domain.logic.WalletCategoryLogic +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.WalletCategoryLogic +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.IncomeExpenseChartPoint +import com.ivy.wallet.domain.pure.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.incomeExpenseChart +import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.onboarding.model.FromToTimeRange @@ -19,14 +24,15 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import javax.inject.Inject -import kotlin.math.absoluteValue @HiltViewModel class ChartsViewModel @Inject constructor( private val walletDAOs: WalletDAOs, private val settingsDao: SettingsDao, private val categoryDao: CategoryDao, - private val walletCategoryLogic: WalletCategoryLogic + private val walletCategoryLogic: WalletCategoryLogic, + private val baseCurrencyAct: BaseCurrencyAct, + private val balanceChartAct: BalanceChartAct ) : ViewModel() { private val _period = MutableStateFlow(ChartPeriod.LAST_12_MONTHS) @@ -68,7 +74,7 @@ class ChartsViewModel @Inject constructor( fun start() { viewModelScope.launch { - _baseCurrencyCode.value = ioThread { baseCurrencyCode(settingsDao) } +// _baseCurrencyCode.value = ioThread { baseCurrencyCode(settingsDao) } walletCharts(period = period.value) } @@ -79,13 +85,15 @@ class ChartsViewModel @Inject constructor( _incomeExpenseChart.value = generateIncomeExpenseChart(period) } - private suspend fun generateBalanceChart(period: ChartPeriod) = ioThread { - balanceChart( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - period = period - ) - } + private suspend fun generateBalanceChart(period: ChartPeriod) = + (baseCurrencyAct then { baseCurrency -> + balanceChartAct( + BalanceChartAct.Input( + baseCurrency = baseCurrency, + period = period + ) + ) + })(Unit) private suspend fun generateIncomeExpenseChart(period: ChartPeriod) = ioThread { incomeExpenseChart( @@ -128,16 +136,16 @@ class ChartsViewModel @Inject constructor( period: ChartPeriod, category: Category ) { - _categoryExpenseValues.value = categoryExpenseValues.loadCategoryValue( - period = period, - category = category, - calculateValue = { range -> - walletCategoryLogic.calculateCategoryExpenses( - category = category, - range = range - ).absoluteValue - } - ) +// _categoryExpenseValues.value = categoryExpenseValues.loadCategoryValue( +// period = period, +// category = category, +// calculateValue = { range -> +// walletCategoryLogic.calculateCategoryExpenses( +// category = category, +// range = range +// ).absoluteValue +// } +// ) } private suspend fun loadCategoryExpenseCount( diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/TimeValue.kt b/app/src/main/java/com/ivy/wallet/ui/charts/TimeValue.kt index 5205ae623d..ba1ff83729 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/TimeValue.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/TimeValue.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.charts -import com.ivy.wallet.domain.fp.charts.ChartPeriod -import com.ivy.wallet.domain.fp.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.SingleChartPoint import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.ui.theme.components.charts.linechart.Value diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/charts/AccountCharts.kt b/app/src/main/java/com/ivy/wallet/ui/charts/charts/AccountCharts.kt index a0ddefe7d6..c752d4ad19 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/charts/AccountCharts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/charts/AccountCharts.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.charts.charts import androidx.compose.foundation.lazy.LazyListScope -import com.ivy.wallet.domain.fp.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.ChartPeriod fun LazyListScope.accountCharts(period: ChartPeriod) { diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt b/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt index c1297b8931..637886d048 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/charts/CategoryCharts.kt @@ -16,8 +16,8 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.fp.charts.ChartPeriod +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.pure.charts.ChartPeriod import com.ivy.wallet.stringRes import com.ivy.wallet.ui.charts.CategoryValues import com.ivy.wallet.ui.charts.toValue diff --git a/app/src/main/java/com/ivy/wallet/ui/charts/charts/WalletCharts.kt b/app/src/main/java/com/ivy/wallet/ui/charts/charts/WalletCharts.kt index 97ca7c9977..30b6e2f712 100644 --- a/app/src/main/java/com/ivy/wallet/ui/charts/charts/WalletCharts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/charts/charts/WalletCharts.kt @@ -13,8 +13,8 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.fp.charts.ChartPeriod -import com.ivy.wallet.domain.fp.charts.SingleChartPoint +import com.ivy.wallet.domain.pure.charts.ChartPeriod +import com.ivy.wallet.domain.pure.charts.SingleChartPoint import com.ivy.wallet.ui.charts.toValues2 import com.ivy.wallet.ui.theme.Green import com.ivy.wallet.ui.theme.Ivy diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt index da82d745f5..fa7a30423e 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt @@ -8,8 +8,8 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel -import com.ivy.wallet.domain.logic.csv.model.ImportResult -import com.ivy.wallet.domain.logic.csv.model.ImportType +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType import com.ivy.wallet.ui.Import import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.csvimport.flow.ImportFrom diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt index 1087eb0fc5..5cec1d883a 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportViewModel.kt @@ -6,13 +6,13 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation -import com.ivy.wallet.domain.logic.csv.CSVImporter -import com.ivy.wallet.domain.logic.csv.CSVMapper -import com.ivy.wallet.domain.logic.csv.CSVNormalizer -import com.ivy.wallet.domain.logic.csv.IvyFileReader -import com.ivy.wallet.domain.logic.csv.model.ImportResult -import com.ivy.wallet.domain.logic.csv.model.ImportType -import com.ivy.wallet.domain.logic.zip.ExportZipLogic +import com.ivy.wallet.domain.deprecated.logic.csv.CSVImporter +import com.ivy.wallet.domain.deprecated.logic.csv.CSVMapper +import com.ivy.wallet.domain.deprecated.logic.csv.CSVNormalizer +import com.ivy.wallet.domain.deprecated.logic.csv.IvyFileReader +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType +import com.ivy.wallet.domain.deprecated.logic.zip.ExportZipLogic import com.ivy.wallet.ui.Import import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.viewmodel.OnboardingViewModel diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt index 560860a1e3..5666223427 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.ui.csvimport.flow + import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -21,12 +22,10 @@ import com.google.accompanist.insets.statusBarsPadding import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style -import com.ivy.wallet.domain.logic.csv.model.ImportType +import com.ivy.wallet.R +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.onboarding.components.OnboardingToolbar -import com.ivy.wallet.R - - import com.ivy.wallet.ui.theme.components.GradientCutBottom import com.ivy.wallet.ui.theme.components.IvyIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt index dd671f5679..8e90c0bb68 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt @@ -12,14 +12,14 @@ import com.google.accompanist.insets.systemBarsPadding import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style -import com.ivy.wallet.domain.logic.csv.model.ImportResult +import com.ivy.wallet.R +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportResult import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.BackButton import com.ivy.wallet.ui.theme.components.IvyDividerLine import com.ivy.wallet.ui.theme.components.OnboardingButton import com.ivy.wallet.utils.format -import com.ivy.wallet.R @Composable fun ImportResultUI( diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/instructions/ImportInstructions.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/instructions/ImportInstructions.kt index 7c345b65ac..d17772e14d 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/instructions/ImportInstructions.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/instructions/ImportInstructions.kt @@ -26,8 +26,7 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.logic.csv.model.ImportType -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.ui.onboarding.components.OnboardingToolbar diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt index 3090dff966..6059431725 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionScreen.kt @@ -25,10 +25,10 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.CustomExchangeRateState import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.EditTransaction import com.ivy.wallet.ui.IvyWalletPreview @@ -54,24 +54,24 @@ fun BoxWithConstraintsScope.EditTransactionScreen(screen: EditTransaction) { val viewModel: EditTransactionViewModel = viewModel() val transactionType by viewModel.transactionType.observeAsState(screen.type) - val initialTitle by viewModel.initialTitle.observeAsState() + val initialTitle by viewModel.initialTitle.collectAsState() val titleSuggestions by viewModel.titleSuggestions.collectAsState() - val currency by viewModel.currency.observeAsState("") - val description by viewModel.description.observeAsState() - val dateTime by viewModel.dateTime.observeAsState() - val category by viewModel.category.observeAsState() - val account by viewModel.account.observeAsState() - val toAccount by viewModel.toAccount.observeAsState() - val dueDate by viewModel.dueDate.observeAsState() - val amount by viewModel.amount.observeAsState(0.0) + val currency by viewModel.currency.collectAsState() + val description by viewModel.description.collectAsState() + val dateTime by viewModel.dateTime.collectAsState() + val category by viewModel.category.collectAsState() + val account by viewModel.account.collectAsState() + val toAccount by viewModel.toAccount.collectAsState() + val dueDate by viewModel.dueDate.collectAsState() + val amount by viewModel.amount.collectAsState() val loanData by viewModel.displayLoanHelper.collectAsState() val backgroundProcessing by viewModel.backgroundProcessingStarted.collectAsState() val customExchangeRateState by viewModel.customExchangeRateState.collectAsState() - val categories by viewModel.categories.observeAsState(emptyList()) - val accounts by viewModel.accounts.observeAsState(emptyList()) + val categories by viewModel.categories.collectAsState(emptyList()) + val accounts by viewModel.accounts.collectAsState(emptyList()) - val hasChanges by viewModel.hasChanges.observeAsState(false) + val hasChanges by viewModel.hasChanges.collectAsState(false) onScreenStart { viewModel.start(screen) @@ -387,7 +387,11 @@ private fun BoxWithConstraintsScope.UI( } } else { //no changes, pay - ModalCheck(label = if (transactionType == TransactionType.EXPENSE) stringResource(R.string.pay) else stringResource(R.string.get)) { + ModalCheck( + label = if (transactionType == TransactionType.EXPENSE) stringResource( + R.string.pay + ) else stringResource(R.string.get) + ) { onPayPlannedPayment() } } diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt index 69c1faa53c..f8c8fb2107 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt @@ -4,18 +4,23 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.action.account.AccountByIdAct +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.category.CategoryByIdAct +import com.ivy.wallet.domain.action.transaction.TrnByIdAct import com.ivy.wallet.domain.data.CustomExchangeRateState import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.sync.uploader.TransactionUploader import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.sync.uploader.TransactionUploader import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.ui.EditTransaction @@ -28,6 +33,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import org.greenrobot.eventbus.EventBus +import java.math.BigDecimal import java.time.LocalDateTime import java.util.* import javax.inject.Inject @@ -49,50 +55,55 @@ class EditTransactionViewModel @Inject constructor( private val paywallLogic: PaywallLogic, private val plannedPaymentsLogic: PlannedPaymentsLogic, private val smartTitleSuggestionsLogic: SmartTitleSuggestionsLogic, - private val loanTransactionsLogic: LoanTransactionsLogic + private val loanTransactionsLogic: LoanTransactionsLogic, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val trnByIdAct: TrnByIdAct, + private val categoryByIdAct: CategoryByIdAct, + private val accountByIdAct: AccountByIdAct ) : ViewModel() { private val _transactionType = MutableLiveData() val transactionType = _transactionType - private val _initialTitle = MutableLiveData() - val initialTitle = _initialTitle.asLiveData() + private val _initialTitle = MutableStateFlow(null) + val initialTitle = _initialTitle.readOnly() private val _titleSuggestions = MutableStateFlow(emptySet()) val titleSuggestions = _titleSuggestions.asStateFlow() - private val _currency = MutableLiveData() - val currency = _currency.asLiveData() + private val _currency = MutableStateFlow("") + val currency = _currency.readOnly() - private val _description = MutableLiveData() - val description = _description.asLiveData() + private val _description = MutableStateFlow(null) + val description = _description.readOnly() - private val _dateTime = MutableLiveData() - val dateTime = _dateTime.asLiveData() + private val _dateTime = MutableStateFlow(null) + val dateTime = _dateTime.readOnly() - private val _dueDate = MutableLiveData() - val dueDate = _dueDate.asLiveData() + private val _dueDate = MutableStateFlow(null) + val dueDate = _dueDate.readOnly() - private val _accounts = MutableLiveData>() - val accounts = _accounts.asLiveData() + private val _accounts = MutableStateFlow>(emptyList()) + val accounts = _accounts.readOnly() - private val _categories = MutableLiveData>() - val categories = _categories.asLiveData() + private val _categories = MutableStateFlow>(emptyList()) + val categories = _categories.readOnly() - private val _account = MutableLiveData() - val account = _account.asLiveData() + private val _account = MutableStateFlow(null) + val account = _account.readOnly() - private val _toAccount = MutableLiveData() - val toAccount = _toAccount.asLiveData() + private val _toAccount = MutableStateFlow(null) + val toAccount = _toAccount.readOnly() - private val _category = MutableLiveData() - val category = _category.asLiveData() + private val _category = MutableStateFlow(null) + val category = _category.readOnly() - private val _amount = MutableLiveData(0.0) - val amount = _amount.asLiveData() + private val _amount = MutableStateFlow(0.0) + val amount = _amount.readOnly() - private val _hasChanges = MutableLiveData(false) - val hasChanges = _hasChanges.asLiveData() + private val _hasChanges = MutableStateFlow(false) + val hasChanges = _hasChanges.readOnly() private val _displayLoanHelper: MutableStateFlow = MutableStateFlow(EditTransactionDisplayLoan()) @@ -123,19 +134,19 @@ class EditTransactionViewModel @Inject constructor( baseUserCurrency = baseCurrency() - val accounts = ioThread { accountDao.findAll() }!! + val accounts = accountsAct(Unit) if (accounts.isEmpty()) { closeScreen() return@launch } _accounts.value = accounts - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit) reset() loadedTransaction = screen.initialTransactionId?.let { - ioThread { transactionDao.findById(it)!! } + trnByIdAct(it) } ?: Transaction( accountId = defaultAccountId( screen = screen, @@ -143,7 +154,8 @@ class EditTransactionViewModel @Inject constructor( ), categoryId = screen.categoryId, type = screen.type, - amount = 0.0, + amount = BigDecimal.ZERO, + toAmount = BigDecimal.ZERO ) display(loadedTransaction!!) @@ -208,33 +220,34 @@ class EditTransactionViewModel @Inject constructor( _dateTime.value = transaction.dateTime _description.value = transaction.description _dueDate.value = transaction.dueDate - val selectedAccount = ioThread { accountDao.findById(transaction.accountId)!! } + val selectedAccount = accountByIdAct(transaction.accountId)!! _account.value = selectedAccount _toAccount.value = transaction.toAccountId?.let { - ioThread { accountDao.findById(it) } + accountByIdAct(it) } - _category.value = transaction.smartCategoryId()?.let { - ioThread { categoryDao.findById(it) } + _category.value = transaction.categoryId?.let { + categoryByIdAct(it) } - _amount.value = transaction.amount + _amount.value = transaction.amount.toDouble() updateCurrency(account = selectedAccount) - transaction.toAmount?.let { - val exchangeRate = it / transaction.amount - val toAccountCurrency = - _accounts.value?.find { acc -> acc.id == transaction.toAccountId }?.currency - _customExchangeRateState.value = - _customExchangeRateState.value.copy( - showCard = toAccountCurrency != account.value?.currency, - exchangeRate = exchangeRate, - convertedAmount = it, - toCurrencyCode = toAccountCurrency, - fromCurrencyCode = currency.value - ) - } ?: let { - _customExchangeRateState.value = CustomExchangeRateState() - } + //TODO: Fix that +// transaction.toAmount?.let { +// val exchangeRate = it / transaction.amount +// val toAccountCurrency = +// _accounts.value?.find { acc -> acc.id == transaction.toAccountId }?.currency +// _customExchangeRateState.value = +// _customExchangeRateState.value.copy( +// showCard = toAccountCurrency != account.value?.currency, +// exchangeRate = exchangeRate, +// convertedAmount = it, +// toCurrencyCode = toAccountCurrency, +// fromCurrencyCode = currency.value +// ) +// } ?: let { +// _customExchangeRateState.value = CustomExchangeRateState() +// } _displayLoanHelper.value = getDisplayLoanHelper(trans = transaction) } @@ -248,7 +261,7 @@ class EditTransactionViewModel @Inject constructor( fun onAmountChanged(newAmount: Double) { viewModelScope.launch { loadedTransaction = loadedTransaction().copy( - amount = newAmount + amount = newAmount.toBigDecimal() ) _amount.value = newAmount updateCustomExchangeRateState(amt = newAmount) @@ -418,7 +431,7 @@ class EditTransactionViewModel @Inject constructor( TestIdlingResource.increment() categoryCreator.createCategory(data) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit) //Select the newly created category onCategoryChanged(it) @@ -433,7 +446,7 @@ class EditTransactionViewModel @Inject constructor( TestIdlingResource.increment() categoryCreator.editCategory(updatedCategory) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit) } TestIdlingResource.decrement() @@ -446,7 +459,7 @@ class EditTransactionViewModel @Inject constructor( accountCreator.createAccount(data) { EventBus.getDefault().post(AccountsUpdatedEvent()) - _accounts.value = ioThread { accountDao.findAll() }!! + _accounts.value = accountsAct(Unit) } TestIdlingResource.decrement() @@ -484,12 +497,13 @@ class EditTransactionViewModel @Inject constructor( private suspend fun saveInternal(closeScreen: Boolean) { try { ioThread { - val amount = amount.value ?: error("no amount") + val amount = amount.value.toBigDecimal() loadedTransaction = loadedTransaction().copy( accountId = account.value?.id ?: error("no accountId"), toAccountId = toAccount.value?.id, - toAmount = _customExchangeRateState.value.convertedAmount, + toAmount = _customExchangeRateState.value.convertedAmount?.toBigDecimal() + ?: amount, title = title?.trim(), description = description.value?.trim(), amount = amount, @@ -522,7 +536,7 @@ class EditTransactionViewModel @Inject constructor( accountsChanged = false } - transactionDao.save(loadedTransaction()) + transactionDao.save(loadedTransaction().toEntity()) } if (closeScreen) { diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/core/Category.kt b/app/src/main/java/com/ivy/wallet/ui/edit/core/Category.kt index b43e101c52..bcf2dcfa05 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/core/Category.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/core/Category.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.theme.Gradient import com.ivy.wallet.ui.theme.components.IvyBorderButton diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/core/EditBottomSheet.kt b/app/src/main/java/com/ivy/wallet/ui/edit/core/EditBottomSheet.kt index 7feaf65cc7..e1d68b5a99 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/core/EditBottomSheet.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/core/EditBottomSheet.kt @@ -34,7 +34,7 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.ivyWalletCtx import com.ivy.wallet.ui.theme.* diff --git a/app/src/main/java/com/ivy/wallet/ui/home/CustomerJourney.kt b/app/src/main/java/com/ivy/wallet/ui/home/CustomerJourney.kt index 2579bb6d15..9ffc97c915 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/CustomerJourney.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/CustomerJourney.kt @@ -17,8 +17,8 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.logic.CustomerJourneyLogic -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.ui.IvyWalletComponentPreview import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.ui.ivyWalletCtx diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt index 1aab9a51ac..2a87bca951 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeState.kt @@ -2,11 +2,11 @@ package com.ivy.wallet.ui.home import com.ivy.design.l0_system.Theme import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.IncomeExpensePair -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.pure.data.IncomeExpensePair import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.onboarding.model.TimePeriod import java.math.BigDecimal @@ -15,20 +15,25 @@ data class HomeState( val theme: Theme, val name: String, val baseCurrencyCode: String, + val buffer: BigDecimal, + val period: TimePeriod, + val accounts: List, val categories: List, + + val history: List, + val monthly: IncomeExpensePair, val balance: BigDecimal, - val buffer: BigDecimal, val bufferDiff: BigDecimal, - val monthly: IncomeExpensePair, + val upcoming: IncomeExpensePair, val upcomingTrns: List, val upcomingExpanded: Boolean, val overdue: IncomeExpensePair, val overdueTrns: List, val overdueExpanded: Boolean, - val history: List, + val customerJourneyCards: List, val hideCurrentBalance: Boolean ) { diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt index 50d427b3b5..c2518c2968 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt @@ -24,10 +24,10 @@ import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.stringRes import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Main @@ -445,7 +445,10 @@ fun HomeLazyColumn( history = history, onPayOrGet = onPayOrGet, emptyStateTitle = stringRes(R.string.no_transactions), - emptyStateText = stringRes(R.string.no_transactions_description, period.toDisplayLong(ivyContext.startDayOfMonth)) + emptyStateText = stringRes( + R.string.no_transactions_description, + period.toDisplayLong(ivyContext.startDayOfMonth) + ) ) } } diff --git a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt index 4cb87fdefb..a609de10e7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt @@ -3,21 +3,23 @@ package com.ivy.wallet.ui.home import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation -import com.ivy.design.viewmodel.IvyViewModel -import com.ivy.wallet.domain.action.wallet.CalcOverdueAct -import com.ivy.wallet.domain.action.wallet.CalcUpcomingAct +import com.ivy.fp.viewmodel.IvyViewModel +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.settings.CalcBufferDiffAct +import com.ivy.wallet.domain.action.settings.SettingsAct +import com.ivy.wallet.domain.action.transaction.HistoryWithDateDivsAct +import com.ivy.wallet.domain.action.viewmodel.home.HasTrnsAct +import com.ivy.wallet.domain.action.viewmodel.home.OverdueAct +import com.ivy.wallet.domain.action.viewmodel.home.UpcomingAct +import com.ivy.wallet.domain.action.wallet.CalcIncomeExpenseAct import com.ivy.wallet.domain.action.wallet.CalcWalletBalanceAct -import com.ivy.wallet.domain.action.wallet.HistoryWithDateDivAct -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeExpense -import com.ivy.wallet.domain.fp.wallet.walletBufferDiff -import com.ivy.wallet.domain.logic.CustomerJourneyLogic -import com.ivy.wallet.domain.logic.PlannedPaymentsLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CustomerJourneyCardData +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.CustomerJourneyLogic +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.model.CustomerJourneyCardData import com.ivy.wallet.io.persistence.SharedPrefs -import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.BalanceScreen import com.ivy.wallet.ui.IvyWalletCtx @@ -37,19 +39,23 @@ import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( - private val walletDAOs: WalletDAOs, - private val settingsDao: SettingsDao, - private val categoryDao: CategoryDao, private val ivyContext: IvyWalletCtx, private val nav: Navigation, + private val settingsDao: SettingsDao, private val exchangeRatesLogic: ExchangeRatesLogic, private val plannedPaymentsLogic: PlannedPaymentsLogic, private val customerJourneyLogic: CustomerJourneyLogic, private val sharedPrefs: SharedPrefs, + private val historyWithDateDivsAct: HistoryWithDateDivsAct, + private val calcIncomeExpenseAct: CalcIncomeExpenseAct, private val calcWalletBalanceAct: CalcWalletBalanceAct, - private val calcUpcomingAct: CalcUpcomingAct, - private val calcOverdueAct: CalcOverdueAct, - private val historyWithDateDivAct: HistoryWithDateDivAct, + private val settingsAct: SettingsAct, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val calcBufferDiffAct: CalcBufferDiffAct, + private val upcomingAct: UpcomingAct, + private val overdueAct: OverdueAct, + private val hasTrnsAct: HasTrnsAct ) : IvyViewModel() { override val mutableState: MutableStateFlow = MutableStateFlow( HomeState.initial(ivyWalletCtx = ivyContext) @@ -74,15 +80,19 @@ class HomeViewModel @Inject constructor( viewModelScope.launch { TestIdlingResource.increment() - val settings = ioThread { settingsDao.findFirst() } + val settings = settingsAct(Unit) + val baseCurrency = settings.baseCurrency - val hideCurrentBalance = sharedPrefs.getBoolean(SharedPrefs.HIDE_CURRENT_BALANCE, false) + val hideCurrentBalance = sharedPrefs.getBoolean( + SharedPrefs.HIDE_CURRENT_BALANCE, + false + ) updateState { it.copy( theme = settings.theme, name = settings.name, - baseCurrencyCode = settings.currency, + baseCurrencyCode = baseCurrency, period = period, hideCurrentBalance = hideCurrentBalance ) @@ -91,47 +101,55 @@ class HomeViewModel @Inject constructor( //This method is used to restore the theme when user imports locally backed up data loadNewTheme(settings.theme) + val accounts = accountsAct(Unit) + updateState { it.copy( - categories = ioThread { categoryDao.findAll() }, - accounts = ioThread { walletDAOs.accountDao.findAll() } + categories = categoriesAct(Unit), + accounts = accounts ) } val timeRange = period.toRange(ivyContext.startDayOfMonth) + .toCloseTimeRange() - updateState { - it.copy( - balance = calcWalletBalanceAct(settings.currency) + val monthlyIncomeExpense = calcIncomeExpenseAct( + CalcIncomeExpenseAct.Input( + baseCurrency = baseCurrency, + accounts = accounts, + range = timeRange ) - } + ) + + val balance = calcWalletBalanceAct( + CalcWalletBalanceAct.Input(baseCurrency = baseCurrency) + ) updateState { it.copy( - buffer = settings.bufferAmount.toBigDecimal(), - bufferDiff = ioThread { - walletBufferDiff( - settings = settings, - balance = stateVal().balance - ) - } + balance = balance, + monthly = monthlyIncomeExpense ) } updateState { it.copy( - monthly = ioThread { - calculateWalletIncomeExpense( - walletDAOs = walletDAOs, - baseCurrencyCode = stateVal().baseCurrencyCode, - range = timeRange.toCloseTimeRange() - ).value - } + history = historyWithDateDivsAct( + HistoryWithDateDivsAct.Input( + range = timeRange, + baseCurrency = baseCurrency + ) + ) ) } updateState { - val result = calcUpcomingAct(timeRange) + val result = upcomingAct( + UpcomingAct.Input( + range = timeRange, + baseCurrency = baseCurrency + ) + ) it.copy( upcoming = result.upcoming, upcomingTrns = result.upcomingTrns @@ -139,7 +157,12 @@ class HomeViewModel @Inject constructor( } updateState { - val result = calcOverdueAct(timeRange) + val result = overdueAct( + OverdueAct.Input( + range = timeRange, + baseCurrency = baseCurrency + ) + ) it.copy( overdue = result.overdue, overdueTrns = result.overdueTrns @@ -148,18 +171,19 @@ class HomeViewModel @Inject constructor( updateState { it.copy( - history = historyWithDateDivAct( - HistoryWithDateDivAct.Input( - timeRange = timeRange.toCloseTimeRange(), - baseCurrencyCode = stateVal().baseCurrencyCode - ) - ) + customerJourneyCards = ioThread { customerJourneyLogic.loadCards() } ) } updateState { it.copy( - customerJourneyCards = ioThread { customerJourneyLogic.loadCards() } + buffer = settings.bufferAmount, + bufferDiff = calcBufferDiffAct( + CalcBufferDiffAct.Input( + balance = balance, + buffer = settings.bufferAmount + ) + ) ) } @@ -183,9 +207,7 @@ class HomeViewModel @Inject constructor( viewModelScope.launch { TestIdlingResource.increment() - val hasTransactions = ioThread { - walletDAOs.transactionDao.findAll_LIMIT_1().isNotEmpty() - } + val hasTransactions = hasTrnsAct(Unit) if (hasTransactions) { //has transactions show him "Balance" screen nav.navigateTo(BalanceScreen) diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt index 8f377521ee..4bb3f115d7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/LoanViewModel.kt @@ -2,15 +2,18 @@ package com.ivy.wallet.ui.loan import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.loan.LoansAct +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.logic.LoanCreator +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData +import com.ivy.wallet.domain.deprecated.sync.item.LoanSync import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.logic.LoanCreator -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanData -import com.ivy.wallet.domain.sync.item.LoanSync import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.LoanDao @@ -42,7 +45,10 @@ class LoanViewModel @Inject constructor( private val sharedPrefs: SharedPrefs, private val accountDao: AccountDao, private val accountCreator: AccountCreator, - private val loanTransactionsLogic: LoanTransactionsLogic + private val loanTransactionsLogic: LoanTransactionsLogic, + private val loansAct: LoansAct, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct ) : ViewModel() { private val _baseCurrencyCode = MutableStateFlow(getDefaultFIATCurrency().currencyCode) @@ -75,7 +81,7 @@ class LoanViewModel @Inject constructor( initialiseAccounts() _loans.value = ioThread { - loanDao.findAll() + loansAct(Unit) .map { loan -> val amountPaid = calculateAmountPaid(loan) val loanAmount = loan.amount @@ -111,7 +117,7 @@ class LoanViewModel @Inject constructor( } private suspend fun initialiseAccounts() { - val accounts = ioThread { accountDao.findAll() } + val accounts = accountsAct(Unit) _accounts.value = accounts _selectedAccount.value = defaultAccountId(accounts) _selectedAccount.value?.let { @@ -142,7 +148,7 @@ class LoanViewModel @Inject constructor( ioThread { newOrder.forEachIndexed { index, item -> loanDao.save( - item.loan.copy( + item.loan.toEntity().copy( orderNum = index.toDouble(), isSynced = false ) @@ -165,7 +171,7 @@ class LoanViewModel @Inject constructor( accountCreator.createAccount(data) { EventBus.getDefault().post(AccountsUpdatedEvent()) - _accounts.value = ioThread { accountDao.findAll() }!! + _accounts.value = accountsAct(Unit) _state.value = state.value.copy(accounts = _accounts.value) } diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/LoansScreen.kt b/app/src/main/java/com/ivy/wallet/ui/loan/LoansScreen.kt index 9469325d4b..d4eb917f48 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/LoansScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/LoansScreen.kt @@ -25,7 +25,7 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.LoanType -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.LoanDetails import com.ivy.wallet.ui.Loans diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoan.kt b/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoan.kt index 54a61b7e24..00655cc7b6 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoan.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoan.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.loan.data import com.ivy.wallet.domain.data.Reorderable -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.utils.getDefaultFIATCurrency data class DisplayLoan( diff --git a/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoanRecord.kt b/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoanRecord.kt index 936613c09e..4f73ac75cb 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoanRecord.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loan/data/DisplayLoanRecord.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.loan.data -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.LoanRecord +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.LoanRecord data class DisplayLoanRecord( val loanRecord: LoanRecord, diff --git a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt index 7592822814..26c9b9a328 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsScreen.kt @@ -30,12 +30,12 @@ import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData -import com.ivy.wallet.domain.logic.model.EditLoanRecordData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.EditLoanRecordData import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.LoanDetails diff --git a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt index 78381571b8..b8f3b7eb0f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/loandetails/LoanDetailsViewModel.kt @@ -3,18 +3,20 @@ package com.ivy.wallet.ui.loandetails import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.loan.LoanByIdAct +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.logic.LoanCreator +import com.ivy.wallet.domain.deprecated.logic.LoanRecordCreator +import com.ivy.wallet.domain.deprecated.logic.loantrasactions.LoanTransactionsLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.EditLoanRecordData import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.logic.LoanCreator -import com.ivy.wallet.domain.logic.LoanRecordCreator -import com.ivy.wallet.domain.logic.loantrasactions.LoanTransactionsLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData -import com.ivy.wallet.domain.logic.model.EditLoanRecordData import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.LoanDetails @@ -42,7 +44,9 @@ class LoanDetailsViewModel @Inject constructor( private val accountDao: AccountDao, private val accountCreator: AccountCreator, private val loanTransactionsLogic: LoanTransactionsLogic, - private val nav: Navigation + private val nav: Navigation, + private val accountsAct: AccountsAct, + private val loanByIdAct: LoanByIdAct ) : ViewModel() { private val _baseCurrency = MutableStateFlow("") @@ -87,13 +91,9 @@ class LoanDetailsViewModel @Inject constructor( _baseCurrency.value = it } - _accounts.value = ioThread { - accountDao.findAll() - } + _accounts.value = accountsAct(Unit) - _loan.value = ioThread { - loanDao.findById(id = loanId) - } + _loan.value = loanByIdAct(loanId) loan.value?.let { loan -> _selectedLoanAccount.value = accounts.value.find { @@ -120,7 +120,7 @@ class LoanDetailsViewModel @Inject constructor( ) DisplayLoanRecord( - it, + it.toDomain(), account = account, loanRecordTransaction = trans != null, loanRecordCurrencyCode = account?.currency ?: defaultCurrencyCode, @@ -148,7 +148,7 @@ class LoanDetailsViewModel @Inject constructor( } associatedTransaction = ioThread { - transactionDao.findLoanTransaction(loanId = loan.value!!.id) + transactionDao.findLoanTransaction(loanId = loan.value!!.id)?.toDomain() } associatedTransaction?.let { @@ -296,7 +296,7 @@ class LoanDetailsViewModel @Inject constructor( accountCreator.createAccount(data) { EventBus.getDefault().post(AccountsUpdatedEvent()) - _accounts.value = ioThread { accountDao.findAll() } + _accounts.value = accountsAct(Unit) } TestIdlingResource.decrement() diff --git a/app/src/main/java/com/ivy/wallet/ui/main/MainScreen.kt b/app/src/main/java/com/ivy/wallet/ui/main/MainScreen.kt index beb290d435..c56d23df65 100644 --- a/app/src/main/java/com/ivy/wallet/ui/main/MainScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/main/MainScreen.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel import com.ivy.design.api.navigation import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData import com.ivy.wallet.ui.* import com.ivy.wallet.ui.accounts.AccountsTab import com.ivy.wallet.ui.home.HomeTab diff --git a/app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt index 4068c1da28..e4e7906d7c 100644 --- a/app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/main/MainViewModel.kt @@ -4,11 +4,11 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.sync.IvySync import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.sync.IvySync import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.Main diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt index 3d16df6d0d..05cced0598 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/OnboardingScreen.kt @@ -9,10 +9,10 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Onboarding import com.ivy.wallet.ui.onboarding.model.AccountBalance diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt index ef962be248..01239cf54b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/components/Suggestions.kt @@ -16,9 +16,9 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletComponentPreview import com.ivy.wallet.ui.theme.components.IvyIcon import com.ivy.wallet.ui.theme.components.WrapContentRow diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/AccountBalance.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/AccountBalance.kt index cbf19e34d7..36049d07d4 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/AccountBalance.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/AccountBalance.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.ui.onboarding.model -import com.ivy.wallet.domain.data.entity.Account +import com.ivy.wallet.domain.data.core.Account data class AccountBalance( val account: Account, diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt index 8921b93819..f99c454cc0 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/model/FromToTimeRange.kt @@ -1,9 +1,7 @@ package com.ivy.wallet.ui.onboarding.model -import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.data.ClosedTimeRange -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.pure.data.ClosedTimeRange import com.ivy.wallet.utils.* import java.time.LocalDateTime @@ -38,13 +36,13 @@ data class FromToTimeRange( "${from.toLocalDate().formatDateOnly()} - ${to.toLocalDate().formatDateOnly()}" } from != null && to == null -> { - stringRes(R.string.from_date, from.toLocalDate().formatDateOnly()) + "From ${from.toLocalDate().formatDateOnly()}" } from == null && to != null -> { - stringRes(R.string.to_date, to.toLocalDate().formatDateOnly()) + "To ${to.toLocalDate().formatDateOnly()}" } else -> { - stringRes(R.string.range) + "Range" } } } diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt index 491f4aa236..cb68f637ad 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingAccounts.kt @@ -22,8 +22,8 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.logic.model.CreateAccountData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Paywall import com.ivy.wallet.ui.ivyWalletCtx diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt index e51dbb96dd..345e4ed417 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/steps/OnboardingCategories.kt @@ -25,8 +25,8 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.onboarding.components.OnboardingProgressSlider import com.ivy.wallet.ui.onboarding.components.OnboardingToolbar diff --git a/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt b/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt index 04a36e53d7..0c24b9a501 100644 --- a/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt +++ b/app/src/main/java/com/ivy/wallet/ui/onboarding/viewmodel/OnboardingRouter.kt @@ -4,14 +4,14 @@ import androidx.lifecycle.MutableLiveData import com.ivy.design.navigation.Navigation import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.analytics.AnalyticsEvent -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.LogoutLogic -import com.ivy.wallet.domain.logic.PreloadDataLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic -import com.ivy.wallet.domain.sync.IvySync +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.LogoutLogic +import com.ivy.wallet.domain.deprecated.logic.PreloadDataLogic +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.sync.IvySync import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.persistence.SharedPrefs import com.ivy.wallet.io.persistence.dao.AccountDao @@ -246,7 +246,7 @@ class OnboardingRouter( } private suspend fun routeToCategories() { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = ioThread { categoryDao.findAll().map { it.toDomain() } }!! _categorySuggestions.value = preloadDataLogic.categorySuggestions() _state.value = OnboardingState.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 2ecd126936..4d8c66f9aa 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 @@ -5,16 +5,18 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.l0_system.Theme import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Settings -import com.ivy.wallet.domain.logic.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic -import com.ivy.wallet.domain.sync.IvySync +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Settings +import com.ivy.wallet.domain.deprecated.logic.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.sync.IvySync import com.ivy.wallet.io.network.FCMClient import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.network.IvySession @@ -48,6 +50,9 @@ class OnboardingViewModel @Inject constructor( private val categoryDao: CategoryDao, private val accountCreator: AccountCreator, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + //Only OnboardingRouter stuff sharedPrefs: SharedPrefs, ivySync: IvySync, @@ -132,9 +137,9 @@ class OnboardingViewModel @Inject constructor( Settings( theme = if (isSystemDarkMode) Theme.DARK else Theme.LIGHT, name = "", - currency = defaultCurrency.code, - bufferAmount = 1000.0 - ) + baseCurrency = defaultCurrency.code, + bufferAmount = 1000.0.toBigDecimal() + ).toEntity() ) } @@ -283,15 +288,13 @@ class OnboardingViewModel @Inject constructor( } } - private suspend fun accountsWithBalance(): List = ioThread { - accountDao.findAll() - .map { - AccountBalance( - account = it, - balance = accountLogic.calculateAccountBalance(it) - ) - } - } + private suspend fun accountsWithBalance(): List = accountsAct(Unit) + .map { + AccountBalance( + account = it, + balance = accountLogic.calculateAccountBalance(it) + ) + } fun onAddAccountsDone() { viewModelScope.launch { @@ -320,7 +323,7 @@ class OnboardingViewModel @Inject constructor( TestIdlingResource.increment() categoryCreator.editCategory(updatedCategory) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! } TestIdlingResource.decrement() @@ -332,7 +335,7 @@ class OnboardingViewModel @Inject constructor( TestIdlingResource.increment() categoryCreator.createCategory(data) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! } TestIdlingResource.decrement() diff --git a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallScreen.kt b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallScreen.kt index e76c588830..650c1730fb 100644 --- a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallScreen.kt @@ -25,10 +25,10 @@ import com.ivy.wallet.Constants import com.ivy.wallet.R import com.ivy.wallet.android.billing.Plan import com.ivy.wallet.android.billing.PlanType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Loan +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Loan import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Paywall import com.ivy.wallet.ui.RootActivity diff --git a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt index b76148cc13..e91de323f9 100644 --- a/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/paywall/PaywallViewModel.kt @@ -7,21 +7,20 @@ import com.android.billingclient.api.Purchase import com.ivy.wallet.android.billing.IvyBilling import com.ivy.wallet.android.billing.Plan import com.ivy.wallet.android.billing.PlanType +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.budget.BudgetsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.loan.LoansAct import com.ivy.wallet.domain.data.analytics.AnalyticsEvent -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.logic.PaywallLogic +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.deprecated.logic.PaywallLogic import com.ivy.wallet.io.network.IvyAnalytics -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.BudgetDao -import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.io.persistence.dao.LoanDao import com.ivy.wallet.ui.Paywall import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.utils.asLiveData -import com.ivy.wallet.utils.ioThread import com.ivy.wallet.utils.sendToCrashlytics import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch @@ -33,10 +32,10 @@ class PaywallViewModel @Inject constructor( private val ivyBilling: IvyBilling, private val paywallLogic: PaywallLogic, private val ivyAnalytics: IvyAnalytics, - private val categoryDao: CategoryDao, - private val accountDao: AccountDao, - private val budgetDao: BudgetDao, - private val loanDao: LoanDao + private val categoriesAct: CategoriesAct, + private val accountsAct: AccountsAct, + private val budgetsAct: BudgetsAct, + private val loansAct: LoansAct ) : ViewModel() { private val _plans = MutableLiveData>() @@ -90,10 +89,10 @@ class PaywallViewModel @Inject constructor( ) viewModelScope.launch { - _categories.value = ioThread { categoryDao.findAll() }!! - _accounts.value = ioThread { accountDao.findAll() }!! - _budgets.value = ioThread { budgetDao.findAll() }!! - _loans.value = ioThread { loanDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! + _accounts.value = accountsAct(Unit)!! + _budgets.value = budgetsAct(Unit)!! + _loans.value = loansAct(Unit)!! ivyAnalytics.logEvent( when (screen.paywallReason) { diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt index 7570d7140d..5c59e1b4d1 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedScreen.kt @@ -19,10 +19,10 @@ import com.google.accompanist.insets.statusBarsPadding import com.ivy.wallet.R import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.edit.core.* diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt index 3c30048c24..5273de8870 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/edit/EditPlannedViewModel.kt @@ -4,19 +4,21 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.deprecated.logic.AccountCreator +import com.ivy.wallet.domain.deprecated.logic.CategoryCreator +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsGenerator +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData +import com.ivy.wallet.domain.deprecated.sync.item.TransactionSync +import com.ivy.wallet.domain.deprecated.sync.uploader.PlannedPaymentRuleUploader import com.ivy.wallet.domain.event.AccountsUpdatedEvent -import com.ivy.wallet.domain.logic.AccountCreator -import com.ivy.wallet.domain.logic.CategoryCreator -import com.ivy.wallet.domain.logic.PlannedPaymentsGenerator -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateCategoryData -import com.ivy.wallet.domain.sync.item.TransactionSync -import com.ivy.wallet.domain.sync.uploader.PlannedPaymentRuleUploader import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.IvyWalletCtx @@ -42,7 +44,9 @@ class EditPlannedViewModel @Inject constructor( private val plannedPaymentRuleUploader: PlannedPaymentRuleUploader, private val plannedPaymentsGenerator: PlannedPaymentsGenerator, private val categoryCreator: CategoryCreator, - private val accountCreator: AccountCreator + private val accountCreator: AccountCreator, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct ) : ViewModel() { private val _transactionType = MutableLiveData() @@ -95,19 +99,19 @@ class EditPlannedViewModel @Inject constructor( editMode = screen.plannedPaymentRuleId != null - val accounts = ioThread { accountDao.findAll() }!! + val accounts = accountsAct(Unit) if (accounts.isEmpty()) { nav.back() return@launch } _accounts.value = accounts - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! reset() loadedRule = screen.plannedPaymentRuleId?.let { - ioThread { plannedPaymentRuleDao.findById(it)!! } + ioThread { plannedPaymentRuleDao.findById(it)!!.toDomain() } } ?: PlannedPaymentRule( startDate = null, intervalN = null, @@ -137,10 +141,10 @@ class EditPlannedViewModel @Inject constructor( _intervalType.value = rule.intervalType _initialTitle.value = rule.title _description.value = rule.description - val selectedAccount = ioThread { accountDao.findById(rule.accountId)!! } + val selectedAccount = ioThread { accountDao.findById(rule.accountId)!!.toDomain() } _account.value = selectedAccount _category.value = rule.categoryId?.let { - ioThread { categoryDao.findById(rule.categoryId) } + ioThread { categoryDao.findById(rule.categoryId)?.toDomain() } } _amount.value = rule.amount @@ -262,7 +266,7 @@ class EditPlannedViewModel @Inject constructor( isSynced = false ) - plannedPaymentRuleDao.save(loadedRule()) + plannedPaymentRuleDao.save(loadedRule().toEntity()) plannedPaymentsGenerator.generate(loadedRule()) } @@ -327,7 +331,7 @@ class EditPlannedViewModel @Inject constructor( fun createCategory(data: CreateCategoryData) { viewModelScope.launch { categoryCreator.createCategory(data) { - _categories.value = ioThread { categoryDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! onCategoryChanged(it) } @@ -338,7 +342,7 @@ class EditPlannedViewModel @Inject constructor( viewModelScope.launch { accountCreator.createAccount(data) { EventBus.getDefault().post(AccountsUpdatedEvent()) - _accounts.value = ioThread { accountDao.findAll() }!! + _accounts.value = accountsAct(Unit)!! } } } diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentCard.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentCard.kt index cf4f689437..495b063289 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentCard.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentCard.kt @@ -23,9 +23,9 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.Gradient diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsLazyColumn.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsLazyColumn.kt index f94775464b..ce62f9d763 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsLazyColumn.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsLazyColumn.kt @@ -6,7 +6,6 @@ import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp @@ -17,10 +16,9 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.design.navigation.Navigation import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.theme.Gray @@ -113,7 +111,7 @@ private fun LazyListScope.plannedPaymentItems( SectionDivider( expanded = oneTimeExpanded, setExpanded = setOneTimeExpanded, - title = stringRes(R.string.one_time_payments), + title = "One time payments", titleColor = UI.colors.pureInverse, baseCurrency = currency, income = oneTimeIncome, @@ -145,7 +143,7 @@ private fun LazyListScope.plannedPaymentItems( SectionDivider( expanded = recurringExpanded, setExpanded = setRecurringExpanded, - title = stringRes(R.string.recurring_payments), + title = "Recurring payments", titleColor = UI.colors.pureInverse, baseCurrency = currency, income = recurringIncome, @@ -214,7 +212,7 @@ private fun LazyItemScope.NoPlannedPaymentsEmptyState() { Spacer(Modifier.height(24.dp)) Text( - text = stringResource(R.string.no_planned_payments), + text = "No planned payments", style = UI.typo.b1.style( color = Gray, fontWeight = FontWeight.ExtraBold @@ -224,7 +222,7 @@ private fun LazyItemScope.NoPlannedPaymentsEmptyState() { Spacer(Modifier.height(8.dp)) Text( - text = stringResource(R.string.no_planned_payments_description), + text = "You don't have any planed payments.\nPress the '⚡' bottom at the bottom to add one.", style = UI.typo.b2.style( color = Gray, fontWeight = FontWeight.Medium, diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsScreen.kt index 8568c94325..d1e19ec616 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsScreen.kt @@ -21,9 +21,9 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IntervalType import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule import com.ivy.wallet.ui.EditPlanned import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.PlannedPayments diff --git a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt index c3797f97f4..f48a58e551 100644 --- a/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/planned/list/PlannedPaymentsViewModel.kt @@ -3,13 +3,14 @@ package com.ivy.wallet.ui.planned.list import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.PlannedPaymentRule -import com.ivy.wallet.domain.logic.PlannedPaymentsLogic +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.PlannedPaymentRule +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic import com.ivy.wallet.io.persistence.dao.AccountDao import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.io.persistence.dao.PlannedPaymentRuleDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.ui.PlannedPayments import com.ivy.wallet.utils.TestIdlingResource @@ -22,10 +23,11 @@ import javax.inject.Inject @HiltViewModel class PlannedPaymentsViewModel @Inject constructor( private val settingsDao: SettingsDao, - private val plannedPaymentRuleDao: PlannedPaymentRuleDao, private val categoryDao: CategoryDao, private val accountDao: AccountDao, - private val plannedPaymentsLogic: PlannedPaymentsLogic + private val plannedPaymentsLogic: PlannedPaymentsLogic, + private val categoriesAct: CategoriesAct, + private val accountsAct: AccountsAct ) : ViewModel() { private val _currency = MutableLiveData() @@ -65,8 +67,8 @@ class PlannedPaymentsViewModel @Inject constructor( _currency.value = settings.currency - _categories.value = ioThread { categoryDao.findAll() }!! - _accounts.value = ioThread { accountDao.findAll() }!! + _categories.value = categoriesAct(Unit)!! + _accounts.value = accountsAct(Unit)!! _oneTime.value = ioThread { plannedPaymentsLogic.oneTime() }!! _oneTimeIncome.value = ioThread { plannedPaymentsLogic.oneTimeIncome() }!! diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/FilterOverlay.kt b/app/src/main/java/com/ivy/wallet/ui/reports/FilterOverlay.kt index 268463b3e8..cb4b771085 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/FilterOverlay.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/FilterOverlay.kt @@ -25,8 +25,8 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.ivyWalletCtx import com.ivy.wallet.ui.theme.* diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportFilter.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportFilter.kt index e4ca11a807..09cdc4cf1c 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportFilter.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportFilter.kt @@ -1,8 +1,8 @@ package com.ivy.wallet.ui.reports import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.onboarding.model.TimePeriod import java.util.* diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreen.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreen.kt index cb66786a5a..f85b27a6c4 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreen.kt @@ -13,7 +13,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview @@ -26,9 +25,8 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.PieChartStatistic import com.ivy.wallet.ui.Report @@ -116,7 +114,7 @@ private fun BoxWithConstraintsScope.UI( modifier = Modifier.padding( start = 32.dp ), - text = stringResource(R.string.reports), + text = "Reports", style = UI.typo.h2.style( fontWeight = FontWeight.ExtraBold ) @@ -209,9 +207,9 @@ private fun BoxWithConstraintsScope.UI( onPayOrGet = { onEventHandler.invoke(ReportScreenEvent.OnPayOrGet(transaction = it)) }, - emptyStateTitle = stringRes(R.string.no_transactions), + emptyStateTitle = "No transactions", - emptyStateText = stringRes(R.string.no_transactions_for_your_filter) + emptyStateText = "You don't have any transactions for your filter." ) } else { item { @@ -265,7 +263,7 @@ private fun NoFilterEmptyState( Spacer(Modifier.height(8.dp)) Text( - text = stringResource(R.string.no_filter), + text = "No Filter", style = UI.typo.b1.style( color = Gray, fontWeight = FontWeight.ExtraBold @@ -276,7 +274,7 @@ private fun NoFilterEmptyState( Text( modifier = Modifier.padding(horizontal = 32.dp), - text = stringResource(R.string.invalid_filter_warning), + text = "To generate a report you must first set a valid filter.", style = UI.typo.b2.style( color = Gray, fontWeight = FontWeight.Medium, @@ -288,7 +286,7 @@ private fun NoFilterEmptyState( IvyButton( iconStart = R.drawable.ic_filter_xs, - text = stringResource(R.string.set_filter) + text = "Set Filter" ) { setFilterOverlayVisible(true) } @@ -313,7 +311,7 @@ private fun Toolbar( //Export CSV IvyOutlinedButton( - text = stringResource(R.string.export), + text = "Export", iconTint = Green, textColor = Green, solidBackground = true, diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenEvent.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenEvent.kt index c4360d4e9c..7fb7283d3b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenEvent.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenEvent.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.reports import android.content.Context -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Transaction sealed class ReportScreenEvent { data class OnFilter(val filter: ReportFilter?) : ReportScreenEvent() diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenState.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenState.kt index 7f06456657..4c6fbcb4db 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenState.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportScreenState.kt @@ -1,9 +1,9 @@ package com.ivy.wallet.ui.reports import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import java.util.* data class ReportScreenState( diff --git a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt index b818810f0e..f19bee7620 100644 --- a/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/reports/ReportViewModel.kt @@ -5,17 +5,26 @@ import androidx.compose.ui.graphics.toArgb import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.ivy.design.navigation.Navigation -import com.ivy.design.viewmodel.IvyViewModel +import com.ivy.fp.filterSuspend +import com.ivy.fp.sumOfSuspend +import com.ivy.fp.viewmodel.IvyViewModel +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.transaction.CalcTrnsIncomeExpenseAct +import com.ivy.wallet.domain.action.transaction.TrnsWithDateDivsAct import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.wallet.withDateDividers -import com.ivy.wallet.domain.logic.PlannedPaymentsLogic -import com.ivy.wallet.domain.logic.WalletLogic -import com.ivy.wallet.domain.logic.csv.ExportCSVLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.io.persistence.dao.* +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.PlannedPaymentsLogic +import com.ivy.wallet.domain.deprecated.logic.csv.ExportCSVLogic +import com.ivy.wallet.domain.pure.exchange.ExchangeData +import com.ivy.wallet.domain.pure.transaction.trnCurrency +import com.ivy.wallet.domain.pure.util.orZero +import com.ivy.wallet.io.persistence.dao.SettingsDao +import com.ivy.wallet.io.persistence.dao.TransactionDao import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.RootActivity import com.ivy.wallet.ui.onboarding.model.TimePeriod @@ -33,15 +42,16 @@ import javax.inject.Inject class ReportViewModel @Inject constructor( private val plannedPaymentsLogic: PlannedPaymentsLogic, private val settingsDao: SettingsDao, - private val walletLogic: WalletLogic, private val transactionDao: TransactionDao, private val ivyContext: IvyWalletCtx, private val nav: Navigation, - private val accountDao: AccountDao, - private val categoryDao: CategoryDao, - private val exchangeRatesLogic: ExchangeRatesLogic, - private val exchangeRateDao: ExchangeRateDao, - private val exportCSVLogic: ExportCSVLogic + private val exportCSVLogic: ExportCSVLogic, + private val exchangeAct: ExchangeAct, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val trnsWithDateDivsAct: TrnsWithDateDivsAct, + private val calcTrnsIncomeExpenseAct: CalcTrnsIncomeExpenseAct, + private val baseCurrencyAct: BaseCurrencyAct ) : IvyViewModel() { override val mutableState: MutableStateFlow = MutableStateFlow( ReportScreenState() @@ -65,9 +75,9 @@ class ReportViewModel @Inject constructor( fun start() { viewModelScope.launch(Dispatchers.IO) { - _baseCurrency.value = settingsDao.findFirst().currency - _accounts.value = accountDao.findAll() - _categories.value = listOf(unSpecifiedCategory) + categoryDao.findAll() + _baseCurrency.value = baseCurrencyAct(Unit) + _accounts.value = accountsAct(Unit) + _categories.value = listOf(unSpecifiedCategory) + categoriesAct(Unit) updateState { it.copy( @@ -107,23 +117,29 @@ class ReportViewModel @Inject constructor( .sortedByDescending { it.dateTime } val historyWithDateDividers = scope.async { - history.withDateDividers( - exchangeRateDao = exchangeRateDao, - accountDao = accountDao, - baseCurrencyCode = _baseCurrency.value + trnsWithDateDivsAct( + TrnsWithDateDivsAct.Input( + baseCurrency = stateVal().baseCurrency, + transactions = history + ) ) } - val income = scope.async { walletLogic.calculateIncome(history) } - val expenses = scope.async { walletLogic.calculateExpenses(history) } + val historyIncomeExpense = calcTrnsIncomeExpenseAct( + CalcTrnsIncomeExpenseAct.Input( + transactions = history, + accounts = accounts, + baseCurrency = baseCurrency + ) + ) val balance = scope.async { calculateBalance( baseCurrency = baseCurrency, accounts = accounts, history = history, - income = income.await(), - expenses = expenses.await(), + income = historyIncomeExpense.income.toDouble(), + expenses = historyIncomeExpense.expense.toDouble(), filter = filter ) } @@ -138,27 +154,36 @@ class ReportViewModel @Inject constructor( it.dueDate != null && it.dueDate.isAfter(timeNowUTC) } .sortedBy { it.dueDate } - val upcomingIncome = scope.async { walletLogic.calculateIncome(upcomingTransactions) } - val upcomingExpenses = - scope.async { walletLogic.calculateExpenses(upcomingTransactions) } + val upcomingIncomeExpense = calcTrnsIncomeExpenseAct( + CalcTrnsIncomeExpenseAct.Input( + transactions = upcomingTransactions, + accounts = accounts, + baseCurrency = baseCurrency + ) + ) //Overdue val overdue = transactions.filter { it.dueDate != null && it.dueDate.isBefore(timeNowUTC) }.sortedByDescending { it.dueDate } - val overdueIncome = scope.async { walletLogic.calculateIncome(overdue) } - val overdueExpenses = scope.async { walletLogic.calculateExpenses(overdue) } + val overdueIncomeExpense = calcTrnsIncomeExpenseAct( + CalcTrnsIncomeExpenseAct.Input( + transactions = overdue, + accounts = accounts, + baseCurrency = baseCurrency + ) + ) updateState { it.copy( - income = income.await(), - expenses = expenses.await(), - upcomingIncome = upcomingIncome.await(), - upcomingExpenses = upcomingExpenses.await(), - overdueIncome = overdueIncome.await(), - overdueExpenses = overdueExpenses.await(), + income = historyIncomeExpense.income.toDouble(), + expenses = historyIncomeExpense.expense.toDouble(), + upcomingIncome = upcomingIncomeExpense.income.toDouble(), + upcomingExpenses = upcomingIncomeExpense.expense.toDouble(), + overdueIncome = overdueIncomeExpense.income.toDouble(), + overdueExpenses = overdueIncomeExpense.expense.toDouble(), history = historyWithDateDividers.await(), upcomingTransactions = upcomingTransactions, overdueTransactions = overdue, @@ -175,7 +200,7 @@ class ReportViewModel @Inject constructor( } } - private fun filterTransactions( + private suspend fun filterTransactions( baseCurrency: String, accounts: List, filter: ReportFilter, @@ -187,7 +212,7 @@ class ReportViewModel @Inject constructor( return transactionDao .findAll() - .asSequence() + .map { it.toDomain() } .filter { //Filter by Transaction Type filter.trnTypes.contains(it.type) @@ -209,17 +234,21 @@ class ReportViewModel @Inject constructor( .filter { trn -> //Filter by Categories - filterCategoryIds.contains(trn.smartCategoryId()) || (trn.type == TransactionType.TRANSFER) + filterCategoryIds.contains(trn.categoryId) || (trn.type == TransactionType.TRANSFER) } - .filter { + .filterSuspend { //Filter by Amount //!NOTE: Amount must be converted to baseCurrency amount - val trnAmountBaseCurrency = exchangeRatesLogic.amountBaseCurrency( - transaction = it, - baseCurrency = baseCurrency, - accounts = accounts - ) + val trnAmountBaseCurrency = exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency(it, accounts), + ), + amount = it.amount + ) + ).orZero().toDouble() (filter.minAmount == null || trnAmountBaseCurrency >= filter.minAmount) && (filter.maxAmount == null || trnAmountBaseCurrency <= filter.maxAmount) @@ -279,7 +308,7 @@ class ReportViewModel @Inject constructor( return this.toLowerCaseLocal().contains(anotherString.toLowerCaseLocal()) } - private fun calculateBalance( + private suspend fun calculateBalance( baseCurrency: String, accounts: List, history: List, @@ -294,12 +323,16 @@ class ReportViewModel @Inject constructor( it.type == TransactionType.TRANSFER && it.toAccountId != null && includedAccountsIds.contains(it.toAccountId) } - .sumOf { trn -> - exchangeRatesLogic.toAmountBaseCurrency( - transaction = trn, - baseCurrency = baseCurrency, - accounts = accounts - ) + .sumOfSuspend { trn -> + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency(trn, accounts), + ), + amount = trn.amount + ) + ).orZero().toDouble() } //- Transfers Out (#conv to BaseCurrency) @@ -308,19 +341,23 @@ class ReportViewModel @Inject constructor( it.type == TransactionType.TRANSFER && includedAccountsIds.contains(it.accountId) } - .sumOf { trn -> - exchangeRatesLogic.amountBaseCurrency( - transaction = trn, - baseCurrency = baseCurrency, - accounts = accounts - ) + .sumOfSuspend { trn -> + exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency, + fromCurrency = trnCurrency(trn, accounts), + ), + amount = trn.amount + ) + ).orZero().toDouble() } //Income - Expenses (#conv to BaseCurrency) return income - expenses + transfersIn - transfersOut } - private fun export(context: Context) { + private suspend fun export(context: Context) { ivyContext.protectWithPaywall( paywallReason = PaywallReason.EXPORT_CSV, navigation = nav diff --git a/app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt b/app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt index 95c5c72f61..2385784cf2 100644 --- a/app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/search/SearchScreen.kt @@ -14,7 +14,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -24,9 +23,8 @@ import com.ivy.design.api.navigation import com.ivy.design.l0_system.UI import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Search import com.ivy.wallet.ui.ivyWalletCtx @@ -125,8 +123,8 @@ private fun UI( history = transactions, onPayOrGet = { }, dateDividerMarginTop = 16.dp, - emptyStateTitle = stringRes(R.string.no_transactions), - emptyStateText = stringRes(R.string.no_transactions_for_query, searchQueryTextFieldValue.text) + emptyStateTitle = "No transactions", + emptyStateText = "You don't have any transactions for \"${searchQueryTextFieldValue.text}\" query." ) item { @@ -171,7 +169,7 @@ private fun SearchInput( .padding(vertical = 12.dp) .focusRequester(searchFocus), value = searchQueryTextFieldValue, - hint = stringResource(R.string.search_transactions), + hint = "Search transactions", onValueChanged = { onSetSearchQueryTextField(it) } diff --git a/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt index 4ac8e422c5..fda9410402 100644 --- a/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/search/SearchViewModel.kt @@ -2,15 +2,14 @@ package com.ivy.wallet.ui.search import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.transaction.AllTrnsAct +import com.ivy.wallet.domain.action.transaction.TrnsWithDateDivsAct import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.withDateDividers -import com.ivy.wallet.io.persistence.dao.AccountDao -import com.ivy.wallet.io.persistence.dao.CategoryDao -import com.ivy.wallet.io.persistence.dao.SettingsDao -import com.ivy.wallet.io.persistence.dao.TransactionDao +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.utils.TestIdlingResource import com.ivy.wallet.utils.getDefaultFIATCurrency import com.ivy.wallet.utils.ioThread @@ -22,11 +21,11 @@ import javax.inject.Inject @HiltViewModel class SearchViewModel @Inject constructor( - private val transactionDao: TransactionDao, - private val settingsDao: SettingsDao, - private val categoryDao: CategoryDao, - private val accountDao: AccountDao, - private val exchangeRatesLogic: ExchangeRatesLogic + private val trnsWithDateDivsAct: TrnsWithDateDivsAct, + private val accountsAct: AccountsAct, + private val categoriesAct: CategoriesAct, + private val baseCurrencyAct: BaseCurrencyAct, + private val allTrnsAct: AllTrnsAct ) : ViewModel() { private val _baseCurrencyCode = MutableStateFlow(getDefaultFIATCurrency().currencyCode) @@ -47,28 +46,24 @@ class SearchViewModel @Inject constructor( viewModelScope.launch { TestIdlingResource.increment() - _baseCurrencyCode.value = ioThread { - settingsDao.findFirst().currency - } + _baseCurrencyCode.value = baseCurrencyAct(Unit) - _categories.value = ioThread { - categoryDao.findAll() - } + _categories.value = categoriesAct(Unit) - _accounts.value = ioThread { - accountDao.findAll() - } + _accounts.value = accountsAct(Unit) _transactions.value = ioThread { - transactionDao.findAll() + val trns = allTrnsAct(Unit) .filter { it.title.matchesQuery(normalizedQuery) || it.description.matchesQuery(normalizedQuery) - }.withDateDividers( - exchangeRatesLogic = exchangeRatesLogic, - accountDao = accountDao, - settingsDao = settingsDao + } + trnsWithDateDivsAct( + TrnsWithDateDivsAct.Input( + baseCurrency = baseCurrencyCode.value, + transactions = trns ) + ) } TestIdlingResource.decrement() diff --git a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt index e9913a7942..95c2615f1c 100644 --- a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt @@ -35,7 +35,7 @@ import com.ivy.wallet.Constants.URL_IVY_CONTRIBUTORS import com.ivy.wallet.R import com.ivy.wallet.domain.data.AuthProviderType import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User import com.ivy.wallet.ui.* import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.IvyButton diff --git a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt index d5b969acba..fda25c3cd5 100644 --- a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt @@ -5,12 +5,12 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.domain.data.analytics.AnalyticsEvent -import com.ivy.wallet.domain.data.entity.User -import com.ivy.wallet.domain.logic.LogoutLogic -import com.ivy.wallet.domain.logic.csv.ExportCSVLogic -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.zip.ExportZipLogic -import com.ivy.wallet.domain.sync.IvySync +import com.ivy.wallet.domain.data.core.User +import com.ivy.wallet.domain.deprecated.logic.LogoutLogic +import com.ivy.wallet.domain.deprecated.logic.csv.ExportCSVLogic +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.zip.ExportZipLogic +import com.ivy.wallet.domain.deprecated.sync.IvySync import com.ivy.wallet.io.network.FCMClient import com.ivy.wallet.io.network.IvyAnalytics import com.ivy.wallet.io.network.IvySession @@ -88,12 +88,13 @@ class SettingsViewModel @Inject constructor( _user.value = ioThread { val userId = ivySession.getUserIdSafe() - if (userId != null) userDao.findById(userId) else null + if (userId != null) userDao.findById(userId)?.toDomain() else null } _currencyCode.value = settings.currency _lockApp.value = sharedPrefs.getBoolean(SharedPrefs.APP_LOCK_ENABLED, false) - _hideCurrentBalance.value = sharedPrefs.getBoolean(SharedPrefs.HIDE_CURRENT_BALANCE, false) + _hideCurrentBalance.value = + sharedPrefs.getBoolean(SharedPrefs.HIDE_CURRENT_BALANCE, false) _showNotifications.value = sharedPrefs.getBoolean(SharedPrefs.SHOW_NOTIFICATIONS, true) diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/CategoryAmount.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/CategoryAmount.kt index 425b198aec..3f8c39e9ac 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/CategoryAmount.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/CategoryAmount.kt @@ -1,7 +1,7 @@ package com.ivy.wallet.ui.statistic.level1 -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction data class CategoryAmount( val category: Category?, diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChart.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChart.kt index 2084d934b3..541b279ff9 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChart.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChart.kt @@ -22,7 +22,7 @@ import androidx.compose.ui.viewinterop.AndroidView import com.ivy.design.l0_system.UI import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletComponentPreview import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.IvyIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticScreen.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticScreen.kt index 24ca1787a0..6ff491aa2f 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticScreen.kt @@ -31,8 +31,8 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.ui.* import com.ivy.wallet.ui.onboarding.model.TimePeriod import com.ivy.wallet.ui.theme.* diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt index 0a0f898908..8a46a42f72 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/PieChartStatisticViewModel.kt @@ -5,15 +5,11 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.category.calculateCategoryExpenseWithAccountFilters -import com.ivy.wallet.domain.fp.category.calculateCategoryIncomeWithAccountFilters -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.wallet.calculateWalletExpenseWithAccountFilters -import com.ivy.wallet.domain.fp.wallet.calculateWalletIncomeWithAccountFilters -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.logic.currency.sumInBaseCurrency +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.logic.currency.sumInBaseCurrency +import com.ivy.wallet.domain.pure.data.WalletDAOs import com.ivy.wallet.io.persistence.dao.CategoryDao import com.ivy.wallet.io.persistence.dao.SettingsDao import com.ivy.wallet.io.persistence.dao.TransactionDao @@ -22,7 +18,6 @@ import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.PieChartStatistic import com.ivy.wallet.ui.onboarding.model.FromToTimeRange import com.ivy.wallet.ui.onboarding.model.TimePeriod -import com.ivy.wallet.ui.onboarding.model.toCloseTimeRange import com.ivy.wallet.ui.theme.IvyLight import com.ivy.wallet.utils.dateNowUTC import com.ivy.wallet.utils.ioThread @@ -76,7 +71,11 @@ class PieChartStatisticViewModel @Inject constructor( private var filterExcluded = true private val transfersCategory = - Category(stringRes(R.string.account_transfers), color = IvyLight.toArgb(), icon = "transfer") + Category( + stringRes(R.string.account_transfers), + color = IvyLight.toArgb(), + icon = "transfer" + ) fun start( screen: PieChartStatistic @@ -149,7 +148,7 @@ class PieChartStatisticViewModel @Inject constructor( accountDao = walletDAOs.accountDao ) - CategoryAmount(category, amount, trans) + CategoryAmount(category?.toDomain(), amount, trans) } }.awaitAll().sortedByDescending { it.amount } } @@ -183,7 +182,7 @@ class PieChartStatisticViewModel @Inject constructor( exchangeRatesLogic.toAmountBaseCurrency( transaction = it, baseCurrency = baseCurrencyCode.value, - accounts = walletDAOs.accountDao.findAll() + accounts = walletDAOs.accountDao.findAll().map { it.toDomain() } ) } CategoryAmount(transfersCategory, amt, trans) @@ -211,22 +210,26 @@ class PieChartStatisticViewModel @Inject constructor( _totalAmount.value = ioThread { when (type) { TransactionType.INCOME -> { - calculateWalletIncomeWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - range = range.toCloseTimeRange(), - accountIdFilterList = accountFilterList, - filterExcluded = filterExcluded - ).value.toDouble() + //TODO: Fix that +// calculateWalletIncomeWithAccountFilters( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode.value, +// range = range.toCloseTimeRange(), +// accountIdFilterList = accountFilterList, +// filterExcluded = filterExcluded +// ).value.toDouble() + 0.0 } TransactionType.EXPENSE -> { - calculateWalletExpenseWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - range = range.toCloseTimeRange(), - accountIdFilterList = accountFilterList, - filterExcluded = filterExcluded - ).value.toDouble() + //TODO: Fix that +// calculateWalletExpenseWithAccountFilters( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode.value, +// range = range.toCloseTimeRange(), +// accountIdFilterList = accountFilterList, +// filterExcluded = filterExcluded +// ).value.toDouble() + 0.0 } else -> error("not supported transactionType - $type") } @@ -247,22 +250,26 @@ class PieChartStatisticViewModel @Inject constructor( category = category, amount = when (type) { TransactionType.INCOME -> { - calculateCategoryIncomeWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - categoryId = category?.id, - accountIdFilterList = accountFilterList, - range = range.toCloseTimeRange() - ).toDouble() + //TODO: Fix that +// calculateCategoryIncomeWithAccountFilters( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode.value, +// categoryId = category?.id, +// accountIdFilterList = accountFilterList, +// range = range.toCloseTimeRange() +// ).toDouble() + 0.0 } TransactionType.EXPENSE -> { - calculateCategoryExpenseWithAccountFilters( - walletDAOs = walletDAOs, - baseCurrencyCode = baseCurrencyCode.value, - categoryId = category?.id, - accountIdList = accountFilterList, - range = range.toCloseTimeRange() - ).toDouble() + //TODO: Fix that +// calculateCategoryExpenseWithAccountFilters( +// walletDAOs = walletDAOs, +// baseCurrencyCode = baseCurrencyCode.value, +// categoryId = category?.id, +// accountIdList = accountFilterList, +// range = range.toCloseTimeRange() +// ).toDouble() + 0.0 } else -> error("not supported transactionType - $type") } @@ -329,15 +336,17 @@ class PieChartStatisticViewModel @Inject constructor( ): List { return scopedIOThread { scope -> if (fetchCategoriesFromTransactions) { - transactionDao.findAllBetween(timeRange.from(), timeRange.to()).filter { - it.categoryId != null - }.map { - scope.async { - categoryDao.findById(it.categoryId!!) - } - }.awaitAll().filterNotNull().distinctBy { it.id } + transactionDao.findAllBetween(timeRange.from(), timeRange.to()) + .map { it.toDomain() } + .filter { + it.categoryId != null + }.map { + scope.async { + categoryDao.findById(it.categoryId!!)?.toDomain() + } + }.awaitAll().filterNotNull().distinctBy { it.id } } else - categoryDao.findAll() + categoryDao.findAll().map { it.toDomain() } } } diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/SelectedCategory.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/SelectedCategory.kt index 6b355b4030..ca05361aba 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level1/SelectedCategory.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level1/SelectedCategory.kt @@ -1,6 +1,6 @@ package com.ivy.wallet.ui.statistic.level1 -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category data class SelectedCategory( val category: Category? //null - Unspecified diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticScreen.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticScreen.kt index 1a622fe669..8139f49541 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticScreen.kt @@ -30,9 +30,9 @@ import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.stringRes import com.ivy.wallet.ui.* import com.ivy.wallet.ui.onboarding.model.TimePeriod diff --git a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt index d3f4d9656b..82f18a1d65 100644 --- a/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/statistic/level2/ItemStatisticViewModel.kt @@ -4,22 +4,27 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import arrow.core.toOption import com.ivy.design.navigation.Navigation +import com.ivy.fp.action.then import com.ivy.wallet.R +import com.ivy.wallet.domain.action.account.AccTrnsAct +import com.ivy.wallet.domain.action.account.AccountsAct +import com.ivy.wallet.domain.action.account.CalcAccBalanceAct +import com.ivy.wallet.domain.action.account.CalcAccIncomeExpenseAct +import com.ivy.wallet.domain.action.category.CategoriesAct +import com.ivy.wallet.domain.action.exchange.ExchangeAct +import com.ivy.wallet.domain.action.settings.BaseCurrencyAct +import com.ivy.wallet.domain.action.transaction.TrnsWithDateDivsAct import com.ivy.wallet.domain.data.TransactionHistoryItem import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.domain.fp.account.calculateAccountBalance -import com.ivy.wallet.domain.fp.account.calculateAccountIncomeExpense -import com.ivy.wallet.domain.fp.data.WalletDAOs -import com.ivy.wallet.domain.fp.exchangeToBaseCurrency -import com.ivy.wallet.domain.fp.wallet.baseCurrencyCode -import com.ivy.wallet.domain.fp.wallet.withDateDividers -import com.ivy.wallet.domain.logic.* -import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic -import com.ivy.wallet.domain.sync.uploader.AccountUploader -import com.ivy.wallet.domain.sync.uploader.CategoryUploader +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction +import com.ivy.wallet.domain.deprecated.logic.* +import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic +import com.ivy.wallet.domain.deprecated.sync.uploader.AccountUploader +import com.ivy.wallet.domain.deprecated.sync.uploader.CategoryUploader +import com.ivy.wallet.domain.pure.data.WalletDAOs +import com.ivy.wallet.domain.pure.exchange.ExchangeData import com.ivy.wallet.io.persistence.dao.* import com.ivy.wallet.stringRes import com.ivy.wallet.ui.ItemStatistic @@ -52,6 +57,14 @@ class ItemStatisticViewModel @Inject constructor( private val accountCreator: AccountCreator, private val plannedPaymentsLogic: PlannedPaymentsLogic, private val exchangeRatesLogic: ExchangeRatesLogic, + private val categoriesAct: CategoriesAct, + private val accountsAct: AccountsAct, + private val accTrnsAct: AccTrnsAct, + private val trnsWithDateDivsAct: TrnsWithDateDivsAct, + private val baseCurrencyAct: BaseCurrencyAct, + private val calcAccBalanceAct: CalcAccBalanceAct, + private val calcAccIncomeExpenseAct: CalcAccIncomeExpenseAct, + private val exchangeAct: ExchangeAct ) : ViewModel() { private val _period = MutableStateFlow(ivyContext.selectedPeriod) @@ -134,12 +147,12 @@ class ItemStatisticViewModel @Inject constructor( viewModelScope.launch { _period.value = period ?: ivyContext.selectedPeriod - val baseCurrency = ioThread { baseCurrencyCode(settingsDao) } + val baseCurrency = baseCurrencyAct(Unit) _baseCurrency.value = baseCurrency _currency.value = baseCurrency - _categories.value = ioThread { categoryDao.findAll() } - _accounts.value = ioThread { accountDao.findAll() } + _categories.value = categoriesAct(Unit) + _accounts.value = accountsAct(Unit) _initWithTransactions.value = false when { @@ -177,7 +190,7 @@ class ItemStatisticViewModel @Inject constructor( private suspend fun initForAccount(accountId: UUID) { val account = ioThread { - accountDao.findById(accountId) ?: error("account not found") + accountDao.findById(accountId)?.toDomain() ?: error("account not found") } _account.value = account val range = period.value.toRange(ivyContext.startDayOfMonth) @@ -186,37 +199,46 @@ class ItemStatisticViewModel @Inject constructor( _currency.value = account.currency!! } - val balance = ioThread { - calculateAccountBalance( - transactionDao = walletDAOs.transactionDao, - accountId = accountId - ).toDouble() - } + val balance = calcAccBalanceAct( + CalcAccBalanceAct.Input( + account = account + ) + ).balance.toDouble() _balance.value = balance if (baseCurrency.value != currency.value) { - _balanceBaseCurrency.value = ioThread { - exchangeToBaseCurrency( - exchangeRateDao = exchangeRateDao, - baseCurrencyCode = baseCurrency.value, - fromCurrencyCode = currency.value.toOption(), - fromAmount = balance.toBigDecimal() - ).orNull()?.toDouble() - } + _balanceBaseCurrency.value = exchangeAct( + ExchangeAct.Input( + data = ExchangeData( + baseCurrency = baseCurrency.value, + fromCurrency = currency.value.toOption() + ), + amount = balance.toBigDecimal() + ) + ).orNull()?.toDouble() } - val incomeExpensePair = ioThread { - calculateAccountIncomeExpense( - transactionDao = transactionDao, - accountId = accountId, + val incomeExpensePair = calcAccIncomeExpenseAct( + CalcAccIncomeExpenseAct.Input( + account = account, range = range.toCloseTimeRange() ) - } + ).incomeExpensePair _income.value = incomeExpensePair.income.toDouble() _expenses.value = incomeExpensePair.expense.toDouble() - _history.value = ioThread { - accountLogic.historyForAccount(account, range) - } + _history.value = (accTrnsAct then { + trnsWithDateDivsAct( + TrnsWithDateDivsAct.Input( + baseCurrency = baseCurrency.value, + transactions = it + ) + ) + })( + AccTrnsAct.Input( + accountId = account.id, + range = range.toCloseTimeRange() + ) + ) //Upcoming _upcomingIncome.value = ioThread { @@ -244,7 +266,7 @@ class ItemStatisticViewModel @Inject constructor( private suspend fun initForCategory(categoryId: UUID, accountFilterList: List) { val accountFilterSet = accountFilterList.toSet() val category = ioThread { - categoryDao.findById(categoryId) ?: error("category not found") + categoryDao.findById(categoryId)?.toDomain() ?: error("category not found") } _category.value = category val range = period.value.toRange(ivyContext.startDayOfMonth) @@ -308,7 +330,7 @@ class ItemStatisticViewModel @Inject constructor( val accountFilterSet = accountFilterList.toSet() val category = ioThread { - categoryDao.findById(categoryId) ?: error("category not found") + categoryDao.findById(categoryId)?.toDomain() ?: error("category not found") } _category.value = category val range = period.value.toRange(ivyContext.startDayOfMonth) @@ -465,22 +487,21 @@ class ItemStatisticViewModel @Inject constructor( _income.value - _expenses.value + if (accountTransferCategoryEnabled) trans.filter { it.type == TransactionType.TRANSFER } - .sumOf { - exchangeRatesLogic.toAmountBaseCurrency( - transaction = it, - baseCurrency = baseCurrency.value, - accounts = walletDAOs.accountDao.findAll() - ) - } else 0.0 - } - - _history.value = ioThread { - trans.withDateDividers( - exchangeRateDao = exchangeRateDao, - accountDao = walletDAOs.accountDao, - baseCurrencyCode = baseCurrency.value + .sumOf { + exchangeRatesLogic.toAmountBaseCurrency( + transaction = it, + baseCurrency = baseCurrency.value, + accounts = accountsAct(Unit) + ) + } else 0.0 + } + + _history.value = trnsWithDateDivsAct( + TrnsWithDateDivsAct.Input( + baseCurrency = baseCurrency.value, + transactions = transactions ) - } + ) } private fun reset() { diff --git a/app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt b/app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt index 509396dd95..4a80bb1000 100644 --- a/app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import com.ivy.design.api.navigation -import com.ivy.wallet.domain.data.entity.User +import com.ivy.wallet.domain.data.core.User import com.ivy.wallet.ui.AnalyticsReport import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.Test diff --git a/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt index d8bd81a844..a988e7664b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt @@ -3,9 +3,9 @@ package com.ivy.wallet.ui.test import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.ivy.wallet.domain.data.entity.User -import com.ivy.wallet.domain.logic.notification.TransactionReminderLogic -import com.ivy.wallet.domain.sync.item.CategorySync +import com.ivy.wallet.domain.data.core.User +import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic +import com.ivy.wallet.domain.deprecated.sync.item.CategorySync import com.ivy.wallet.io.network.IvySession import com.ivy.wallet.io.persistence.dao.UserDao import com.ivy.wallet.utils.TestIdlingResource @@ -32,7 +32,7 @@ class TestViewModel @Inject constructor( _user.value = ioThread { val userId = ivySession.getUserIdSafe() - if (userId != null) userDao.findById(userId) else null + if (userId != null) userDao.findById(userId)?.toDomain() else null } TestIdlingResource.decrement() diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/components/WrapContentRow.kt b/app/src/main/java/com/ivy/wallet/ui/theme/components/WrapContentRow.kt index 95ffd68a5c..22baf4a433 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/components/WrapContentRow.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/components/WrapContentRow.kt @@ -18,7 +18,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.ivy.design.l0_system.UI -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt index 81b3daf04f..53dfa94db7 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/BudgetModal.kt @@ -14,7 +14,6 @@ import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.testTag -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardCapitalization @@ -24,11 +23,10 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style -import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Budget -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateBudgetData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Budget +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateBudgetData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.reports.ListItem import com.ivy.wallet.ui.theme.Green @@ -121,8 +119,7 @@ fun BoxWithConstraintsScope.BudgetModal( verticalAlignment = Alignment.CenterVertically ) { ModalTitle( - text = if (modal?.budget != null) stringResource(R.string.edit_budget) else stringResource( - R.string.create_budget) + text = if (modal?.budget != null) "Edit budget" else "Create budget" ) if (initialBudget != null) { @@ -140,7 +137,7 @@ fun BoxWithConstraintsScope.BudgetModal( Spacer(Modifier.height(24.dp)) ModalNameInput( - hint = stringResource(R.string.budget_name), + hint = "Budget name", autoFocusKeyboard = modal?.autoFocusKeyboard ?: true, textFieldValue = nameTextFieldValue, setTextFieldValue = { @@ -161,7 +158,7 @@ fun BoxWithConstraintsScope.BudgetModal( Spacer(Modifier.height(24.dp)) ModalAmountSection( - label = stringResource(R.string.budget_amount_uppercase), + label = "BUDGET AMOUNT", currency = modal?.baseCurrency ?: "", amount = amount, amountPaddingTop = 24.dp, @@ -186,8 +183,8 @@ fun BoxWithConstraintsScope.BudgetModal( DeleteModal( visible = deleteModalVisible, - title = stringResource(R.string.confirm_deletion), - description = stringResource(R.string.confirm_budget_deletion_warning, nameTextFieldValue.text), + title = "Confirm deletion", + description = "Are you sure that you want to delete \"${nameTextFieldValue.text}\" budget?", dismiss = { deleteModalVisible = false } ) { if (initialBudget != null) { diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt index a682999de1..42e88a716b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanModal.kt @@ -26,10 +26,10 @@ import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency import com.ivy.wallet.domain.data.LoanType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Loan -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Loan +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.ItemIconSDefaultIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt index ade51e898e..5c1e38fe50 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/LoanRecordModal.kt @@ -21,11 +21,11 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.LoanRecord -import com.ivy.wallet.domain.logic.model.CreateAccountData -import com.ivy.wallet.domain.logic.model.CreateLoanRecordData -import com.ivy.wallet.domain.logic.model.EditLoanRecordData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.LoanRecord +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData +import com.ivy.wallet.domain.deprecated.logic.model.CreateLoanRecordData +import com.ivy.wallet.domain.deprecated.logic.model.EditLoanRecordData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.ivyWalletCtx import com.ivy.wallet.ui.theme.components.ItemIconSDefaultIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt index f2871d7b37..a62f4d9656 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AccountModal.kt @@ -21,8 +21,8 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.IvyCurrency -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.logic.model.CreateAccountData +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.deprecated.logic.model.CreateAccountData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.Gray import com.ivy.wallet.ui.theme.Ivy diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AmountModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AmountModal.kt index 730e268d76..3121e28367 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AmountModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/AmountModal.kt @@ -271,21 +271,21 @@ fun AmountKeyboard( horizontalArrangement = Arrangement.Center ) { CircleNumberButton( - value = "1", + value = "7", onNumberPressed = onNumberPressed ) Spacer(Modifier.width(16.dp)) CircleNumberButton( - value = "2", + value = "8", onNumberPressed = onNumberPressed ) Spacer(Modifier.width(16.dp)) CircleNumberButton( - value = "3", + value = "9", onNumberPressed = onNumberPressed ) @@ -337,21 +337,21 @@ fun AmountKeyboard( horizontalArrangement = Arrangement.Center ) { CircleNumberButton( - value = "7", + value = "1", onNumberPressed = onNumberPressed ) Spacer(Modifier.width(16.dp)) CircleNumberButton( - value = "8", + value = "2", onNumberPressed = onNumberPressed ) Spacer(Modifier.width(16.dp)) CircleNumberButton( - value = "9", + value = "3", onNumberPressed = onNumberPressed ) diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt index 047f5a18b7..991aa7506b 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/CategoryModal.kt @@ -25,8 +25,8 @@ import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.logic.model.CreateCategoryData +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.deprecated.logic.model.CreateCategoryData import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.Ivy import com.ivy.wallet.ui.theme.components.ItemIconMDefaultIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/ChooseCategoryModal.kt b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/ChooseCategoryModal.kt index 4550113178..07d3d2ada2 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/ChooseCategoryModal.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/modal/edit/ChooseCategoryModal.kt @@ -21,7 +21,7 @@ import androidx.compose.ui.unit.dp import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R -import com.ivy.wallet.domain.data.entity.Category +import com.ivy.wallet.domain.data.core.Category import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.* import com.ivy.wallet.ui.theme.components.ItemIconSDefaultIcon diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt index d6346f6b12..ececf3fe25 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/TransactionCard.kt @@ -25,9 +25,9 @@ import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionType -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.ui.ItemStatistic import com.ivy.wallet.ui.IvyWalletPreview import com.ivy.wallet.ui.theme.* @@ -140,13 +140,13 @@ fun LazyItemScope.TransactionCard( transactionType = transaction.type, dueDate = transaction.dueDate, currency = transactionCurrency, - amount = transaction.amount + amount = transaction.amount.toDouble() ) if (transaction.type == TransactionType.TRANSFER && transaction.toAmount != null && toAccountCurrency != transactionCurrency) { Text( modifier = Modifier.padding(start = 68.dp), - text = "${transaction.toAmount.format(2)} $toAccountCurrency", + text = "${transaction.toAmount.toDouble().format(2)} $toAccountCurrency", style = UI.typo.nB2.style( color = Gray, fontWeight = FontWeight.Normal @@ -198,7 +198,7 @@ private fun TransactionHeaderRow( verticalAlignment = Alignment.CenterVertically ) { val category = - transaction.smartCategoryId() + transaction.categoryId ?.let { targetId -> categories.find { it.id == targetId } } if (category != null) { IvyButton( @@ -427,7 +427,7 @@ private fun PreviewUpcomingExpense() { accountId = cash.id, title = "Lidl pazar", categoryId = food.id, - amount = 250.75, + amount = 250.75.toBigDecimal(), dueDate = timeNowUTC().plusDays(5), dateTime = null, type = TransactionType.EXPENSE, @@ -458,7 +458,7 @@ private fun PreviewOverdueExpense() { accountId = cash.id, title = "Rent", categoryId = food.id, - amount = 500.0, + amount = 500.0.toBigDecimal(), dueDate = timeNowUTC().minusDays(5), dateTime = null, type = TransactionType.EXPENSE @@ -493,7 +493,7 @@ private fun PreviewNormalExpense() { accountId = cash.id, title = "Близкия магазин", categoryId = food.id, - amount = 32.51, + amount = 32.51.toBigDecimal(), dateTime = timeNowUTC(), type = TransactionType.EXPENSE ), @@ -522,7 +522,7 @@ private fun PreviewIncome() { accountId = cash.id, title = "Qredo Salary May", categoryId = category.id, - amount = 8049.70, + amount = 8049.70.toBigDecimal(), dateTime = timeNowUTC(), type = TransactionType.INCOME ), @@ -552,7 +552,7 @@ private fun PreviewTransfer() { accountId = acc1.id, toAccountId = acc2.id, title = "Top-up revolut", - amount = 1000.0, + amount = 1000.0.toBigDecimal(), dateTime = timeNowUTC(), type = TransactionType.TRANSFER ), diff --git a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/Transactions.kt b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/Transactions.kt index 3b48f8e8a8..75976ee907 100644 --- a/app/src/main/java/com/ivy/wallet/ui/theme/transaction/Transactions.kt +++ b/app/src/main/java/com/ivy/wallet/ui/theme/transaction/Transactions.kt @@ -9,7 +9,6 @@ import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Dp @@ -20,10 +19,9 @@ import com.ivy.design.navigation.Navigation import com.ivy.wallet.R import com.ivy.wallet.domain.data.TransactionHistoryDateDivider import com.ivy.wallet.domain.data.TransactionHistoryItem -import com.ivy.wallet.domain.data.entity.Account -import com.ivy.wallet.domain.data.entity.Category -import com.ivy.wallet.domain.data.entity.Transaction -import com.ivy.wallet.stringRes +import com.ivy.wallet.domain.data.core.Account +import com.ivy.wallet.domain.data.core.Category +import com.ivy.wallet.domain.data.core.Transaction import com.ivy.wallet.ui.EditTransaction import com.ivy.wallet.ui.IvyWalletCtx import com.ivy.wallet.ui.theme.Gray @@ -52,7 +50,7 @@ fun LazyListScope.transactions( history: List, lastItemSpacer: Dp? = null, onPayOrGet: (Transaction) -> Unit, - emptyStateTitle: String = stringRes(R.string.no_transactions), + emptyStateTitle: String = "No transactions", emptyStateText: String, dateDividerMarginTop: Dp? = null ) { @@ -61,7 +59,7 @@ fun LazyListScope.transactions( SectionDivider( expanded = upcomingExpanded, setExpanded = setUpcomingExpanded, - title = stringResource(R.string.upcoming), + title = "Upcoming", titleColor = Orange, baseCurrency = baseCurrency, income = upcomingIncome, @@ -93,7 +91,7 @@ fun LazyListScope.transactions( SectionDivider( expanded = overdueExpanded, setExpanded = setOverdueExpanded, - title = stringResource(R.string.overdue), + title = "Overdue", titleColor = Red, baseCurrency = baseCurrency, income = overdueIncome, diff --git a/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt b/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt index c251639973..dc72f5bdf5 100644 --- a/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/com/ivy/wallet/buildsrc/dependencies.kt @@ -46,6 +46,7 @@ fun DependencyHandler.appModuleDependencies( kotlinVersion: String = GlobalVersions.kotlinVersion ) { implementation(project(":ivy-design")) + implementation(project(":ivy-fp")) Kotlin(version = kotlinVersion) Coroutines(version = "1.5.0") @@ -91,6 +92,21 @@ fun DependencyHandler.ivyDesignModuleDependencies( Lifecycle(version = "2.3.1") } +fun DependencyHandler.ivyFPModuleDependencies( + kotlinVersion: String = GlobalVersions.kotlinVersion +) { + Kotlin(version = kotlinVersion) + Coroutines(version = "1.5.0") + FunctionalProgramming( + arrowVersion = "1.0.1", + kotestVersion = "5.1.0", + kotlinVersion = kotlinVersion + ) + + AndroidX() + Lifecycle(version = "2.3.1") +} + //--------------------------------------------------------------------------------- diff --git a/ivy-fp/.gitignore b/ivy-fp/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/ivy-fp/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/ivy-fp/build.gradle.kts b/ivy-fp/build.gradle.kts new file mode 100644 index 0000000000..51215e516c --- /dev/null +++ b/ivy-fp/build.gradle.kts @@ -0,0 +1,52 @@ +import com.ivy.wallet.buildsrc.Project +import com.ivy.wallet.buildsrc.ivyFPModuleDependencies + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") + id("kotlin-android") + id("kotlin-kapt") +} + +android { + compileSdk = Project.compileSdkVersion + + defaultConfig { + minSdk = Project.minSdk + targetSdk = Project.targetSdk + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = true + + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = "1.8" + } + + packagingOptions { + //Exclude this files so Jetpack Compose UI tests can build + resources.excludes.add("META-INF/AL2.0") + resources.excludes.add("META-INF/LGPL2.1") + //------------------------------------------------------- + } +} + +dependencies { + ivyFPModuleDependencies() +} \ No newline at end of file diff --git a/ivy-fp/consumer-rules.pro b/ivy-fp/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ivy-fp/proguard-rules.pro b/ivy-fp/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/ivy-fp/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/ivy-fp/src/androidTest/java/com/ivy/design/ExampleInstrumentedTest.kt b/ivy-fp/src/androidTest/java/com/ivy/design/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..272e42be83 --- /dev/null +++ b/ivy-fp/src/androidTest/java/com/ivy/design/ExampleInstrumentedTest.kt @@ -0,0 +1,22 @@ +package com.ivy.design + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.ivy.fp.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/ivy-fp/src/main/AndroidManifest.xml b/ivy-fp/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..6333616ab1 --- /dev/null +++ b/ivy-fp/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ivy-fp/src/main/java/com/ivy/fp/Composition.kt b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt new file mode 100644 index 0000000000..684c40b766 --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/Composition.kt @@ -0,0 +1,55 @@ +package com.ivy.fp + +import com.ivy.fp.action.Action + +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.SOURCE) +@MustBeDocumented +annotation class Pure + +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.SOURCE) +@MustBeDocumented +annotation class Total(val sideEffect: String = "") + +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.SOURCE) +@MustBeDocumented +annotation class Partial(val inCaseOf: String = "") + + +@Target(AnnotationTarget.VALUE_PARAMETER) +@Retention(AnnotationRetention.SOURCE) +@MustBeDocumented +annotation class SideEffect + +infix fun ((A) -> B).then(f: (B) -> C): (A) -> C = { a -> + val b = this(a) + f(b) +} + +infix fun ((B) -> C).after(fn1: (A) -> B): (A) -> C = { a -> + val b = fn1(a) + this(b) +} + +infix fun ((A, B) -> C).then(f: (C) -> D): (A, B) -> D = { a, b -> + val c = this(a, b) + f(c) +} + +infix fun ((A, B) -> C).then(act: Action): suspend (A, B) -> D = { a, b -> + val c = this(a, b) + act(c) +} + +suspend infix fun (suspend (A, B) -> C).then(f: suspend (C) -> D): suspend (A, B) -> D = + { a, b -> + val c = this(a, b) + f(c) + } + +infix fun ((A, B, C) -> D).then(f: (D) -> E): (A, B, C) -> E = { a, b, c -> + val d = this(a, b, c) + f(d) +} \ No newline at end of file diff --git a/ivy-fp/src/main/java/com/ivy/fp/Utils.kt b/ivy-fp/src/main/java/com/ivy/fp/Utils.kt new file mode 100644 index 0000000000..b6fbef2c2e --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/Utils.kt @@ -0,0 +1,19 @@ +package com.ivy.fp + +suspend fun List.sumOfSuspend( + selector: suspend (A) -> Double +): Double { + var sum = 0.0 + for (item in this) { + sum += selector(item) + } + return sum +} + +suspend fun Collection.filterSuspend( + predicate: suspend (A) -> Boolean +): Collection { + return this.filter { a -> + predicate(a) + } +} \ No newline at end of file diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/Action.kt b/ivy-fp/src/main/java/com/ivy/fp/action/Action.kt new file mode 100644 index 0000000000..cc3b8e728c --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/action/Action.kt @@ -0,0 +1,26 @@ +package com.ivy.fp.action + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +abstract class Action { + abstract suspend fun I.willDo(): O + + suspend operator fun invoke(input: I): O { + return input.willDo() + } + + protected suspend fun io(action: suspend () -> T): T = withContext(Dispatchers.IO) { + return@withContext action() + } + + protected suspend fun computation(action: suspend () -> T): T = + withContext(Dispatchers.Default) { + return@withContext action() + } + + protected suspend fun ui(action: suspend () -> T): T = + withContext(Dispatchers.Main) { + return@withContext action() + } +} \ No newline at end of file diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt b/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt new file mode 100644 index 0000000000..2e33c0b663 --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/action/Composition.kt @@ -0,0 +1,58 @@ +package com.ivy.fp.action + + +suspend infix fun (suspend (A) -> B).then(f: suspend (B) -> C): suspend (A) -> C = + { a -> + val b = this@then(a) + f(b) + } + +suspend infix fun (suspend () -> B).then(f: suspend (B) -> C): suspend () -> C = + { + val b = this@then() + f(b) + } + +suspend infix fun (suspend (A) -> B).then(act: Action): suspend (A) -> C = + { a -> + val b = this@then(a) + act(b) + } + +suspend infix fun (suspend () -> B).then(act: Action): suspend () -> C = + { + val b = this@then() + act(b) + } + +suspend infix fun (Action).then(f: suspend (B) -> C): suspend (A) -> C = + { a -> + val b = this@then(a) + f(b) + } + + +suspend infix fun (() -> B).then(f: suspend (B) -> C): suspend () -> C = + { + val b = this@then() + f(b) + } + +fun (() -> C).fixUnit(): suspend (Unit) -> C = + { + this() + } + +fun (suspend () -> C).fixUnit(): suspend (Unit) -> C = + { + this() + } + +fun (suspend (Unit) -> C).fixUnit(): suspend () -> C = + { + this(Unit) + } + +fun (Action).lambda(): suspend (A) -> B = { a -> + this(a) +} \ No newline at end of file diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt new file mode 100644 index 0000000000..2bc93750e7 --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionFilter.kt @@ -0,0 +1,28 @@ +package com.ivy.fp.action + +suspend infix fun (suspend (A) -> List).thenFilter( + predicate: (B) -> Boolean +): suspend (A) -> List = + { a -> + val list = this(a) + list.filter(predicate) + } + +suspend infix fun (Action>).thenFilter( + predicate: (B) -> Boolean +): suspend (A) -> List = + { a -> + val list = this(a) + list.filter(predicate) + } + + +suspend infix fun (suspend () -> List).thenFilter( + predicate: suspend (B) -> Boolean +): suspend () -> List = + { + val list = this() + list.filter { + predicate(it) + } + } diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt new file mode 100644 index 0000000000..ab160bf533 --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionMap.kt @@ -0,0 +1,51 @@ +package com.ivy.fp.action + +suspend infix fun (suspend (A) -> List).thenMap( + transform: suspend (B) -> C +): suspend (A) -> List = + { a -> + val list = this(a) + list.map { + transform(it) + } + } + +suspend infix fun (suspend () -> List).thenMap( + transform: suspend (B) -> C +): suspend () -> List = + { + val list = this() + list.map { + transform(it) + } + } + +suspend infix fun (suspend () -> List).thenFlatMap( + transform: suspend (B) -> List +): suspend () -> List = + { + val list = this() + list.flatMap { + transform(it) + } + } + +suspend infix fun (suspend () -> List).thenMap( + act: Action +): suspend () -> List = + { + val list = this() + list.map { + act(it) + } + } + +suspend infix fun (Action>).thenMap( + transform: suspend (B) -> C +): suspend (A) -> List = + { a -> + val list = this(a) + list.map { + transform(it) + } + } diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/CompositionSum.kt b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionSum.kt new file mode 100644 index 0000000000..72b42f7f47 --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/action/CompositionSum.kt @@ -0,0 +1,29 @@ +package com.ivy.fp.action + +import java.math.BigDecimal + +suspend infix fun (suspend (A) -> List).thenSum( + value: (B) -> BigDecimal +): suspend (A) -> BigDecimal = + { a -> + val list = this(a) + list.fold( + initial = BigDecimal.ZERO, + operation = { acc, b -> + acc + value(b) + } + ) + } + +suspend infix fun (Action>).thenSum( + value: (B) -> BigDecimal +): suspend (A) -> BigDecimal = + { a -> + val list = this(a) + list.fold( + initial = BigDecimal.ZERO, + operation = { acc, b -> + acc + value(b) + } + ) + } \ No newline at end of file diff --git a/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt b/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt new file mode 100644 index 0000000000..0283a4350d --- /dev/null +++ b/ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt @@ -0,0 +1,17 @@ +package com.ivy.fp.action + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +abstract class FPAction : Action() { + protected abstract suspend fun I.compose(): (suspend () -> O) + + protected open fun dispatcher(): CoroutineDispatcher = Dispatchers.IO + + override suspend fun I.willDo(): O { + return withContext(dispatcher()) { + compose().invoke() + } + } +} \ No newline at end of file diff --git a/ivy-design/src/main/java/com/ivy/design/viewmodel/IvyViewModel.kt b/ivy-fp/src/main/java/com/ivy/fp/viewmodel/IvyViewModel.kt similarity index 94% rename from ivy-design/src/main/java/com/ivy/design/viewmodel/IvyViewModel.kt rename to ivy-fp/src/main/java/com/ivy/fp/viewmodel/IvyViewModel.kt index 0773e2c062..9562f5fb97 100644 --- a/ivy-design/src/main/java/com/ivy/design/viewmodel/IvyViewModel.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/viewmodel/IvyViewModel.kt @@ -1,4 +1,4 @@ -package com.ivy.design.viewmodel +package com.ivy.fp.viewmodel import androidx.lifecycle.ViewModel import kotlinx.coroutines.flow.MutableStateFlow diff --git a/ivy-design/src/main/java/com/ivy/design/viewmodel/ViewmodelUtils.kt b/ivy-fp/src/main/java/com/ivy/fp/viewmodel/ViewmodelUtils.kt similarity index 83% rename from ivy-design/src/main/java/com/ivy/design/viewmodel/ViewmodelUtils.kt rename to ivy-fp/src/main/java/com/ivy/fp/viewmodel/ViewmodelUtils.kt index 28f36a8122..4d93e3baa9 100644 --- a/ivy-design/src/main/java/com/ivy/design/viewmodel/ViewmodelUtils.kt +++ b/ivy-fp/src/main/java/com/ivy/fp/viewmodel/ViewmodelUtils.kt @@ -1,4 +1,4 @@ -package com.ivy.design.viewmodel +package com.ivy.fp.viewmodel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow diff --git a/ivy-fp/src/test/java/com/ivy/design/ExampleUnitTest.kt b/ivy-fp/src/test/java/com/ivy/design/ExampleUnitTest.kt new file mode 100644 index 0000000000..08ade6083f --- /dev/null +++ b/ivy-fp/src/test/java/com/ivy/design/ExampleUnitTest.kt @@ -0,0 +1,16 @@ +package com.ivy.design + +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 707897c694..00c27d4b09 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,8 +1,5 @@ import java.net.URI -include(":ivy-design") - - dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { @@ -15,4 +12,7 @@ dependencyResolutionManagement { } rootProject.name = "Ivy Wallet" include(":app") +include(":ivy-design") +include(":ivy-fp") + \ No newline at end of file From d486dca84f55e4f162894dfce411618eab848090 Mon Sep 17 00:00:00 2001 From: code-a1 <68858676+code-a1@users.noreply.github.com> Date: Sun, 24 Apr 2022 23:45:35 +0200 Subject: [PATCH 39/40] Update --- .../main/java/com/ivy/wallet/domain/data/core/Budget.kt | 8 +++++--- app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt index 73ac44ad77..8cafaaabe4 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Budget.kt @@ -1,7 +1,9 @@ package com.ivy.wallet.domain.data.core +import com.ivy.wallet.R import com.ivy.wallet.io.network.data.BudgetDTO import com.ivy.wallet.io.persistence.data.BudgetEntity +import com.ivy.wallet.stringRes import java.util.* data class Budget( @@ -44,9 +46,9 @@ data class Budget( fun type(categoriesCount: Int): String { return when (categoriesCount) { - 0 -> "Total Budget" - 1 -> "Category Budget" - else -> "Multi-Category ($categoriesCount) Budget" + 0 -> stringRes(R.string.total_budget) + 1 -> stringRes(R.string.category_budget) + else -> stringRes(R.string.multi_category_budget, categoriesCount.toString()) } } } diff --git a/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt index 4646aa73a6..c7b61efca6 100644 --- a/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt +++ b/app/src/main/java/com/ivy/wallet/domain/data/core/Loan.kt @@ -1,8 +1,10 @@ package com.ivy.wallet.domain.data.core +import com.ivy.wallet.R import com.ivy.wallet.domain.data.LoanType import com.ivy.wallet.io.network.data.LoanDTO import com.ivy.wallet.io.persistence.data.LoanEntity +import com.ivy.wallet.stringRes import java.util.* data class Loan( @@ -44,6 +46,7 @@ data class Loan( ) fun humanReadableType(): String { - return if (type == LoanType.BORROW) "BORROWED" else "LENT" + return if (type == LoanType.BORROW) stringRes(R.string.borrowed_uppercase) else stringRes( + R.string.lent_uppercase) } } \ No newline at end of file From 69775af939c8b01d81ff30af8ac6d4132ad80caf Mon Sep 17 00:00:00 2001 From: Vishwa Raghavendra K S Date: Mon, 25 Apr 2022 14:12:38 +0530 Subject: [PATCH 40/40] Todo-Fix: CustomExchangeRate --- .../ui/edit/EditTransactionViewModel.kt | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt index f8c8fb2107..d6e32d5fbd 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt @@ -232,22 +232,20 @@ class EditTransactionViewModel @Inject constructor( updateCurrency(account = selectedAccount) - //TODO: Fix that -// transaction.toAmount?.let { -// val exchangeRate = it / transaction.amount -// val toAccountCurrency = -// _accounts.value?.find { acc -> acc.id == transaction.toAccountId }?.currency -// _customExchangeRateState.value = -// _customExchangeRateState.value.copy( -// showCard = toAccountCurrency != account.value?.currency, -// exchangeRate = exchangeRate, -// convertedAmount = it, -// toCurrencyCode = toAccountCurrency, -// fromCurrencyCode = currency.value -// ) -// } ?: let { -// _customExchangeRateState.value = CustomExchangeRateState() -// } + _customExchangeRateState.value = if (transaction.toAccountId == null) + CustomExchangeRateState() + else { + val exchangeRate = transaction.toAmount / transaction.amount + val toAccountCurrency = + _accounts.value.find { acc -> acc.id == transaction.toAccountId }?.currency + CustomExchangeRateState( + showCard = toAccountCurrency != account.value?.currency, + exchangeRate = exchangeRate.toDouble(), + convertedAmount = transaction.toAmount.toDouble(), + toCurrencyCode = toAccountCurrency, + fromCurrencyCode = currency.value + ) + } _displayLoanHelper.value = getDisplayLoanHelper(trans = transaction) }