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

develop
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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cy.agorise.graphenej">
package="cy.agorise.graphenej">
<uses-sdk android:minSdkVersion="1" />

View File

@ -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.

View File

@ -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())

View File

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