Search in sources :

Example 1 with TokenVo

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

the class AccountTokenAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = View.inflate(context, R.layout.wallet_token_item, null);
        holder.tokenImg = (ImageView) convertView.findViewById(R.id.tokenImg);
        holder.tokenPrice = (TextView) convertView.findViewById(R.id.tokenPrice);
        holder.tokenSymbol = (TextView) convertView.findViewById(R.id.tokenSymbol);
        holder.tokenBalance = (TextView) convertView.findViewById(R.id.tokenBalance);
        holder.tokenTotalPrice = (TextView) convertView.findViewById(R.id.tokenTotalPrice);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    TokenVo tokenVo = tokenVos.get(position);
    NextApplication.displayCircleImage(holder.tokenImg, Utils.buildThumb(tokenVo.getTokenLogo()));
    holder.tokenPrice.setText(tokenVo.getTokenPrice());
    holder.tokenSymbol.setText(tokenVo.getTokenSymbol());
    holder.tokenBalance.setText(tokenVo.getTokenNumber());
    return convertView;
}
Also used : TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo)

Example 2 with TokenVo

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

the class AccountFragment method loadData.

/**
 * get token list
 */
private void loadData(final boolean isShowToast) {
    boolean isFirstGet = MySharedPrefs.readBoolean(getActivity(), MySharedPrefs.FILE_USER, MySharedPrefs.KEY_FIRST_GET_TOKEN_LIST);
    tokenVos = FinalUserDataBase.getInstance().getOpenTokenList(walletAddress.getText().toString());
    if (!isFirstGet && tokenVos != null && tokenVos.size() > 0) {
        mTokenAdapter.resetSource(tokenVos);
        getBalance(isShowToast);
    } else {
        NetRequestImpl.getInstance().getTokenList(walletAddress.getText().toString(), new RequestListener() {

            @Override
            public void start() {
            }

            @Override
            public void success(JSONObject response) {
                tokenVos.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));
                        tokenVos.add(tokenVo);
                    }
                }
                FinalUserDataBase.getInstance().beginTransaction();
                for (int i = 0; i < tokenVos.size(); i++) {
                    FinalUserDataBase.getInstance().updateTokenList(tokenVos.get(i), walletAddress.getText().toString(), true);
                }
                FinalUserDataBase.getInstance().endTransactionSuccessful();
                MySharedPrefs.writeBoolean(getActivity(), MySharedPrefs.FILE_USER, MySharedPrefs.KEY_FIRST_GET_TOKEN_LIST, false);
                mTokenAdapter.resetSource(tokenVos);
                getBalance(isShowToast);
            }

            @Override
            public void error(int errorCode, String errorMsg) {
                getBalance(isShowToast);
            }
        });
    }
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo) SuppressLint(android.annotation.SuppressLint)

Example 3 with TokenVo

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

the class AccountFragment method getBalance.

/**
 * get token balance
 */
private void getBalance(final boolean isShowToast) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < tokenVos.size(); i++) {
        builder.append(tokenVos.get(i).getContactAddress()).append(",");
    }
    if (builder.length() > 0) {
        builder.deleteCharAt(builder.length() - 1);
    }
    NetRequestImpl.getInstance().getBalance(walletAddress.getText().toString(), builder.toString(), new RequestListener() {

        @Override
        public void start() {
        }

        @Override
        public void success(JSONObject response) {
            tokenVos.clear();
            swipe_refresh.setRefreshing(false);
            String total = response.optString("total");
            walletBalanceNum.setText(total);
            JSONArray array = response.optJSONArray("data");
            if (array != null) {
                for (int i = 0; i < array.length(); i++) {
                    TokenVo tokenVo = new TokenVo().parse(array.optJSONObject(i));
                    tokenVo.setChecked(true);
                    tokenVos.add(tokenVo);
                }
            }
            FinalUserDataBase.getInstance().beginTransaction();
            for (int i = 0; i < tokenVos.size(); i++) {
                FinalUserDataBase.getInstance().updateTokenList(tokenVos.get(i), walletAddress.getText().toString(), false);
            }
            FinalUserDataBase.getInstance().endTransactionSuccessful();
            mTokenAdapter.resetSource(tokenVos);
        }

        @Override
        public void error(int errorCode, String errorMsg) {
            if (isShowToast) {
                showToast(errorMsg);
            }
            mTokenAdapter.resetSource(tokenVos);
            swipe_refresh.setRefreshing(false);
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo) SuppressLint(android.annotation.SuppressLint)

Example 4 with TokenVo

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

the class AccountFragment method setTokenOnItemClick.

@Override
public void setTokenOnItemClick(int position) {
    if (storableWallet == null || tokenVos == null) {
        return;
    }
    Intent ethIntent = new Intent(getActivity(), WalletSendDetailUI.class);
    ethIntent.putExtra("tokenVo", tokenVos.get(position));
    double smtBalance = 0;
    if (TextUtils.equals(tokenVos.get(0).getTokenSymbol(), getString(R.string.smt))) {
        smtBalance = tokenVos.get(0).getTokenBalance();
    } else {
        for (int i = 0; i < tokenVos.size(); i++) {
            TokenVo tokenVo = tokenVos.get(i);
            if (TextUtils.equals(tokenVo.getTokenSymbol(), getString(R.string.smt))) {
                smtBalance = tokenVo.getTokenBalance();
                break;
            }
        }
    }
    ethIntent.putExtra("smtBalance", smtBalance);
    ethIntent.putExtra("storableWallet", storableWallet);
    startActivity(ethIntent);
    Utils.openNewActivityAnim(getActivity(), false);
}
Also used : Intent(android.content.Intent) TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo) SuppressLint(android.annotation.SuppressLint)

Example 5 with TokenVo

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

the class TokenListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = View.inflate(context, R.layout.token_list_item_layout, null);
        holder.tokenImg = (ImageView) convertView.findViewById(R.id.tokenImg);
        holder.tokenName = (TextView) convertView.findViewById(R.id.tokenName);
        holder.tokenSymbol = (TextView) convertView.findViewById(R.id.tokenSymbol);
        holder.tokenHasCheck = (SwitchButton) convertView.findViewById(R.id.tokenHasCheck);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final TokenVo tokenVo = tokenVos.get(position);
    holder.tokenImg.setImageResource(R.drawable.icon_static_010);
    holder.tokenHasCheck.setOnCheckedChangeListener(null);
    holder.tokenHasCheck.setChecked(tokenVo.isChecked());
    holder.tokenSymbol.setText(tokenVo.getTokenSymbol());
    holder.tokenName.setText(tokenVo.getTokenName());
    if (tokenVo.isChecked()) {
        holder.tokenHasCheck.setBackColor(context.getResources().getColorStateList(R.color.wallet_transfer_bg));
    } else {
        holder.tokenHasCheck.setBackColor(context.getResources().getColorStateList(R.color.switch_button_gray));
    }
    holder.tokenHasCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                holder.tokenHasCheck.setBackColor(context.getResources().getColorStateList(R.color.wallet_transfer_bg));
                tokenVo.setChecked(true);
            } else {
                holder.tokenHasCheck.setBackColor(context.getResources().getColorStateList(R.color.switch_button_gray));
                tokenVo.setChecked(false);
            }
        }
    });
    return convertView;
}
Also used : TokenVo(com.lingtuan.firefly.wallet.vo.TokenVo) CompoundButton(android.widget.CompoundButton)

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