From 0693b535279ad2f39b2011af7564a3a1c441826b Mon Sep 17 00:00:00 2001 From: Ngewi Fet Date: Tue, 28 Jan 2014 18:08:53 +0100 Subject: [PATCH] FIXME: double transactions for editing have wrong sign/type when opened Fixed: CASH accounts should be treated like asset accounts Fixed: Transaction type not properly loaded from database Fixed: Tab title color not shown for favorite/recent accounts immediately after app launch Fixed: Crash when opening and quickly navigating away from list of transactions due to back Added default commonly used account structure for de_AT locale Updated dialog confirmation text for creating default accounts Updated German translation Code refactoring --- app/res/menu/account_actions.xml | 16 +- .../default_accounts.gnucash | 0 app/res/raw-de-rDE/default_accounts.gnucash | 937 ++++++++++++++++++ app/res/values-de/strings.xml | 72 +- app/res/values-el/strings.xml | 6 +- app/res/values-es-rMX/strings.xml | 6 +- app/res/values-es/strings.xml | 6 +- app/res/values-fr/strings.xml | 6 +- app/res/values-hu/strings.xml | 6 +- app/res/values-it/strings.xml | 6 +- app/res/values-nb/strings.xml | 6 +- app/res/values-nl/strings.xml | 6 +- app/res/values-pt-rBR/strings.xml | 6 +- app/res/values-ru/strings.xml | 6 +- app/res/values-zh/strings.xml | 6 +- app/res/values/strings.xml | 10 +- app/src/org/gnucash/android/data/Account.java | 36 +- .../gnucash/android/db/AccountsDbAdapter.java | 16 +- .../android/db/TransactionsDbAdapter.java | 52 +- .../android/ui/accounts/AccountsActivity.java | 6 + .../ui/accounts/AccountsListFragment.java | 24 +- .../settings/AccountPreferencesFragment.java | 12 +- .../transactions/NewTransactionFragment.java | 41 +- .../ui/transactions/TransactionsActivity.java | 13 +- .../TransactionsListFragment.java | 113 ++- 25 files changed, 1231 insertions(+), 183 deletions(-) rename app/res/{raw-de => raw-de-rAT}/default_accounts.gnucash (100%) create mode 100644 app/res/raw-de-rDE/default_accounts.gnucash diff --git a/app/res/menu/account_actions.xml b/app/res/menu/account_actions.xml index 54cd64790..bbe9fe60b 100644 --- a/app/res/menu/account_actions.xml +++ b/app/res/menu/account_actions.xml @@ -20,15 +20,17 @@ android:icon="@drawable/content_new_holo_dark" android:title="@string/title_add_account" android:showAsAction="always"/> - - + + + + \ No newline at end of file diff --git a/app/res/raw-de/default_accounts.gnucash b/app/res/raw-de-rAT/default_accounts.gnucash similarity index 100% rename from app/res/raw-de/default_accounts.gnucash rename to app/res/raw-de-rAT/default_accounts.gnucash diff --git a/app/res/raw-de-rDE/default_accounts.gnucash b/app/res/raw-de-rDE/default_accounts.gnucash new file mode 100644 index 000000000..eb2ff7c19 --- /dev/null +++ b/app/res/raw-de-rDE/default_accounts.gnucash @@ -0,0 +1,937 @@ + + +1 +64 + + ISO4217 + EUR + + currency + + + + template + template + template + template + 1 + + + Root Account + 3f929f1b1e6b465511039499090d73c5 + ROOT + + + Aktiva + bb6283955ae5656075b24063dc1676cb + ASSET + + ISO4217 + EUR + + 100 + Aktiva + + + placeholder + true + + + color + #1469EB + + + 3f929f1b1e6b465511039499090d73c5 + + + Barvermögen + 506ae10d76ccdf86937d7f0daeb5f571 + ASSET + + ISO4217 + EUR + + 100 + Barvermögen + + + placeholder + true + + + bb6283955ae5656075b24063dc1676cb + + + Girokonto + 5552c0109c5d81e33b77b6e81e8fcddd + BANK + + ISO4217 + EUR + + 100 + Girokonto + 506ae10d76ccdf86937d7f0daeb5f571 + + + Sparkonto + 395382d69974593064920ee8360bb980 + BANK + + ISO4217 + EUR + + 100 + Sparkonto + 506ae10d76ccdf86937d7f0daeb5f571 + + + Bargeld + ec82b8b6f9804d11d6e5d73288882ed9 + CASH + + ISO4217 + EUR + + 100 + Bargeld + 506ae10d76ccdf86937d7f0daeb5f571 + + + Fremdkapital + 59f1baba8f40efd334098ab3bb2576ab + LIABILITY + + ISO4217 + EUR + + 100 + alle Verbindlichkeiten + + + placeholder + true + + + color + #B304AD + + + 3f929f1b1e6b465511039499090d73c5 + + + Barverbindlichkeiten + 49daf44dca0ab7c06d88bea1f0c0f95f + LIABILITY + + ISO4217 + EUR + + 100 + Barverbindlichkeiten (noch offenstehende Rechnungen) + + + placeholder + true + + + 59f1baba8f40efd334098ab3bb2576ab + + + Kreditkarte + d76e56c4846eb1050701a7d03c0276ac + CREDIT + + ISO4217 + EUR + + 100 + Kreditkarte + 49daf44dca0ab7c06d88bea1f0c0f95f + + + Erträge + fe0561366e2910da979c59c5076a49d2 + INCOME + + ISO4217 + EUR + + 100 + Erträge + + + placeholder + true + + + color + #319D67 + + + 3f929f1b1e6b465511039499090d73c5 + + + Gehalt + 14a86987d0fc5f26ac2cb261618df0c7 + INCOME + + ISO4217 + EUR + + 100 + Gehalt und Zulagen + + + placeholder + true + + + fe0561366e2910da979c59c5076a49d2 + + + Gehalt + a4c31f68479cc0a170af4c07056e8112 + INCOME + + ISO4217 + EUR + + 100 + Gehalt + 14a86987d0fc5f26ac2cb261618df0c7 + + + Zulagen + 6c4f5490ab74de015d49de590b07836f + INCOME + + ISO4217 + EUR + + 100 + Zulagen und Bonus zum Gehalt + 14a86987d0fc5f26ac2cb261618df0c7 + + + Geschenke + c1dbbbdcc5c85c6de7c5ccf95ba0222c + INCOME + + ISO4217 + EUR + + 100 + Empfangene Geschenke + fe0561366e2910da979c59c5076a49d2 + + + Sonstiges + e500acdffc4ee7fb15ee9f91398d2e80 + INCOME + + ISO4217 + EUR + + 100 + Sonstige Erträge + fe0561366e2910da979c59c5076a49d2 + + + Zinsen + afe7dd6e79c7f6672b23a49af8e49bac + INCOME + + ISO4217 + EUR + + 100 + Zinseinkommen + + + placeholder + true + + + fe0561366e2910da979c59c5076a49d2 + + + Girokonto + 2b6835e0f432520e17f1865e43e2be7a + INCOME + + ISO4217 + EUR + + 100 + Girokonto Zinsen + afe7dd6e79c7f6672b23a49af8e49bac + + + Sonstige + 92367d2b0fa0778a213d48f946e5abab + INCOME + + ISO4217 + EUR + + 100 + Sonstige Zinsen + afe7dd6e79c7f6672b23a49af8e49bac + + + Sparkonto + e6f3ee5b458744f695bd860789597c9a + INCOME + + ISO4217 + EUR + + 100 + Sparkonto Zinsen + afe7dd6e79c7f6672b23a49af8e49bac + + + Aufwendungen + ffa641d7627742e69687ae8bd7018e4e + EXPENSE + + ISO4217 + EUR + + 100 + Aufwendungen + + + placeholder + true + + + color + #D13E29 + + + 3f929f1b1e6b465511039499090d73c5 + + + Bildung + 563e690eff6bda293af526a006f1194e + EXPENSE + + ISO4217 + EUR + + 100 + Bildung + + + placeholder + true + + + ffa641d7627742e69687ae8bd7018e4e + + + Abonnements + 290d2b6e7d88faca102c7ac4c4030132 + EXPENSE + + ISO4217 + EUR + + 100 + Abonnements + 563e690eff6bda293af526a006f1194e + + + Bücher + eacf76f23223f82730927f3ac7186f03 + EXPENSE + + ISO4217 + EUR + + 100 + Bücher + 563e690eff6bda293af526a006f1194e + + + Büroartikel + 49ed449d4d977cecefa97cdcf1066373 + EXPENSE + + ISO4217 + EUR + + 100 + Büroartikel + 563e690eff6bda293af526a006f1194e + + + Zeitungen + 3a6af0fdb8595a0c40dbea382a0ae1a7 + EXPENSE + + ISO4217 + EUR + + 100 + Zeitungen + 563e690eff6bda293af526a006f1194e + + + Computer + 2966daddaab685f16c694d84e6572d07 + EXPENSE + + ISO4217 + EUR + + 100 + Computer + ffa641d7627742e69687ae8bd7018e4e + + + Fahrtkosten + 0eba091fb6c839b139915da94e41c436 + EXPENSE + + ISO4217 + EUR + + 100 + Fahrtkosten + + + placeholder + true + + + ffa641d7627742e69687ae8bd7018e4e + + + Fahrkarten + cfef57480ebbec97a1be62a46008a8fc + EXPENSE + + ISO4217 + EUR + + 100 + Fahrkarten Bus, Bahn, Flugzeug + 0eba091fb6c839b139915da94e41c436 + + + Geschenke + d0d91e0c938d91654ff3556affc139eb + EXPENSE + + ISO4217 + EUR + + 100 + Geschenke + ffa641d7627742e69687ae8bd7018e4e + + + Hobbies + 4247f9ed713922a57922f682b48caedb + EXPENSE + + ISO4217 + EUR + + 100 + Hobbies + ffa641d7627742e69687ae8bd7018e4e + + + Kleidung + ef1d7ea3b2e4f61c9be55947c71b9151 + EXPENSE + + ISO4217 + EUR + + 100 + Kleidung + ffa641d7627742e69687ae8bd7018e4e + + + Lebensmittel + 38d3e070b0e2bd51bb6755484aa9ca85 + EXPENSE + + ISO4217 + EUR + + 100 + Lebensmittel + ffa641d7627742e69687ae8bd7018e4e + + + Medikamente + fbc213b7469530ffc6fa8e65539b2c4d + EXPENSE + + ISO4217 + EUR + + 100 + Medikamente + ffa641d7627742e69687ae8bd7018e4e + + + Sonstiges + 0390c0ec401d77582e8b8997a67f4138 + EXPENSE + + ISO4217 + EUR + + 100 + Sonstiges + + + placeholder + true + + + ffa641d7627742e69687ae8bd7018e4e + + + Bankgebühren + 8149f9f52234d5c07c2c156d05ac6bb3 + EXPENSE + + ISO4217 + EUR + + 100 + Konto- und Bankgebühren + 0390c0ec401d77582e8b8997a67f4138 + + + Sonstiges + b2374ec9c7a86e218fbe3152c9117c64 + EXPENSE + + ISO4217 + EUR + + 100 + nicht aufgegliederte Ausgaben + 0390c0ec401d77582e8b8997a67f4138 + + + Spenden + 7b5425586aea52ce0a7aac120c5e3af9 + EXPENSE + + ISO4217 + EUR + + 100 + Wohltätige Spenden + ffa641d7627742e69687ae8bd7018e4e + + + Steuern + 008681ff038780e248d4b54447d5f7db + EXPENSE + + ISO4217 + EUR + + 100 + Steuern und Sozialabgaben + + + placeholder + true + + + ffa641d7627742e69687ae8bd7018e4e + + + Einkommenssteuer + 27bf8a087690bff2ad8f9c4369213293 + EXPENSE + + ISO4217 + EUR + + 100 + Einkommenssteuer + 008681ff038780e248d4b54447d5f7db + + + Pflegeversicherung + cad7aeba8266854070e9abdeb120a73d + EXPENSE + + ISO4217 + EUR + + 100 + Pflegeversicherung + 008681ff038780e248d4b54447d5f7db + + + Rentenversicherung + 6c9c7f7dac3354fcde65cf7bbd9e2c51 + EXPENSE + + ISO4217 + EUR + + 100 + Rentenversicherung + 008681ff038780e248d4b54447d5f7db + + + Solidarzuschlag + 033765ac68f31a08e844baf3c859d626 + EXPENSE + + ISO4217 + EUR + + 100 + Solidarzuschlag + 008681ff038780e248d4b54447d5f7db + + + Sonstige + 1fcbd312f9c76e1b8a7ee5a5cdeb9c89 + EXPENSE + + ISO4217 + EUR + + 100 + Sonstige Steuern + 008681ff038780e248d4b54447d5f7db + + + Sozialabgaben + 41f379aef9e82583079e0f431b21c5e4 + EXPENSE + + ISO4217 + EUR + + 100 + Sonstige Sozialabgaben + 008681ff038780e248d4b54447d5f7db + + + Telekommunikation + 61aaa0927d60049e8d8af14b8bc9caa3 + EXPENSE + + ISO4217 + EUR + + 100 + Telekommunikation + + + placeholder + true + + + ffa641d7627742e69687ae8bd7018e4e + + + Fernsehen + 54f22dcc8d2700b12afeb5159f6a9569 + EXPENSE + + ISO4217 + EUR + + 100 + GEZ und Kabelfernsehen + 61aaa0927d60049e8d8af14b8bc9caa3 + + + Online-Dienste + 9172576b59d1299931a1c9cb84a2743c + EXPENSE + + ISO4217 + EUR + + 100 + Online-Dienste + 61aaa0927d60049e8d8af14b8bc9caa3 + + + Telefon + c22fa6bba735490c8eb4107a83b2c71f + EXPENSE + + ISO4217 + EUR + + 100 + Telefon + 61aaa0927d60049e8d8af14b8bc9caa3 + + + Unterhaltung + 601efb35975bce5cca6278a6825e2339 + EXPENSE + + ISO4217 + EUR + + 100 + Unterhaltung + + + placeholder + true + + + ffa641d7627742e69687ae8bd7018e4e + + + Ausgehen + 1b96fd879ce1727c556976c57977aeed + EXPENSE + + ISO4217 + EUR + + 100 + Auswärts Essen + 601efb35975bce5cca6278a6825e2339 + + + Musik/Kino + 1f7e3b0e07787cf8a1ee85fa833da225 + EXPENSE + + ISO4217 + EUR + + 100 + Musik/Kino + 601efb35975bce5cca6278a6825e2339 + + + Reisen + a02d8f04599bdf6f22730fed7e841664 + EXPENSE + + ISO4217 + EUR + + 100 + Reisen + 601efb35975bce5cca6278a6825e2339 + + + Sport + 8131201ef42debd456438934eeaf5c6d + EXPENSE + + ISO4217 + EUR + + 100 + Sport + 601efb35975bce5cca6278a6825e2339 + + + Versicherungen + ae19542498b7869b10996934e7e76043 + EXPENSE + + ISO4217 + EUR + + 100 + Versicherungen + + + placeholder + true + + + ffa641d7627742e69687ae8bd7018e4e + + + Haftpflicht + a3c4edbdb87bb445254ee177aba3ef5c + EXPENSE + + ISO4217 + EUR + + 100 + Haftpflichtversicherung + ae19542498b7869b10996934e7e76043 + + + Krankenversicherung + 022087cc16c7115bdfcfec1e11f4e806 + EXPENSE + + ISO4217 + EUR + + 100 + Krankenversicherung + ae19542498b7869b10996934e7e76043 + + + Wohnen + bafbda77fb0c330593c1b767fcd493ad + EXPENSE + + ISO4217 + EUR + + 100 + Ausgaben für Wohnung/Haus + + + placeholder + true + + + ffa641d7627742e69687ae8bd7018e4e + + + Miete + 56759e7bab7c34324bffa512e6fb21d8 + EXPENSE + + ISO4217 + EUR + + 100 + Miete + bafbda77fb0c330593c1b767fcd493ad + + + Nebenkosten + 1e70f91bc100daab15a620cc03b3aa69 + EXPENSE + + ISO4217 + EUR + + 100 + Wohnnebenkosten + + + placeholder + true + + + bafbda77fb0c330593c1b767fcd493ad + + + Abfall + 50d4150d98ec5c05beefdb7b07a88269 + EXPENSE + + ISO4217 + EUR + + 100 + Abfallentsorgung + 1e70f91bc100daab15a620cc03b3aa69 + + + Gas + 837d03e3d8f7d3abe6b2f90606d5b6a7 + EXPENSE + + ISO4217 + EUR + + 100 + Gas + 1e70f91bc100daab15a620cc03b3aa69 + + + Strom + 278057b6c44ebabcb8abe27f07fb89de + EXPENSE + + ISO4217 + EUR + + 100 + Strom + 1e70f91bc100daab15a620cc03b3aa69 + + + Wasser + a082529a28f6b3f7ef97acf089b62708 + EXPENSE + + ISO4217 + EUR + + 100 + Wasser + 1e70f91bc100daab15a620cc03b3aa69 + + + Anfangsbestand + 9adade15378180f6b2fc74b3519044fe + EQUITY + + ISO4217 + EUR + + 100 + Anfangsbestand + + + color + #EE8600 + + + 3f929f1b1e6b465511039499090d73c5 + + + + + + diff --git a/app/res/values-de/strings.xml b/app/res/values-de/strings.xml index 63ad0b014..b12a249ad 100644 --- a/app/res/values-de/strings.xml +++ b/app/res/values-de/strings.xml @@ -316,42 +316,40 @@ Schließen Geben Sie einen Betrag ein um die Buchung speichern zu können - Import GnuCash Accounts - Import Accounts - An error occurred while importing the GnuCash accounts - GnuCash Accounts successfully imported + GnuCash Konten importieren + Konten importieren + Beim importieren von den GnuCash Konten ist einen Fehler aufgetreten! + GnuCash Konten wurden erfolgreich importiert Import account structure exported from GnuCash desktop - Import GnuCash accounts - Delete all accounts in the database. All transactions will be deleted as - well. + GnuCash Konten importieren + Alle Konten löschen. Alle Buchungen werden ebenfalls gelöscht! + Alle Konten löschen + Konten + Alle Konten wurden erfolgreich gelöscht + Wollen Sie wirklich ALLE Konten und Buchungen löschen? + \n\nDiese Operation kann nicht rückgängig gemacht werden! - Delete all accounts - Accounts - All accounts have been successfully deleted - Are you sure you want to delete all accounts and transactions? \nThis - operation cannot be undone! - - Account Type - All transactions in all accounts will be deleted! - Delete all transactions - All transactions successfully deleted! + Kontoart + Alle Buchungen in alle Konten werden gelöscht + Alle Buchungen löschen + Alle Buchungen wurden erfolgreich gelöscht Importing accounts Tap again to confirm. ALL entries will be deleted!! - Transactions - Sub-Accounts - Search - Default Export Format + Buchungen + Unterkonten + Suchen + Standard Export Format File format to use by default when exporting transactions - Export transactions… + Buchungen exportieren… Recurrence Ausgleichskonto - Exporting transactions - No recurring transactions to display. - Successfully deleted recurring transaction - Placeholder account - Default Transfer Account - Account Color & Type + Die Buchungen werden exportiert + Keine wiederkehrende Buchungen vorhanden + Die wiederkehrende Buchung wurde erfolgreich gelöscht + Platzhalter Konto + Standard Überweisungskonto + Kontofarbe & -art %d Unterkonto %d Unterkonten @@ -376,11 +374,15 @@ OFX - Select a Color - Delete sub-accounts - Recent - Favorites - All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! - Create default accounts + Farbe auswählen + Unterkonten löschen + Kürzlich + Favoriten + Alle + Erstellt die häufig verwendete standard GnuCash Konten + Standard Konten erstellen + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Wiederkehrende Buchungen \ No newline at end of file diff --git a/app/res/values-el/strings.xml b/app/res/values-el/strings.xml index c58c5250c..00ac5a362 100644 --- a/app/res/values-el/strings.xml +++ b/app/res/values-el/strings.xml @@ -395,6 +395,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values-es-rMX/strings.xml b/app/res/values-es-rMX/strings.xml index 58e5a4b0a..5fffe80f0 100644 --- a/app/res/values-es-rMX/strings.xml +++ b/app/res/values-es-rMX/strings.xml @@ -379,6 +379,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values-es/strings.xml b/app/res/values-es/strings.xml index b27c9b8de..b9e022aa2 100644 --- a/app/res/values-es/strings.xml +++ b/app/res/values-es/strings.xml @@ -379,6 +379,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values-fr/strings.xml b/app/res/values-fr/strings.xml index c9c807bd7..fd6fffd9c 100644 --- a/app/res/values-fr/strings.xml +++ b/app/res/values-fr/strings.xml @@ -377,6 +377,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions \ No newline at end of file diff --git a/app/res/values-hu/strings.xml b/app/res/values-hu/strings.xml index 5d06bad79..74110e4dc 100644 --- a/app/res/values-hu/strings.xml +++ b/app/res/values-hu/strings.xml @@ -380,6 +380,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions \ No newline at end of file diff --git a/app/res/values-it/strings.xml b/app/res/values-it/strings.xml index f62434159..ebb2f657d 100644 --- a/app/res/values-it/strings.xml +++ b/app/res/values-it/strings.xml @@ -380,6 +380,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values-nb/strings.xml b/app/res/values-nb/strings.xml index 4876942f6..c7bcb29d8 100644 --- a/app/res/values-nb/strings.xml +++ b/app/res/values-nb/strings.xml @@ -382,6 +382,10 @@ format og importeres i regnskapsprogrammet GnuCash for PC. Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values-nl/strings.xml b/app/res/values-nl/strings.xml index 467a981b6..9c1eec8cb 100644 --- a/app/res/values-nl/strings.xml +++ b/app/res/values-nl/strings.xml @@ -381,6 +381,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values-pt-rBR/strings.xml b/app/res/values-pt-rBR/strings.xml index 7dc3df5bc..3230b66d1 100644 --- a/app/res/values-pt-rBR/strings.xml +++ b/app/res/values-pt-rBR/strings.xml @@ -379,6 +379,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values-ru/strings.xml b/app/res/values-ru/strings.xml index 434369cae..d85fccdae 100644 --- a/app/res/values-ru/strings.xml +++ b/app/res/values-ru/strings.xml @@ -377,6 +377,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values-zh/strings.xml b/app/res/values-zh/strings.xml index 2b37e4695..aae41e9d4 100644 --- a/app/res/values-zh/strings.xml +++ b/app/res/values-zh/strings.xml @@ -377,6 +377,10 @@ Recent Favorites All - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/res/values/strings.xml b/app/res/values/strings.xml index ef1163b5d..c889147db 100644 --- a/app/res/values/strings.xml +++ b/app/res/values/strings.xml @@ -523,7 +523,7 @@ Delete all accounts Accounts All accounts have been successfully deleted - Are you sure you want to delete all accounts and transactions? \nThis + Are you sure you want to delete all accounts and transactions? \n\nThis operation cannot be undone! Account Type @@ -539,7 +539,7 @@ Default Export Format default_export_format File format to use by default when exporting transactions - Export transactions... + Export transactions… Recurrence Imbalance @@ -615,6 +615,10 @@ Favorites All create_default_accounts - Creates default GnuCash account structure. All current accounts (and transactions) will be deleted! + Creates default GnuCash commonly-used account structure Create default accounts + New accounts will be created in addition to the existing + account structure.\n\nIf you wish to replace currently existing accounts, delete them first before proceeding! + + Recurring Transactions diff --git a/app/src/org/gnucash/android/data/Account.java b/app/src/org/gnucash/android/data/Account.java index dd6e053ea..6e4a6e8d6 100644 --- a/app/src/org/gnucash/android/data/Account.java +++ b/app/src/org/gnucash/android/data/Account.java @@ -20,6 +20,7 @@ import org.gnucash.android.db.AccountsDbAdapter; import org.gnucash.android.export.ofx.OfxExporter; import org.gnucash.android.export.qif.QifHelper; +import org.gnucash.android.data.Transaction.TransactionType; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -70,34 +71,43 @@ public class Account { * they are currently not used except for exporting */ public enum AccountType { - CASH, BANK, CREDIT, ASSET(true), LIABILITY, INCOME, EXPENSE(true), - PAYABLE, RECEIVABLE, EQUITY, CURRENCY, STOCK, MUTUAL, ROOT; + CASH(TransactionType.DEBIT), BANK, CREDIT, ASSET(TransactionType.DEBIT), LIABILITY, INCOME, + EXPENSE(TransactionType.DEBIT), PAYABLE, RECEIVABLE, EQUITY, CURRENCY, STOCK, MUTUAL, ROOT; /** - * Indicates that this type of account has an inverted state for credits and debits. - * Credits decrease the account balance, while debits increase it. + * Indicates that this type of normal balance the account type has + *

To increase the value of an account with normal balance of credit, one would credit the account. + * To increase the value of an account with normal balance of debit, one would likewise debit the account.

*/ - private boolean mInvertedCredit = false; + private TransactionType mNormalBalance = TransactionType.CREDIT; - private AccountType(boolean invertedCredit){ - mInvertedCredit = invertedCredit; + private AccountType(TransactionType normalBalance){ + this.mNormalBalance = normalBalance; } private AccountType() { //nothing to see here, move along } - public boolean hasInvertedCredit(){ - return mInvertedCredit; + public boolean hasDebitNormalBalance(){ + return mNormalBalance == TransactionType.DEBIT; } - }; + + /** + * Returns the type of normal balance this account possesses + * @return TransactionType balance of the account type + */ + public TransactionType getNormalBalanceType(){ + return mNormalBalance; + } + } /** * Accounts types which are used by the OFX standard */ - public enum OfxAccountType {CHECKING, SAVINGS, MONEYMRKT, CREDITLINE }; - - /** + public enum OfxAccountType {CHECKING, SAVINGS, MONEYMRKT, CREDITLINE } + + /** * Unique Identifier of the account * It is generated when the account is created and can be set a posteriori as well */ diff --git a/app/src/org/gnucash/android/db/AccountsDbAdapter.java b/app/src/org/gnucash/android/db/AccountsDbAdapter.java index 1cd306ace..a928f4312 100644 --- a/app/src/org/gnucash/android/db/AccountsDbAdapter.java +++ b/app/src/org/gnucash/android/db/AccountsDbAdapter.java @@ -360,16 +360,7 @@ public String getAccountColorCode(long accountId){ * @return {@link AccountType} of the account */ public AccountType getAccountType(String uid){ - String type = null; - Cursor c = mDb.query(DatabaseHelper.ACCOUNTS_TABLE_NAME, - new String[]{DatabaseHelper.KEY_TYPE}, - DatabaseHelper.KEY_UID + "='" + uid + "'", - null, null, null, null); - if (c != null && c.moveToFirst()){ - type = c.getString(0); //0 because we requested only the type column - c.close(); - } - return AccountType.valueOf(type); + return mTransactionsAdapter.getAccountType(uid); } /** @@ -562,7 +553,7 @@ public Cursor fetchTopLevelAccounts(){ public Cursor fetchRecentAccounts(int numberOfRecents){ Cursor recentTxCursor = mDb.query(true, DatabaseHelper.TRANSACTIONS_TABLE_NAME, new String[]{DatabaseHelper.KEY_ACCOUNT_UID}, - null, null, null, null, DatabaseHelper.KEY_TIMESTAMP, Integer.toString(numberOfRecents)); + null, null, null, null, DatabaseHelper.KEY_TIMESTAMP + " DESC", Integer.toString(numberOfRecents)); StringBuilder recentAccountUIDs = new StringBuilder("("); while (recentTxCursor.moveToNext()){ String uid = recentTxCursor.getString(recentTxCursor.getColumnIndexOrThrow(DatabaseHelper.KEY_ACCOUNT_UID)); @@ -698,6 +689,9 @@ public String getCurrencyCode(String accountUID){ * @see #getFullyQualifiedAccountName(String) */ public String getAccountName(String accountUID){ + if (accountUID == null) + return null; + Cursor cursor = mDb.query(DatabaseHelper.ACCOUNTS_TABLE_NAME, new String[]{DatabaseHelper.KEY_ROW_ID, DatabaseHelper.KEY_NAME}, DatabaseHelper.KEY_UID + " = ?", diff --git a/app/src/org/gnucash/android/db/TransactionsDbAdapter.java b/app/src/org/gnucash/android/db/TransactionsDbAdapter.java index ac44ebe40..ed9c1fd55 100644 --- a/app/src/org/gnucash/android/db/TransactionsDbAdapter.java +++ b/app/src/org/gnucash/android/db/TransactionsDbAdapter.java @@ -16,21 +16,19 @@ package org.gnucash.android.db; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Currency; -import java.util.List; - -import com.sun.swing.internal.plaf.metal.resources.metal_pt_BR; -import org.gnucash.android.data.Account; -import org.gnucash.android.data.Money; -import org.gnucash.android.data.Transaction; - import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteStatement; import android.util.Log; +import org.gnucash.android.data.Account; +import org.gnucash.android.data.Money; +import org.gnucash.android.data.Transaction; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Currency; +import java.util.List; /** * Manages persistence of {@link Transaction}s in the database @@ -108,11 +106,11 @@ public long fetchTransactionWithUID(String uid){ * @return {@link Transaction} object corresponding to database record */ public Transaction getTransaction(long rowId){ - Transaction transaction = null; if (rowId <= 0) - return transaction; + return null; Log.v(TAG, "Fetching transaction with id " + rowId); + Transaction transaction = null; Cursor c = fetchRecord(DatabaseHelper.TRANSACTIONS_TABLE_NAME, rowId); if (c != null && c.moveToFirst()){ transaction = buildTransactionInstance(c); @@ -214,7 +212,8 @@ public Transaction buildTransactionInstance(Cursor c){ transaction.setExported(c.getInt(DatabaseAdapter.COLUMN_EXPORTED) == 1); transaction.setDoubleEntryAccountUID(doubleAccountUID); transaction.setRecurrencePeriod(recurrencePeriod); - + transaction.setTransactionType(Transaction.TransactionType.valueOf(c.getString(DatabaseAdapter.COLUMN_TYPE))); + return transaction; } @@ -325,8 +324,7 @@ public int getTransactionsCount(long accountId){ public long getAllTransactionsCount(){ String sql = "SELECT COUNT(*) FROM " + DatabaseHelper.TRANSACTIONS_TABLE_NAME; SQLiteStatement statement = mDb.compileStatement(sql); - long count = statement.simpleQueryForLong(); - return count; + return statement.simpleQueryForLong(); } /** @@ -336,6 +334,7 @@ public long getAllTransactionsCount(){ * @return Sum of transactions belonging to the account */ public Money getTransactionsSum(long accountId){ + //FIXME: Properly compute the balance while considering normal account balance String accountUID = getAccountUID(accountId); String querySum = "SELECT TOTAL(" + DatabaseHelper.KEY_AMOUNT @@ -365,8 +364,7 @@ public Money getTransactionsSum(long accountId){ BigDecimal sumDecimal = new BigDecimal(sum); Currency currency = Currency.getInstance(getCurrencyCode(accountUID)); - Money transactionSum = new Money(sumDecimal, currency); - return transactionSum; + return new Money(sumDecimal, currency); } /** @@ -378,7 +376,25 @@ public Money getTransactionsSum(long accountId){ public boolean isSameAccount(long rowId, String accountUID){ return getAccountID(accountUID) == rowId; } - + + /** + * Returns the {@link Account.AccountType} of the account with unique ID uid + * @param accountUID Unique ID of the account + * @return {@link Account.AccountType} of the account + */ + public Account.AccountType getAccountType(String accountUID){ + String type = null; + Cursor c = mDb.query(DatabaseHelper.ACCOUNTS_TABLE_NAME, + new String[]{DatabaseHelper.KEY_TYPE}, + DatabaseHelper.KEY_UID + "='" + accountUID + "'", + null, null, null, null); + if (c != null && c.moveToFirst()){ + type = c.getString(c.getColumnIndexOrThrow(DatabaseHelper.KEY_TYPE)); + c.close(); + } + return Account.AccountType.valueOf(type); + } + /** * Marks an account record as exported * @param accountUID Unique ID of the record to be marked as exported diff --git a/app/src/org/gnucash/android/ui/accounts/AccountsActivity.java b/app/src/org/gnucash/android/ui/accounts/AccountsActivity.java index 62e0ed225..6c089bdc8 100644 --- a/app/src/org/gnucash/android/ui/accounts/AccountsActivity.java +++ b/app/src/org/gnucash/android/ui/accounts/AccountsActivity.java @@ -261,6 +261,12 @@ private void init() { } } + @Override + protected void onResume() { + super.onResume(); + TransactionsActivity.sLastTitleColor = -1; + } + /** * Checks if the minor version has been increased and displays the What's New dialog box. * This is the minor version as per semantic versioning. diff --git a/app/src/org/gnucash/android/ui/accounts/AccountsListFragment.java b/app/src/org/gnucash/android/ui/accounts/AccountsListFragment.java index 9ca0ffba5..2a27be039 100644 --- a/app/src/org/gnucash/android/ui/accounts/AccountsListFragment.java +++ b/app/src/org/gnucash/android/ui/accounts/AccountsListFragment.java @@ -37,7 +37,10 @@ import android.support.v4.widget.SimpleCursorAdapter; import android.text.TextUtils; import android.util.Log; -import android.view.*; +import android.view.LayoutInflater; +import android.view.TouchDelegate; +import android.view.View; +import android.view.ViewGroup; import android.widget.*; import android.widget.AdapterView.OnItemLongClickListener; import com.actionbarsherlock.app.ActionBar; @@ -48,7 +51,6 @@ import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; -import com.viewpagerindicator.TitlePageIndicator; import org.gnucash.android.R; import org.gnucash.android.data.Account; import org.gnucash.android.data.Money; @@ -772,14 +774,16 @@ public View getView(int position, View convertView, ViewGroup parent) { parentView.post(new Runnable() { @Override public void run() { - final android.graphics.Rect hitRect = new Rect(); - float extraPadding = getResources().getDimension(R.dimen.edge_padding); - addTransactionButton.getHitRect(hitRect); - hitRect.right += extraPadding; - hitRect.bottom += extraPadding; - hitRect.top -= extraPadding; - hitRect.left -= extraPadding; - parentView.setTouchDelegate(new TouchDelegate(hitRect, addTransactionButton)); + if (isAdded()){ //may be run when fragment has been unbound from activity + final android.graphics.Rect hitRect = new Rect(); + float extraPadding = getResources().getDimension(R.dimen.edge_padding); + addTransactionButton.getHitRect(hitRect); + hitRect.right += extraPadding; + hitRect.bottom += extraPadding; + hitRect.top -= extraPadding; + hitRect.left -= extraPadding; + parentView.setTouchDelegate(new TouchDelegate(hitRect, addTransactionButton)); + } } }); diff --git a/app/src/org/gnucash/android/ui/settings/AccountPreferencesFragment.java b/app/src/org/gnucash/android/ui/settings/AccountPreferencesFragment.java index d8f9c4cc2..44d318b83 100644 --- a/app/src/org/gnucash/android/ui/settings/AccountPreferencesFragment.java +++ b/app/src/org/gnucash/android/ui/settings/AccountPreferencesFragment.java @@ -23,6 +23,7 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; +import android.view.ContextThemeWrapper; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockPreferenceActivity; import org.gnucash.android.R; @@ -74,18 +75,17 @@ public boolean onPreferenceClick(Preference preference) { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(getActivity()) - .setTitle("Confirm") - .setMessage("The new accounts will be created in addition to the existing account structure. " + - "Any accounts with the same ID, they will simple be updated." + - "If you wish to replace any currently existing accounts, delete them first before continuing this action!") - .setPositiveButton("Create Accounts", new DialogInterface.OnClickListener() { + .setTitle(R.string.title_create_default_accounts) + .setMessage(R.string.message_create_default_accounts_confirmation) + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton(R.string.btn_create_accounts, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { InputStream accountFileInputStream = getResources().openRawResource(R.raw.default_accounts); new AccountsActivity.AccountImporterTask(getActivity()).execute(accountFileInputStream); } }) - .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + .setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); diff --git a/app/src/org/gnucash/android/ui/transactions/NewTransactionFragment.java b/app/src/org/gnucash/android/ui/transactions/NewTransactionFragment.java index 9dd437482..f6b9ef050 100644 --- a/app/src/org/gnucash/android/ui/transactions/NewTransactionFragment.java +++ b/app/src/org/gnucash/android/ui/transactions/NewTransactionFragment.java @@ -255,20 +255,17 @@ public void onActivityCreated(Bundle savedInstanceState) { /** * Toggles the state transaction type button in response to the type of account. + * This just changes what label is shown to the user, but basically the button in checked state still + * represents a negative amount, and unchecked is positive. The CREDIT/DEBIT label depends on the account. * Different types of accounts handle CREDITS/DEBITS differently */ private void toggleTransactionTypeState() { - switch (mAccountType) { - case ASSET: - case EXPENSE: - mTransactionTypeButton.setTextOff(getString(R.string.label_debit)); - mTransactionTypeButton.setTextOn(getString(R.string.label_credit)); - break; - - default: - mTransactionTypeButton.setTextOff(getString(R.string.label_credit)); - mTransactionTypeButton.setTextOn(getString(R.string.label_debit)); - break; + if (mAccountType.hasDebitNormalBalance()){ + mTransactionTypeButton.setTextOff(getString(R.string.label_debit)); + mTransactionTypeButton.setTextOn(getString(R.string.label_credit)); + } else { + mTransactionTypeButton.setTextOff(getString(R.string.label_credit)); + mTransactionTypeButton.setTextOn(getString(R.string.label_debit)); } mTransactionTypeButton.invalidate(); } @@ -321,7 +318,17 @@ public void onItemClick(AdapterView adapterView, View view, int position, lon */ private void initializeViewsWithTransaction(){ mNameEditText.setText(mTransaction.getName()); - mTransactionTypeButton.setChecked(mTransaction.getTransactionType() == TransactionType.DEBIT); + + //FIXME: Better handle the different kinds of accounts and how transfers between the different types affect balance + //checking the type button means the amount will be shown as negative (in red) to user +// if (mAccountType.hasDebitNormalBalance()){ +// mTransactionTypeButton.setChecked(); +// mTransactionTypeButton.setChecked(mTransaction.getTransactionType() == TransactionType.CREDIT); +// } +// else { +// mTransactionTypeButton.setChecked(mTransaction.getTransactionType() == TransactionType.DEBIT); +// } + mTransactionTypeButton.setChecked(mTransaction.getTransactionType() == TransactionType.DEBIT); if (!mAmountManuallyEdited){ //when autocompleting, only change the amount if the user has not manually changed it already mAmountEditText.setText(mTransaction.getAmount().toPlainString()); @@ -363,12 +370,12 @@ private void initalizeViews() { String typePref = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(getString(R.string.key_default_transaction_type), "DEBIT"); if (typePref.equals("CREDIT")){ - if (mAccountType == Account.AccountType.ASSET || mAccountType == Account.AccountType.EXPENSE) + if (mAccountType.hasDebitNormalBalance()) mTransactionTypeButton.setChecked(false); else mTransactionTypeButton.setChecked(true); - } else { - if (mAccountType == Account.AccountType.ASSET || mAccountType == Account.AccountType.EXPENSE) + } else { //DEBIT + if (mAccountType.hasDebitNormalBalance()) mTransactionTypeButton.setChecked(true); else mTransactionTypeButton.setChecked(false); @@ -541,7 +548,7 @@ public void onAccountChanged(long newAccountId){ toggleTransactionTypeState(); //if the new account has a different credit/debit philosophy as the previous one, then toggle the button - if (mAccountType.hasInvertedCredit() != previousAccountType.hasInvertedCredit()){ + if (mAccountType.hasDebitNormalBalance() != previousAccountType.hasDebitNormalBalance()){ mTransactionTypeButton.toggle(); } @@ -568,7 +575,7 @@ private void saveNewTransaction() { Currency currency = Currency.getInstance(mTransactionsDbAdapter.getCurrencyCode(accountID)); Money amount = new Money(amountBigd, currency); TransactionType type; - if (mAccountType.hasInvertedCredit()){ + if (mAccountType.hasDebitNormalBalance()){ type = amount.isNegative() ? TransactionType.CREDIT : TransactionType.DEBIT; } else type = amount.isNegative() ? TransactionType.DEBIT : TransactionType.CREDIT; diff --git a/app/src/org/gnucash/android/ui/transactions/TransactionsActivity.java b/app/src/org/gnucash/android/ui/transactions/TransactionsActivity.java index 2d03994b4..ed5296d4c 100644 --- a/app/src/org/gnucash/android/ui/transactions/TransactionsActivity.java +++ b/app/src/org/gnucash/android/ui/transactions/TransactionsActivity.java @@ -120,7 +120,7 @@ public class TransactionsActivity extends SherlockFragmentActivity implements * This is the last known color for the title indicator. * This is used to remember the color of the top level account if the child account doesn't have one. */ - private static int sLastTitleColor; + public static int sLastTitleColor = -1; private TextView mSectionHeaderTransactions; private TitlePageIndicator mTitlePageIndicator; @@ -273,6 +273,8 @@ protected void onCreate(Bundle savedInstanceState) { mTitlePageIndicator = (TitlePageIndicator) findViewById(R.id.titles); mSectionHeaderTransactions = (TextView) findViewById(R.id.section_header_transactions); + if (sLastTitleColor == -1) //if this is first launch of app. Previous launches would have set the color already + sLastTitleColor = getResources().getColor(R.color.title_green); mAccountId = getIntent().getLongExtra( TransactionsListFragment.SELECTED_ACCOUNT_ID, -1); @@ -330,16 +332,7 @@ protected void onResume() { private void setTitleIndicatorColor() { //Basically, if we are in a top level account, use the default title color. //but propagate a parent account's title color to children who don't have own color - String parentAccountUID = mAccountsDbAdapter.getParentAccountUID(mAccountId); String colorCode = mAccountsDbAdapter.getAccountColorCode(mAccountId); - if (parentAccountUID == null - || parentAccountUID.equals(mAccountsDbAdapter.getGnuCashRootAccountUID())) { - sLastTitleColor = getResources().getColor(R.color.title_green); - } else { - String parentColor = mAccountsDbAdapter.getAccountColorCode(mAccountsDbAdapter.getAccountID(parentAccountUID)); - sLastTitleColor = parentColor != null ? Color.parseColor(parentColor) : sLastTitleColor; - } - if (colorCode != null){ sLastTitleColor = Color.parseColor(colorCode); } diff --git a/app/src/org/gnucash/android/ui/transactions/TransactionsListFragment.java b/app/src/org/gnucash/android/ui/transactions/TransactionsListFragment.java index b7c44464a..570a2e97f 100644 --- a/app/src/org/gnucash/android/ui/transactions/TransactionsListFragment.java +++ b/app/src/org/gnucash/android/ui/transactions/TransactionsListFragment.java @@ -47,9 +47,11 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import org.gnucash.android.R; -import org.gnucash.android.data.Account; import org.gnucash.android.data.Money; -import org.gnucash.android.db.*; +import org.gnucash.android.db.DatabaseAdapter; +import org.gnucash.android.db.DatabaseCursorLoader; +import org.gnucash.android.db.DatabaseHelper; +import org.gnucash.android.db.TransactionsDbAdapter; import org.gnucash.android.ui.Refreshable; import org.gnucash.android.ui.accounts.AccountsListFragment; import org.gnucash.android.ui.widget.WidgetConfigurationActivity; @@ -412,14 +414,16 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { parentView.post(new Runnable() { @Override public void run() { - float extraPadding = getResources().getDimension(R.dimen.edge_padding); - final android.graphics.Rect hitRect = new Rect(); - checkBoxView.getHitRect(hitRect); - hitRect.right += extraPadding; - hitRect.bottom += 3*extraPadding; - hitRect.top -= extraPadding; - hitRect.left -= 2*extraPadding; - parentView.setTouchDelegate(new TouchDelegate(hitRect, checkBoxView)); + if (isAdded()){ //may be run when fragment has been unbound from activity + float extraPadding = getResources().getDimension(R.dimen.edge_padding); + final android.graphics.Rect hitRect = new Rect(); + checkBoxView.getHitRect(hitRect); + hitRect.right += extraPadding; + hitRect.bottom += 3*extraPadding; + hitRect.top -= extraPadding; + hitRect.left -= 2*extraPadding; + parentView.setTouchDelegate(new TouchDelegate(hitRect, checkBoxView)); + } } }); @@ -433,12 +437,20 @@ public void bindView(View view, Context context, Cursor cursor) { Money amount = new Money( cursor.getString(DatabaseAdapter.COLUMN_AMOUNT), mTransactionsDbAdapter.getCurrencyCode(mAccountID)); - + + //FIXME: Take normal account balances into consideration for double entries +// String mainAccountUID = cursor.getString(DatabaseAdapter.COLUMN_ACCOUNT_UID); +// Account.AccountType mainAccountType = mTransactionsDbAdapter.getAccountType(mainAccountUID); + //negate any transactions if this account is the origin in double entry - String doubleEntryAccountUID = cursor.getString(DatabaseAdapter.COLUMN_DOUBLE_ENTRY_ACCOUNT_UID); - if (doubleEntryAccountUID != null - && mTransactionsDbAdapter.isSameAccount(mAccountID, doubleEntryAccountUID)){ - amount = amount.negate(); + String transferAccountUID = cursor.getString(DatabaseAdapter.COLUMN_DOUBLE_ENTRY_ACCOUNT_UID); + + if (transferAccountUID != null + && mTransactionsDbAdapter.isSameAccount(mAccountID, transferAccountUID)){ +// Account.AccountType transferAccountType = mTransactionsDbAdapter.getAccountType(transferAccountUID); +// +// if (mainAccountType.getNormalBalanceType() == transferAccountType.getNormalBalanceType()) + amount = amount.negate(); } TextView tramount = (TextView) view.findViewById(R.id.transaction_amount); @@ -457,34 +469,51 @@ public void bindView(View view, Context context, Cursor cursor) { trNote.setVisibility(View.VISIBLE); trNote.setText(description); } - - long transactionTime = cursor.getLong(DatabaseAdapter.COLUMN_TIMESTAMP); - int position = cursor.getPosition(); - - boolean hasSectionHeader; - if (position == 0){ - hasSectionHeader = true; - } else { - cursor.moveToPosition(position - 1); - long previousTimestamp = cursor.getLong(DatabaseAdapter.COLUMN_TIMESTAMP); - cursor.moveToPosition(position); - //has header if two consecutive transactions were not on same day - hasSectionHeader = !isSameDay(previousTimestamp, transactionTime); - } - - TextView dateHeader = (TextView) view.findViewById(R.id.date_section_header); - - if (hasSectionHeader){ - java.text.DateFormat format = DateFormat.getLongDateFormat(getActivity()); - String dateString = format.format(new Date(transactionTime)); - dateHeader.setText(dateString); - dateHeader.setVisibility(View.VISIBLE); - } else { - dateHeader.setVisibility(View.GONE); - } + + setSectionHeaderVisibility(view, cursor); } - - private boolean isSameDay(long timeMillis1, long timeMillis2){ + + /** + * Toggles the visibilty of the section header based on whether the previous transaction and current were + * booked on the same day or not. Transactions a generally grouped by day + * @param view Parent view within which to find the section header + * @param cursor Cursor containing transaction data set + * @see #isSameDay(long, long) + */ + private void setSectionHeaderVisibility(View view, Cursor cursor) { + long transactionTime = cursor.getLong(DatabaseAdapter.COLUMN_TIMESTAMP); + int position = cursor.getPosition(); + + boolean hasSectionHeader; + if (position == 0){ + hasSectionHeader = true; + } else { + cursor.moveToPosition(position - 1); + long previousTimestamp = cursor.getLong(DatabaseAdapter.COLUMN_TIMESTAMP); + cursor.moveToPosition(position); + //has header if two consecutive transactions were not on same day + hasSectionHeader = !isSameDay(previousTimestamp, transactionTime); + } + + TextView dateHeader = (TextView) view.findViewById(R.id.date_section_header); + + if (hasSectionHeader){ + java.text.DateFormat format = DateFormat.getLongDateFormat(getActivity()); + String dateString = format.format(new Date(transactionTime)); + dateHeader.setText(dateString); + dateHeader.setVisibility(View.VISIBLE); + } else { + dateHeader.setVisibility(View.GONE); + } + } + + /** + * Checks if two timestamps have the same calendar day + * @param timeMillis1 Timestamp in milliseconds + * @param timeMillis2 Timestamp in milliseconds + * @return true if both timestamps are on same day, false otherwise + */ + private boolean isSameDay(long timeMillis1, long timeMillis2){ Date date1 = new Date(timeMillis1); Date date2 = new Date(timeMillis2);