use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Nodes method update.
protected void update(Context context, Node updatenode) {
SharedPreferences sp = context.getSharedPreferences(SP_NODES, Context.MODE_PRIVATE);
JSONArray jar = new JSONArray();
try {
for (Node usenode : usenodes) {
Node node = usenode;
if (node.ip.equals(updatenode.ip) && node.port == updatenode.port) {
node = updatenode;
}
JSONObject job = new JSONObject();
job.put(J_IP, node.ip);
job.put(J_PORT, node.port);
job.put(J_SYNC, node.syncVal);
job.put(J_PROTO, node.protocol);
job.put(J_NAME, node.name);
job.put(J_LAST, node.lastused);
job.put(J_Dead, node.deadcount);
jar.put(job);
}
} catch (Exception e) {
}
if (jar.length() > 0) {
sp.edit().putString(PREF_USE_NODEs, jar.toString()).commit();
load(context);
}
}
use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Seeds method save.
protected void save(Context context) {
// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences sp = context.getSharedPreferences(SP_WALLETS, Context.MODE_PRIVATE);
JSONArray jar = new JSONArray();
try {
for (Seed seed : seeds) {
JSONObject job = new JSONObject();
job.put(J_NAME, seed.name);
job.put(J_VALUE, new String(seed.value));
job.put(J_DEFAULT, seed.isdefault);
job.put(J_ID, seed.id);
job.put(J_APPGEN, seed.isappgenerated);
jar.put(job);
}
} catch (Exception e) {
}
if (jar.length() > 0) {
SpManager.setEncryptedPreference(sp, PREF_SEEDS, jar.toString());
}
}
use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Store method getTransfers.
public static List<Transfer> getTransfers(Context context, Seeds.Seed seed) {
List<Transfer> transfers = new ArrayList<>();
if (Validator.isValidCaller()) {
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);
transfers.add(add);
}
} catch (Exception e) {
}
}
return transfers;
}
use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Store method updateTickerHist.
public static void updateTickerHist(Context context, JSONObject job) {
if (job != null && job.optInt("result") == 200 && job.has("data")) {
JSONArray jar = job.optJSONArray("data");
if (jar != null) {
String cp = job.optString("cp");
List<Tick> history = new ArrayList<>();
for (int i = 0; i < jar.length(); i++) {
Tick ticker = new Tick(jar.optJSONObject(i));
// Log.e("TCIK",ticker.getLast()+"--"+jar.optJSONObject(i).toString());
history.add(ticker);
}
TickerHist thist = new TickerHist();
thist.setTicker(cp);
thist.setStep(job.optInt("step"));
thist.setTicks(history);
thist.setLastUpdate(System.currentTimeMillis());
// Log.e("STORE-THIST",cp);
store.tickerHist.put(cp + thist.getStep(), thist);
// JSONObject save=new JSONObject();
SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
String strJson = sp.getString(PREF_TICKHIST, "{}");
if (strJson != null) {
JSONObject tickerHistories = new JSONObject(strJson);
tickerHistories.put(cp + thist.getStep(), job);
tickerHistories.put("last", System.currentTimeMillis());
// Log.e("STL",tickerHistories.toString());
sp.edit().putString(PREF_TICKHIST, tickerHistories.toString()).commit();
}
}
}
}
use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.
the class Store method loadAddresses.
private static void loadAddresses(Context context) {
if (store.currentSeed != null) {
SharedPreferences sp = context.getSharedPreferences(store.currentSeed.id, Context.MODE_PRIVATE);
String jarrayString = SpManager.getEncryptedPreference(sp, PREF_ADDRESSES, "[]");
// Log.e("LOAD-ADDRESS",jarrayString);
store.addresses.clear();
try {
JSONArray jar = new JSONArray(jarrayString);
for (int i = 0; i < jar.length(); i++) {
JSONObject job = jar.optJSONObject(i);
Address add = new Address(job);
store.addresses.add(add);
}
for (Address add : store.addresses) {
if (add.isUsed() && add.getValue() > 0) {
store.currentSeed.warnUsed = true;
}
}
} catch (Exception e) {
}
}
}
Aggregations