Skip to content

Commit

Permalink
replacing Deposit & Withdrawal constants with enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
Alen Siljak committed May 25, 2015
1 parent 758f05f commit 6404bf1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/com/money/manager/ex/CheckingAccountActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,10 @@ private void initTransactionTypeSelector() {
SpinTransCode.setAdapter(adapterTrans);
// select the current value
if (mTransactionType != null) {
// if (!TextUtils.isEmpty(getTransactionType())) {
if (Arrays.asList(mTransCodeValues).indexOf(getTransactionType()) >= 0) {
SpinTransCode.setSelection(Arrays.asList(mTransCodeValues).indexOf(getTransactionType()), true);
}
} else {
// mTransCode = (String) SpinTransCode.getSelectedItem();
mTransactionType = TransactionTypes.values()[SpinTransCode.getSelectedItemPosition()];
}
SpinTransCode.setOnItemSelectedListener(new OnItemSelectedListener() {
Expand All @@ -805,7 +803,6 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
return;
}

// mTransCode = selectedValue;
mTransactionType = TransactionTypes.values()[position];
}
// aggiornamento dell'interfaccia grafica
Expand Down Expand Up @@ -947,7 +944,6 @@ public void onFinishedInputAmountDialog(int id, Double amount) {
}
}
if (txtTotAmount.equals(view)) {
// if (Constants.TRANSACTION_TYPE_TRANSFER.equals(mTransCode)) {
if (mTransactionType.equals(TransactionTypes.Transfer)) {
accountId = mToAccountId;
} else {
Expand Down
5 changes: 0 additions & 5 deletions src/com/money/manager/ex/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public class Constants {
public static final String EMPTY_STRING = "";
// Database
public static final String PATTERN_DB_DATE = "yyyy-MM-dd";
// todo: use TransactionTypes enum instead of these strings!
// Transaction Type
public static final String TRANSACTION_TYPE_WITHDRAWAL = "Withdrawal";
public static final String TRANSACTION_TYPE_DEPOSIT = "Deposit";
// public static final String TRANSACTION_TYPE_TRANSFER = "Transfer";
// Transaction Status
public static final String TRANSACTION_STATUS_UNRECONCILED = "";
public static final String TRANSACTION_STATUS_RECONCILED = "R";
Expand Down
5 changes: 3 additions & 2 deletions src/com/money/manager/ex/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.money.manager.ex.core.Core;
import com.money.manager.ex.core.MoneyManagerBootReceiver;
import com.money.manager.ex.core.Passcode;
import com.money.manager.ex.core.TransactionTypes;
import com.money.manager.ex.currency.CurrencyFormatsListActivity;
import com.money.manager.ex.database.TableAccountList;
import com.money.manager.ex.dropbox.DropboxHelper;
Expand Down Expand Up @@ -958,13 +959,13 @@ public boolean onDrawerMenuAndOptionMenuSelected(DrawerMenuItem item) {
return true;
} else if (item.getId() == R.id.menu_report_where_money_goes) {
intent = new Intent(this, CategoriesReportActivity.class);
intent.putExtra(CategoriesReportActivity.REPORT_FILTERS, Constants.TRANSACTION_TYPE_WITHDRAWAL);
intent.putExtra(CategoriesReportActivity.REPORT_FILTERS, TransactionTypes.Withdrawal.name());
intent.putExtra(CategoriesReportActivity.REPORT_TITLE, getString(R.string.menu_report_where_money_goes));
startActivity(intent);
return true;
} else if (item.getId() == R.id.menu_report_where_money_comes_from) {
intent = new Intent(this, CategoriesReportActivity.class);
intent.putExtra(CategoriesReportActivity.REPORT_FILTERS, Constants.TRANSACTION_TYPE_DEPOSIT);
intent.putExtra(CategoriesReportActivity.REPORT_FILTERS, TransactionTypes.Deposit.name());
intent.putExtra(CategoriesReportActivity.REPORT_TITLE, getString(R.string.menu_report_where_money_comes_from));
startActivity(intent);
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/com/money/manager/ex/adapter/AllDataAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ public void bindView(View view, Context context, Cursor cursor) {
// check amount sign
CurrencyUtils currencyUtils = new CurrencyUtils(mContext);
holder.txtAmount.setText(currencyUtils.getCurrencyFormatted(getCurrencyId(), amount));

String transType = cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE));
// text color amount
if (isTransfer) {
holder.txtAmount.setTextColor(mContext.getResources().getColor(R.color.material_grey_700));
} else if (Constants.TRANSACTION_TYPE_DEPOSIT.equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE)))) {
} else if (TransactionTypes.valueOf(transType).equals(TransactionTypes.Deposit)) {
holder.txtAmount.setTextColor(mContext.getResources().getColor(R.color.material_green_700));
} else {
holder.txtAmount.setTextColor(mContext.getResources().getColor(R.color.material_red_700));
Expand Down
10 changes: 6 additions & 4 deletions src/com/money/manager/ex/adapter/BalanceAmountTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.widget.TextView;

import com.money.manager.ex.Constants;
import com.money.manager.ex.core.TransactionTypes;
import com.money.manager.ex.database.MoneyManagerOpenHelper;
import com.money.manager.ex.database.TableAccountList;
import com.money.manager.ex.database.TableCheckingAccount;
Expand Down Expand Up @@ -59,13 +60,14 @@ protected Boolean doInBackground(Void... params) {

if (cursor != null && cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
if (Constants.TRANSACTION_TYPE_WITHDRAWAL.equalsIgnoreCase(
cursor.getString(cursor.getColumnIndex(TableCheckingAccount.TRANSCODE)))) {
String transType = cursor.getString(cursor.getColumnIndex(TableCheckingAccount.TRANSCODE));

if (TransactionTypes.valueOf(transType).equals(TransactionTypes.Withdrawal)) {
total -= cursor.getDouble(cursor.getColumnIndex(TableCheckingAccount.TRANSAMOUNT));
} else if (Constants.TRANSACTION_TYPE_DEPOSIT.equalsIgnoreCase(
cursor.getString(cursor.getColumnIndex(TableCheckingAccount.TRANSCODE)))) {
} else if (TransactionTypes.valueOf(transType).equals(TransactionTypes.Deposit)) {
total += cursor.getDouble(cursor.getColumnIndex(TableCheckingAccount.TRANSAMOUNT));
} else {
// transfer
if (cursor.getInt(cursor.getColumnIndex(TableCheckingAccount.ACCOUNTID)) == getAccountId()) {
total -= cursor.getDouble(cursor.getColumnIndex(TableCheckingAccount.TRANSAMOUNT));
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/com/money/manager/ex/businessobjects/qif/QifRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ private String getSplitCategory(TableSplitTransactions split, String transaction
// amount
double amount = split.getSplitTransAmount();
// handle sign
if (transactionType.equals(Constants.TRANSACTION_TYPE_WITHDRAWAL)) {
if (TransactionTypes.valueOf(transactionType).equals(TransactionTypes.Withdrawal)) {
amount = amount * (-1);
}
if (transactionType.equals(Constants.TRANSACTION_TYPE_DEPOSIT)) {
if (TransactionTypes.valueOf(transactionType).equals(TransactionTypes.Deposit)) {
// leave positive?
}
builder.append("$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.money.manager.ex.Constants;
import com.money.manager.ex.R;
import com.money.manager.ex.core.Core;
import com.money.manager.ex.core.TransactionTypes;
import com.money.manager.ex.database.ViewMobileData;
import com.money.manager.ex.fragment.BaseFragmentActivity;
import com.money.manager.ex.fragment.IncomeVsExpensesChartFragment;
Expand Down Expand Up @@ -277,7 +278,8 @@ protected String prepareQuery(String whereClause) {
String groupBy = ViewMobileData.CategID + ", " + ViewMobileData.Category + ", " + ViewMobileData.SubcategID + ", " + ViewMobileData.Subcategory;
String having = null;
if (!TextUtils.isEmpty(((CategoriesReportActivity) getActivity()).mFilter)) {
if (Constants.TRANSACTION_TYPE_WITHDRAWAL.equalsIgnoreCase(((CategoriesReportActivity) getActivity()).mFilter)) {
String filter = ((CategoriesReportActivity) getActivity()).mFilter;
if (TransactionTypes.valueOf(filter).equals(TransactionTypes.Withdrawal)) {
having = "SUM(" + ViewMobileData.AmountBaseConvRate + ") < 0";
} else {
having = "SUM(" + ViewMobileData.AmountBaseConvRate + ") > 0";
Expand Down

0 comments on commit 6404bf1

Please sign in to comment.