Remove network package testing implementation

This commit is contained in:
dtvv 2018-09-03 10:02:52 -06:00
parent e3eeb76f0e
commit 3e150be199
3 changed files with 1 additions and 172 deletions

View file

@ -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<Long, SubscriptionListener> 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);
}
}

View file

@ -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<String>());
}
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) {

View file

@ -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;
}
}