use of it.angelic.mpw.model.jsonpojos.blocks.Block in project MPW by shineangelic.
the class KratosInstrumentedTest method testJsonBlockRequest.
@Test
public void testJsonBlockRequest() throws Exception {
final GsonBuilder builder = new GsonBuilder();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getBlocksURL(sharedPreferences), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.i(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
Block retrieved = gson.fromJson(response.toString(), Block.class);
assertNotNull(retrieved);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(Constants.TAG, "Error: " + error.getMessage());
fail(error.getMessage());
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
use of it.angelic.mpw.model.jsonpojos.blocks.Block in project MPW by shineangelic.
the class NoobPoolInstrumentedTest method testJsonBlockRequest.
@Test
public void testJsonBlockRequest() throws Exception {
final GsonBuilder builder = new GsonBuilder();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getBlocksURL(sharedPreferences), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.i(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
Block retrieved = gson.fromJson(response.toString(), Block.class);
assertNotNull(retrieved);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(Constants.TAG, "Error: " + error.getMessage());
fail();
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
use of it.angelic.mpw.model.jsonpojos.blocks.Block in project MPW by shineangelic.
the class BlocksActivity method issueRefresh.
private void issueRefresh(final GsonBuilder builder) {
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getBlocksURL(PreferenceManager.getDefaultSharedPreferences(BlocksActivity.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
Block retrieved = gson.fromJson(response.toString(), Block.class);
if (retrieved.getMaturedTotal() > 0) {
StringBuilder txtTit = new StringBuilder();
txtTit.append(retrieved.getMaturedTotal()).append(" ").append(mCur.toString());
txtTit.append(" ").append("Blocks");
if (retrieved.getImmature() != null && retrieved.getImmature().size() > 0)
txtTit.append(" and ").append(retrieved.getImmature().size()).append(" immature");
txtTit.append(" found on ").append(mPool.toString());
textViewBlocksTitle.setText(txtTit);
SummaryStatistics sts = doApacheMath(retrieved.getMatured());
if (retrieved.getMaturedTotal() > 1) {
// otherwise inconsistent
textViewMeanBlockTimeValue.setText(Utils.getScaledTime((long) sts.getMean() / 1000));
textViewMaxBlockTimeValue.setText(Utils.getScaledTime((long) sts.getMax() / 1000));
textViewMinBlockTimeValue.setText(Utils.getScaledTime((long) sts.getMin() / 1000));
textViewBlockTimeStdDevValue.setText(Utils.getScaledTime((long) sts.getStandardDeviation() / 1000));
Locale current = getResources().getConfiguration().locale;
textViewBlocksPerDayValue.setText(String.format(current, "%.3f", Utils.getPoolBlockPerDay(retrieved.getMatured())));
}
if (mAdapter == null) {
mAdapter = new BlockAdapter(retrieved.getMatured(), mCur);
mRecyclerView.setAdapter(mAdapter);
}
mAdapter.setBlocksArray(retrieved.getMatured());
mAdapter.notifyDataSetChanged();
} else
textViewBlocksTitle.setText("No Block found on " + mPool.toString());
}
});
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.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);
}
use of it.angelic.mpw.model.jsonpojos.blocks.Block in project MPW by shineangelic.
the class MaxHashInstrumentedTest method testJsonBlockRequest.
@Test
public void testJsonBlockRequest() throws Exception {
final GsonBuilder builder = new GsonBuilder();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getBlocksURL(sharedPreferences), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.i(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
Block retrieved = gson.fromJson(response.toString(), Block.class);
assertNotNull(retrieved);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(Constants.TAG, "Error: " + error.getMessage());
fail();
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
use of it.angelic.mpw.model.jsonpojos.blocks.Block in project MPW by shineangelic.
the class PaymentsActivity method issueRefresh.
private void issueRefresh(final PoolDbHelper mDbHelper, final GsonBuilder builder, String url) {
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
mDbHelper.logWalletStats(retrieved);
// dati semi grezzi
if (retrieved.getPayments() != null) {
drawPaymentsTable(retrieved);
// la seguente inverte ordine lista
ChartUtils.drawPaymentsHistory(paymentsChart, retrieved);
textViewPaymentsTitle.setText(String.format(getString(R.string.paid_out), mPool.toString()) + " " + retrieved.getPayments().size() + " times");
} else {
textViewPaymentsTitle.setText("No payment Yet");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
Snackbar.make(findViewById(android.R.id.content), "Network Error", Snackbar.LENGTH_SHORT).show();
}
});
JsonObjectRequest jsonObjBlockReq = new JsonObjectRequest(Request.Method.GET, Utils.getBlocksURL(PreferenceManager.getDefaultSharedPreferences(PaymentsActivity.this)), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.d(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
Block matured = gson.fromJson(response.toString(), Block.class);
drawProjectionTable(mDbHelper, matured);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.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);
JSONClientSingleton.getInstance(this).addToRequestQueue(jsonObjBlockReq);
}
Aggregations