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
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="cy.agorise.graphenej">
|
package="cy.agorise.graphenej">
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="1" />
|
<uses-sdk android:minSdkVersion="1" />
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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())
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue