Search in sources :

Example 6 with TokenVo

use of com.lingtuan.firefly.wallet.vo.TokenVo in project SmartMesh_Android by SmartMeshFoundation.

the class TokenListUI method loadTokenList.

/**
 * get token list
 */
private void loadTokenList() {
    boolean isFirstGet = MySharedPrefs.readBoolean(TokenListUI.this, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_FIRST_GET_TOKEN_LIST);
    ArrayList<TokenVo> tokenList = FinalUserDataBase.getInstance().getTokenListAll(address);
    if (!isFirstGet && tokenList != null && tokenList.size() > 0) {
        tokenListAdapter.resetSource(tokenList);
        swipeLayout.setRefreshing(false);
    } else {
        NetRequestImpl.getInstance().getTokenList(address, new RequestListener() {

            @Override
            public void start() {
            }

            @Override
            public void success(JSONObject response) {
                source.clear();
                JSONArray array = response.optJSONArray("data");
                if (array != null) {
                    for (int i = 0; i < array.length(); i++) {
                        TokenVo tokenVo = new TokenVo().parse(array.optJSONObject(i));
                        source.add(tokenVo);
                    }
                }
                FinalUserDataBase.getInstance().beginTransaction();
                for (int i = 0; i < source.size(); i++) {
                    FinalUserDataBase.getInstance().updateTokenList(source.get(i), address, true);
                }
                FinalUserDataBase.getInstance().endTransactionSuccessful();
                MySharedPrefs.writeBoolean(TokenListUI.this, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_FIRST_GET_TOKEN_LIST, false);
                tokenListAdapter.resetSource(source);
                swipeLayout.setRefreshing(false);
                checkListEmpty();
            }

            @Override
            public void error(int errorCode, String errorMsg) {
                swipeLayout.setRefreshing(false);
                showToast(errorMsg);
                checkListEmpty();
            }
        });
    }
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo)

Aggregations

TokenVo (com.lingtuan.firefly.wallet.vo.TokenVo)6 SuppressLint (android.annotation.SuppressLint)3 RequestListener (com.lingtuan.firefly.listener.RequestListener)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 Intent (android.content.Intent)1 CompoundButton (android.widget.CompoundButton)1