use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Store method updateTickers.
public static void updateTickers(Context context, JSONObject job) {
if (job != null && job.optInt("result") == 200 && job.has("data")) {
store.tickers.clear();
JSONArray jar = job.optJSONArray("data");
if (jar != null && jar.length() > 0) {
SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
sp.edit().putString(PREF_EXCHANGERATES, jar.toString()).commit();
for (int i = 0; i < jar.length(); i++) {
JSONObject ob = null;
try {
ob = jar.optJSONObject(i);
} catch (Exception e) {
Log.e("EXCH", "e2: " + e.getMessage());
}
if (ob != null) {
Ticker ticker = new Ticker(ob);
if (ticker.getCp() != null) {
store.tickers.put(ticker.getCp(), ticker);
}
}
}
}
}
}
use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Store method addTransfers.
public static List<Transfer> addTransfers(Context context, Seeds.Seed seed, List<Transfer> transfers) {
List<Transfer> ntransfers = new ArrayList<>();
SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
String jarrayString = SpManager.getEncryptedPreference(sp, PREF_TRANSFERS, "[]");
try {
JSONArray jar = new JSONArray(jarrayString);
for (int i = 0; i < jar.length(); i++) {
JSONObject job = jar.getJSONObject(i);
Transfer add = new Transfer(job);
ntransfers.add(add);
}
} catch (Exception e) {
}
Collections.reverse(transfers);
for (Transfer tran : transfers) {
ntransfers.add(0, tran);
}
JSONArray trans = new JSONArray();
for (Transfer t : ntransfers) {
trans.put(t.toJson());
}
SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
if (store.currentSeed.id.equals(seed.id)) {
loadTransfers(context);
}
return transfers;
}
use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Store method updateAllTransfersInSeed.
public static void updateAllTransfersInSeed(Context context, Seeds.Seed seed, List<Transfer> transfers) {
SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
if (!transfers.isEmpty()) {
JSONArray trans = new JSONArray();
for (Transfer t : transfers) {
trans.put(t.toJson());
}
// Log.e("EDATETRAN",trans.toString());
SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
if (store.currentSeed != null && seed.id.equals(store.currentSeed.id)) {
WalletTransfersCardAdapter.load(context, true);
WalletAddressCardAdapter.load(context, true);
reinit(context);
}
}
}
use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Store method setAccountData.
public static synchronized void setAccountData(Context context, Seeds.Seed seed, Wallet wallet, List<Transfer> transfers, List<Address> addresses) {
SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
JSONArray trans = new JSONArray();
for (Transfer t : transfers) {
trans.put(t.toJson());
}
SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
JSONArray jar = new JSONArray();
for (Address add : addresses) {
jar.put(add.toJson());
}
SpManager.setEncryptedPreference(sp, PREF_ADDRESSES, jar.toString());
// Wallet run.wallet.monero.wallet = new Wallet(seed.id,balance,System.currentTimeMillis());
Store.addUpdateWallet(context, seed, wallet);
if (store.currentSeed != null && seed.id.equals(store.currentSeed.id)) {
reinit(context);
}
if (store.currentSeed != null && seed.id.equals(store.currentSeed.id)) {
reinit(context);
}
}
use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Store method loadTickerValues.
private static void loadTickerValues(Context context) {
SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
JSONArray jar = null;
try {
jar = new JSONArray(sp.getString(PREF_EXCHANGERATES, "[]"));
} catch (Exception e) {
}
if (jar != null) {
store.tickers.clear();
for (int i = 0; i < jar.length(); i++) {
JSONObject ob = null;
try {
ob = jar.optJSONObject(i);
} catch (Exception e) {
}
if (ob != null) {
Ticker ticker = new Ticker(ob);
if (ticker.getCp() != null) {
store.tickers.put(ticker.getCp(), ticker);
}
}
}
}
}
Aggregations