From 6ce7c453f48cf3cadf98137e51fb89315f113e78 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 22 Oct 2017 20:36:41 -0400 Subject: [PATCH] Subscrip --- .../crystalwallet/apigenerator/GrapheneApiGenerator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index e1d76bd..d01b989 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -6,6 +6,7 @@ import android.content.Context; import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import cy.agorise.crystalwallet.dao.BitsharesAssetDao; @@ -65,6 +66,7 @@ public abstract class GrapheneApiGenerator { }); private static WebSocketThread subscriptionThread = new WebSocketThread(bitsharesSubscriptionHub,url); + private static HashMap currentBitsharesListener = new HashMap<>(); /** * Retrieves the data of an account searching by it's id @@ -302,6 +304,7 @@ public abstract class GrapheneApiGenerator { } public static void subscribeBitsharesAccount(final long accountId, final String accountBitsharesId, final Context context){ + if(!currentBitsharesListener.containsKey(accountId)){ CrystalDatabase db = CrystalDatabase.getAppDatabase(context); final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao(); final BitsharesAssetDao bitsharesAssetDao = db.bitsharesAssetDao(); @@ -357,6 +360,7 @@ public abstract class GrapheneApiGenerator { } }; + currentBitsharesListener.put(accountId,balanceListener); bitsharesSubscriptionHub.addSubscriptionListener(balanceListener); if(!subscriptionThread.isConnected()){ @@ -364,6 +368,7 @@ public abstract class GrapheneApiGenerator { }else if(!bitsharesSubscriptionHub.isSubscribed()){ bitsharesSubscriptionHub.resubscribe(); } + } } public static void cancelBitsharesAccountSubcriptions(){ @@ -371,6 +376,7 @@ public abstract class GrapheneApiGenerator { } public static void getAccountBalance(final long accountId, final String accountGrapheneId, final Context context){ + CrystalDatabase db = CrystalDatabase.getAppDatabase(context); final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao(); final BitsharesAssetDao bitsharesAssetDao = db.bitsharesAssetDao();