use of it.angelic.mpw.model.db.GranularityEnum in project MPW by shineangelic.
the class MainActivity method issueRefresh.
private void issueRefresh(final PoolDbHelper mDbHelper, final GsonBuilder builder) {
Log.i(Constants.TAG, "JsonObjectRequest for: " + Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(MainActivity.this)));
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getHomeStatsURL(PreferenceManager.getDefaultSharedPreferences(MainActivity.this)), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.d(Constants.TAG, response.toString());
hashText.post(new Runnable() {
@Override
public void run() {
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
HomeStats retrieved = gson.fromJson(response.toString(), HomeStats.class);
mDbHelper.logHomeStats(retrieved);
// dati semi grezzi
int radioButtonID = radioGroupBackTo.getCheckedRadioButtonId();
View radioButton = findViewById(radioButtonID);
storia = mDbHelper.getHistoryData(BackToEnum.valueOf((String) radioButton.getTag()));
updateCurrentStats();
final RadioButton radioDay = findViewById(R.id.radioButtonDay);
final RadioButton radioMin = findViewById(R.id.radioButtonMinutes);
GranularityEnum granoEnum = GranularityEnum.HOUR;
if (radioDay.isChecked())
granoEnum = GranularityEnum.DAY;
else if (radioMin.isChecked())
granoEnum = GranularityEnum.MINUTE;
ChartUtils.drawDifficultyHistory(textViewNetDiffTitle, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_difficulty), granoEnum);
ChartUtils.drawHashrateHistory(hashText, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_hashrate), granoEnum);
}
});
}
}, 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();
// prevent stale data appear
updateCurrentStats();
}
});
/*
JsonArrayRequest jsonArrayCurrenciesReq = new JsonArrayRequest(Request.Method.GET,
Constants.ETHER_STATS_URL, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(final JSONArray response) {
Log.d(Constants.TAG, response.toString());
hashText.post(new Runnable() {
@Override
public void run() {
Gson gson = builder.create();
Log.d(Constants.TAG, response.toString());
Type listType = new TypeToken<List<Ticker>>() {}.getType();
List<Ticker> posts = gson.fromJson(response.toString(), listType);
Ticker fnd = null;
for (Ticker currency : posts) {
if (mCur.name().equalsIgnoreCase(currency.getSymbol()) || mCur.toString().equalsIgnoreCase(currency.getName())) {
fnd = currency;
}
//always save ETH
if (CurrencyEnum.ETH.name().equalsIgnoreCase(currency.getSymbol())) {
CryptoSharedPreferencesUtils.saveEthereumValues(currency, MainActivity.this);
}
//always save BTC
if (CurrencyEnum.BTC.name().equalsIgnoreCase(currency.getSymbol())) {
CryptoSharedPreferencesUtils.saveBtcValues(currency, MainActivity.this);
}
}
//eventually resets when fnd = null
CryptoSharedPreferencesUtils.saveEtherValues(fnd, MainActivity.this);
}
});
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(Constants.TAG, "Error: " + error.getMessage());
Crashlytics.logException(error);
}
});*/
// Adding request to request queue
JSONClientSingleton.getInstance(this).addToRequestQueue(jsonObjReq);
// JSONClientSingleton.getInstance(this).addToRequestQueue(jsonArrayCurrenciesReq);
}
use of it.angelic.mpw.model.db.GranularityEnum in project MPW by shineangelic.
the class MainActivity method onCreate.
/* private static long getAverageBlockSecondsSincePoolsBirth(HomeStats lastHit) {
final Date firstBlockDate = new Date();//2017/07/15
firstBlockDate.setTime(1500099900000L);
long datediffFirst = (new Date().getTime() - firstBlockDate.getTime()) / 1000;
//meno uno perche` il conto parte dal secondo blocco. Il primo boh
return datediffFirst / (lastHit.getMaturedTotal() - 1);
}*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Locale current = getResources().getConfiguration().locale;
mDbHelper = new PoolDbHelper(this, mPool, mCur);
builder = new GsonBuilder();
// gestione UNIX time lungo e non
builder.registerTypeAdapter(Date.class, new MyDateTypeAdapter());
builder.registerTypeAdapter(Calendar.class, new MyTimeStampTypeAdapter());
noobText = findViewById(R.id.textViewWalletTitle);
hashText = findViewById(R.id.hashrateText);
textViewNetDiffTitle = findViewById(R.id.textViewWalHashrateTitle);
poolLastBeat = findViewById(R.id.textViewWalLastShareValue);
textViewNetDiffValue = findViewById(R.id.textViewNetDiffValue);
lastFoundTextLabel = findViewById(R.id.textViewLastBlock);
lastFoundText = findViewById(R.id.textViewWalPaymentsValue);
onlineMinersText = findViewById(R.id.textViewWalCurHashrateValue);
textViewBlockChainHeightValue = findViewById(R.id.textViewBlockChainHeightValue);
poolHashrateText = findViewById(R.id.textViewPoolHashrateValue);
roundSharesText = findViewById(R.id.textViewRoundSharesValue);
textViewVarianceValue = findViewById(R.id.textViewVarianceValue);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Async Refresh Sent", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
issueRefresh(mDbHelper, builder);
}
});
// i grafici hanno controlli globali
RadioGroup radioGroupChartGranularity = findViewById(R.id.radioDifficultyGranularity);
radioGroupBackTo = findViewById(R.id.radioBackto);
final RadioButton radioDay = findViewById(R.id.radioButtonDay);
final RadioButton radioMin = findViewById(R.id.radioButtonMinutes);
final RadioGroup.OnCheckedChangeListener mescola = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
radioGroupBackTo.post(new Runnable() {
@Override
public void run() {
GranularityEnum granoEnum = GranularityEnum.HOUR;
if (radioDay.isChecked())
granoEnum = GranularityEnum.DAY;
else if (radioMin.isChecked())
granoEnum = GranularityEnum.MINUTE;
int radioButtonID = radioGroupBackTo.getCheckedRadioButtonId();
View radioButton = findViewById(radioButtonID);
LinkedMap<Date, HomeStats> storia = mDbHelper.getHistoryData(BackToEnum.valueOf((String) radioButton.getTag()));
ChartUtils.drawDifficultyHistory(textViewNetDiffTitle, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_difficulty), granoEnum);
ChartUtils.drawHashrateHistory(hashText, PoolQueryGrouper.groupAvgQueryResult(storia, granoEnum), (LineView) findViewById(R.id.line_view_hashrate), granoEnum);
}
});
}
};
radioGroupBackTo.setOnCheckedChangeListener(mescola);
radioGroupChartGranularity.setOnCheckedChangeListener(mescola);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = MPWCoinmarketcapService.getJobUpdate(dispatcher);
dispatcher.schedule(myJob);
// ADS
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
Aggregations