use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class MsgStore 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) {
}
for (Transfer tran : transfers) {
ntransfers.add(tran);
}
JSONArray trans = new JSONArray();
for (Transfer t : ntransfers) {
trans.put(t.toJson());
}
SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
return transfers;
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Nodes method load.
private void load(Context context) {
usenodes.add(getRandomDefault());
SharedPreferences sp = context.getSharedPreferences(SP_NODES, Context.MODE_PRIVATE);
String uarrayString = sp.getString(PREF_USE_NODEs, "[]");
try {
JSONArray jar = new JSONArray(uarrayString);
if (jar.length() != 0) {
usenodes.clear();
for (int i = 0; i < jar.length(); i++) {
JSONObject job = jar.getJSONObject(i);
Node node = new Node();
node.ip = job.optString(J_IP);
node.port = job.optInt(J_PORT);
node.syncVal = job.optInt(J_SYNC);
node.protocol = job.optString(J_PROTO);
node.name = job.optString(J_NAME);
node.lastused = job.optLong(J_LAST);
node.deadcount = job.optInt(J_Dead);
usenodes.add(node);
}
} else {
// Log.e("NODES","init()");
if (!alreadyinit) {
init(context);
}
}
} catch (Exception e) {
}
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Nodes method loadOthers.
private void loadOthers(Context context) {
SharedPreferences sp = context.getSharedPreferences(SP_NODES, Context.MODE_PRIVATE);
othernodes.clear();
String uarrayString = sp.getString(PREF_NODES, "[]");
try {
JSONArray jar = new JSONArray(uarrayString);
if (jar.length() != 0) {
for (int i = 0; i < jar.length(); i++) {
JSONObject job = jar.getJSONObject(i);
Node node = new Node();
node.ip = job.optString(J_IP);
node.port = job.optInt(J_PORT);
node.syncVal = job.optInt(J_SYNC);
node.protocol = job.optString(J_PROTO);
node.name = job.optString(J_NAME);
node.lastused = job.optLong(J_LAST);
node.deadcount = job.optInt(J_Dead);
othernodes.add(node);
}
}
} catch (Exception e) {
}
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Nodes method save.
protected void save(Context context) {
SharedPreferences sp = context.getSharedPreferences(SP_NODES, Context.MODE_PRIVATE);
JSONArray jar = new JSONArray();
try {
for (Node node : usenodes) {
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();
}
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class NudgeTransfer method toJson.
public JSONObject toJson() {
JSONObject job = new JSONObject();
job.put("seed", seedShort);
job.put("tran", transfer.toJson());
job.put("status", status);
return job;
}
Aggregations