use of com.cloudrail.si.services.PayPal 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