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();
}
});
}
}
Aggregations