Search in sources :

Example 1 with PayPal

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;
}
Also used : PopupWindow(android.widget.PopupWindow) Activity(android.app.Activity) ListView(android.widget.ListView) Stripe(com.cloudrail.si.services.Stripe) List(java.util.List) TextView(android.widget.TextView) PayPal(com.cloudrail.si.services.PayPal) MenuInflater(android.view.MenuInflater) Charge(com.cloudrail.si.types.Charge) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Refund(com.cloudrail.si.types.Refund) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView) PopupMenu(android.widget.PopupMenu)

Aggregations

Activity (android.app.Activity)1 LayoutInflater (android.view.LayoutInflater)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 PopupMenu (android.widget.PopupMenu)1 PopupWindow (android.widget.PopupWindow)1 TextView (android.widget.TextView)1 PayPal (com.cloudrail.si.services.PayPal)1 Stripe (com.cloudrail.si.services.Stripe)1 Charge (com.cloudrail.si.types.Charge)1 Refund (com.cloudrail.si.types.Refund)1 List (java.util.List)1