Fix total value calculus and allow fiat display

- Fix Deduct switch not being updated when editing a transaction

Previous commit tested and working
This commit is contained in:
Tanguy Herbron 2018-08-27 03:41:33 +02:00
parent 4738a65dcc
commit 7623012353
4 changed files with 33 additions and 19 deletions

View File

@ -213,7 +213,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) { for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) {
final Currency currency = balanceManager.getTotalBalance().get(i); final Currency currency = balanceManager.getTotalBalance().get(i);
if (!currency.getSymbol().equals("USD") && (Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) { if ((Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) {
//currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); //currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden()));
renderedCurrencies.add(currency); renderedCurrencies.add(currency);
} }
@ -236,6 +236,8 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
loadingDialog.dismiss(); loadingDialog.dismiss();
} }
updateTitle();
handler.removeCallbacks(updateRunnable); handler.removeCallbacks(updateRunnable);
} }
}); });
@ -371,9 +373,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
{ {
coinCounter = 0; coinCounter = 0;
iconCounter = 0; iconCounter = 0;
totalValue = 0;
totalFluctuation = 0;
} }
private void adaptView() private void adaptView()
@ -466,8 +465,25 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
}); });
} }
private void computeTotalValue()
{
totalValue = 0;
totalFluctuation = 0;
for(int i = 0; i < currencyLayout.getChildCount(); i++)
{
if(currencyLayout.getChildAt(i) instanceof CurrencyCardview)
{
totalValue += ((CurrencyCardview) currencyLayout.getChildAt(i)).getOwnedValue();
totalFluctuation += ((CurrencyCardview) currencyLayout.getChildAt(i)).getFluctuation();
}
}
}
protected void updateTitle() protected void updateTitle()
{ {
computeTotalValue();
float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) * 100; float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) * 100;
if(preferencesManager.isBalanceHidden()) if(preferencesManager.isBalanceHidden())
@ -700,13 +716,8 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
private void loadCurrency(Currency currency) private void loadCurrency(Currency currency)
{ {
if(!currency.getSymbol().equals("USD")) currency.setName(balanceManager.getCurrencyName(currency.getSymbol()));
{ currency.setId(balanceManager.getCurrencyId(currency.getSymbol()));
currency.setName(balanceManager.getCurrencyName(currency.getSymbol()));
currency.setId(balanceManager.getCurrencyId(currency.getSymbol()));
totalValue += currency.getValue() * currency.getBalance();
totalFluctuation += (currency.getValue() * currency.getBalance()) * (currency.getDayFluctuationPercentage() / 100);
}
} }
@Override @Override
@ -732,13 +743,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
balanceManager.getTotalBalance().set(i, localCurrency); balanceManager.getTotalBalance().set(i, localCurrency);
} }
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateTitle();
}
});
return null; return null;
} }

View File

@ -275,6 +275,7 @@ public class BuyFragment extends CustomRecordFragment {
totalValueEditText.setText(String.valueOf(transaction.getAmount() * transaction.getPrice())); totalValueEditText.setText(String.valueOf(transaction.getAmount() * transaction.getPrice()));
fees_editText.setText(String.valueOf(transaction.getFees())); fees_editText.setText(String.valueOf(transaction.getFees()));
note_editText.setText(transaction.getNote()); note_editText.setText(transaction.getNote());
deductHoldingsSwitch.setChecked(transaction.isDeducted());
} }
private void initializeViewElements() private void initializeViewElements()

View File

@ -30,7 +30,6 @@ public class BalanceManager implements BinanceUpdateNotifierInterface, HitBTCUpd
private int balanceCounter; private int balanceCounter;
//NEW IMPLEMENTATION
private List<HitBtcManager> hitBtcManagers; private List<HitBtcManager> hitBtcManagers;
private List<BinanceManager> binanceManagers; private List<BinanceManager> binanceManagers;

View File

@ -305,6 +305,16 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
} }
} }
public double getOwnedValue()
{
return currency.getValue() * currency.getBalance();
}
public double getFluctuation()
{
return getOwnedValue() * (currency.getDayFluctuationPercentage() / 100);
}
private LineData generateData(Currency currency) private LineData generateData(Currency currency)
{ {
LineDataSet dataSet; LineDataSet dataSet;