From 3e150be1997e8c937aca53ca58090c2d76bf5b15 Mon Sep 17 00:00:00 2001 From: dtvv Date: Mon, 3 Sep 2018 10:02:52 -0600 Subject: [PATCH] Remove network package testing implementation --- .../apigenerator/GrapheneApiGenerator.java | 58 -------------- .../network/CryptoNetManager.java | 37 +-------- .../network/WebSocketThread.java | 78 ------------------- 3 files changed, 1 insertion(+), 172 deletions(-) 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 9d781fd..575a75c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -1,6 +1,5 @@ package cy.agorise.crystalwallet.apigenerator; -import android.app.Activity; import android.content.Context; import java.io.Serializable; @@ -9,7 +8,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; -import cy.agorise.crystalwallet.application.constant.BitsharesConstant; import cy.agorise.crystalwallet.dao.BitsharesAssetDao; import cy.agorise.crystalwallet.dao.CryptoCoinBalanceDao; import cy.agorise.crystalwallet.dao.CryptoCurrencyDao; @@ -82,28 +80,6 @@ public abstract class GrapheneApiGenerator { */ private static HashMap currentBitsharesListener = new HashMap<>(); - /* - * - * To present erros to user - * */ - private static Activity activity; - - - /* - * - * Interface to catch only errors in connection with sockets - * */ - private static OnErrorWebSocket onErrorWebSocket; - - /* - * - * Interface to catch both errors and success in connection with sockets - * */ - private static OnResponsesWebSocket onResponsesWebSocker; - - - - /** @@ -246,8 +222,6 @@ public abstract class GrapheneApiGenerator { request.getListener().fail(request.getId()); } }), CryptoNetManager.getURL(CryptoNet.BITSHARES)); - thread.setActivity(activity); //To catch websocket errors to user interface - thread.setOnErrorWebSocker(onErrorWebSocket); //To deliver websocket errors to user interface thread.start(); } @@ -729,36 +703,4 @@ public abstract class GrapheneApiGenerator { } } - - - public static void setActivity(Activity activity) { - GrapheneApiGenerator.activity = activity; - } - - - public static void setOnResponsesWebSocker(OnResponsesWebSocket onResponsesWebSocker) { - GrapheneApiGenerator.onResponsesWebSocker = onResponsesWebSocker; - } - - public static void setOnErrorWebSocket(OnErrorWebSocket onErrorWebSocket) { - GrapheneApiGenerator.onErrorWebSocket = onErrorWebSocket; - } - - /* - * - * Interface to catch errors in connection with sockets - * */ - public interface OnErrorWebSocket { - void onError(Exception exception); - } - - /* - * - * Interface to catch succesfully connection with sockets - * */ - public interface OnResponsesWebSocket { - void onSuccess(); - void onError(Exception exception); - } - } diff --git a/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetManager.java b/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetManager.java index 8084096..5603df8 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/network/CryptoNetManager.java @@ -1,6 +1,5 @@ package cy.agorise.crystalwallet.network; -import android.app.Activity; import android.support.annotation.NonNull; import java.util.ArrayList; @@ -8,7 +7,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator; import cy.agorise.crystalwallet.enums.CryptoNet; /** @@ -62,51 +60,18 @@ public abstract class CryptoNetManager { } - /* - * Add url with listener on error only for sockets - * */ - public static void addCryptoNetURL(CryptoNet crypto, - String[] urls, - final Activity activity, - final GrapheneApiGenerator.OnErrorWebSocket onErrorWebSocker, - final boolean showNormalError){ - addCryptoNetURL(crypto,urls,activity,onErrorWebSocker,null,showNormalError); - } - - - /* - * Add url with listener on error and response for sockets - * */ - public static void addCryptoNetURL(CryptoNet crypto, - String[] urls, - final Activity activity, - final GrapheneApiGenerator.OnResponsesWebSocket onResponsesWebSocket, - final boolean showNormalError){ - addCryptoNetURL(crypto,urls,activity,null,onResponsesWebSocket,showNormalError); - } - - /* * Utility for above methods * * */ public static void addCryptoNetURL(CryptoNet crypto, - String[] urls, - final Activity activity, - final GrapheneApiGenerator.OnErrorWebSocket onErrorWebSocker, - final GrapheneApiGenerator.OnResponsesWebSocket onResponsesWebSocket, - final boolean showNormalError) { + String[] urls) { if (!CryptoNetURLs.containsKey(crypto)) { CryptoNetURLs.put(crypto, new HashSet()); } CryptoNetVerifier verifier = CryptoNetVerifier.getNetworkVerify(crypto); - verifier.getThread().setActivity(activity); //Logical connection to ui - verifier.getThread().setOnErrorWebSocker(onErrorWebSocker); //Connect response web socket error to ui response - verifier.getThread().setOnResponsesWebSocket(onResponsesWebSocket); //Connect response and error web socket error to ui response - verifier.getThread().setShowNormalMessage(showNormalError); //Not show native message error, we handle it - for (String url : urls) { CryptoNetURLs.get(crypto).add(url); if (verifier != null) { diff --git a/app/src/main/java/cy/agorise/crystalwallet/network/WebSocketThread.java b/app/src/main/java/cy/agorise/crystalwallet/network/WebSocketThread.java index 3009f2e..58f4dad 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/network/WebSocketThread.java +++ b/app/src/main/java/cy/agorise/crystalwallet/network/WebSocketThread.java @@ -1,8 +1,6 @@ package cy.agorise.crystalwallet.network; -import android.app.Activity; import android.util.Log; -import android.widget.Toast; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketFactory; @@ -11,9 +9,6 @@ import com.neovisionaries.ws.client.WebSocketListener; import java.io.IOException; import java.util.HashMap; -import cy.agorise.crystalwallet.activities.LoadingActivity; -import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator; - /** * Created by henry on 8/10/2017. */ @@ -37,29 +32,6 @@ public class WebSocketThread extends Thread { // If the parameters of this class can be change private boolean canChange = true; - /* - * - * Interface to catch only errors in connection with sockets - * */ - private GrapheneApiGenerator.OnErrorWebSocket onErrorWebSocker; - - /* - * - * Interface to catch errors and success responses in connection with sockets - * */ - private GrapheneApiGenerator.OnResponsesWebSocket onResponsesWebSocket; - - - /* - * To catch websocket errors - * */ - private Activity activity; - - /* - * To show normal error message or not - * */ - private boolean showNormalMessage = true; - /* * Object needed for socket connection @@ -173,42 +145,8 @@ public class WebSocketThread extends Thread { WebSocketThread.currentThreads.put(this.getId(),this); mWebSocket.connect(); - /* - * - * Websocket success response - * */ - if(onResponsesWebSocket!=null){ - onResponsesWebSocket.onSuccess(); - } - } catch (final Exception e) { Log.e(TAG, "WebSocketException. Msg: "+e.getMessage()); - - //Deliver error to user - if(activity!=null){ - - /* - * Show error to user if aplies - * */ - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - - if(showNormalMessage){ - Toast.makeText(activity, e.getMessage(), Toast.LENGTH_LONG).show(); - } - } - }); - - /*Deliver response in the listeners*/ - if(onErrorWebSocker!=null){ - onErrorWebSocker.onError(e); - } - else if(onResponsesWebSocket!=null){ - onResponsesWebSocket.onError(e); - } - } - } WebSocketThread.currentThreads.remove(this.getId()); } @@ -218,23 +156,7 @@ public class WebSocketThread extends Thread { } - public void setOnErrorWebSocker(GrapheneApiGenerator.OnErrorWebSocket onErrorWebSocker) { - this.onErrorWebSocker = onErrorWebSocker; - } - - public void setActivity(Activity activity) { - this.activity = activity; - } - - public void setShowNormalMessage(boolean showNormalMessage) { - this.showNormalMessage = showNormalMessage; - } - public void setmUrl(String mUrl) { this.mUrl = mUrl; } - - public void setOnResponsesWebSocket(GrapheneApiGenerator.OnResponsesWebSocket onResponsesWebSocket) { - this.onResponsesWebSocket = onResponsesWebSocket; - } }