Search in sources :

Example 1 with Charge

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;
}
Also used : LayoutInflater(android.view.LayoutInflater) Charge(com.cloudrail.si.types.Charge) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 2 with Charge

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;
}
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

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