use of it.angelic.mpw.model.jsonpojos.coinmarketcap.Ticker in project MPW by shineangelic.
the class Utils method synchCurrenciesFromCoinmarketcap.
public static void synchCurrenciesFromCoinmarketcap(Context ctx, CurrencyEnum mCur) {
try {
// synch jason
RequestFuture<JSONArray> future = RequestFuture.newFuture();
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, Constants.ETHER_STATS_URL, new JSONArray(), future, future);
JSONClientSingleton.getInstance(ctx).addToRequestQueue(request);
// this will block
JSONArray response = future.get();
Log.d(Constants.TAG, response.toString());
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
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, ctx);
}
// always save BTC
if (CurrencyEnum.BTC.name().equalsIgnoreCase(currency.getSymbol())) {
CryptoSharedPreferencesUtils.saveBtcValues(currency, ctx);
}
}
CryptoSharedPreferencesUtils.saveEtherValues(fnd, ctx);
} catch (Exception e) {
Log.d(Constants.TAG, "ERROR DURING COINMARKETCAP: " + e.getMessage());
}
}
use of it.angelic.mpw.model.jsonpojos.coinmarketcap.Ticker in project MPW by shineangelic.
the class MPWCoinmarketcapService method saveCurrencyValue.
public static void saveCurrencyValue(JSONArray response, CurrencyEnum mCur, Context ctx) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
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, ctx);
}
// always save BTC
if (CurrencyEnum.BTC.name().equalsIgnoreCase(currency.getSymbol())) {
CryptoSharedPreferencesUtils.saveBtcValues(currency, ctx);
}
}
// eventually resets when fnd = null
CryptoSharedPreferencesUtils.saveEtherValues(fnd, ctx);
}
Aggregations