use of com.cloudrail.si.types.Charge in project cloudrail-si-android-sdk by CloudRail.
the class ChargeAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.list_item, null);
}
final Charge charge = this.data.get(position);
if (charge != null) {
TextView tvId = (TextView) v.findViewById(R.id.list_item_id);
TextView tvPrice = (TextView) v.findViewById(R.id.list_item_price);
TextView tvDate = (TextView) v.findViewById(R.id.list_item_date);
TextView tvStatus = (TextView) v.findViewById(R.id.list_item_status);
TextView tvRefunded = (TextView) v.findViewById(R.id.list_item_refunded);
tvId.setText(charge.getId());
tvPrice.setText(formatAmount(charge.getAmount()) + " " + charge.getCurrency());
tvDate.setText(formatTime(charge.getCreated()));
tvStatus.setText(charge.getStatus());
switch(charge.getStatus()) {
case "succeeded":
{
tvStatus.setTextColor(Color.GREEN);
break;
}
case "pending":
{
tvStatus.setTextColor(Color.YELLOW);
break;
}
case "failed":
{
tvStatus.setTextColor(Color.RED);
break;
}
}
if (charge.isRefunded()) {
tvRefunded.setText("refunded");
tvRefunded.setVisibility(View.VISIBLE);
} else {
tvRefunded.setVisibility(View.GONE);
}
}
return v;
}
use of com.cloudrail.si.types.Charge in project cloudrail-si-android-sdk by CloudRail.
the class ChargeViewer method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_charge_viewer, container, false);
this.listView = (ListView) v.findViewById(R.id.chargeListView);
this.spinner = (ProgressBar) v.findViewById(R.id.spinner);
switch(mServiceString) {
case "paypal":
{
service = new PayPal(context, true, MainActivity.PAYPAL_CLIENT_IDENTIFIER, MainActivity.PAYPAL_CLIENT_SECRET);
break;
}
case "stripe":
{
service = new Stripe(context, MainActivity.STRIPE_SECRET_KEY);
break;
}
}
refreshList();
this.listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, final View view, final int position, long id) {
selectedItem = view;
final PopupMenu popupMenu = new PopupMenu(context, view);
MenuInflater menuInflater = ((Activity) context).getMenuInflater();
menuInflater.inflate(R.menu.selected_item_bar, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_refund_fully:
{
refundCharge(listAdapter.getItem(position));
refreshList();
return true;
}
case R.id.action_refund_partially:
{
refundPartially(listAdapter.getItem(position));
refreshList();
return true;
}
default:
return false;
}
}
});
popupMenu.show();
return true;
}
});
this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View v, int position, long id) {
final Charge charge = listAdapter.getItem(position);
new Thread(new Runnable() {
@Override
public void run() {
final List<Refund> refunds = service.getRefundsForCharge(charge.getId());
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
String[] refundStrings = new String[refunds.size()];
int i = 0;
for (Refund r : refunds) {
refundStrings[i] = formatAmount(r.getAmount()) + r.getCurrency() + " (" + formatTime(r.getCreated()) + ")";
i++;
}
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.display_charge, (ViewGroup) ((Activity) context).findViewById(R.id.display_charge_root));
enterContents(layout, charge, refunds);
PopupWindow pw = new PopupWindow(layout, 900, 1000, true);
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
ListView lv = layout.findViewById(R.id.refunds_list_view);
lv.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, refundStrings));
}
});
}
}).start();
}
});
((TextView) v.findViewById(R.id.text2)).setText(mServiceString);
return v;
}
Aggregations