- Equivalence values working!
This commit is contained in:
parent
8bec42de1a
commit
8745b32446
3 changed files with 56 additions and 42 deletions
|
@ -72,7 +72,8 @@ public class CrystalWalletService extends LifecycleService {
|
|||
|
||||
preferredCurrencySetting.observe(service, new Observer<GeneralSetting>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable GeneralSetting generalSetting) {
|
||||
public void onChanged(final @Nullable GeneralSetting generalSetting) {
|
||||
if (generalSetting != null) {
|
||||
CryptoCurrency preferredCurrency = CrystalDatabase.getAppDatabase(service).cryptoCurrencyDao().getByNameAndCryptoNet("EUR", CryptoNet.BITSHARES.name());
|
||||
|
||||
if (preferredCurrency != null) {
|
||||
|
@ -106,14 +107,18 @@ public class CrystalWalletService extends LifecycleService {
|
|||
bitsharesAssets.add(nextAsset);
|
||||
}
|
||||
|
||||
if (LoadEquivalencesThread != null){LoadEquivalencesThread.stopLoadingEquivalences();};
|
||||
LoadEquivalencesThread = new EquivalencesThread(service, preferredCurrencyBitshareAsset, bitsharesAssets);
|
||||
if (LoadEquivalencesThread != null) {
|
||||
LoadEquivalencesThread.stopLoadingEquivalences();
|
||||
}
|
||||
;
|
||||
LoadEquivalencesThread = new EquivalencesThread(service, generalSetting.getValue(), bitsharesAssets);
|
||||
LoadEquivalencesThread.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ import cy.agorise.crystalwallet.models.BitsharesAsset;
|
|||
public class EquivalencesThread extends Thread{
|
||||
private boolean keepLoadingEquivalences = true;
|
||||
private LifecycleService service;
|
||||
private BitsharesAsset fromAsset;
|
||||
private String fromAsset;
|
||||
private List<BitsharesAsset> bitsharesAssets;
|
||||
|
||||
public EquivalencesThread(LifecycleService service, BitsharesAsset fromAsset, List<BitsharesAsset> bitsharesAssets){
|
||||
public EquivalencesThread(LifecycleService service, String fromAsset, List<BitsharesAsset> bitsharesAssets){
|
||||
this.service = service;
|
||||
this.fromAsset = fromAsset;
|
||||
this.bitsharesAssets = bitsharesAssets;
|
||||
|
@ -30,7 +30,7 @@ public class EquivalencesThread extends Thread{
|
|||
|
||||
while(this.keepLoadingEquivalences){
|
||||
try {
|
||||
GrapheneApiGenerator.getEquivalentValue(fromAsset, bitsharesAssets, this.service);
|
||||
GrapheneApiGenerator.getEquivalenValue(fromAsset, bitsharesAssets, this.service);
|
||||
Log.i("Equivalences Thread", "In loop");
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -70,8 +70,9 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
|
|||
//Retrieves the currency of this balance
|
||||
final CryptoCurrency currencyFrom = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId());
|
||||
//Sets the name and amount of the balance in the view
|
||||
String balanceString = String.format("%.2f",balance.getBalance()/Math.pow(10,currencyFrom.getPrecision()));
|
||||
cryptoCoinName.setText(currencyFrom.getName());
|
||||
cryptoCoinBalance.setText("" + balance.getBalance());
|
||||
cryptoCoinBalance.setText(balanceString);
|
||||
|
||||
//Observes the preferred currency of the user. If the user changes it, this will change the equivalent value
|
||||
preferedCurrencySetting.observe((LifecycleOwner) this.context, new Observer<GeneralSetting>() {
|
||||
|
@ -84,8 +85,9 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
|
|||
//Retrieves the equivalent value of this balance using the "From" currency and the "To" currency
|
||||
LiveData<CryptoCurrencyEquivalence> currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(context)
|
||||
.cryptoCurrencyEquivalenceDao().getByFromTo(
|
||||
currencyFrom.getId(),
|
||||
currencyTo.getId()
|
||||
currencyTo.getId(),
|
||||
currencyFrom.getId()
|
||||
|
||||
);
|
||||
|
||||
//Observes the equivalent value. If the equivalent value changes, this will keep the value showed correct
|
||||
|
@ -93,8 +95,15 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
|
|||
@Override
|
||||
public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) {
|
||||
if (cryptoCurrencyEquivalence != null) {
|
||||
CryptoCurrency toCurrency = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(cryptoCurrencyEquivalence.getToCurrencyId());
|
||||
cryptoCoinBalanceEquivalence.setText(cryptoCurrencyEquivalence.getValue() + " " + toCurrency.getName());
|
||||
CryptoCurrency toCurrency = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(cryptoCurrencyEquivalence.getFromCurrencyId());
|
||||
String equivalenceString = String.format(
|
||||
"%.2f",
|
||||
(balance.getBalance()/Math.pow(10,currencyFrom.getPrecision()))/
|
||||
(cryptoCurrencyEquivalence.getValue()/Math.pow(10,toCurrency.getPrecision()))
|
||||
);
|
||||
|
||||
cryptoCoinBalanceEquivalence.setText(
|
||||
equivalenceString + " " + toCurrency.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue