From f3731d140b75a94cddf297708aade84e20a6322f Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Wed, 7 Nov 2018 17:36:35 -0500 Subject: [PATCH] Logging connection status updates and including a new node URL in the sample app --- .../cy/agorise/labs/sample/CallsActivity.java | 31 +++++++++++++++++++ .../labs/sample/SampleApplication.java | 1 + 2 files changed, 32 insertions(+) diff --git a/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java b/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java index f2a9638..bcd8ab8 100644 --- a/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java +++ b/sample/src/main/java/cy/agorise/labs/sample/CallsActivity.java @@ -7,6 +7,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.TextView; @@ -14,12 +15,21 @@ import android.widget.TextView; import butterknife.BindView; import butterknife.ButterKnife; import cy.agorise.graphenej.RPC; +import cy.agorise.graphenej.api.ConnectionStatusUpdate; +import cy.agorise.graphenej.api.android.RxBus; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.disposables.Disposable; +import io.reactivex.functions.Consumer; public class CallsActivity extends AppCompatActivity { + private final String TAG = this.getClass().getName(); @BindView(R.id.call_list) RecyclerView mRecyclerView; + private CompositeDisposable compositeDisposable = new CompositeDisposable(); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -29,6 +39,21 @@ public class CallsActivity extends AppCompatActivity { mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL)); mRecyclerView.setAdapter(new CallAdapter()); + + Disposable disposable = RxBus.getBusInstance() + .asFlowable() + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer() { + + @Override + public void accept(Object message) throws Exception { + if(message instanceof ConnectionStatusUpdate){ + ConnectionStatusUpdate statusUpdate = (ConnectionStatusUpdate) message; + Log.d(TAG, String.format("ConnectionStatusUpdate. code: %d, api: %d", statusUpdate.getUpdateCode(),statusUpdate.getApi())); + } + } + }); + compositeDisposable.add(disposable); } private final class CallAdapter extends RecyclerView.Adapter { @@ -93,4 +118,10 @@ public class CallsActivity extends AppCompatActivity { } } } + + @Override + protected void onDestroy() { + super.onDestroy(); + compositeDisposable.dispose(); + } } diff --git a/sample/src/main/java/cy/agorise/labs/sample/SampleApplication.java b/sample/src/main/java/cy/agorise/labs/sample/SampleApplication.java index c911611..1336b2d 100644 --- a/sample/src/main/java/cy/agorise/labs/sample/SampleApplication.java +++ b/sample/src/main/java/cy/agorise/labs/sample/SampleApplication.java @@ -23,6 +23,7 @@ public class SampleApplication extends Application { int requestedApis = ApiAccess.API_DATABASE | ApiAccess.API_HISTORY | ApiAccess.API_NETWORK_BROADCAST; String[] nodeURLs = new String[]{ + "wss://miami.bitshares.apasia.tech/ws", "wss://bitshares.crypto.fans/ws", "wss://bitshares.openledger.info/ws", "wss://us.nodes.bitshares.ws",