Search in sources :

Example 26 with JSONObject

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

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

the class Store method getWallet.

@Nullable
public static Wallet getWallet(Context context, Seeds.Seed seed) {
    if (Validator.isValidCaller()) {
        SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
        String jobString = SpManager.getEncryptedPreference(sp, PREF_WALLET, "[]");
        try {
            JSONObject job = new JSONObject(jobString);
            if (job != null) {
                return new Wallet(job);
            }
        } catch (Exception e) {
        }
    }
    return null;
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) Nullable(android.support.annotation.Nullable)

Example 28 with JSONObject

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

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

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

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