Skip to content

Commit

Permalink
Merge branch '#876_balance_liability' into tw_develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanGarf committed May 24, 2020
2 parents 0d7f308 + b59e69b commit ed7de67
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 94 deletions.
4 changes: 1 addition & 3 deletions app/src/main/java/org/gnucash/android/model/AccountType.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ public void displayBalance(final TextView balanceTextView,
* {@link org.gnucash.android.model.Money} balance (>0 or <0) to display
*/
public void displayBalance(final TextView balanceTextView,
final Money balance,
// TODO TW C 2020-05-23 : A supprimer
final boolean shallDisplayNegativeSignumInSplits) {
final Money balance) {

displayBalance(balanceTextView,
balance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,8 @@ public void onBindViewHolderCursor(final AccountViewHolder holder, final Cursor

// add a summary of transactions to the account view

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);
// Make sure the balance task is truly multithread
new AccountBalanceTask(holder.accountBalance,
shallDisplayNegativeSignumInSplits).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
new AccountBalanceTask(holder.accountBalance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
accountUID);

// #871 Display inherited color from ancestor's account on the Strip View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,13 @@ protected void displayReport() {
mChart.highlightValues(null);
mChart.invalidate();

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);

AccountType.ASSET.displayBalance(mTotalAssets,
mAssetsBalance,
shallDisplayNegativeSignumInSplits);
mAssetsBalance);
AccountType.LIABILITY.displayBalance(mTotalLiabilities,
mLiabilitiesBalance,
shallDisplayNegativeSignumInSplits);
mLiabilitiesBalance);
// #8xx
AccountType.ASSET.displayBalance(mNetWorth,
mAssetsBalance.add(mLiabilitiesBalance),
shallDisplayNegativeSignumInSplits);
mAssetsBalance.add(mLiabilitiesBalance));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -103,14 +102,9 @@ protected void displayReport() {
loadAccountViews(LIABLITY_ACCOUNT_TYPES, mLiabilitiesTableLayout);
loadAccountViews(EQUITY_ACCOUNT_TYPES, mEquityTableLayout);

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);
AccountType.ASSET.displayBalance(mNetWorth,
// #8xx
mAssetsBalance.add(mLiabilitiesBalance),
shallDisplayNegativeSignumInSplits);
mAssetsBalance.add(mLiabilitiesBalance));
}

@Override
Expand Down Expand Up @@ -144,14 +138,8 @@ private void loadAccountViews(List<AccountType> accountTypes, TableLayout tableL
TextView balanceTextView = (TextView) view.findViewById(R.id.account_balance);
accountType = AccountType.valueOf(cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.AccountEntry.COLUMN_TYPE)));

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);

accountType.displayBalance(balanceTextView,
balance,
shallDisplayNegativeSignumInSplits);
balance);

tableLayout.addView(view);
}
Expand All @@ -168,15 +156,10 @@ private void loadAccountViews(List<AccountType> accountTypes, TableLayout tableL
accountBalance.setTextSize(16);
accountBalance.setTypeface(null, Typeface.BOLD);

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);
accountType.displayBalance(accountBalance,
mAccountsDbAdapter.getAccountBalance(accountTypes,
-1,
System.currentTimeMillis()),
shallDisplayNegativeSignumInSplits);
System.currentTimeMillis()));

tableLayout.addView(totalView);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,10 @@ public void onActivityCreated(Bundle savedInstanceState) {
view.findViewById(R.id.input_accounts_spinner).setEnabled(false);
view.findViewById(R.id.btn_remove_split).setVisibility(View.GONE);

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);
accountType.displayBalance(mImbalanceTextView,
// Display imbalance with signum and currency as if it was an asset
AccountType.ASSET.displayBalance(mImbalanceTextView,
new Money(mBaseAmount.negate(),
mCommodity),
shallDisplayNegativeSignumInSplits);
mCommodity));
}

}
Expand Down Expand Up @@ -674,15 +670,12 @@ public void afterTextChanged(Editable editable) {

} // for

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);
// AccountType accountType = mAccountsDbAdapter.getAccountType(mAccountUID);

// Display imbalance with signum and currency as if it was an asset
AccountType.ASSET.displayBalance(mImbalanceTextView,
new Money(imbalance,
mCommodity),
shallDisplayNegativeSignumInSplits);
mCommodity));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ public SplitAmountViewHolder(View view,
final AccountType accountType = AccountsDbAdapter.getInstance()
.getAccountType(split.getAccountUID());

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);

// Display absolute value because it is displayed either in debit or credit column
accountType.displayBalance(balanceView,
splitSignedAmount,
shallDisplayNegativeSignumInSplits);
false,
true);
}

} // Class SplitAmountViewHolder
Expand Down Expand Up @@ -233,20 +229,18 @@ private void bindViews() {
transaction.getTimeMillis());

// #8xx
// Define in which field (Debit or Credit) the balance shall be displayed
TextView balanceTextView = accountBalance.isNegative()
? mCreditBalance
: mDebitBalance;
// Use Debit TextView to display the account balance (with signum)
// TextView balanceTextView = accountBalance.isNegative()
// ? mCreditBalance
// : mDebitBalance;
TextView balanceTextView = mDebitBalance;

final AccountType accountType = accountsDbAdapter.getAccountType(mAccountUID);

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);
accountType.displayBalance(balanceTextView,
accountBalance,
shallDisplayNegativeSignumInSplits);
true,
true);

//
// Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,7 @@ public void refresh(String accountUID) {
if (mPagerAdapter != null)
mPagerAdapter.notifyDataSetChanged();

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);
new AccountBalanceTask(mSumTextView,
shallDisplayNegativeSignumInSplits).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
new AccountBalanceTask(mSumTextView).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
getCurrentAccountUID());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,8 @@ public void onBindViewHolderCursor(ViewHolder holder, Cursor cursor) {
final AccountType accountType = GnuCashApplication.getAccountsDbAdapter()
.getAccountType(mAccountUID);

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);

accountType.displayBalance(holder.transactionAmount,
amount,
shallDisplayNegativeSignumInSplits);
amount);

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 @@ -98,14 +98,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View view = inflater.inflate(R.layout.dialog_transfer_funds, container, false);
ButterKnife.bind(this, view);

// Get Preference about showing signum in Splits
boolean shallDisplayNegativeSignumInSplits = PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.key_display_negative_signum_in_splits),
false);

AccountType.ASSET.displayBalance(mStartAmountLabel,
mOriginAmount,
shallDisplayNegativeSignumInSplits);
mOriginAmount);

String fromCurrencyCode = mOriginAmount.getCommodity().getCurrencyCode();
mFromCurrencyLabel.setText(fromCurrencyCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ public class AccountBalanceTask extends AsyncTask<String, Void, Money> {
private final WeakReference<TextView> accountBalanceTextViewReference;
private final AccountsDbAdapter accountsDbAdapter;
private String mAccountUID;
private boolean mShallDisplayNegativeSignumInSplits;

public AccountBalanceTask(TextView balanceTextView,
boolean shallDisplayNegativeSignumInSplits) {
public AccountBalanceTask(TextView balanceTextView) {
accountBalanceTextViewReference = new WeakReference<>(balanceTextView);
accountsDbAdapter = AccountsDbAdapter.getInstance();
mShallDisplayNegativeSignumInSplits = shallDisplayNegativeSignumInSplits;
}

@Override
Expand Down Expand Up @@ -83,8 +80,7 @@ protected void onPostExecute(Money balance) {

// Get Preference about showing signum in Splits
accountType.displayBalance(balanceTextView,
balance,
mShallDisplayNegativeSignumInSplits);
balance);
}
}
}
Expand Down

0 comments on commit ed7de67

Please sign in to comment.