Search in sources :

Example 1 with MobileDebit

use of net.iGap.model.bill.MobileDebit in project iGap-Android by KianIranian-STDG.

the class ElectricityBillListVM method getPhoneDebit.

private void getPhoneDebit(BillList.Bill dataModel) {
    BillInfo info = new BillInfo();
    info.setBillTypeString(dataModel.getBillType());
    info.setPhoneNum(dataModel.getPhoneNumber());
    if (dataModel.getBillType().equals("PHONE")) {
        info.setAreaCode(dataModel.getAreaCode());
    }
    new BillsAPIRepository().phoneAndMobileInquiry(info, this, new ResponseCallback<ElectricityResponseModel<MobileDebit>>() {

        @Override
        public void onSuccess(ElectricityResponseModel<MobileDebit> data) {
            Map<BillList.Bill, Debit> tmp = mMapData.getValue();
            data.getData().setLoading(false);
            tmp.put(dataModel, new Debit<>(data.getData()));
            mMapData.setValue(tmp);
        }

        @Override
        public void onError(String error) {
            Map<BillList.Bill, Debit> tmp = mMapData.getValue();
            Debit<MobileDebit> debitTmp = tmp.get(dataModel);
            debitTmp.getData().setLoading(false);
            debitTmp.getData().setFail(true);
            debitTmp.getData().setLastTerm(new MobileDebit.MobileInquiryObject("0", "0", "0"));
            debitTmp.getData().setMidTerm(new MobileDebit.MobileInquiryObject("0", "0", "0"));
            tmp.put(dataModel, debitTmp);
            mMapData.setValue(tmp);
        }

        @Override
        public void onFailed() {
            Map<BillList.Bill, Debit> tmp = mMapData.getValue();
            Debit<MobileDebit> debitTmp = tmp.get(dataModel);
            debitTmp.getData().setLoading(false);
            debitTmp.getData().setFail(true);
            debitTmp.getData().setLastTerm(new MobileDebit.MobileInquiryObject("0", "0", "0"));
            debitTmp.getData().setMidTerm(new MobileDebit.MobileInquiryObject("0", "0", "0"));
            tmp.put(dataModel, debitTmp);
            mMapData.setValue(tmp);
        }
    });
}
Also used : Debit(net.iGap.model.bill.Debit) MobileDebit(net.iGap.model.bill.MobileDebit) ServiceDebit(net.iGap.model.bill.ServiceDebit) BillsAPIRepository(net.iGap.repository.BillsAPIRepository) ElectricityResponseModel(net.iGap.model.electricity_bill.ElectricityResponseModel) BillList(net.iGap.model.bill.BillList) BillInfo(net.iGap.model.bill.BillInfo) MobileDebit(net.iGap.model.bill.MobileDebit) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MobileDebit

use of net.iGap.model.bill.MobileDebit in project iGap-Android by KianIranian-STDG.

the class ElectricityBillListFrag method initRecycler.

private void initRecycler(Map<BillList.Bill, Debit> bills) {
    adapter = new ElectricityBillListAdapter(getContext(), bills, (item, btnAction) -> {
        // ServiceDebit temp = viewModel.getmMapData().getValue().get(item);
        switch(btnAction) {
            case PAY:
                ServiceDebit tempService = (ServiceDebit) bills.get(item).getData();
                viewModel.payServiceBill(tempService.getBillID(), tempService.getPaymentID(), tempService.getTotalElectricityBillDebt() != null ? tempService.getTotalElectricityBillDebt() : tempService.getTotalGasBillDebt(), ProtoMplGetBillToken.MplGetBillToken.Type.NONE_VALUE);
                break;
            case EDIT:
                if (item.getBillTitle() == null) {
                    showDialog(getResources().getString(R.string.elecBill_error_title), getResources().getString(R.string.elecBill_error_notPossible), getResources().getString(R.string.ok));
                    return;
                }
                ElectricityBillAddFrag frag = ElectricityBillAddFrag.newInstance(viewModel.getBillInfo(item), true);
                frag.setCompleteListener(new ElectricityBillAddFrag.CompleteListener() {

                    @Override
                    public void loadAgain() {
                        viewModel.getBillsList();
                    }
                });
                frag.show(getFragmentManager(), "BillAddEdit");
                break;
            case DELETE:
                final MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.elecBill_deleteBill_title).content(R.string.elecBill_deleteBill_desc).positiveText(R.string.elecBill_deleteBill_pos).negativeText(R.string.elecBill_deleteBill_neg).positiveColor(getContext().getResources().getColor(R.color.red)).widgetColor(new Theme().getAccentColor(getContext())).onPositive((dialog1, which) -> {
                    viewModel.deleteItem(item);
                    Toast.makeText(getContext(), "Deleted", Toast.LENGTH_SHORT).show();
                }).build();
                dialog.show();
                break;
            case SHOW_DETAIL:
                if (item.getBillTitle() == null) {
                    showDialog(getResources().getString(R.string.elecBill_error_title), getResources().getString(R.string.elecBill_error_notPossible), getResources().getString(R.string.ok));
                    return;
                }
                BillInfo temp = viewModel.getBillInfo(item);
                new HelperFragment(getFragmentManager(), ElectricityBillPayFrag.newInstance(temp.getBillType(), temp.getBillID(), temp.getTitle(), true)).setReplace(false).load();
                break;
            case MID_PAY:
                MobileDebit tempMid = (MobileDebit) bills.get(item).getData();
                viewModel.payServiceBill(tempMid.getMidTerm().getBillID(), tempMid.getMidTerm().getPayID(), tempMid.getMidTerm().getAmount(), ProtoMplGetBillToken.MplGetBillToken.Type.MID_TERM_VALUE);
                break;
            case LAST_PAY:
                MobileDebit tempLast = (MobileDebit) bills.get(item).getData();
                viewModel.payServiceBill(tempLast.getLastTerm().getBillID(), tempLast.getLastTerm().getPayID(), tempLast.getLastTerm().getAmount(), ProtoMplGetBillToken.MplGetBillToken.Type.LAST_TERM_VALUE);
                break;
            case RELOAD:
                viewModel.reloadData(item);
        }
    });
    binding.billRecycler.setAdapter(adapter);
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) NonNull(androidx.annotation.NonNull) ProtoMplGetBillToken(net.iGap.proto.ProtoMplGetBillToken) Theme(net.iGap.module.Theme) ElectricityBillListVM(net.iGap.viewmodel.electricity_bill.ElectricityBillListVM) ArrayList(java.util.ArrayList) MobileDebit(net.iGap.model.bill.MobileDebit) FragmentElecBillListBinding(net.iGap.databinding.FragmentElecBillListBinding) Toast(android.widget.Toast) Map(java.util.Map) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) HelperError(net.iGap.helper.HelperError) HelperFragment(net.iGap.helper.HelperFragment) BillList(net.iGap.model.bill.BillList) DataBindingUtil(androidx.databinding.DataBindingUtil) Debit(net.iGap.model.bill.Debit) LayoutInflater(android.view.LayoutInflater) TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) ViewGroup(android.view.ViewGroup) BaseAPIViewFrag(net.iGap.api.apiService.BaseAPIViewFrag) BillInfo(net.iGap.model.bill.BillInfo) ElectricityBillListAdapter(net.iGap.adapter.electricity_bill.ElectricityBillListAdapter) List(java.util.List) Nullable(androidx.annotation.Nullable) R(net.iGap.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) HelperToolbar(net.iGap.helper.HelperToolbar) ServiceDebit(net.iGap.model.bill.ServiceDebit) ElectricityBillListAdapter(net.iGap.adapter.electricity_bill.ElectricityBillListAdapter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ServiceDebit(net.iGap.model.bill.ServiceDebit) Theme(net.iGap.module.Theme) BillInfo(net.iGap.model.bill.BillInfo) HelperFragment(net.iGap.helper.HelperFragment) MobileDebit(net.iGap.model.bill.MobileDebit)

Example 3 with MobileDebit

use of net.iGap.model.bill.MobileDebit in project iGap-Android by KianIranian-STDG.

the class ElectricityBillListVM method getBillsList.

public void getBillsList() {
    progressVisibility.set(View.VISIBLE);
    errorVisibility.set(View.GONE);
    showRetryView.set(View.GONE);
    new BillsAPIRepository().getBillList(this, new ResponseCallback<BillList>() {

        @Override
        public void onSuccess(BillList data) {
            if (data.getBills() == null || data.getBills().size() == 0) {
                errorVisibility.set(View.VISIBLE);
            }
            Map<BillList.Bill, Debit> tmp = new HashMap<>();
            for (BillList.Bill dataModel : data.getBills()) {
                switch(dataModel.getBillType()) {
                    case "ELECTRICITY":
                    case "GAS":
                        Debit<ServiceDebit> temp = new Debit<>();
                        temp.setData(new ServiceDebit());
                        tmp.put(dataModel, temp);
                        getServiceDebit(dataModel);
                        break;
                    case "MOBILE_MCI":
                    case "PHONE":
                        Debit<MobileDebit> temp1 = new Debit<>();
                        temp1.setData(new MobileDebit());
                        tmp.put(dataModel, temp1);
                        getPhoneDebit(dataModel);
                        break;
                }
            }
            mMapData.setValue(tmp);
            progressVisibility.set(View.GONE);
        }

        @Override
        public void onError(String error) {
            showRetryView.set(View.VISIBLE);
            progressVisibility.set(View.GONE);
            errorM.setValue(new ErrorModel("", error));
            errorVisibility.set(View.VISIBLE);
        }

        @Override
        public void onFailed() {
            showRetryView.set(View.VISIBLE);
            progressVisibility.set(View.GONE);
            showRequestFailedError.setValue(R.string.connection_error);
        }
    });
}
Also used : Debit(net.iGap.model.bill.Debit) MobileDebit(net.iGap.model.bill.MobileDebit) ServiceDebit(net.iGap.model.bill.ServiceDebit) BillsAPIRepository(net.iGap.repository.BillsAPIRepository) ServiceDebit(net.iGap.model.bill.ServiceDebit) BillList(net.iGap.model.bill.BillList) ErrorModel(net.iGap.api.errorhandler.ErrorModel) HashMap(java.util.HashMap) Map(java.util.Map) MobileDebit(net.iGap.model.bill.MobileDebit)

Example 4 with MobileDebit

use of net.iGap.model.bill.MobileDebit in project iGap-Android by KianIranian-STDG.

the class ElectricityBillListVM method reloadData.

public void reloadData(BillList.Bill data) {
    Map<BillList.Bill, Debit> tmp = mMapData.getValue();
    switch(data.getBillType()) {
        case "ELECTRICITY":
        case "GAS":
            ServiceDebit temp = (ServiceDebit) tmp.get(data).getData();
            temp.setLoading(true);
            temp.setFail(false);
            tmp.put(data, new Debit(temp));
            getServiceDebit(data);
            break;
        case "MOBILE_MCI":
        case "PHONE":
            MobileDebit temp1 = (MobileDebit) tmp.get(data).getData();
            temp1.setLoading(true);
            temp1.setFail(false);
            tmp.put(data, new Debit(temp1));
            getPhoneDebit(data);
            break;
    }
}
Also used : Debit(net.iGap.model.bill.Debit) MobileDebit(net.iGap.model.bill.MobileDebit) ServiceDebit(net.iGap.model.bill.ServiceDebit) ServiceDebit(net.iGap.model.bill.ServiceDebit) MobileDebit(net.iGap.model.bill.MobileDebit)

Example 5 with MobileDebit

use of net.iGap.model.bill.MobileDebit in project iGap-Android by KianIranian-STDG.

the class ElectricityBillPayVM method payBtn.

public void payBtn(int buttonID) {
    if (debit == null)
        return;
    if (buttonID == 0) {
        // main Btn for pay
        progressVisibilityPay.set(View.VISIBLE);
        payBtnEnable.set(false);
        switch(info.getBillType()) {
            case ELECTRICITY:
            case GAS:
                ServiceDebit temp = (ServiceDebit) debit.getData();
                if (info.getBillType() == BillInfo.BillType.ELECTRICITY)
                    payBill(temp.getBillID(), temp.getPaymentID(), temp.getTotalElectricityBillDebt());
                else
                    payBill(temp.getBillID(), temp.getPaymentID(), temp.getTotalGasBillDebt());
                break;
            case MOBILE:
            case PHONE:
                MobileDebit temp2 = (MobileDebit) debit.getData();
                payBill(temp2.getLastTerm().getBillID(), temp2.getLastTerm().getPayID(), temp2.getLastTerm().getAmount(), ProtoMplGetBillToken.MplGetBillToken.Type.LAST_TERM_VALUE);
                break;
        }
    } else {
        // secondary Btn for phone pay
        progressVisibilityPay.set(View.VISIBLE);
        pay2BtnEnable.set(false);
        MobileDebit temp2 = (MobileDebit) debit.getData();
        payBill(temp2.getMidTerm().getBillID(), temp2.getMidTerm().getPayID(), temp2.getMidTerm().getAmount(), ProtoMplGetBillToken.MplGetBillToken.Type.MID_TERM_VALUE);
    }
    switch(info.getBillType()) {
        case MOBILE:
            HelperTracker.sendTracker(HelperTracker.TRACKER_MOBILE_BILL_PAY);
            break;
        case PHONE:
            HelperTracker.sendTracker(HelperTracker.TRACKER_PHONE_BILL_PAY);
            break;
        case ELECTRICITY:
            HelperTracker.sendTracker(HelperTracker.TRACKER_ELECTRIC_BILL_PAY);
            break;
        case GAS:
            HelperTracker.sendTracker(HelperTracker.TRACKER_GAS_BILL_PAY);
            break;
    }
}
Also used : ServiceDebit(net.iGap.model.bill.ServiceDebit) MobileDebit(net.iGap.model.bill.MobileDebit)

Aggregations

MobileDebit (net.iGap.model.bill.MobileDebit)5 ServiceDebit (net.iGap.model.bill.ServiceDebit)5 Debit (net.iGap.model.bill.Debit)4 Map (java.util.Map)3 BillList (net.iGap.model.bill.BillList)3 HashMap (java.util.HashMap)2 BillInfo (net.iGap.model.bill.BillInfo)2 BillsAPIRepository (net.iGap.repository.BillsAPIRepository)2 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 LinearLayout (android.widget.LinearLayout)1 Toast (android.widget.Toast)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 DataBindingUtil (androidx.databinding.DataBindingUtil)1 ViewModelProviders (androidx.lifecycle.ViewModelProviders)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 Snackbar (com.google.android.material.snackbar.Snackbar)1