Search in sources :

Example 1 with OnGetPermission

use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.

the class ChargeFragment method contactButtonClicked.

private View.OnClickListener contactButtonClicked() {
    return v -> {
        hideKeyboard();
        progressBar.setVisibility(View.VISIBLE);
        closeKeyboard(editTextNumber);
        try {
            HelperPermission.getContactPermision(getActivity(), new OnGetPermission() {

                @Override
                public void Allow() {
                    ChargeContactNumberAdapter adapter = new ChargeContactNumberAdapter();
                    contactButton.setEnabled(false);
                    PhoneContactProvider.getInstance().getAllPhoneContactForPayment(contactNumbers -> {
                        if (getContext() == null) {
                            return;
                        }
                        contactButton.setEnabled(true);
                        progressBar.setVisibility(View.GONE);
                        if (contactNumbers.size() == 0) {
                            HelperError.showSnackMessage(getResources().getString(R.string.no_number_found), false);
                        } else {
                            adapter.setContactNumbers(contactNumbers);
                            MaterialDialog dialog = new MaterialDialog.Builder(getContext()).customView(R.layout.popup_paymet_contact, false).build();
                            View contactDialogView = dialog.getCustomView();
                            if (contactDialogView != null) {
                                RecyclerView contactRecyclerView = contactDialogView.findViewById(R.id.rv_contact);
                                EditText editText = contactDialogView.findViewById(R.id.etSearch);
                                setDialogBackground(contactRecyclerView);
                                setDialogBackground(editText);
                                contactRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
                                contactRecyclerView.setAdapter(adapter);
                                adapter.setOnItemClickListener(position -> {
                                    contactPositionClicked = position;
                                    onContactItemClicked(adapter);
                                    dialog.dismiss();
                                });
                                ChargeContactNumberAdapter adapterContactNumber = (ChargeContactNumberAdapter) contactRecyclerView.getAdapter();
                                if (textWatcher != null)
                                    editText.removeTextChangedListener(textWatcher);
                                textWatcher = new TextWatcher() {

                                    @Override
                                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                                    }

                                    @Override
                                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                                        if (adapterContactNumber != null)
                                            adapterContactNumber.search(s.toString());
                                    }

                                    @Override
                                    public void afterTextChanged(Editable s) {
                                    }
                                };
                                editText.addTextChangedListener(textWatcher);
                                contactDialogView.findViewById(R.id.closeView).setOnClickListener(v12 -> dialog.dismiss());
                            }
                            dialog.show();
                        }
                    });
                }

                @Override
                public void deny() {
                    progressBar.setVisibility(View.GONE);
                    showDeniedPermissionMessage(G.context.getString(R.string.permission_contact));
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    };
}
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) AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) EditText(android.widget.EditText) ChargeContactNumberAdapter(net.iGap.adapter.payment.ChargeContactNumberAdapter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) IOException(java.io.IOException) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) CircleImageView(net.iGap.module.CircleImageView) ScrollView(android.widget.ScrollView) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with OnGetPermission

use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.

the class ScanCodeQRCodePaymentFragment method checkCameraPermission.

private void checkCameraPermission() {
    PackageManager packageManager = context.getPackageManager();
    if (!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Toast.makeText(context, context.getString(R.string.device_dosenot_camera_en), Toast.LENGTH_SHORT).show();
        popBackStackFragment();
        return;
    }
    try {
        HelperPermission.getCameraPermission(context, new OnGetPermission() {

            @Override
            public void Allow() throws IOException {
                if (getActivity() != null) {
                    if (mCodeScanner == null) {
                        mCodeScanner = new CodeScanner(getActivity(), mBinding.codeScanner);
                    }
                    initCodeScanner();
                }
            }

            @Override
            public void deny() {
                if (ScanCodeQRCodePaymentFragment.this.isAdded()) {
                    popBackStackFragment();
                }
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : PackageManager(android.content.pm.PackageManager) CodeScanner(net.iGap.libs.codescanner.CodeScanner) IOException(java.io.IOException) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission)

Example 3 with OnGetPermission

use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.

the class InternetFragment method onContactNumberButtonClick.

private void onContactNumberButtonClick() {
    progressBar.setVisibility(View.VISIBLE);
    frameContact.setEnabled(false);
    closeKeyboard(editTextNumber);
    try {
        HelperPermission.getContactPermision(getActivity(), new OnGetPermission() {

            @Override
            public void Allow() {
                ChargeContactNumberAdapter adapterContact = new ChargeContactNumberAdapter();
                PhoneContactProvider.getInstance().getAllPhoneContactForPayment(contactNumbers -> {
                    if (getContext() == null) {
                        return;
                    }
                    frameContact.setEnabled(true);
                    progressBar.setVisibility(View.GONE);
                    if (contactNumbers.size() == 0) {
                        HelperError.showSnackMessage(getActivity().getString(R.string.no_number_found), false);
                    } else {
                        adapterContact.setContactNumbers(contactNumbers);
                        MaterialDialog dialog = new MaterialDialog.Builder(getContext()).customView(R.layout.popup_paymet_contact, false).build();
                        View contactDialogView = dialog.getCustomView();
                        if (contactDialogView != null) {
                            RecyclerView contactRecyclerView = contactDialogView.findViewById(R.id.rv_contact);
                            EditText editText = contactDialogView.findViewById(R.id.etSearch);
                            setDialogBackground(contactRecyclerView);
                            setDialogBackground(editText);
                            contactRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
                            adapterContact.setOnItemClickListener(position -> {
                                clickedPosition = position;
                                onContactClicked(adapterContact);
                                dialog.dismiss();
                            });
                            contactRecyclerView.setAdapter(adapterContact);
                            if (watcher != null)
                                editText.removeTextChangedListener(watcher);
                            watcher = new TextWatcher() {

                                @Override
                                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                                }

                                @Override
                                public void onTextChanged(CharSequence s, int start, int before, int count) {
                                    if (s != null)
                                        adapterContact.search(s.toString());
                                }

                                @Override
                                public void afterTextChanged(Editable s) {
                                }
                            };
                            editText.addTextChangedListener(watcher);
                            contactDialogView.findViewById(R.id.closeView).setOnClickListener(v12 -> dialog.dismiss());
                        }
                        dialog.show();
                    }
                });
            }

            @Override
            public void deny() {
                progressBar.setVisibility(View.GONE);
                showDeniedPermissionMessage(G.context.getString(R.string.permission_contact));
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
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) AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) EditText(android.widget.EditText) ChargeContactNumberAdapter(net.iGap.adapter.payment.ChargeContactNumberAdapter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) IOException(java.io.IOException) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) CircleImageView(net.iGap.module.CircleImageView) ScrollView(android.widget.ScrollView) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 4 with OnGetPermission

use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.

the class BaseViewHolder method handleDiscoveryFieldsClickStatic.

public static void handleDiscoveryFieldsClickStatic(DiscoveryItemField discoveryField, FragmentActivity activity, boolean haveNext) {
    if (activity == null || activity.isFinishing()) {
        return;
    }
    if (discoveryField.agreementSlug != null && discoveryField.agreementSlug.length() > 1) {
        if (!discoveryField.agreement) {
            DiscoveryFragmentAgreement.newInstance(discoveryField, discoveryField.agreementSlug).show(activity.getSupportFragmentManager(), null);
            return;
        }
    }
    new RequestClientSetDiscoveryItemClick().setDiscoveryClicked(discoveryField.id);
    switch(discoveryField.actionType) {
        case PAGE:
            /**
             * tested *
             */
            actionPage(discoveryField.value, activity, haveNext);
            break;
        case JOIN_LINK:
            int index = discoveryField.value.lastIndexOf("/");
            if (index >= 0 && index < discoveryField.value.length() - 1) {
                String token = discoveryField.value.substring(index + 1);
                if (discoveryField.value.toLowerCase().contains("join")) {
                    HelperUrl.checkAndJoinToRoom(activity, token);
                } else {
                    HelperUrl.checkUsernameAndGoToRoom(activity, token, HelperUrl.ChatEntry.profile);
                }
            }
            break;
        case WEB_LINK:
            /**
             * tested *
             */
            SharedPreferences sharedPreferences = activity.getSharedPreferences(SHP_SETTING.FILE_NAME, Context.MODE_PRIVATE);
            int checkedInAppBrowser = sharedPreferences.getInt(SHP_SETTING.KEY_IN_APP_BROWSER, 1);
            if (checkedInAppBrowser == 1 && !HelperUrl.isNeedOpenWithoutBrowser(discoveryField.value)) {
                HelperUrl.openBrowser(discoveryField.value);
            } else {
                HelperUrl.openWithoutBrowser(discoveryField.value);
            }
            break;
        case IVAND:
            new HelperFragment(activity.getSupportFragmentManager(), new FragmentUserScore()).setReplace(false).load();
            break;
        case IVANDQR:
            UserScoreViewModel.scanBarCode(activity);
            break;
        case IVANDLIST:
            new HelperFragment(activity.getSupportFragmentManager(), FragmentIVandActivities.newInstance()).setReplace(false).load();
            break;
        case WEB_VIEW_LINK:
            /**
             * tested title needed*
             */
            if (HelperUrl.isNeedOpenWithoutBrowser(discoveryField.value)) {
                HelperUrl.openWithoutBrowser(discoveryField.value);
            } else {
                new HelperFragment(activity.getSupportFragmentManager(), FragmentWebView.newInstance(discoveryField.value, discoveryField.refresh, discoveryField.param)).setReplace(false).load();
            }
            break;
        case USERNAME_LINK:
            /**
             * tested *
             */
            HelperUrl.checkUsernameAndGoToRoomWithMessageId(activity, discoveryField.value.replace("@", ""), HelperUrl.ChatEntry.chat, 0, 0);
            break;
        case TOPUP_MENU:
            /**
             * tested *
             */
            new HelperFragment(activity.getSupportFragmentManager(), ChargeFragment.newInstance()).setReplace(false).load();
            break;
        case BILL_MENU:
            try {
                JSONObject jsonObject = new JSONObject(discoveryField.value);
                new HelperFragment(activity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills, jsonObject)).setReplace(false).load();
            } catch (JSONException e) {
                new HelperFragment(activity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills)).setReplace(false).load();
            }
            break;
        case TRAFFIC_BILL_MENU:
            /**
             * tested *
             */
            try {
                JSONObject jsonObject = new JSONObject(discoveryField.value);
                new HelperFragment(activity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills_crime, jsonObject)).setReplace(false).load();
            } catch (JSONException e) {
                new HelperFragment(activity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills_crime)).setReplace(false).load();
            }
            break;
        case PHONE_BILL_MENU:
            /**
             * tested *
             */
            new HelperFragment(activity.getSupportFragmentManager(), new FragmentPaymentInquiryTelephone()).setReplace(false).load();
            break;
        case ELECTRIC_BILL_MENU:
            new HelperFragment(activity.getSupportFragmentManager(), new ElectricityBillMainFrag()).setReplace(false).load();
            // new HelperFragment(activity.getSupportFragmentManager(), new MobileBankLoginFragment()).setReplace(false).load();
            break;
        case PARSLAND:
            break;
        case FUN_SERVICE:
            new HelperFragment(activity.getSupportFragmentManager(), new IGashtProvinceFragment()).setReplace(false).load();
            break;
        case BLOCKCHAIN:
            break;
        case VIRTUAL_GIFT_CARD:
            break;
        case NEWS:
            NewsMainFrag frag = new NewsMainFrag();
            if (!discoveryField.value.equals(""))
                frag.setSpecificNewsID(discoveryField.value);
            new HelperFragment(activity.getSupportFragmentManager(), frag).setReplace(false).load();
            break;
        case MOBILE_BILL_MENU:
            /**
             * tested *
             */
            new HelperFragment(activity.getSupportFragmentManager(), new FragmentPaymentInquiryMobile()).setReplace(false).load();
            break;
        case FINANCIAL_MENU:
            /**
             * tested *
             */
            new HelperFragment(activity.getSupportFragmentManager(), FragmentPayment.newInstance()).setReplace(false).load();
            break;
        case NEARBY_MENU:
            /**
             * tested *
             */
            try {
                HelperPermission.getLocationPermission(activity, new OnGetPermission() {

                    @Override
                    public void Allow() throws IOException {
                        try {
                            if (!waitingForConfiguration) {
                                waitingForConfiguration = true;
                                if (mapUrls == null || mapUrls.isEmpty() || mapUrls.size() == 0) {
                                    G.onGeoGetConfiguration = new OnGeoGetConfiguration() {

                                        @Override
                                        public void onGetConfiguration() {
                                            G.handler.postDelayed(new Runnable() {

                                                @Override
                                                public void run() {
                                                    waitingForConfiguration = false;
                                                }
                                            }, 2000);
                                            new HelperFragment(activity.getSupportFragmentManager(), FragmentiGapMap.getInstance()).setReplace(false).load();
                                        }

                                        @Override
                                        public void getConfigurationTimeOut() {
                                            G.handler.postDelayed(new Runnable() {

                                                @Override
                                                public void run() {
                                                    waitingForConfiguration = false;
                                                }
                                            }, 2000);
                                        }
                                    };
                                    new RequestGeoGetConfiguration().getConfiguration();
                                } else {
                                    G.handler.postDelayed(new Runnable() {

                                        @Override
                                        public void run() {
                                            waitingForConfiguration = false;
                                        }
                                    }, 2000);
                                    new HelperFragment(activity.getSupportFragmentManager(), FragmentiGapMap.getInstance()).setReplace(false).load();
                                }
                            }
                        } catch (Exception e) {
                            e.getStackTrace();
                        }
                    }

                    @Override
                    public void deny() {
                        showDeniedPermissionMessage(G.context.getString(R.string.permission_location));
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
            break;
        case REQUEST_PHONE:
            // this item is for bot
            break;
        case REQUEST_LOCATION:
            // this item is for bot
            break;
        case BOT_ACTION:
            // this item is for bot
            break;
        case PAY_BY_WALLET:
            // coming soon
            break;
        case PAY_DIRECT:
            try {
                JSONObject jsonObject = new JSONObject(discoveryField.value);
                DirectPayHelper.directPay(jsonObject);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        case CALL:
            /**
             * tested *
             */
            dialPhoneNumber(activity, discoveryField.value, activity);
            break;
        case SHOW_ALERT:
            /**
             * tested *
             */
            new MaterialDialog.Builder(activity).content(discoveryField.value).positiveText(R.string.dialog_ok).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                }
            }).show();
            break;
        case STREAM_PLAY:
            // coming soon
            break;
        case STICKER_SHOP:
            /**
             * tested *
             */
            StickerRepository.getInstance().getUserStickersGroup();
            if (discoveryField.value.isEmpty()) {
                new HelperFragment(activity.getSupportFragmentManager(), FragmentSettingAddStickers.newInstance("ALL")).setReplace(false).load();
            } else {
                try {
                    String title = "";
                    JSONObject jsonObject = new JSONObject(discoveryField.value);
                    if (jsonObject.has("title"))
                        title = jsonObject.getString("title");
                    if (jsonObject.has("group")) {
                        String category = jsonObject.getString("group");
                        if (!category.isEmpty()) {
                            if (jsonObject.has("type")) {
                                String type = jsonObject.getString("type");
                                new HelperFragment(activity.getSupportFragmentManager(), AddStickersFragment.newInstance(category, type, title)).setReplace(false).load();
                            } else {
                                new HelperFragment(activity.getSupportFragmentManager(), AddStickersFragment.newInstance(category, "ALL", title)).setReplace(false).load();
                            }
                        }
                    } else if (jsonObject.has("type")) {
                        String type = jsonObject.getString("type");
                        new HelperFragment(activity.getSupportFragmentManager(), FragmentSettingAddStickers.newInstance(type)).setReplace(false).load();
                    } else if (jsonObject.has("id")) {
                        String id = jsonObject.getString("id");
                        StickerDialogFragment dialogFragment = StickerDialogFragment.getInstance(id);
                        dialogFragment.show(activity.getSupportFragmentManager(), "BaseViewHolder");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            break;
        case CARD_TO_CARD:
            CardToCardHelper.CallCardToCard(activity);
            break;
        case IVANDSCORE:
            new MaterialDialog.Builder(activity).content(R.string.are_you_sure_request).positiveText(R.string.yes).negativeText(R.string.no).onPositive((dialog, which) -> {
                dialog.dismiss();
                ActivityMain.doIvandScore(discoveryField.value, activity);
            }).onNegative((dialog, which) -> {
                dialog.dismiss();
            }).show();
            break;
        case NONE:
            break;
        case POLL:
            new HelperFragment(activity.getSupportFragmentManager(), PollFragment.newInstance(Integer.parseInt(HelperString.isNumeric(discoveryField.value) ? discoveryField.value : "0"))).setReplace(false).load();
            break;
        case POLL_RESULT:
            new HelperFragment(activity.getSupportFragmentManager(), ChartFragment.newInstance(Integer.parseInt(HelperString.isNumeric(discoveryField.value) ? discoveryField.value : "0"))).setReplace(false).load();
            break;
        case FAVORITE_CHANNEL:
            if (discoveryField.value.equals(""))
                new HelperFragment(activity.getSupportFragmentManager(), new PopularChannelHomeFragment()).setReplace(false).load();
            else {
                PopularMoreChannelFragment popularMoreChannelFragment = new PopularMoreChannelFragment();
                Bundle bundle = new Bundle();
                bundle.putString("id", discoveryField.value);
                popularMoreChannelFragment.setArguments(bundle);
                new HelperFragment(activity.getSupportFragmentManager(), popularMoreChannelFragment).setReplace(false).load();
            }
            break;
        case FINANCIAL_HISTORY:
            new HelperFragment(activity.getSupportFragmentManager(), new MplTransactionFragment()).setReplace(false).load();
            break;
        case INTERNET_PACKAGE_MENU:
            new HelperFragment(activity.getSupportFragmentManager(), InternetFragment.newInstance()).setReplace(false).load();
            break;
        case CHARITY:
            try {
                JSONObject jsonObject = new JSONObject(discoveryField.value);
                if (jsonObject.getInt("price") == 0) {
                    new MaterialDialog.Builder(activity).title(activity.getResources().getString(R.string.insert_amount_in_rial)).customView(R.layout.charity_custom_amount, false).positiveText(activity.getResources().getString(R.string.B_ok)).negativeText(activity.getResources().getString(R.string.B_cancel)).onPositive((dialog, which) -> {
                        EditText editText = dialog.getView().findViewById(R.id.editText);
                        if (editText.getText() != null) {
                            if (editText.getText().toString().length() > 0) {
                                int price = Integer.parseInt(editText.getText().toString());
                                if (price > 10000) {
                                    HelperUrl.showIndeterminateProgressDialog(activity);
                                    try {
                                        dialog.cancel();
                                        sendRequestGetCharityPaymentToken(activity, jsonObject.getString("charityId"), price);
                                    } catch (JSONException e) {
                                        HelperUrl.closeDialogWaiting();
                                        e.printStackTrace();
                                    }
                                } else {
                                    Toast.makeText(activity, activity.getResources().getString(R.string.amount_must_be_greater_10000), Toast.LENGTH_SHORT).show();
                                }
                            }
                        }
                    }).build().show();
                } else {
                    HelperUrl.showIndeterminateProgressDialog(activity);
                    sendRequestGetCharityPaymentToken(activity, jsonObject.getString("charityId"), jsonObject.getInt("price"));
                }
            } catch (JSONException e) {
                HelperUrl.closeDialogWaiting();
                e.printStackTrace();
            }
            break;
        case INVITE_FRIEND:
            try {
                HelperPermission.getContactPermision(activity, new OnGetPermission() {

                    @Override
                    public void Allow() {
                        new HelperFragment(activity.getSupportFragmentManager(), new LocalContactFragment()).setReplace(false).load(true);
                    }

                    @Override
                    public void deny() {
                        showDeniedPermissionMessage(G.context.getString(R.string.permission_contact));
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
            break;
        case QRPAY:
            new HelperFragment(activity.getSupportFragmentManager(), ScanCodeQRCodePaymentFragment.newInstance()).setReplace(false).load();
            break;
        default:
            new MaterialDialog.Builder(activity).content(R.string.install_latest_version).positiveText(R.string.ok).onPositive((dialog, which) -> dialog.dismiss()).show();
            break;
    }
}
Also used : Bundle(android.os.Bundle) DiscoveryFragmentAgreement(net.iGap.fragments.discovery.DiscoveryFragmentAgreement) NonNull(androidx.annotation.NonNull) HandShakeCallback(net.iGap.observers.interfaces.HandShakeCallback) Uri(android.net.Uri) ImageView(android.widget.ImageView) ChargeFragment(net.iGap.fragments.payment.ChargeFragment) UserScoreViewModel(net.iGap.viewmodel.UserScoreViewModel) StickerDialogFragment(net.iGap.fragments.emoji.add.StickerDialogFragment) DiscoveryFragment(net.iGap.fragments.discovery.DiscoveryFragment) G(net.iGap.G) MciPurchaseResponse(net.iGap.model.paymentPackage.MciPurchaseResponse) RequestClientSetDiscoveryItemClick(net.iGap.request.RequestClientSetDiscoveryItemClick) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) HelperPermission(net.iGap.helper.HelperPermission) HelperPermission.showDeniedPermissionMessage(net.iGap.helper.HelperPermission.showDeniedPermissionMessage) PollFragment(net.iGap.fragments.poll.PollFragment) View(android.view.View) HelperError(net.iGap.helper.HelperError) RecyclerView(androidx.recyclerview.widget.RecyclerView) FragmentPayment(net.iGap.fragments.FragmentPayment) HelperFragment(net.iGap.helper.HelperFragment) FragmentIVandActivities(net.iGap.fragments.FragmentIVandActivities) FragmentPaymentInquiryMobile(net.iGap.fragments.inquiryBill.FragmentPaymentInquiryMobile) MplTransactionFragment(net.iGap.fragments.mplTranaction.MplTransactionFragment) IGashtProvinceFragment(net.iGap.fragments.igasht.IGashtProvinceFragment) FragmentSettingAddStickers(net.iGap.fragments.emoji.add.FragmentSettingAddStickers) AddStickersFragment(net.iGap.fragments.emoji.add.AddStickersFragment) DiscoveryItemField(net.iGap.adapter.items.discovery.DiscoveryItemField) SHP_SETTING(net.iGap.module.SHP_SETTING) LocalContactFragment(net.iGap.fragments.LocalContactFragment) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) StickerRepository(net.iGap.repository.StickerRepository) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ResponseCallback(net.iGap.observers.interfaces.ResponseCallback) Context(android.content.Context) ActivityMain(net.iGap.activities.ActivityMain) HelperUrl(net.iGap.helper.HelperUrl) ApiInitializer(net.iGap.api.apiService.ApiInitializer) Intent(android.content.Intent) SystemClock(android.os.SystemClock) FragmentiGapMap.mapUrls(net.iGap.fragments.FragmentiGapMap.mapUrls) InternetFragment(net.iGap.fragments.payment.InternetFragment) FragmentActivity(androidx.fragment.app.FragmentActivity) Toast(android.widget.Toast) ChartFragment(net.iGap.fragments.poll.ChartFragment) ImageLoadingServiceInjector(net.iGap.module.imageLoaderService.ImageLoadingServiceInjector) FragmentUserScore(net.iGap.fragments.FragmentUserScore) PopularMoreChannelFragment(net.iGap.fragments.populaChannel.PopularMoreChannelFragment) FragmentPaymentInquiryTelephone(net.iGap.fragments.FragmentPaymentInquiryTelephone) FragmentiGapMap(net.iGap.fragments.FragmentiGapMap) NewsMainFrag(net.iGap.fragments.news.NewsMainFrag) PopularChannelHomeFragment(net.iGap.fragments.populaChannel.PopularChannelHomeFragment) DialogAction(com.afollestad.materialdialogs.DialogAction) FragmentPaymentBill(net.iGap.fragments.FragmentPaymentBill) IOException(java.io.IOException) ScanCodeQRCodePaymentFragment(net.iGap.fragments.qrCodePayment.fragments.ScanCodeQRCodePaymentFragment) OnGeoGetConfiguration(net.iGap.observers.interfaces.OnGeoGetConfiguration) DiscoveryItem(net.iGap.adapter.items.discovery.DiscoveryItem) CardToCardHelper(net.iGap.helper.CardToCardHelper) RequestGeoGetConfiguration(net.iGap.request.RequestGeoGetConfiguration) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) ElectricityBillMainFrag(net.iGap.fragments.electricity_bill.ElectricityBillMainFrag) SharedPreferences(android.content.SharedPreferences) HelperString(net.iGap.helper.HelperString) ActivityMain.waitingForConfiguration(net.iGap.activities.ActivityMain.waitingForConfiguration) R(net.iGap.R) DirectPayHelper(net.iGap.helper.DirectPayHelper) EditText(android.widget.EditText) FragmentWebView(net.iGap.fragments.FragmentWebView) PopularChannelHomeFragment(net.iGap.fragments.populaChannel.PopularChannelHomeFragment) FragmentPaymentInquiryTelephone(net.iGap.fragments.FragmentPaymentInquiryTelephone) FragmentUserScore(net.iGap.fragments.FragmentUserScore) ElectricityBillMainFrag(net.iGap.fragments.electricity_bill.ElectricityBillMainFrag) HelperString(net.iGap.helper.HelperString) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) NewsMainFrag(net.iGap.fragments.news.NewsMainFrag) PopularMoreChannelFragment(net.iGap.fragments.populaChannel.PopularMoreChannelFragment) NonNull(androidx.annotation.NonNull) IGashtProvinceFragment(net.iGap.fragments.igasht.IGashtProvinceFragment) RequestGeoGetConfiguration(net.iGap.request.RequestGeoGetConfiguration) EditText(android.widget.EditText) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) FragmentPaymentInquiryMobile(net.iGap.fragments.inquiryBill.FragmentPaymentInquiryMobile) Bundle(android.os.Bundle) MplTransactionFragment(net.iGap.fragments.mplTranaction.MplTransactionFragment) JSONException(org.json.JSONException) IOException(java.io.IOException) LocalContactFragment(net.iGap.fragments.LocalContactFragment) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONObject(org.json.JSONObject) DialogAction(com.afollestad.materialdialogs.DialogAction) RequestClientSetDiscoveryItemClick(net.iGap.request.RequestClientSetDiscoveryItemClick) OnGeoGetConfiguration(net.iGap.observers.interfaces.OnGeoGetConfiguration) HelperFragment(net.iGap.helper.HelperFragment) StickerDialogFragment(net.iGap.fragments.emoji.add.StickerDialogFragment)

Example 5 with OnGetPermission

use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.

the class HelperSaveFile method saveToMusicFolder.

// public static void savePicToGallery(final String filePath, final boolean showToast) {
// 
// if (!HelperPermision.grantedUseStorage()) {
// try {
// HelperPermision.getStoragePermision(G.fragmentActivity, new OnGetPermission() {
// @Override
// public void Allow() throws IOException {
// savePicToGallery(filePath, showToast);
// }
// 
// @Override
// public void deny() {
// 
// }
// });
// } catch (IOException e) {
// e.printStackTrace();
// }
// } else {
// ContentValues values = new ContentValues();
// values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
// values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
// values.put(MediaStore.MediaColumns.DATA, filePath);
// 
// try {
// G.context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
// if (showToast) {
// Toast.makeText(G.context, R.string.picture_save_to_galary, Toast.LENGTH_SHORT).show();
// }
// } catch (Exception e) {
// 
// Bitmap bitmap = BitmapFactory.decodeFile(filePath);
// String name = filePath.substring(filePath.lastIndexOf("/"));
// 
// MediaStore.Images.Media.insertImage(G.context.getContentResolver(), bitmap, name, "yourDescription");
// 
// if (showToast) {
// Toast.makeText(G.context, R.string.picture_save_to_galary, Toast.LENGTH_SHORT).show();
// }
// }
// }
// }
public static void saveToMusicFolder(final String path, final String name) {
    if (!HelperPermission.grantedUseStorage()) {
        try {
            HelperPermission.getStoragePermission(G.fragmentActivity, new OnGetPermission() {

                @Override
                public void Allow() throws IOException {
                    saveToMusicFolder(path, name);
                }

                @Override
                public void deny() {
                    showDeniedPermissionMessage(G.context.getString(R.string.permission_storage));
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        if (path == null)
            return;
        File mPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        File file = new File(mPath, name);
        try {
            // Make sure the Pictures directory exists.
            mPath.mkdirs();
            InputStream is = new FileInputStream(path);
            OutputStream os = new FileOutputStream(file);
            byte[] data = new byte[is.available()];
            is.read(data);
            os.write(data);
            is.close();
            os.close();
            // Tell the media scanner about the new file so that it is
            // immediately available to the user.
            MediaScannerConnection.scanFile(G.context, new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {

                public void onScanCompleted(String mPath, Uri uri) {
                }
            });
            Toast.makeText(G.context, G.context.getResources().getString(R.string.save_to_music_folder), Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            // Unable to create file, likely because external storage is
            // not currently mounted.
            e.printStackTrace();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Uri(android.net.Uri) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) MediaScannerConnection(android.media.MediaScannerConnection) File(java.io.File)

Aggregations

OnGetPermission (net.iGap.observers.interfaces.OnGetPermission)31 IOException (java.io.IOException)29 View (android.view.View)14 HelperFragment (net.iGap.helper.HelperFragment)14 Intent (android.content.Intent)13 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)11 Bundle (android.os.Bundle)10 RecyclerView (androidx.recyclerview.widget.RecyclerView)9 Uri (android.net.Uri)8 ArrayList (java.util.ArrayList)8 TextView (android.widget.TextView)7 File (java.io.File)7 FrameLayout (android.widget.FrameLayout)6 Nullable (androidx.annotation.Nullable)6 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)6 List (java.util.List)6 G (net.iGap.G)6 R (net.iGap.R)6 HelperPermission (net.iGap.helper.HelperPermission)6 Editable (android.text.Editable)5