From bf4948222925d8bf27571666bc1995661993a01d Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sat, 7 Mar 2020 12:31:04 +0100 Subject: [PATCH] #876 - Replace mAssetAccountTypes with ASSET_ACCOUNT_TYPES from AccountType --- .../gnucash/android/model/AccountType.java | 22 ++++++++++++-- .../ui/report/sheet/BalanceSheetFragment.java | 30 ++++++------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/model/AccountType.java b/app/src/main/java/org/gnucash/android/model/AccountType.java index 9b856ef90..fd5dccb94 100644 --- a/app/src/main/java/org/gnucash/android/model/AccountType.java +++ b/app/src/main/java/org/gnucash/android/model/AccountType.java @@ -6,12 +6,17 @@ import org.gnucash.android.R; import org.gnucash.android.app.GnuCashApplication; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + /** * The type of account * This are the different types specified by the OFX format and * they are currently not used except for exporting */ public enum AccountType { + CASH(TransactionType.DEBIT), BANK(TransactionType.DEBIT), CREDIT, @@ -28,19 +33,30 @@ public enum AccountType { TRADING, ROOT; + public final static List ASSET_ACCOUNT_TYPES = new ArrayList(Arrays.asList(AccountType.ASSET, + AccountType.CASH, + AccountType.BANK)); + + public final static List LIABLITY_ACCOUNT_TYPES = new ArrayList(Arrays.asList(AccountType.LIABILITY, + AccountType.CREDIT)); + + public final static List EQUITY_ACCOUNT_TYPES = new ArrayList(Arrays.asList(AccountType.EQUITY)); + + /** * 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 TransactionType mNormalBalance = TransactionType.CREDIT; + private TransactionType mNormalBalance; + + AccountType(TransactionType normalBalance) { - AccountType(TransactionType normalBalance){ this.mNormalBalance = normalBalance; } AccountType() { - //nothing to see here, move along + this(TransactionType.CREDIT); } // TODO TW C 2020-03-06 : Enlever le static diff --git a/app/src/main/java/org/gnucash/android/ui/report/sheet/BalanceSheetFragment.java b/app/src/main/java/org/gnucash/android/ui/report/sheet/BalanceSheetFragment.java index e234f126c..2de5f32d3 100644 --- a/app/src/main/java/org/gnucash/android/ui/report/sheet/BalanceSheetFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/report/sheet/BalanceSheetFragment.java @@ -40,6 +40,10 @@ import butterknife.BindView; +import static org.gnucash.android.model.AccountType.ASSET_ACCOUNT_TYPES; +import static org.gnucash.android.model.AccountType.EQUITY_ACCOUNT_TYPES; +import static org.gnucash.android.model.AccountType.LIABLITY_ACCOUNT_TYPES; + /** * Balance sheet report fragment * @author Ngewi Fet @@ -56,9 +60,6 @@ public class BalanceSheetFragment extends BaseReportFragment { private Money mAssetsBalance; private Money mLiabilitiesBalance; - private List mAssetAccountTypes; - private List mLiabilityAccountTypes; - private List mEquityAccountTypes; @Override public int getLayoutResource() { @@ -78,19 +79,6 @@ public ReportType getReportType() { @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - - // TODO TW C 2020-03-06 : A mettre dans AccountType sous formes de constantes - mAssetAccountTypes = new ArrayList<>(); - mAssetAccountTypes.add(AccountType.ASSET); - mAssetAccountTypes.add(AccountType.CASH); - mAssetAccountTypes.add(AccountType.BANK); - - mLiabilityAccountTypes = new ArrayList<>(); - mLiabilityAccountTypes.add(AccountType.LIABILITY); - mLiabilityAccountTypes.add(AccountType.CREDIT); - - mEquityAccountTypes = new ArrayList<>(); - mEquityAccountTypes.add(AccountType.EQUITY); } @Override @@ -105,16 +93,16 @@ public boolean requiresTimeRangeOptions() { @Override protected void generateReport() { - mAssetsBalance = mAccountsDbAdapter.getAccountBalance(mAssetAccountTypes, -1, System.currentTimeMillis()); - mLiabilitiesBalance = mAccountsDbAdapter.getAccountBalance(mLiabilityAccountTypes, -1, System.currentTimeMillis()); + mAssetsBalance = mAccountsDbAdapter.getAccountBalance(ASSET_ACCOUNT_TYPES, -1, System.currentTimeMillis()); + mLiabilitiesBalance = mAccountsDbAdapter.getAccountBalance(LIABLITY_ACCOUNT_TYPES, -1, System.currentTimeMillis()); } @Override protected void displayReport() { - loadAccountViews(mAssetAccountTypes, mAssetsTableLayout); - loadAccountViews(mLiabilityAccountTypes, mLiabilitiesTableLayout); - loadAccountViews(mEquityAccountTypes, mEquityTableLayout); + loadAccountViews(ASSET_ACCOUNT_TYPES, mAssetsTableLayout); + loadAccountViews(LIABLITY_ACCOUNT_TYPES, mLiabilitiesTableLayout); + loadAccountViews(EQUITY_ACCOUNT_TYPES, mEquityTableLayout); TransactionsActivity.displayBalance(mNetWorth, // #8xx