From 04e6fe5b5cfb36966906b6038d9f72cf4488a9ea Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Thu, 5 Apr 2018 23:16:10 -0500 Subject: [PATCH] Increasing the current id after sending the message and moved the shared preferences setup to the SampleApplication class --- graphenej/src/main/AndroidManifest.xml | 2 +- .../graphenej/api/android/NetworkService.java | 7 +++---- .../com/luminiasoft/labs/sample/MainActivity.java | 12 ------------ .../luminiasoft/labs/sample/SampleApplication.java | 13 +++++++++++++ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/graphenej/src/main/AndroidManifest.xml b/graphenej/src/main/AndroidManifest.xml index 245e180..1531629 100644 --- a/graphenej/src/main/AndroidManifest.xml +++ b/graphenej/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="cy.agorise.graphenej"> diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java index 882bcd4..de26eb2 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java @@ -71,7 +71,6 @@ public class NetworkService extends Service { @Override public void onCreate() { super.onCreate(); - Log.d(TAG,"onCreate"); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); // Retrieving credentials and requested API data from the shared preferences @@ -104,9 +103,9 @@ public class NetworkService extends Service { if(requiredApi != -1 && mApiIds.containsKey(requiredApi)){ apiId = mApiIds.get(requiredApi); } - ApiCall call = apiCallable.toApiCall(apiId, mCurrentId); + ApiCall call = apiCallable.toApiCall(apiId, ++mCurrentId); if(mWebSocket.send(call.toJsonString())){ - Log.v(TAG,"> "+call.toJsonString()); + Log.v(TAG,"-> "+call.toJsonString()); }else{ Log.w(TAG,"Message not enqueued"); } @@ -168,7 +167,7 @@ public class NetworkService extends Service { @Override public void onMessage(WebSocket webSocket, String text) { super.onMessage(webSocket, text); - Log.v(TAG,"< "+text); + Log.v(TAG,"<- "+text); JsonRpcResponse response = gson.fromJson(text, JsonRpcResponse.class); // We will only handle messages that relate to the login and API accesses here. diff --git a/sample/src/main/java/com/luminiasoft/labs/sample/MainActivity.java b/sample/src/main/java/com/luminiasoft/labs/sample/MainActivity.java index b2e280f..7ccefb0 100644 --- a/sample/src/main/java/com/luminiasoft/labs/sample/MainActivity.java +++ b/sample/src/main/java/com/luminiasoft/labs/sample/MainActivity.java @@ -6,7 +6,6 @@ import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; -import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; @@ -17,7 +16,6 @@ import com.google.gson.Gson; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -import cy.agorise.graphenej.api.ApiAccess; import cy.agorise.graphenej.api.ConnectionStatusUpdate; import cy.agorise.graphenej.api.android.NetworkService; import cy.agorise.graphenej.api.android.RxBus; @@ -46,16 +44,6 @@ public class MainActivity extends AppCompatActivity { setContentView(R.layout.activity_main); ButterKnife.bind(this); - // Specifying some important information regarding the connection, such as the - // credentials and the requested API accesses - int requestedApis = ApiAccess.API_DATABASE | ApiAccess.API_HISTORY | ApiAccess.API_NETWORK_BROADCAST; - PreferenceManager.getDefaultSharedPreferences(this) - .edit() - .putString(NetworkService.KEY_USERNAME, "nelson") - .putString(NetworkService.KEY_PASSWORD, "secret") - .putInt(NetworkService.KEY_REQUESTED_APIS, requestedApis) - .apply(); - RxBus.getBusInstance() .asFlowable() .observeOn(AndroidSchedulers.mainThread()) diff --git a/sample/src/main/java/com/luminiasoft/labs/sample/SampleApplication.java b/sample/src/main/java/com/luminiasoft/labs/sample/SampleApplication.java index ba2b651..37286ad 100644 --- a/sample/src/main/java/com/luminiasoft/labs/sample/SampleApplication.java +++ b/sample/src/main/java/com/luminiasoft/labs/sample/SampleApplication.java @@ -1,7 +1,10 @@ package com.luminiasoft.labs.sample; import android.app.Application; +import android.preference.PreferenceManager; +import cy.agorise.graphenej.api.ApiAccess; +import cy.agorise.graphenej.api.android.NetworkService; import cy.agorise.graphenej.api.android.NetworkServiceManager; /** @@ -15,6 +18,16 @@ public class SampleApplication extends Application { public void onCreate() { super.onCreate(); + // Specifying some important information regarding the connection, such as the + // credentials and the requested API accesses + int requestedApis = ApiAccess.API_DATABASE | ApiAccess.API_HISTORY | ApiAccess.API_NETWORK_BROADCAST; + PreferenceManager.getDefaultSharedPreferences(this) + .edit() + .putString(NetworkService.KEY_USERNAME, "nelson") + .putString(NetworkService.KEY_PASSWORD, "secret") + .putInt(NetworkService.KEY_REQUESTED_APIS, requestedApis) + .apply(); + /* * Registering this class as a listener to all activity's callback cycle events, in order to * better estimate when the user has left the app and it is safe to disconnect the websocket connection