From a5dcf393bfe1e82aaea8873aa9d6fe3b267973cb Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 20 Jun 2018 22:25:53 -0400 Subject: [PATCH] - Added function to Crystal Service to get the bitshares account names of the transaction's accounts id --- .../dao/BitsharesAccountNameCacheDao.java | 5 +++ .../GetBitsharesAccountNameCacheRequest.java | 34 +++++++++++++++ .../service/CrystalWalletService.java | 41 ++++++++++++++----- 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/GetBitsharesAccountNameCacheRequest.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/BitsharesAccountNameCacheDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/BitsharesAccountNameCacheDao.java index e54c11a..f674095 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/BitsharesAccountNameCacheDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/BitsharesAccountNameCacheDao.java @@ -27,6 +27,11 @@ public interface BitsharesAccountNameCacheDao { @Query("SELECT * FROM bitshares_account_name_cache WHERE name = :account_name") BitsharesAccountNameCache getByAccountName(String account_name); + @Query("SELECT -1 AS id, cct.'to' AS account_id, '' AS name FROM crypto_coin_transaction AS cct WHERE cct.'to' NOT IN (SELECT account_id FROM bitshares_account_name_cache banc)" + + " UNION " + + "SELECT -1 AS id, cct.'from' AS account_id, '' AS name FROM crypto_coin_transaction AS cct WHERE cct.'from' NOT IN (SELECT account_id FROM bitshares_account_name_cache banc)") + LiveData> getUncachedBitsharesAccountName(); + @Insert(onConflict = OnConflictStrategy.REPLACE) public long[] insertBitsharesAccountNameCache(BitsharesAccountNameCache... accountsNames); diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/GetBitsharesAccountNameCacheRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/GetBitsharesAccountNameCacheRequest.java new file mode 100644 index 0000000..48cbef0 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/GetBitsharesAccountNameCacheRequest.java @@ -0,0 +1,34 @@ +package cy.agorise.crystalwallet.requestmanagers; + +import android.content.Context; + +import cy.agorise.crystalwallet.enums.CryptoCoin; + +/** + * Created by henry on 6/20/2018. + */ + +public class GetBitsharesAccountNameCacheRequest extends CryptoNetInfoRequest { + + private String accountId; + private String accountName; + + public GetBitsharesAccountNameCacheRequest(Context context, String accountId) { + super(CryptoCoin.BITSHARES); + this.accountId = accountId; + this.accountName = ""; + } + + public void setAccountName(String accountName){ + this.accountName = accountName; + this.validate(); + } + + public void validate(){ + if ((!this.accountName.equals(""))){ + this._fireOnCarryOutEvent(); + } + } + + +} 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 1fb1442..ecffcc3 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/service/CrystalWalletService.java +++ b/app/src/main/java/cy/agorise/crystalwallet/service/CrystalWalletService.java @@ -15,7 +15,9 @@ import android.util.Log; import java.util.ArrayList; import java.util.List; +import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator; import cy.agorise.crystalwallet.manager.FileBackupManager; +import cy.agorise.crystalwallet.models.BitsharesAccountNameCache; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.enums.CryptoNet; @@ -29,6 +31,7 @@ import cy.agorise.crystalwallet.models.GrapheneAccount; import cy.agorise.crystalwallet.models.GrapheneAccountInfo; import cy.agorise.crystalwallet.requestmanagers.FileServiceRequest; import cy.agorise.crystalwallet.requestmanagers.FileServiceRequests; +import cy.agorise.crystalwallet.requestmanagers.GetBitsharesAccountNameCacheRequest; /** * Created by Henry Varona on 3/10/2017. @@ -41,6 +44,7 @@ public class CrystalWalletService extends LifecycleService { private ServiceHandler mServiceHandler; private BitsharesAccountManager bitsharesAccountManager; private Thread LoadAccountTransactionsThread; + private Thread LoadBitsharesAccountNamesThread; private EquivalencesThread LoadEquivalencesThread; private boolean keepLoadingAccountTransactions; private boolean keepLoadingEquivalences; @@ -64,6 +68,23 @@ public class CrystalWalletService extends LifecycleService { } } + public void loadBitsharesAccountNames(){ + final LifecycleService service = this; + final LiveData> uncachedBitsharesAccountNames = + CrystalDatabase.getAppDatabase(service).bitsharesAccountNameCacheDao().getUncachedBitsharesAccountName(); + + uncachedBitsharesAccountNames.observe(service, new Observer>() { + @Override + public void onChanged(@Nullable List bitsharesAccountNameCacheList) { + for (BitsharesAccountNameCache nextAccountId : bitsharesAccountNameCacheList){ + GetBitsharesAccountNameCacheRequest request = new GetBitsharesAccountNameCacheRequest(service, nextAccountId.getAccountId()); + + CryptoNetInfoRequests.getInstance().addRequest(request); + } + } + }); + } + public void loadEquivalentsValues(){ this.keepLoadingEquivalences = true; final LifecycleService service = this; @@ -189,16 +210,16 @@ public class CrystalWalletService extends LifecycleService { }; LoadAccountTransactionsThread.start(); } - - //if (LoadEquivalencesThread == null) { - // LoadEquivalencesThread = new EquivalencesThread() { - // @Override - // public void run() { - loadEquivalentsValues(); - // } - // }; - // LoadEquivalencesThread.start(); - // } + if (LoadBitsharesAccountNamesThread == null) { + LoadBitsharesAccountNamesThread = new Thread() { + @Override + public void run() { + loadBitsharesAccountNames(); + } + }; + LoadBitsharesAccountNamesThread.start(); + } + loadEquivalentsValues(); // If we get killed, after returning from here, restart return START_STICKY;