Search in sources :

Example 11 with JSONObject

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;
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) JSONArray(run.wallet.common.json.JSONArray)

Example 12 with JSONObject

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) {
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 13 with JSONObject

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) {
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 14 with JSONObject

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();
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 15 with JSONObject

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;
}
Also used : JSONObject(run.wallet.common.json.JSONObject)

Aggregations

JSONObject (run.wallet.common.json.JSONObject)37 SharedPreferences (android.content.SharedPreferences)24 JSONArray (run.wallet.common.json.JSONArray)21 ArrayList (java.util.ArrayList)6 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 FragmentTransaction (android.app.FragmentTransaction)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 File (java.io.File)1 HttpURLConnection (java.net.HttpURLConnection)1 TextFile (run.wallet.common.TextFile)1 JSONException (run.wallet.common.json.JSONException)1 WebGetExchangeRatesHistoryRequest (run.wallet.iota.api.requests.WebGetExchangeRatesHistoryRequest)1