diff --git a/app/src/main/java/cy/agorise/crystalwallet/service/CrystalWalletService.java b/app/src/main/java/cy/agorise/crystalwallet/service/CrystalWalletService.java index ab048f6..ebb55ef 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/service/CrystalWalletService.java +++ b/app/src/main/java/cy/agorise/crystalwallet/service/CrystalWalletService.java @@ -41,7 +41,7 @@ public class CrystalWalletService extends LifecycleService { private ServiceHandler mServiceHandler; private BitsharesAccountManager bitsharesAccountManager; private Thread LoadAccountTransactionsThread; - private Thread LoadEquivalencesThread; + private EquivalencesThread LoadEquivalencesThread; private boolean keepLoadingAccountTransactions; private boolean keepLoadingEquivalences; private CryptoNetInfoRequests cryptoNetInfoRequests; @@ -106,22 +106,15 @@ public class CrystalWalletService extends LifecycleService { bitsharesAssets.add(nextAsset); } - while (keepLoadingEquivalences) { - try { - GrapheneApiGenerator.getEquivalentValue(preferredCurrencyBitshareAsset, bitsharesAssets, service); - Thread.sleep(/*60000*/500); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } + if (LoadEquivalencesThread != null){LoadEquivalencesThread.stopLoadingEquivalences();}; + LoadEquivalencesThread = new EquivalencesThread(service, preferredCurrencyBitshareAsset, bitsharesAssets); + LoadEquivalencesThread.start(); } }); } } } }); - - } public void loadAccountTransactions(){ @@ -177,6 +170,7 @@ public class CrystalWalletService extends LifecycleService { if (LoadAccountTransactionsThread == null) { LoadAccountTransactionsThread = new Thread() { + @Override public void run() { loadAccountTransactions(); } @@ -184,14 +178,15 @@ public class CrystalWalletService extends LifecycleService { LoadAccountTransactionsThread.start(); } - if (LoadEquivalencesThread == null) { - LoadEquivalencesThread = new Thread() { - public void run() { + //if (LoadEquivalencesThread == null) { + // LoadEquivalencesThread = new Thread() { + // @Override + // public void run() { loadEquivalentsValues(); - } - }; - LoadEquivalencesThread.start(); - } + // } + // }; + // LoadEquivalencesThread.start(); + //} // If we get killed, after returning from here, restart return START_STICKY; diff --git a/app/src/main/java/cy/agorise/crystalwallet/service/EquivalencesThread.java b/app/src/main/java/cy/agorise/crystalwallet/service/EquivalencesThread.java new file mode 100644 index 0000000..1248ccc --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/service/EquivalencesThread.java @@ -0,0 +1,46 @@ +package cy.agorise.crystalwallet.service; + +import android.arch.lifecycle.LifecycleService; +import android.util.Log; + +import java.util.List; + +import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator; +import cy.agorise.crystalwallet.models.BitsharesAsset; + +/** + * Created by Henry Varona on 14/11/2017. + */ + +public class EquivalencesThread extends Thread{ + private boolean keepLoadingEquivalences = true; + private LifecycleService service; + private BitsharesAsset fromAsset; + private List bitsharesAssets; + + public EquivalencesThread(LifecycleService service, BitsharesAsset fromAsset, List bitsharesAssets){ + this.service = service; + this.fromAsset = fromAsset; + this.bitsharesAssets = bitsharesAssets; + } + + @Override + public void run() { + super.run(); + + while(this.keepLoadingEquivalences){ + try { + GrapheneApiGenerator.getEquivalentValue(fromAsset, bitsharesAssets, this.service); + Log.i("Equivalences Thread", "In loop"); + Thread.sleep(1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + + } + } + + public void stopLoadingEquivalences(){ + this.keepLoadingEquivalences = false; + } +}