Esempio n. 1
0
    @Override
    public void afterTextChanged(Editable editable) {
      BigDecimal imbalance = BigDecimal.ZERO;

      for (View splitItem : mSplitItemViewList) {
        SplitViewHolder viewHolder = (SplitViewHolder) splitItem.getTag();
        BigDecimal amount = viewHolder.getAmountValue().abs();
        if (viewHolder.splitTypeSwitch.isChecked()) {
          imbalance = imbalance.subtract(amount);
        } else {
          imbalance = imbalance.add(amount);
        }
      }

      TransactionsActivity.displayBalance(
          mImbalanceTextView, new Money(imbalance.negate(), mCommodity));
    }
Esempio n. 2
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    assert actionBar != null;
    actionBar.setTitle(R.string.title_split_editor);
    setHasOptionsMenu(true);

    mCalculatorKeyboard =
        new CalculatorKeyboard(getActivity(), mKeyboardView, R.xml.calculator_keyboard);
    mSplitItemViewList = new ArrayList<>();

    // we are editing splits for a new transaction.
    // But the user may have already created some splits before. Let's check
    List<String> splitStrings = getArguments().getStringArrayList(UxArgument.SPLIT_LIST);
    List<Split> splitList = new ArrayList<>();
    if (splitStrings != null) {
      for (String splitString : splitStrings) {
        splitList.add(Split.parseSplit(splitString));
      }
    }

    initArgs();
    if (!splitList.isEmpty()) {
      // aha! there are some splits. Let's load those instead
      loadSplitViews(splitList);
      mImbalanceWatcher.afterTextChanged(null);
    } else {
      final String currencyCode = mAccountsDbAdapter.getAccountCurrencyCode(mAccountUID);
      Split split =
          new Split(new Money(mBaseAmount.abs(), Commodity.getInstance(currencyCode)), mAccountUID);
      AccountType accountType = mAccountsDbAdapter.getAccountType(mAccountUID);
      TransactionType transactionType =
          Transaction.getTypeForBalance(accountType, mBaseAmount.signum() < 0);
      split.setType(transactionType);
      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));
    }
  }