Increasing the current id after sending the message and moved the shared preferences setup to the SampleApplication class
This commit is contained in:
parent
1848c82a46
commit
6bda451f72
4 changed files with 17 additions and 17 deletions
|
@ -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.
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue