private void setDefaultCard(int cardId) { AndyUtils.showCustomProgressDialog( context, context.getString(R.string.text_changing_default_card), true, null); HashMap<String, String> map = new HashMap<String, String>(); map.put(Const.URL, Const.ServiceType.DEFAULT_CARD); map.put(Const.Params.ID, String.valueOf(pHelper.getUserId())); map.put(Const.Params.TOKEN, String.valueOf(pHelper.getSessionToken())); map.put(Const.Params.DEFAULT_CARD_ID, String.valueOf(cardId)); // new HttpRequester((Activity) context, map, // Const.ServiceCode.DEFAULT_CARD, this); requestQueue.add( new VolleyHttpRequest(Method.POST, map, Const.ServiceCode.DEFAULT_CARD, this, this)); }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.view_payment_list_item, parent, false); holder = new ViewHolder(); holder.ivCard = (ImageView) convertView.findViewById(R.id.ivCard); holder.tvNo = (TextView) convertView.findViewById(R.id.tvNo); holder.rdCardSelection = (RadioButton) convertView.findViewById(R.id.rdCardSelection); convertView.setTag(holder); holder.rdCardSelection.setTag(position); } else { holder = (ViewHolder) convertView.getTag(); } final Card card = listCard.get(position); final int cardId = card.getId(); holder.tvNo.setText("*****" + card.getLastFour()); String type = card.getCardType(); if (type.equalsIgnoreCase(Const.VISA)) { holder.ivCard.setImageResource(R.drawable.ub__creditcard_visa); } else if (type.equalsIgnoreCase(Const.MASTERCARD)) { holder.ivCard.setImageResource(R.drawable.ub__creditcard_mastercard); } else if (type.equalsIgnoreCase(Const.AMERICAN_EXPRESS)) { holder.ivCard.setImageResource(R.drawable.ub__creditcard_amex); } else if (type.equalsIgnoreCase(Const.DISCOVER)) { holder.ivCard.setImageResource(R.drawable.ub__creditcard_discover); } else if (type.equalsIgnoreCase(Const.DINERS_CLUB)) { holder.ivCard.setImageResource(R.drawable.ub__creditcard_discover); } else { holder.ivCard.setImageResource(R.drawable.ub__nav_payment); } if (selectedPosition == cardId) holder.rdCardSelection.setChecked(true); else holder.rdCardSelection.setChecked(false); if (card.isDefault()) { holder.rdCardSelection.setChecked(true); PreferenceHelper pref = new PreferenceHelper(context); pref.putDefaultCard(cardId); pref.putDefaultCardNo(card.getLastFour()); pref.putDefaultCardType(card.getCardType()); } else holder.rdCardSelection.setChecked(false); holder.rdCardSelection.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { RadioButton rd = (RadioButton) v; if (rd.isChecked()) { AppLog.Log("PaymentAdapater", "checked Id " + cardId); selectedPosition = cardId; PreferenceHelper pref = new PreferenceHelper(context); pref.putDefaultCard(cardId); pref.putDefaultCardNo(card.getLastFour()); pref.putDefaultCardType(card.getCardType()); notifyDataSetChanged(); setDefaultCard(cardId); } else { AppLog.Log("PaymentAdapater", "unchecked Id " + cardId); } Intent i = new Intent("card_change_receiver"); context.sendBroadcast(i); } }); return convertView; }