- Fixed EquivalenceThread to loop in a separated thread.
This commit is contained in:
parent
cf6fcac6cc
commit
2afd7ec47a
2 changed files with 59 additions and 18 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue