Search in sources :

Example 1 with JSONArray

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

the class WebGetExchangeRatesRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest apiRequest) {
    JSONObject result = JSONUrlReader.readJsonObjectFromUrl(context, Constants.WWW_RUN_IOTA + "/xchange.jsp");
    if (result != null) {
        Store.updateTickers(context, result);
        JSONArray msgs = result.optJSONArray("sysmsg");
        if (msgs != null && msgs.length() > 0) {
            for (int i = 0; i < msgs.length(); i++) {
                Store.addSystemMessage(context, msgs.optJSONObject(i));
            }
        }
        return new WebGetExchangeRatesResponse(result);
    }
    return new WebGetExchangeRatesResponse(new JSONObject());
// NetworkError error = new NetworkError();
// error.setErrorType(NetworkErrorType.NETWORK_ERROR);
// return error;
}
Also used : JSONObject(run.wallet.common.json.JSONObject) JSONArray(run.wallet.common.json.JSONArray) WebGetExchangeRatesResponse(run.wallet.iota.api.responses.WebGetExchangeRatesResponse)

Example 2 with JSONArray

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

the class MsgStore method loadAddresses.

private static void loadAddresses(Context context) {
    if (msgStore.currentSeed != null) {
        SharedPreferences sp = context.getSharedPreferences(msgStore.currentSeed.id, Context.MODE_PRIVATE);
        String jarrayString = SpManager.getEncryptedPreference(sp, PREF_ADDRESSES, "[]");
        // Log.e("MSG-LOAD-ADDRESS",jarrayString);
        msgStore.addresses.clear();
        try {
            JSONArray jar = new JSONArray(jarrayString);
            for (int i = 0; i < jar.length(); i++) {
                JSONObject job = jar.getJSONObject(i);
                Address add = new Address(job.optString("address"), job.optBoolean("used"));
                msgStore.addresses.add(add);
            }
        } catch (Exception e) {
        }
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 3 with JSONArray

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

the class MsgStore method loadTransfers.

private static void loadTransfers(Context context) {
    if (msgStore.currentSeed != null) {
        SharedPreferences sp = context.getSharedPreferences(msgStore.currentSeed.id, Context.MODE_PRIVATE);
        String jarrayString = SpManager.getEncryptedPreference(sp, PREF_TRANSFERS, "[]");
        // String jarrayString = sp.getString(PREF_SEEDS,"[]");
        msgStore.transfers.clear();
        try {
            JSONArray jar = new JSONArray(jarrayString);
            for (int i = 0; i < jar.length(); i++) {
                JSONObject job = jar.getJSONObject(i);
                Transfer add = new Transfer(job);
                msgStore.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 4 with JSONArray

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

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

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