Search in sources :

Example 1 with Block

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);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Block(it.angelic.mpw.model.jsonpojos.blocks.Block) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 2 with Block

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);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Block(it.angelic.mpw.model.jsonpojos.blocks.Block) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 3 with Block

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);
}
Also used : Locale(java.util.Locale) VolleyError(com.android.volley.VolleyError) Gson(com.google.gson.Gson) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Block(it.angelic.mpw.model.jsonpojos.blocks.Block) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 4 with Block

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);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Block(it.angelic.mpw.model.jsonpojos.blocks.Block) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 5 with Block

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);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Gson(com.google.gson.Gson) Block(it.angelic.mpw.model.jsonpojos.blocks.Block) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Aggregations

Response (com.android.volley.Response)5 VolleyError (com.android.volley.VolleyError)5 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)5 Gson (com.google.gson.Gson)5 Block (it.angelic.mpw.model.jsonpojos.blocks.Block)5 JSONObject (org.json.JSONObject)5 GsonBuilder (com.google.gson.GsonBuilder)3 Test (org.junit.Test)3 Wallet (it.angelic.mpw.model.jsonpojos.wallet.Wallet)1 Locale (java.util.Locale)1 SummaryStatistics (org.apache.commons.math3.stat.descriptive.SummaryStatistics)1