Search in sources :

Example 1 with Payment

use of it.angelic.mpw.model.jsonpojos.wallet.Payment in project MPW by shineangelic.

the class MinersActivity method fetchMinerStats.

private void fetchMinerStats(final MinerDBRecord rec) {
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Utils.getWalletStatsUrl(PreferenceManager.getDefaultSharedPreferences(this)) + rec.getAddress(), null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            // update known miners TABLE
            Log.d(Constants.TAG, response.toString());
            Gson gson = builder.create();
            // Register an adapter to manage the date types as long values
            final Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
            if (retrieved.getWorkersTotal() > (rec.getTopMiners() == null ? -1 : rec.getTopMiners()))
                rec.setTopMiners(retrieved.getWorkersTotal());
            if (retrieved.getCurrentHashrate() > (rec.getTopHr() == null ? -1 : rec.getTopHr()))
                rec.setTopHr(retrieved.getCurrentHashrate());
            rec.setPaid(retrieved.getStats().getPaid());
            try {
                // compute first paymt
                Payment pp = retrieved.getPayments().get(retrieved.getPayments().size() - 1);
                rec.setFirstSeen(pp.getTimestamp());
            } catch (Exception io) {
            // dont look back in anger
            }
            rec.setAvgHr(rec.getAvgHr() == null ? retrieved.getHashrate() : ((rec.getAvgHr() + retrieved.getHashrate()) / 2));
            // aggiorna UI
            rec.setLastSeen(retrieved.getStats().getLastShare());
            rec.setBlocksFound(retrieved.getStats().getBlocksFound());
            mDbHelper.updateMiner(rec);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.e(Constants.TAG, "Error: " + error.getMessage());
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(this).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) Payment(it.angelic.mpw.model.jsonpojos.wallet.Payment) JSONObject(org.json.JSONObject) Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest)

Example 2 with Payment

use of it.angelic.mpw.model.jsonpojos.wallet.Payment in project MPW by shineangelic.

the class PaymentsActivity method drawPaymentsTable.

private void drawPaymentsTable(Wallet retrieved) {
    TableLayout minersTable = findViewById(R.id.tableLayoutPayments);
    minersTable.removeAllViews();
    // table header
    TableRow row = (TableRow) LayoutInflater.from(PaymentsActivity.this).inflate(R.layout.row_payment, null);
    (row.findViewById(R.id.buttonPay)).setVisibility(View.INVISIBLE);
    minersTable.addView(row);
    for (final Payment thispay : retrieved.getPayments()) {
        // one row for each payment
        TableRow rowt = (TableRow) LayoutInflater.from(PaymentsActivity.this).inflate(R.layout.row_payment, null);
        ((TextView) rowt.findViewById(R.id.textViewWorkerName)).setText(yearFormat.format(thispay.getTimestamp()));
        ((TextView) rowt.findViewById(R.id.textViewWorkerHashrate)).setText(Utils.formatCurrency(PaymentsActivity.this, thispay.getAmount(), mCur));
        rowt.findViewById(R.id.buttonPay).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (mCur.getScannerSite() != null) {
                    // mostra transazione pagamento
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(mCur.getScannerSite() + "/tx/" + thispay.getTx()));
                    startActivity(i);
                } else {
                    Snackbar.make(view, "Blockchain explorer not available for " + mCur.toString(), Snackbar.LENGTH_SHORT).setAction("Action", null).show();
                }
            }
        });
        minersTable.addView(rowt);
    }
}
Also used : Payment(it.angelic.mpw.model.jsonpojos.wallet.Payment) TableRow(android.widget.TableRow) TextView(android.widget.TextView) Intent(android.content.Intent) TableLayout(android.widget.TableLayout) NavigationView(android.support.design.widget.NavigationView) LineView(im.dacer.androidcharts.LineView) View(android.view.View) AdView(com.google.android.gms.ads.AdView) TextView(android.widget.TextView)

Example 3 with Payment

use of it.angelic.mpw.model.jsonpojos.wallet.Payment in project MPW by shineangelic.

the class ChartUtils method drawPaymentsHistory.

public static void drawPaymentsHistory(LineView chart, Wallet retrieved) {
    ArrayList<Float> dataList = new ArrayList<>();
    ArrayList<String> labelsArr = new ArrayList<>();
    float accumulator = 0;
    List<Payment> paymnts = retrieved.getPayments();
    // mostro in ordine
    Collections.reverse(paymnts);
    for (final Payment thispay : paymnts) {
        accumulator += thispay.getAmount() / 1000000000F;
        dataList.add(accumulator);
        labelsArr.add(MainActivity.dayFormat.format(thispay.getTimestamp()));
    }
    // optional
    chart.setDrawDotLine(false);
    chart.setBottomTextList(labelsArr);
    List<Integer> colArr = new ArrayList<>();
    colArr.add(ResourcesCompat.getColor(chart.getResources(), R.color.colorPrimary, null));
    int[] ret = new int[colArr.size()];
    int i = 0;
    for (Integer e : colArr) ret[i++] = e.intValue();
    chart.setColorArray(ret);
    ArrayList<ArrayList<Float>> dataLists = new ArrayList<>();
    dataLists.add(dataList);
    // or lineView.setFloatDataList(floatDataLists)
    chart.setFloatDataList(dataLists);
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Payment(it.angelic.mpw.model.jsonpojos.wallet.Payment)

Aggregations

Payment (it.angelic.mpw.model.jsonpojos.wallet.Payment)3 Intent (android.content.Intent)1 NavigationView (android.support.design.widget.NavigationView)1 View (android.view.View)1 TableLayout (android.widget.TableLayout)1 TableRow (android.widget.TableRow)1 TextView (android.widget.TextView)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)1 AdView (com.google.android.gms.ads.AdView)1 Gson (com.google.gson.Gson)1 LineView (im.dacer.androidcharts.LineView)1 Wallet (it.angelic.mpw.model.jsonpojos.wallet.Wallet)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1