Search in sources :

Example 1 with OperatorAdapter

use of net.iGap.adapter.OperatorAdapter in project iGap-Android by KianIranian-STDG.

the class ChargeFragment method initForm.

private void initForm() {
    // init number from dataBase
    DbManager.getInstance().doRealmTask(realm -> {
        RealmRegisteredInfo userInfo = realm.where(RealmRegisteredInfo.class).findFirst();
        if (userInfo != null && editTextNumber.getText() != null) {
            userNumber = userInfo.getPhoneNumber();
            if (phoneNumber != null && !phoneNumber.isEmpty() && !phoneNumber.equals("0")) {
                setPhoneNumberEditText(phoneNumber);
                if (peerId != 0) {
                    avatarHandler.getAvatar(new ParamWithAvatarType(imageViewAvatar, peerId).avatarType(AvatarHandler.AvatarType.ROOM).showMain());
                }
            } else if (phoneNumber != null && phoneNumber.equals("0")) {
                imageViewAvatar.setVisibility(View.GONE);
                editTextNumber.setHint(getResources().getString(R.string.please_enter_phone_number));
                iconRemove.setText(R.string.icon_edit);
            } else {
                imageViewAvatar.setVisibility(View.GONE);
                setPhoneNumberEditText(userNumber);
            }
        }
    });
    // init RecyclerViewOperator
    recyclerViewOperator.setLayoutManager(new GridLayoutManager(context, 3, RecyclerView.VERTICAL, false));
    adapterOperator = new OperatorAdapter(getContext(), operators, operatorName -> {
        if (currentConfigData != null) {
            for (ConfigData configData : config.getData()) {
                if (configData.getOperator().getKey().equals(operatorName)) {
                    currentConfigData = configData;
                    changeOperator(currentConfigData.getOperator());
                    break;
                }
            }
        } else {
            adapterOperator.setCheckedRadioButton(null);
            HelperError.showSnackMessage(getResources().getString(R.string.please_enter_phone_number), false);
        }
    });
    recyclerViewOperator.setAdapter(adapterOperator);
    detectOperatorByNumber(editTextNumber.getText().toString());
    editTextNumber.addTextChangedListener(editTextNumberWatcher());
    iconRemove.setOnClickListener(removeNumberClicked());
    historyButton.setOnClickListener(historyButtonClicked());
    contactButton.setOnClickListener(contactButtonClicked());
    buttonAmount.setOnClickListener(v -> {
        choosePriceButtonClicked();
    });
    amountPlusButton.setOnClickListener(v -> {
        if (currentAmount != null) {
            isHistorySelected(false);
            currentAmount = new Amount(currentAmount, true);
            buttonAmount.setText(currentAmount.getTextAmount());
        } else {
            HelperError.showSnackMessage(getResources().getString(R.string.please_enter_desired_amount), false);
        }
    });
    amountMinesButton.setOnClickListener(v -> {
        if (currentAmount != null) {
            if (currentAmount.getAmount() > 10000) {
                isHistorySelected(false);
                currentAmount = new Amount(currentAmount, false);
                buttonAmount.setText(currentAmount.getTextAmount());
            } else {
                HelperError.showSnackMessage(getResources().getString(R.string.minimizeAmount), false);
            }
        } else {
            HelperError.showSnackMessage(getResources().getString(R.string.please_enter_desired_amount), false);
        }
    });
    buttonChargeType.setOnClickListener(v -> {
        chooseChargeTypeClicked();
    });
    buttonEnter.setOnClickListener(v -> onSaveBtnClicked());
    scrollView.setVisibility(View.VISIBLE);
    progressBar.setVisibility(View.GONE);
}
Also used : JsonObject(com.google.gson.JsonObject) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) FrameLayout(android.widget.FrameLayout) ConfigData(net.iGap.model.paymentPackage.ConfigData) Theme(net.iGap.module.Theme) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) G(net.iGap.G) MciPurchaseResponse(net.iGap.model.paymentPackage.MciPurchaseResponse) AdapterChargeType(net.iGap.adapter.payment.AdapterChargeType) HelperPermission(net.iGap.helper.HelperPermission) HelperPermission.showDeniedPermissionMessage(net.iGap.helper.HelperPermission.showDeniedPermissionMessage) View(android.view.View) ChargeContactNumberAdapter(net.iGap.adapter.payment.ChargeContactNumberAdapter) HelperError(net.iGap.helper.HelperError) Schedulers(io.reactivex.schedulers.Schedulers) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) ResponseBody(okhttp3.ResponseBody) AdapterChargeAmount(net.iGap.adapter.payment.AdapterChargeAmount) IGSingleObserver(net.iGap.observers.rx.IGSingleObserver) OperatorAdapter(net.iGap.adapter.OperatorAdapter) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) FaceValue(net.iGap.model.paymentPackage.FaceValue) AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) BaseFragment(net.iGap.fragments.BaseFragment) ViewGroup(android.view.ViewGroup) Objects(java.util.Objects) PaymentRepository(net.iGap.repository.PaymentRepository) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Nullable(androidx.annotation.Nullable) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Call(retrofit2.Call) TextWatcher(android.text.TextWatcher) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) AndroidUtils(net.iGap.module.AndroidUtils) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) GravityEnum(com.afollestad.materialdialogs.GravityEnum) Response(retrofit2.Response) Editable(android.text.Editable) ArrayList(java.util.ArrayList) MaterialButton(com.google.android.material.button.MaterialButton) LayoutCreator(net.iGap.helper.LayoutCreator) TokenContainer(net.iGap.api.apiService.TokenContainer) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) Config(net.iGap.model.paymentPackage.Config) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) ContactNumber(net.iGap.adapter.payment.ContactNumber) LayoutInflater(android.view.LayoutInflater) Amount(net.iGap.adapter.payment.Amount) Operator(net.iGap.model.paymentPackage.Operator) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) ChargeHistoryNumberAdapter(net.iGap.adapter.payment.ChargeHistoryNumberAdapter) TopupChargeType(net.iGap.model.paymentPackage.TopupChargeType) CircleImageView(net.iGap.module.CircleImageView) PhoneContactProvider(net.iGap.controllers.PhoneContactProvider) Gravity(android.view.Gravity) GetFavoriteNumber(net.iGap.model.paymentPackage.GetFavoriteNumber) ChargeApi(net.iGap.api.ChargeApi) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) EditText(android.widget.EditText) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ConfigData(net.iGap.model.paymentPackage.ConfigData) AdapterChargeAmount(net.iGap.adapter.payment.AdapterChargeAmount) Amount(net.iGap.adapter.payment.Amount) OperatorAdapter(net.iGap.adapter.OperatorAdapter) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo)

Example 2 with OperatorAdapter

use of net.iGap.adapter.OperatorAdapter in project iGap-Android by KianIranian-STDG.

the class InternetFragment method initForm.

private void initForm() {
    DbManager.getInstance().doRealmTask(realm -> {
        RealmRegisteredInfo userInfo = realm.where(RealmRegisteredInfo.class).findFirst();
        if (userInfo != null) {
            userNumber = userInfo.getPhoneNumber();
            if (phoneNumber != null && !phoneNumber.isEmpty() && !phoneNumber.equals("0")) {
                setPhoneNumberEditText(phoneNumber);
                if (peerId != 0) {
                    avatarHandler.getAvatar(new ParamWithAvatarType(avatar, peerId).avatarType(AvatarHandler.AvatarType.ROOM).showMain());
                }
            }
            if (phoneNumber != null && phoneNumber.equals("0")) {
                avatar.setVisibility(View.GONE);
                editTextNumber.setHint(getActivity().getString(R.string.please_enter_phone_number));
                removeButton.setText(R.string.icon_edit);
            } else {
                avatar.setVisibility(View.GONE);
                setPhoneNumberEditText(userNumber);
            }
            if (editTextNumber.getText() != null && editTextNumber.getText().length() == 11) {
                hideKeyboard();
            }
            editTextNumber.setSelection(editTextNumber.getText() == null ? 0 : editTextNumber.getText().length());
        }
    });
    operatorAdapter = new OperatorAdapter(getContext(), operators, operatorName -> {
        if (currentConfigData != null) {
            changeOperator(currentConfigData.getOperator());
        } else {
            operatorAdapter.setCheckedRadioButton(null);
            HelperError.showSnackMessage(getActivity().getString(R.string.please_enter_phone_number), false);
        }
    });
    lstOperator.setAdapter(operatorAdapter);
    detectOperatorByNumber(editTextNumber.getText().toString());
    chargeApi = new RetrofitFactory().getChargeRetrofit();
    editTextNumber.addTextChangedListener(editTextNumberWatcher());
    removeButton.setOnClickListener(removeNumberClicked());
    frameContact.setOnClickListener(v -> onContactNumberButtonClick());
    frameHistory.setOnClickListener(v -> onHistoryNumberButtonClick());
    radioGroup.setOnCheckedChangeListener((group, checkedId) -> InternetFragment.this.changeSimType());
    goNextButton.setOnClickListener(v -> {
        RadioButton radioButton = radioGroup.findViewById(radioGroup.getCheckedRadioButtonId());
        if (radioButton != null) {
            if (currentSimType == null) {
                showError(getActivity().getString(R.string.invalid_sim_type));
                return;
            }
            if (editTextNumber.getText() == null) {
                editTextNumber.setError(getString(R.string.phone_number_is_not_valid));
                return;
            }
            String rechargeableNumber = editTextNumber.getText().toString().trim();
            if (!isNumeric(rechargeableNumber) || rechargeableNumber.length() < 11) {
                editTextNumber.setError(getString(R.string.phone_number_is_not_valid));
                return;
            }
            if (!isNumberFromIran(rechargeableNumber)) {
                editTextNumber.setError(getString(R.string.phone_number_is_not_valid));
                return;
            }
            int packageType = historyNumber != null ? Integer.parseInt(historyNumber.getPackageType()) : -1;
            new HelperFragment(getActivity().getSupportFragmentManager(), PaymentInternetFragment.newInstance(userNumber, rechargeableNumber, currentOperator.getKey(), currentSimType, packageType)).setAnimated(false).setReplace(false).load();
        } else {
            showError(getActivity().getString(R.string.sim_type_not_choosed));
        }
    });
    progressBar.setVisibility(View.GONE);
    scrollView.setVisibility(View.VISIBLE);
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) HandShakeCallback(net.iGap.observers.interfaces.HandShakeCallback) FrameLayout(android.widget.FrameLayout) RadioButton(android.widget.RadioButton) FavoriteNumber(net.iGap.model.paymentPackage.FavoriteNumber) ConfigData(net.iGap.model.paymentPackage.ConfigData) Theme(net.iGap.module.Theme) G(net.iGap.G) HelperPermission(net.iGap.helper.HelperPermission) HelperPermission.showDeniedPermissionMessage(net.iGap.helper.HelperPermission.showDeniedPermissionMessage) View(android.view.View) ChargeContactNumberAdapter(net.iGap.adapter.payment.ChargeContactNumberAdapter) HelperError(net.iGap.helper.HelperError) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) OperatorAdapter(net.iGap.adapter.OperatorAdapter) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperString.isNumeric(net.iGap.helper.HelperString.isNumeric) AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) BaseFragment(net.iGap.fragments.BaseFragment) ViewGroup(android.view.ViewGroup) PaymentRepository(net.iGap.repository.PaymentRepository) List(java.util.List) Nullable(androidx.annotation.Nullable) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) InternetHistoryPackageAdapter(net.iGap.adapter.payment.InternetHistoryPackageAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) PackageChargeType(net.iGap.model.paymentPackage.PackageChargeType) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NotNull(org.jetbrains.annotations.NotNull) Call(retrofit2.Call) TextWatcher(android.text.TextWatcher) AndroidUtils(net.iGap.module.AndroidUtils) ResourcesCompat(androidx.core.content.res.ResourcesCompat) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Response(retrofit2.Response) RadioGroup(android.widget.RadioGroup) Editable(android.text.Editable) ArrayList(java.util.ArrayList) MaterialButton(com.google.android.material.button.MaterialButton) LayoutCreator(net.iGap.helper.LayoutCreator) TokenContainer(net.iGap.api.apiService.TokenContainer) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) Config(net.iGap.model.paymentPackage.Config) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) ContactNumber(net.iGap.adapter.payment.ContactNumber) LayoutInflater(android.view.LayoutInflater) Operator(net.iGap.model.paymentPackage.Operator) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) IOException(java.io.IOException) CircleImageView(net.iGap.module.CircleImageView) PhoneContactProvider(net.iGap.controllers.PhoneContactProvider) Gravity(android.view.Gravity) GetFavoriteNumber(net.iGap.model.paymentPackage.GetFavoriteNumber) ChargeApi(net.iGap.api.ChargeApi) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) EditText(android.widget.EditText) OperatorAdapter(net.iGap.adapter.OperatorAdapter) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) RadioButton(android.widget.RadioButton) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperFragment(net.iGap.helper.HelperFragment) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo)

Aggregations

Bundle (android.os.Bundle)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 Gravity (android.view.Gravity)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 EditText (android.widget.EditText)2 FrameLayout (android.widget.FrameLayout)2 ScrollView (android.widget.ScrollView)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 AppCompatEditText (androidx.appcompat.widget.AppCompatEditText)2 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 MaterialButton (com.google.android.material.button.MaterialButton)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2