Increasing the current id after sending the message and moved the shared preferences setup to the SampleApplication class

This commit is contained in:
Nelson R. Perez 2018-04-05 23:16:10 -05:00
parent 1848c82a46
commit 6bda451f72
4 changed files with 17 additions and 17 deletions

View file

@ -71,7 +71,6 @@ public class NetworkService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
Log.d(TAG,"onCreate");
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
// Retrieving credentials and requested API data from the shared preferences // 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)){ if(requiredApi != -1 && mApiIds.containsKey(requiredApi)){
apiId = mApiIds.get(requiredApi); apiId = mApiIds.get(requiredApi);
} }
ApiCall call = apiCallable.toApiCall(apiId, mCurrentId); ApiCall call = apiCallable.toApiCall(apiId, ++mCurrentId);
if(mWebSocket.send(call.toJsonString())){ if(mWebSocket.send(call.toJsonString())){
Log.v(TAG,"> "+call.toJsonString()); Log.v(TAG,"-> "+call.toJsonString());
}else{ }else{
Log.w(TAG,"Message not enqueued"); Log.w(TAG,"Message not enqueued");
} }
@ -168,7 +167,7 @@ public class NetworkService extends Service {
@Override @Override
public void onMessage(WebSocket webSocket, String text) { public void onMessage(WebSocket webSocket, String text) {
super.onMessage(webSocket, text); super.onMessage(webSocket, text);
Log.v(TAG,"< "+text); Log.v(TAG,"<- "+text);
JsonRpcResponse<?> response = gson.fromJson(text, JsonRpcResponse.class); JsonRpcResponse<?> response = gson.fromJson(text, JsonRpcResponse.class);
// We will only handle messages that relate to the login and API accesses here. // We will only handle messages that relate to the login and API accesses here.

View file

@ -6,7 +6,6 @@ import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -17,7 +16,6 @@ import com.google.gson.Gson;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import cy.agorise.graphenej.api.ApiAccess;
import cy.agorise.graphenej.api.ConnectionStatusUpdate; import cy.agorise.graphenej.api.ConnectionStatusUpdate;
import cy.agorise.graphenej.api.android.NetworkService; import cy.agorise.graphenej.api.android.NetworkService;
import cy.agorise.graphenej.api.android.RxBus; import cy.agorise.graphenej.api.android.RxBus;
@ -46,16 +44,6 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ButterKnife.bind(this); 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() RxBus.getBusInstance()
.asFlowable() .asFlowable()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())

View file

@ -1,7 +1,10 @@
package com.luminiasoft.labs.sample; package com.luminiasoft.labs.sample;
import android.app.Application; 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; import cy.agorise.graphenej.api.android.NetworkServiceManager;
/** /**
@ -15,6 +18,16 @@ public class SampleApplication extends Application {
public void onCreate() { public void onCreate() {
super.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 * 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 * better estimate when the user has left the app and it is safe to disconnect the websocket connection