Search in sources :

Example 26 with JSONArray

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

Example 27 with JSONArray

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

Example 28 with JSONArray

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

Example 29 with JSONArray

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

Example 30 with JSONArray

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