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