/**
   * Add Cash as a separate, automatic asset class that uses all the cash amounts from the
   * investment accounts.
   *
   * @param assetAllocation Main asset allocation object.
   */
  private void addCash(AssetClass assetAllocation) {
    // get all investment accounts, their currencies and cash balances.
    AccountRepository repo = new AccountRepository(getContext());
    AccountService accountService = new AccountService(getContext());
    List<String> investmentAccounts = new ArrayList<>();
    investmentAccounts.add(AccountTypes.INVESTMENT.toString());
    CurrencyService currencyService = new CurrencyService(getContext());
    int destinationCurrency = currencyService.getBaseCurrencyId();
    Money zero = MoneyFactory.fromDouble(0);

    List<Account> accounts = accountService.loadAccounts(false, false, investmentAccounts);

    Money sum = MoneyFactory.fromDouble(0);

    // Get the balances in base currency.
    for (Account account : accounts) {
      int sourceCurrency = account.getCurrencyId();
      Money amountInBase =
          currencyService.doCurrencyExchange(
              destinationCurrency, account.getInitialBalance(), sourceCurrency);
      sum = sum.add(amountInBase);
    }

    // add the cash asset class
    // todo: the allocation needs to be editable!
    AssetClass cash = AssetClass.create(getContext().getString(R.string.cash));
    cash.setType(ItemType.Cash);
    cash.setAllocation(zero);
    cash.setCurrentAllocation(zero);
    cash.setDifference(zero);
    cash.setValue(sum);

    assetAllocation.addChild(cash);
  }
  private Money sumStockValues(List<Stock> stocks) {
    Money sum = MoneyFactory.fromString("0");
    CurrencyService currencyService = new CurrencyService(getContext());
    AccountRepository repo = new AccountRepository(getContext());
    int baseCurrencyId = currencyService.getBaseCurrencyId();

    for (Stock stock : stocks) {
      // convert the stock value to the base currency.
      int accountId = stock.getHeldAt();
      int currencyId = repo.loadCurrencyIdFor(accountId);
      Money value =
          currencyService.doCurrencyExchange(baseCurrencyId, stock.getValue(), currencyId);

      sum = sum.add(value);
    }
    return sum;
  }
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    TextView txtColumn1 = (TextView) view.findViewById(R.id.textViewColumn1);
    TextView txtColumn2 = (TextView) view.findViewById(R.id.textViewColumn2);

    Core core = new Core(context);
    double total = cursor.getDouble(cursor.getColumnIndex("TOTAL"));
    String column1;
    String category = cursor.getString(cursor.getColumnIndex(ViewMobileData.Category));
    if (!TextUtils.isEmpty(category)) {
      column1 = "<b>" + category + "</b>";
      String subCategory = cursor.getString(cursor.getColumnIndex(ViewMobileData.Subcategory));
      if (!TextUtils.isEmpty(subCategory)) {
        column1 += " : " + subCategory;
      }
    } else {
      column1 = "<i>" + context.getString(R.string.empty_category);
    }
    txtColumn1.setText(Html.fromHtml(column1));

    CurrencyService currencyService = new CurrencyService(mContext);

    txtColumn2.setText(
        currencyService.getCurrencyFormatted(
            currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(total)));
    if (total < 0) {
      txtColumn2.setTextColor(
          context.getResources().getColor(core.resolveIdAttribute(R.attr.holo_red_color_theme)));
    } else {
      txtColumn2.setTextColor(
          context.getResources().getColor(core.resolveIdAttribute(R.attr.holo_green_color_theme)));
    }

    // view.setBackgroundColor(core.resolveColorAttribute(cursor.getPosition() % 2 == 1 ?
    // R.attr.row_dark_theme : R.attr.row_light_theme));
  }