Search in sources :

Example 31 with JSONArray

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

the class Store method updateTickers.

public static void updateTickers(Context context, JSONObject job) {
    if (job != null && job.optInt("result") == 200 && job.has("data")) {
        store.tickers.clear();
        JSONArray jar = job.optJSONArray("data");
        if (jar != null && jar.length() > 0) {
            SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
            sp.edit().putString(PREF_EXCHANGERATES, jar.toString()).commit();
            for (int i = 0; i < jar.length(); i++) {
                JSONObject ob = null;
                try {
                    ob = jar.optJSONObject(i);
                } catch (Exception e) {
                    Log.e("EXCH", "e2: " + e.getMessage());
                }
                if (ob != null) {
                    Ticker ticker = new Ticker(ob);
                    if (ticker.getCp() != null) {
                        store.tickers.put(ticker.getCp(), ticker);
                    }
                }
            }
        }
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 32 with JSONArray

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

the class Store 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) {
    }
    Collections.reverse(transfers);
    for (Transfer tran : transfers) {
        ntransfers.add(0, tran);
    }
    JSONArray trans = new JSONArray();
    for (Transfer t : ntransfers) {
        trans.put(t.toJson());
    }
    SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
    if (store.currentSeed.id.equals(seed.id)) {
        loadTransfers(context);
    }
    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 33 with JSONArray

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

the class Store method updateAllTransfersInSeed.

public static void updateAllTransfersInSeed(Context context, Seeds.Seed seed, List<Transfer> transfers) {
    SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
    if (!transfers.isEmpty()) {
        JSONArray trans = new JSONArray();
        for (Transfer t : transfers) {
            trans.put(t.toJson());
        }
        // Log.e("EDATETRAN",trans.toString());
        SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
        if (store.currentSeed != null && seed.id.equals(store.currentSeed.id)) {
            WalletTransfersCardAdapter.load(context, true);
            WalletAddressCardAdapter.load(context, true);
            reinit(context);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 34 with JSONArray

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

the class Store method setAccountData.

public static synchronized void setAccountData(Context context, Seeds.Seed seed, Wallet wallet, List<Transfer> transfers, List<Address> addresses) {
    SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
    JSONArray trans = new JSONArray();
    for (Transfer t : transfers) {
        trans.put(t.toJson());
    }
    SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
    JSONArray jar = new JSONArray();
    for (Address add : addresses) {
        jar.put(add.toJson());
    }
    SpManager.setEncryptedPreference(sp, PREF_ADDRESSES, jar.toString());
    // Wallet run.wallet.monero.wallet = new Wallet(seed.id,balance,System.currentTimeMillis());
    Store.addUpdateWallet(context, seed, wallet);
    if (store.currentSeed != null && seed.id.equals(store.currentSeed.id)) {
        reinit(context);
    }
    if (store.currentSeed != null && seed.id.equals(store.currentSeed.id)) {
        reinit(context);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 35 with JSONArray

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

the class Store method loadTickerValues.

private static void loadTickerValues(Context context) {
    SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
    JSONArray jar = null;
    try {
        jar = new JSONArray(sp.getString(PREF_EXCHANGERATES, "[]"));
    } catch (Exception e) {
    }
    if (jar != null) {
        store.tickers.clear();
        for (int i = 0; i < jar.length(); i++) {
            JSONObject ob = null;
            try {
                ob = jar.optJSONObject(i);
            } catch (Exception e) {
            }
            if (ob != null) {
                Ticker ticker = new Ticker(ob);
                if (ticker.getCp() != null) {
                    store.tickers.put(ticker.getCp(), ticker);
                }
            }
        }
    }
}
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