Search in sources :

Example 6 with MinerRoot

use of it.angelic.mpw.model.jsonpojos.miners.MinerRoot in project MPW by shineangelic.

the class MasterInstrumentedTest method TestJsonMinerSyncReq.

@Test
public void TestJsonMinerSyncReq() {
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, Utils.getMinersStatsUrl(sharedPreferences), new JSONObject(), future, future);
    JSONClientSingleton.getInstance(appContext).addToRequestQueue(request);
    Gson gson = TestUtils.getGsonFromBuilder();
    try {
        // this will block
        JSONObject response = future.get();
        MinerRoot retrieved = gson.fromJson(response.toString(), MinerRoot.class);
        assertNotNull(retrieved);
        HashMap<String, Miner> map = retrieved.getMiners();
        String[] minerArr = new String[map.size()];
        minerArr = map.keySet().toArray(minerArr);
        assertNotNull(minerArr);
    } catch (InterruptedException e) {
        fail(e.getMessage());
    } catch (ExecutionException e) {
        fail(e.getMessage());
    }
}
Also used : Miner(it.angelic.mpw.model.jsonpojos.miners.Miner) JSONObject(org.json.JSONObject) MinerRoot(it.angelic.mpw.model.jsonpojos.miners.MinerRoot) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 7 with MinerRoot

use of it.angelic.mpw.model.jsonpojos.miners.MinerRoot in project MPW by shineangelic.

the class MinersActivity method issueRefresh.

private void issueRefresh() {
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getMinersStatsUrl(PreferenceManager.getDefaultSharedPreferences(MinersActivity.this)), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.d(Constants.TAG, response.toString());
            textViewBlocksTitle.post(new Runnable() {

                @Override
                public void run() {
                    Gson gson = builder.create();
                    // Register an adapter to manage the date types as long values
                    MinerRoot retrieved = gson.fromJson(response.toString(), MinerRoot.class);
                    // sort order
                    RadioButton rb = findViewById(R.id.radioButtonLastSeen);
                    new UpdateUIAsynchTask(retrieved, rb.isChecked() ? MinerSortEnum.LAST_SEEN : MinerSortEnum.HASHRATE).execute();
                }
            });
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.e(Constants.TAG, "Error: " + error.getMessage());
            Snackbar.make(findViewById(android.R.id.content), "Network Error", Snackbar.LENGTH_SHORT).show();
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(this).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) MinerRoot(it.angelic.mpw.model.jsonpojos.miners.MinerRoot) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) RadioButton(android.widget.RadioButton)

Aggregations

MinerRoot (it.angelic.mpw.model.jsonpojos.miners.MinerRoot)7 JSONObject (org.json.JSONObject)7 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)6 Gson (com.google.gson.Gson)6 Test (org.junit.Test)5 Response (com.android.volley.Response)4 VolleyError (com.android.volley.VolleyError)4 GsonBuilder (com.google.gson.GsonBuilder)3 Miner (it.angelic.mpw.model.jsonpojos.miners.Miner)3 ExecutionException (java.util.concurrent.ExecutionException)2 RadioButton (android.widget.RadioButton)1 Wallet (it.angelic.mpw.model.jsonpojos.wallet.Wallet)1