diff --git a/app/src/main/java/org/gnucash/android/model/Money.java b/app/src/main/java/org/gnucash/android/model/Money.java index 331a0bd95..e2df19714 100644 --- a/app/src/main/java/org/gnucash/android/model/Money.java +++ b/app/src/main/java/org/gnucash/android/model/Money.java @@ -315,6 +315,19 @@ public Money negate(){ * @param amount {@link BigDecimal} amount to be set */ private void setAmount(@NonNull BigDecimal amount) { + + if (amount != null) { + // Amount is not null + + // NTD + + } else { + // Amount is null + + // init to 0 + amount = new BigDecimal(0); + } + mAmount = amount.setScale(mCommodity.getSmallestFractionDigits(), ROUNDING_MODE); } diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java index a5dc76b1b..3f3e2eae1 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java @@ -716,59 +716,51 @@ private void updateTransferAccountsList(){ */ private void openSplitEditor() { - if (mAmountEditText.getValue() == null) { + String baseAmountString; - Toast.makeText(getActivity(), - R.string.toast_enter_amount_to_split, - Toast.LENGTH_SHORT) - .show(); - - } else { - - String baseAmountString; - - if (mTransaction == null) { - // we are creating a new transaction (not editing an existing one) + if (mTransaction == null) { + // we are creating a new transaction (not editing an existing one) - BigDecimal enteredAmount = mAmountEditText.getValue(); + BigDecimal enteredAmount = mAmountEditText.getValue() != null + ? mAmountEditText.getValue() + : new BigDecimal(0); - baseAmountString = enteredAmount.toPlainString(); + baseAmountString = enteredAmount.toPlainString(); - } else { - // we are editing an existing transaction + } else { + // we are editing an existing transaction - // - // Find splits biggest amount (in absolute value) - // + // + // Find splits biggest amount (in absolute value) + // - Money biggestAmount = Money.createZeroInstance(mTransaction.getCurrencyCode()); + Money biggestAmount = Money.createZeroInstance(mTransaction.getCurrencyCode()); - for (Split split : mTransaction.getSplits()) { - if (split.getValue() - .asBigDecimal() - .compareTo(biggestAmount.asBigDecimal()) > 0) { - biggestAmount = split.getValue(); - } - } // for + for (Split split : mTransaction.getSplits()) { + if (split.getValue() + .asBigDecimal() + .compareTo(biggestAmount.asBigDecimal()) > 0) { + biggestAmount = split.getValue(); + } + } // for - baseAmountString = biggestAmount.toPlainString(); - } + baseAmountString = biggestAmount.toPlainString(); + } - Intent intent = new Intent(getActivity(), - FormActivity.class); - intent.putExtra(UxArgument.FORM_TYPE, - FormActivity.FormType.SPLIT_EDITOR.name()); - intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, - mAccountUID); - intent.putExtra(UxArgument.AMOUNT_STRING, - baseAmountString); + Intent intent = new Intent(getActivity(), + FormActivity.class); + intent.putExtra(UxArgument.FORM_TYPE, + FormActivity.FormType.SPLIT_EDITOR.name()); + intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, + mAccountUID); + intent.putExtra(UxArgument.AMOUNT_STRING, + baseAmountString); - intent.putParcelableArrayListExtra(UxArgument.SPLIT_LIST, - (ArrayList) extractSplitsFromView()); + intent.putParcelableArrayListExtra(UxArgument.SPLIT_LIST, + (ArrayList) extractSplitsFromView()); - startActivityForResult(intent, - REQUEST_SPLIT_EDITOR); - } + startActivityForResult(intent, + REQUEST_SPLIT_EDITOR); } /** @@ -869,18 +861,6 @@ private List extractSplitsFromView() { BigDecimal amountBigD = mAmountEditText.getValue(); - if (amountBigD != null) { - // Amount is null - - // RAF - - } else { - // Amount is not null - - // init to 0 - amountBigD=new BigDecimal(0); - } - String baseCurrencyCode = mTransactionsDbAdapter.getAccountCurrencyCode(mAccountUID); // Store signed amount