From 88440026067f99bc1b85bd28ab58200c1645c4b9 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sat, 7 Mar 2020 14:20:07 +0100 Subject: [PATCH] #876 - Use AccountType.displayBalance(...) --- .../ui/report/ReportsOverviewFragment.java | 6 ++--- .../ui/report/sheet/BalanceSheetFragment.java | 23 ++++++++----------- .../ui/transaction/SplitEditorFragment.java | 14 +++++------ .../TransactionDetailActivity.java | 18 ++++++++------- .../transaction/TransactionsListFragment.java | 11 +++++---- .../dialog/TransferFundsDialogFragment.java | 10 ++++---- .../android/ui/util/AccountBalanceTask.java | 9 ++++---- .../ui/util/widget/TransactionTypeSwitch.java | 3 +-- 8 files changed, 45 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/report/ReportsOverviewFragment.java b/app/src/main/java/org/gnucash/android/ui/report/ReportsOverviewFragment.java index 6d99db6fd..df5d58e62 100644 --- a/app/src/main/java/org/gnucash/android/ui/report/ReportsOverviewFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/report/ReportsOverviewFragment.java @@ -213,10 +213,10 @@ protected void displayReport() { mChart.highlightValues(null); mChart.invalidate(); - TransactionsActivity.displayBalance(mTotalAssets, mAssetsBalance, AccountType.ASSET); - TransactionsActivity.displayBalance(mTotalLiabilities, mLiabilitiesBalance, AccountType.LIABILITY); + AccountType.ASSET.displayBalance(mTotalAssets, mAssetsBalance); + AccountType.LIABILITY.displayBalance(mTotalLiabilities, mLiabilitiesBalance); // #8xx - TransactionsActivity.displayBalance(mNetWorth, mAssetsBalance.add(mLiabilitiesBalance), null); + AccountType.ASSET.displayBalance(mNetWorth, mAssetsBalance.add(mLiabilitiesBalance)); } /** 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 2de5f32d3..2ce902d97 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 @@ -33,9 +33,7 @@ import org.gnucash.android.model.Money; import org.gnucash.android.ui.report.BaseReportFragment; import org.gnucash.android.ui.report.ReportType; -import org.gnucash.android.ui.transaction.TransactionsActivity; -import java.util.ArrayList; import java.util.List; import butterknife.BindView; @@ -104,10 +102,9 @@ protected void displayReport() { loadAccountViews(LIABLITY_ACCOUNT_TYPES, mLiabilitiesTableLayout); loadAccountViews(EQUITY_ACCOUNT_TYPES, mEquityTableLayout); - TransactionsActivity.displayBalance(mNetWorth, - // #8xx - mAssetsBalance.add(mLiabilitiesBalance), - null); + AccountType.ASSET.displayBalance(mNetWorth, + // #8xx + mAssetsBalance.add(mLiabilitiesBalance)); } @Override @@ -140,9 +137,8 @@ private void loadAccountViews(List accountTypes, TableLayout tableL ((TextView)view.findViewById(R.id.account_name)).setText(name); TextView balanceTextView = (TextView) view.findViewById(R.id.account_balance); accountType = AccountType.valueOf(cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.AccountEntry.COLUMN_TYPE))); - TransactionsActivity.displayBalance(balanceTextView, - balance, - accountType); + accountType.displayBalance(balanceTextView, + balance); tableLayout.addView(view); } @@ -157,11 +153,10 @@ private void loadAccountViews(List accountTypes, TableLayout tableL TextView accountBalance = (TextView) totalView.findViewById(R.id.account_balance); accountBalance.setTextSize(16); accountBalance.setTypeface(null, Typeface.BOLD); - TransactionsActivity.displayBalance(accountBalance, - mAccountsDbAdapter.getAccountBalance(accountTypes, - -1, - System.currentTimeMillis()), - accountType); + accountType.displayBalance(accountBalance, + mAccountsDbAdapter.getAccountBalance(accountTypes, + -1, + System.currentTimeMillis())); tableLayout.addView(totalView); } diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java index 7ca854708..8de1cb932 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java @@ -152,10 +152,9 @@ public void onActivityCreated(Bundle savedInstanceState) { view.findViewById(R.id.input_accounts_spinner).setEnabled(false); view.findViewById(R.id.btn_remove_split).setVisibility(View.GONE); - TransactionsActivity.displayBalance(mImbalanceTextView, - new Money(mBaseAmount.negate(), - mCommodity), - accountType); + accountType.displayBalance(mImbalanceTextView, + new Money(mBaseAmount.negate(), + mCommodity)); } } @@ -628,10 +627,9 @@ public void afterTextChanged(Editable editable) { } // for - TransactionsActivity.displayBalance(mImbalanceTextView, - new Money(imbalance, - mCommodity), - null); + AccountType.ASSET.displayBalance(mImbalanceTextView, + new Money(imbalance, + mCommodity)); } } diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionDetailActivity.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionDetailActivity.java index eb22e5352..4ce39ef0a 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionDetailActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionDetailActivity.java @@ -18,6 +18,7 @@ import org.gnucash.android.db.adapter.AccountsDbAdapter; import org.gnucash.android.db.adapter.ScheduledActionDbAdapter; import org.gnucash.android.db.adapter.TransactionsDbAdapter; +import org.gnucash.android.model.AccountType; import org.gnucash.android.model.Money; import org.gnucash.android.model.ScheduledAction; import org.gnucash.android.model.Split; @@ -26,7 +27,6 @@ import org.gnucash.android.ui.common.FormActivity; import org.gnucash.android.ui.common.UxArgument; import org.gnucash.android.ui.passcode.PasscodeLockActivity; -import org.gnucash.android.ui.util.AccountUtils; import java.text.DateFormat; import java.util.Date; @@ -75,10 +75,11 @@ public SplitAmountViewHolder(View view, ? splitCreditView : splitDebitView; - TransactionsActivity.displayBalance(balanceView, - quantity, - AccountsDbAdapter.getInstance() - .getAccountType(split.getAccountUID())); + final AccountType accountType = AccountsDbAdapter.getInstance() + .getAccountType(split.getAccountUID()); + + accountType.displayBalance(balanceView, + quantity); } } // Class SplitAmountViewHolder @@ -161,9 +162,10 @@ private void bindViews(){ // Define in which field (Debit or Credit) the balance shall be displayed TextView balanceTextView = accountBalance.isNegative() ? mCreditBalance : mDebitBalance ; - TransactionsActivity.displayBalance(balanceTextView, - accountBalance, - accountsDbAdapter.getAccountType(mAccountUID)); + final AccountType accountType = accountsDbAdapter.getAccountType(mAccountUID); + + accountType.displayBalance(balanceTextView, + accountBalance); // // Détails diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java index 13dbde277..37e8c5dd6 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java @@ -49,6 +49,7 @@ import org.gnucash.android.db.adapter.DatabaseAdapter; import org.gnucash.android.db.adapter.SplitsDbAdapter; import org.gnucash.android.db.adapter.TransactionsDbAdapter; +import org.gnucash.android.model.AccountType; import org.gnucash.android.model.Money; import org.gnucash.android.model.Split; import org.gnucash.android.model.Transaction; @@ -275,10 +276,12 @@ public void onBindViewHolderCursor(ViewHolder holder, Cursor cursor) { final String transactionUID = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.TransactionEntry.COLUMN_UID)); Money amount = mTransactionsDbAdapter.getBalance(transactionUID, mAccountUID); - TransactionsActivity.displayBalance(holder.transactionAmount, - amount, - GnuCashApplication.getAccountsDbAdapter() - .getAccountType(mAccountUID)); + + final AccountType accountType = GnuCashApplication.getAccountsDbAdapter() + .getAccountType(mAccountUID); + + accountType.displayBalance(holder.transactionAmount, + amount); long dateMillis = cursor.getLong(cursor.getColumnIndexOrThrow(DatabaseSchema.TransactionEntry.COLUMN_TIMESTAMP)); String dateText = TransactionsActivity.getPrettyDateFormat(getActivity(), dateMillis); diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java index 9db08fa47..aa2eb94a1 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java @@ -35,14 +35,13 @@ import android.widget.TextView; import org.gnucash.android.R; -import org.gnucash.android.app.GnuCashApplication; import org.gnucash.android.db.adapter.CommoditiesDbAdapter; import org.gnucash.android.db.adapter.PricesDbAdapter; +import org.gnucash.android.model.AccountType; import org.gnucash.android.model.Commodity; import org.gnucash.android.model.Money; import org.gnucash.android.model.Price; import org.gnucash.android.ui.transaction.OnTransferFundsListener; -import org.gnucash.android.ui.transaction.TransactionsActivity; import org.gnucash.android.util.AmountParser; import java.math.BigDecimal; @@ -98,10 +97,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View view = inflater.inflate(R.layout.dialog_transfer_funds, container, false); ButterKnife.bind(this, view); - TransactionsActivity.displayBalance(mStartAmountLabel, - mOriginAmount, - // TODO TW C 2020-03-05 : A vérifier - null); + // TODO TW C 2020-03-05 : A vérifier + AccountType.ASSET.displayBalance(mStartAmountLabel, + mOriginAmount); String fromCurrencyCode = mOriginAmount.getCommodity().getCurrencyCode(); mFromCurrencyLabel.setText(fromCurrencyCode); diff --git a/app/src/main/java/org/gnucash/android/ui/util/AccountBalanceTask.java b/app/src/main/java/org/gnucash/android/ui/util/AccountBalanceTask.java index 7192927c7..d9b68acd2 100644 --- a/app/src/main/java/org/gnucash/android/ui/util/AccountBalanceTask.java +++ b/app/src/main/java/org/gnucash/android/ui/util/AccountBalanceTask.java @@ -24,8 +24,8 @@ import com.crashlytics.android.Crashlytics; import org.gnucash.android.db.adapter.AccountsDbAdapter; +import org.gnucash.android.model.AccountType; import org.gnucash.android.model.Money; -import org.gnucash.android.ui.transaction.TransactionsActivity; import java.lang.ref.WeakReference; @@ -76,9 +76,10 @@ protected void onPostExecute(Money balance) { if (balanceTextView != null) { - TransactionsActivity.displayBalance(balanceTextView, - balance, - accountsDbAdapter.getAccountType(mAccountUID)); + final AccountType accountType = accountsDbAdapter.getAccountType(mAccountUID); + + accountType.displayBalance(balanceTextView, + balance); } } } diff --git a/app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java b/app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java index 66f249c71..b94276a87 100644 --- a/app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java +++ b/app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java @@ -237,8 +237,7 @@ private void setSwitchTextAndColor(final boolean isCredit) { // Set text color of views // - @ColorInt final int color = AccountType.getAmountColor(isCredit, - getAccountType()); + @ColorInt final int color = getAccountType().getAmountColor(isCredit); TransactionTypeSwitch.this.setTextColor(color); mAmountEditText.setTextColor(color);