Skip to content

Commit

Permalink
codinguser#876 - use displayBalance(...) with AccountType
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanGarf committed Mar 6, 2020
1 parent b7c042f commit e178e3a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -128,21 +134,27 @@ public void onPrepareOptionsMenu(Menu menu) {
* @param tableLayout Table layout into which to load the rows
*/
private void loadAccountViews(List<AccountType> accountTypes, TableLayout tableLayout){

LayoutInflater inflater = LayoutInflater.from(getActivity());

Cursor cursor = mAccountsDbAdapter.fetchAccounts(DatabaseSchema.AccountEntry.COLUMN_TYPE
+ " IN ( '" + TextUtils.join("' , '", accountTypes) + "' ) AND "
+ 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);
}

Expand All @@ -157,7 +169,11 @@ private void loadAccountViews(List<AccountType> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -626,7 +631,8 @@ public void afterTextChanged(Editable editable) {

TransactionsActivity.displayBalance(mImbalanceTextView,
new Money(imbalance,
mCommodity));
mCommodity),
null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void refresh(){
@Override
public void onResume() {
super.onResume();
((TransactionsActivity)getActivity()).updateNavigationSelection();
((TransactionsActivity)getActivity()).selectCurrentAccountInToolbarSpinner();
refresh();
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class AccountBalanceTask extends AsyncTask<String, Void, Money> {
public static final String LOG_TAG = AccountBalanceTask.class.getName();

private final WeakReference<TextView> accountBalanceTextViewReference;
private final AccountsDbAdapter accountsDbAdapter;
private final AccountsDbAdapter accountsDbAdapter;
private String mAccountUID;

public AccountBalanceTask(TextView balanceTextView){
accountBalanceTextViewReference = new WeakReference<>(balanceTextView);
Expand All @@ -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);
Expand All @@ -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));
}
}
}
Expand Down

0 comments on commit e178e3a

Please sign in to comment.