Search in sources :

Example 6 with JSONArray

use of run.wallet.common.json.JSONArray 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 7 with JSONArray

use of run.wallet.common.json.JSONArray 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 8 with JSONArray

use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.

the class Store method addAddress.

public static void addAddress(Context context, GetNewAddressRequest request, GetNewAddressResponse response) {
    if (request != null && response != null) {
        SharedPreferences sp = context.getSharedPreferences(request.getSeed().id, Context.MODE_PRIVATE);
        List<Address> alreadyAddress = getAddresses(context, request.getSeed());
        JSONArray jar = new JSONArray();
        for (Address already : alreadyAddress) {
            jar.put(already.toJson());
        }
        for (String add : response.getAddresses()) {
            Address address = new Address(add, false, false);
            address.setIndex(request.getIndex());
            address.setIndexName(request.getIndex() + 1);
            jar.put(address.toJson());
        }
        SpManager.setEncryptedPreference(sp, PREF_ADDRESSES, jar.toString());
        if (store.currentSeed.id.equals(request.getSeed().id)) {
            loadAddresses(context);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 9 with JSONArray

use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.

the class Store method loadTransfers.

private static void loadTransfers(Context context) {
    if (store.currentSeed != null) {
        SharedPreferences sp = context.getSharedPreferences(store.currentSeed.id, Context.MODE_PRIVATE);
        String jarrayString = SpManager.getEncryptedPreference(sp, PREF_TRANSFERS, "[]");
        // String jarrayString = sp.getString(PREF_SEEDS,"[]");
        store.transfers.clear();
        try {
            JSONArray jar = new JSONArray(jarrayString);
            // Log.e("LOAD-TRANSFERS","json: "+jar.toString());
            for (int i = 0; i < jar.length(); i++) {
                JSONObject job = jar.getJSONObject(i);
                Transfer add = new Transfer(job);
                store.transfers.add(add);
            }
        } catch (Exception e) {
        }
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 10 with JSONArray

use of run.wallet.common.json.JSONArray in project run-wallet-android by runplay.

the class Store method getAddresses.

public static List<Address> getAddresses(Context context, Seeds.Seed seed) {
    List<Address> addresses = new ArrayList<>();
    if (Validator.isValidCaller()) {
        SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
        String jarrayString = SpManager.getEncryptedPreference(sp, PREF_ADDRESSES, "[]");
        // Log.e("TMP-LOAD-ADDRESS",jarrayString);
        try {
            JSONArray jar = new JSONArray(jarrayString);
            for (int i = 0; i < jar.length(); i++) {
                JSONObject job = jar.getJSONObject(i);
                Address add = new Address(job);
                addresses.add(add);
            }
        } catch (Exception e) {
        }
    }
    return addresses;
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) JSONArray(run.wallet.common.json.JSONArray)

Aggregations

JSONArray (run.wallet.common.json.JSONArray)36 SharedPreferences (android.content.SharedPreferences)33 JSONObject (run.wallet.common.json.JSONObject)21 ArrayList (java.util.ArrayList)6 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 WebGetExchangeRatesResponse (run.wallet.iota.api.responses.WebGetExchangeRatesResponse)1