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 4ca91569d..e234f126c 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 @@ -78,6 +78,8 @@ 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); @@ -109,11 +111,15 @@ protected void generateReport() { @Override protected void displayReport() { + loadAccountViews(mAssetAccountTypes, mAssetsTableLayout); loadAccountViews(mLiabilityAccountTypes, mLiabilitiesTableLayout); loadAccountViews(mEquityAccountTypes, mEquityTableLayout); - TransactionsActivity.displayBalance(mNetWorth, mAssetsBalance.subtract(mLiabilitiesBalance)); + TransactionsActivity.displayBalance(mNetWorth, + // #8xx + mAssetsBalance.add(mLiabilitiesBalance), + null); } @Override @@ -128,6 +134,7 @@ public void onPrepareOptionsMenu(Menu menu) { * @param tableLayout Table layout into which to load the rows */ private void loadAccountViews(List accountTypes, TableLayout tableLayout){ + LayoutInflater inflater = LayoutInflater.from(getActivity()); Cursor cursor = mAccountsDbAdapter.fetchAccounts(DatabaseSchema.AccountEntry.COLUMN_TYPE @@ -135,14 +142,19 @@ private void loadAccountViews(List accountTypes, TableLayout tableL + DatabaseSchema.AccountEntry.COLUMN_PLACEHOLDER + " = 0", null, DatabaseSchema.AccountEntry.COLUMN_FULL_NAME + " ASC"); + AccountType accountType = null; + while (cursor.moveToNext()){ String accountUID = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.AccountEntry.COLUMN_UID)); String name = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.AccountEntry.COLUMN_NAME)); Money balance = mAccountsDbAdapter.getAccountBalance(accountUID); View view = inflater.inflate(R.layout.row_balance_sheet, tableLayout, false); ((TextView)view.findViewById(R.id.account_name)).setText(name); - TextView balanceTextView = (TextView) view.findViewById(R.id.account_balance); - TransactionsActivity.displayBalance(balanceTextView, balance); + 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); tableLayout.addView(view); } @@ -157,7 +169,11 @@ 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())); + TransactionsActivity.displayBalance(accountBalance, + mAccountsDbAdapter.getAccountBalance(accountTypes, + -1, + System.currentTimeMillis()), + accountType); 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 18ad5a27b..297f5f919 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 @@ -151,7 +151,11 @@ public void onActivityCreated(Bundle savedInstanceState) { View view = addSplitView(split); 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)); + + TransactionsActivity.displayBalance(mImbalanceTextView, + new Money(mBaseAmount.negate(), + mCommodity), + accountType); } } @@ -580,6 +584,7 @@ public void afterTextChanged(Editable editable) { BigDecimal imbalance = BigDecimal.ZERO; for (View splitItem : mSplitItemViewList) { + SplitViewHolder viewHolder = (SplitViewHolder) splitItem.getTag(); // Get the absolute value of the amount @@ -626,7 +631,8 @@ public void afterTextChanged(Editable editable) { TransactionsActivity.displayBalance(mImbalanceTextView, new Money(imbalance, - mCommodity)); + mCommodity), + null); } } 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 9ea0847e9..13dbde277 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 @@ -165,7 +165,7 @@ public void refresh(){ @Override public void onResume() { super.onResume(); - ((TransactionsActivity)getActivity()).updateNavigationSelection(); + ((TransactionsActivity)getActivity()).selectCurrentAccountInToolbarSpinner(); refresh(); } @@ -275,7 +275,10 @@ 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); + TransactionsActivity.displayBalance(holder.transactionAmount, + amount, + GnuCashApplication.getAccountsDbAdapter() + .getAccountType(mAccountUID)); 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 55bccd9c8..9db08fa47 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,6 +35,7 @@ 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.Commodity; @@ -97,7 +98,11 @@ 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); + TransactionsActivity.displayBalance(mStartAmountLabel, + mOriginAmount, + // TODO TW C 2020-03-05 : A vérifier + null); + String fromCurrencyCode = mOriginAmount.getCommodity().getCurrencyCode(); mFromCurrencyLabel.setText(fromCurrencyCode); mToCurrencyLabel.setText(mTargetCommodity.getCurrencyCode()); 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 8bef261af..7192927c7 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 @@ -38,7 +38,8 @@ public class AccountBalanceTask extends AsyncTask { public static final String LOG_TAG = AccountBalanceTask.class.getName(); private final WeakReference accountBalanceTextViewReference; - private final AccountsDbAdapter accountsDbAdapter; + private final AccountsDbAdapter accountsDbAdapter; + private String mAccountUID; public AccountBalanceTask(TextView balanceTextView){ accountBalanceTextViewReference = new WeakReference<>(balanceTextView); @@ -55,7 +56,10 @@ protected Money doInBackground(String... params) { Money balance = Money.getZeroInstance(); try { - balance = accountsDbAdapter.getAccountBalance(params[0], -1, -1); + mAccountUID = params[0]; + balance = accountsDbAdapter.getAccountBalance(mAccountUID, + -1, + -1); } catch (Exception ex) { Log.e(LOG_TAG, "Error computing account balance ", ex); Crashlytics.logException(ex); @@ -65,10 +69,16 @@ protected Money doInBackground(String... params) { @Override protected void onPostExecute(Money balance) { - if (accountBalanceTextViewReference.get() != null && balance != null){ + + if (accountBalanceTextViewReference.get() != null && balance != null) { + final TextView balanceTextView = accountBalanceTextViewReference.get(); - if (balanceTextView != null){ - TransactionsActivity.displayBalance(balanceTextView, balance); + + if (balanceTextView != null) { + + TransactionsActivity.displayBalance(balanceTextView, + balance, + accountsDbAdapter.getAccountType(mAccountUID)); } } }