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());
}
}
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);
}
Aggregations