- Fixed EquivalenceThread to loop in a separated thread.

This commit is contained in:
Javier Varona 2017-11-14 22:29:11 -04:00
parent cf6fcac6cc
commit 2afd7ec47a
2 changed files with 59 additions and 18 deletions

View file

@ -41,7 +41,7 @@ public class CrystalWalletService extends LifecycleService {
private ServiceHandler mServiceHandler; private ServiceHandler mServiceHandler;
private BitsharesAccountManager bitsharesAccountManager; private BitsharesAccountManager bitsharesAccountManager;
private Thread LoadAccountTransactionsThread; private Thread LoadAccountTransactionsThread;
private Thread LoadEquivalencesThread; private EquivalencesThread LoadEquivalencesThread;
private boolean keepLoadingAccountTransactions; private boolean keepLoadingAccountTransactions;
private boolean keepLoadingEquivalences; private boolean keepLoadingEquivalences;
private CryptoNetInfoRequests cryptoNetInfoRequests; private CryptoNetInfoRequests cryptoNetInfoRequests;
@ -106,22 +106,15 @@ public class CrystalWalletService extends LifecycleService {
bitsharesAssets.add(nextAsset); bitsharesAssets.add(nextAsset);
} }
while (keepLoadingEquivalences) { if (LoadEquivalencesThread != null){LoadEquivalencesThread.stopLoadingEquivalences();};
try { LoadEquivalencesThread = new EquivalencesThread(service, preferredCurrencyBitshareAsset, bitsharesAssets);
GrapheneApiGenerator.getEquivalentValue(preferredCurrencyBitshareAsset, bitsharesAssets, service); LoadEquivalencesThread.start();
Thread.sleep(/*60000*/500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
} }
}); });
} }
} }
} }
}); });
} }
public void loadAccountTransactions(){ public void loadAccountTransactions(){
@ -177,6 +170,7 @@ public class CrystalWalletService extends LifecycleService {
if (LoadAccountTransactionsThread == null) { if (LoadAccountTransactionsThread == null) {
LoadAccountTransactionsThread = new Thread() { LoadAccountTransactionsThread = new Thread() {
@Override
public void run() { public void run() {
loadAccountTransactions(); loadAccountTransactions();
} }
@ -184,14 +178,15 @@ public class CrystalWalletService extends LifecycleService {
LoadAccountTransactionsThread.start(); LoadAccountTransactionsThread.start();
} }
if (LoadEquivalencesThread == null) { //if (LoadEquivalencesThread == null) {
LoadEquivalencesThread = new Thread() { // LoadEquivalencesThread = new Thread() {
public void run() { // @Override
// public void run() {
loadEquivalentsValues(); loadEquivalentsValues();
} // }
}; // };
LoadEquivalencesThread.start(); // LoadEquivalencesThread.start();
} //}
// If we get killed, after returning from here, restart // If we get killed, after returning from here, restart
return START_STICKY; return START_STICKY;

View file

@ -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<BitsharesAsset> bitsharesAssets;
public EquivalencesThread(LifecycleService service, BitsharesAsset fromAsset, List<BitsharesAsset> 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;
}
}