Search in sources :

Example 1 with HelperFragment

use of net.iGap.helper.HelperFragment in project iGap-Android by KianIranian-STDG.

the class NewsGroupPagerFrag method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Bundle arg = getArguments();
    String groupID = arg.getString("GroupID");
    HelperToolbar mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            popBackStackFragment();
        }
    }).setDefaultTitle(arg.getString("GroupTitle")).setRoundBackground(// cause of imageView below toolbar use flat toolbar is better than round
    false).setLogoShown(true);
    binding.Toolbar.addView(mHelperToolbar.getView());
    if (!arg.getString("GroupPic").equals(""))
        Glide.with(G.context).load(arg.getString("GroupPic")).placeholder(R.mipmap.news_temp_banner).into(binding.groupImage);
    ViewPager viewPager = binding.secondaryLayout.viewPager;
    tabLayout = binding.secondaryLayout.pagerTabLayout;
    // TabAdapter adapter = new TabAdapter(getFragmentManager());
    NewsListFrag frag = new NewsListFrag();
    frag.setApiArg(new NewsApiArg(1, 10, Integer.parseInt(groupID), NewsApiArg.NewsType.GROUP_NEWS));
    frag.setHandler(news -> {
        Glide.with(G.context).load(news.getImage()).into(binding.groupImage);
        binding.groupTitle.setText(news.getTitle());
        binding.headerNews.setOnClickListener(v -> {
            FragmentManager fragmentManager = getChildFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            Fragment fragment = fragmentManager.findFragmentByTag(NewsDetailFrag.class.getName());
            if (fragment == null) {
                fragment = NewsDetailFrag.newInstance();
                fragmentTransaction.addToBackStack(fragment.getClass().getName());
            }
            Bundle args = new Bundle();
            args.putString("NewsID", news.getId());
            fragment.setArguments(args);
            new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
        });
    });
    // adapter.addFragment(frag, getResources().getString(R.string.news_latest));
    NewsListFrag frag2 = new NewsListFrag();
    frag2.setApiArg(new NewsApiArg(1, 10, Integer.parseInt(groupID), NewsApiArg.NewsType.MOST_HITS));
    // adapter.addFragment(frag2, getResources().getString(R.string.news_MHits));
    NewsListFrag frag3 = new NewsListFrag();
    frag3.setApiArg(new NewsApiArg(1, 10, Integer.parseInt(groupID), NewsApiArg.NewsType.CONTROVERSIAL_NEWS));
    // adapter.addFragment(frag3, getResources().getString(R.string.news_ergent));
    // viewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);
    updateFontTabLayout();
}
Also used : Bundle(android.os.Bundle) View(android.view.View) TextView(android.widget.TextView) ViewPager(androidx.viewpager.widget.ViewPager) Fragment(androidx.fragment.app.Fragment) HelperFragment(net.iGap.helper.HelperFragment) BaseFragment(net.iGap.fragments.BaseFragment) FragmentManager(androidx.fragment.app.FragmentManager) NewsApiArg(net.iGap.model.news.NewsApiArg) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) HelperToolbar(net.iGap.helper.HelperToolbar) HelperFragment(net.iGap.helper.HelperFragment)

Example 2 with HelperFragment

use of net.iGap.helper.HelperFragment in project iGap-Android by KianIranian-STDG.

the class NewsMainFrag method openNewsDetail.

private void openNewsDetail(String newsID) {
    FragmentManager fragmentManager = getChildFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Fragment fragment = fragmentManager.findFragmentByTag(NewsDetailFrag.class.getName());
    if (fragment == null) {
        fragment = NewsDetailFrag.newInstance();
        fragmentTransaction.addToBackStack(fragment.getClass().getName());
    }
    Bundle args = new Bundle();
    args.putString("NewsID", newsID);
    fragment.setArguments(args);
    new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) Bundle(android.os.Bundle) HelperFragment(net.iGap.helper.HelperFragment) DiscoveryFragment(net.iGap.fragments.discovery.DiscoveryFragment) Fragment(androidx.fragment.app.Fragment) HelperFragment(net.iGap.helper.HelperFragment) BottomNavigationFragment(net.iGap.fragments.BottomNavigationFragment)

Example 3 with HelperFragment

use of net.iGap.helper.HelperFragment in project iGap-Android by KianIranian-STDG.

the class PopularChannelHomeFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    RecyclerView recyclerView = view.findViewById(R.id.rv_popularChannel_home);
    swipeRefreshLayout = view.findViewById(R.id.sr_popularChannel_home);
    epmtyView = view.findViewById(R.id.emptyRecycle);
    Toolbar popularChannelsToolbar = new Toolbar(getContext());
    popularChannelsToolbar.setBackIcon(new BackDrawable(false));
    popularChannelsToolbar.setTitle(getString(R.string.popular_channel));
    popularChannelsToolbar.setListener(i -> {
        if (i == -1) {
            if (getActivity() != null)
                getActivity().onBackPressed();
        }
    });
    recyclerView.setAdapter(new PopularChannelHomeAdapter(viewModel.getRecyclerItemClick()));
    ((ViewGroup) view.findViewById(R.id.ll_popularChannel_toolBar)).addView(popularChannelsToolbar);
    viewModel.getFirstPageMutableLiveData().observe(getViewLifecycleOwner(), parentChannel -> {
        if (recyclerView.getAdapter() instanceof PopularChannelHomeAdapter && parentChannel != null) {
            ((PopularChannelHomeAdapter) recyclerView.getAdapter()).setData(parentChannel.getData());
        }
    });
    viewModel.getProgressMutableLiveData().observe(getViewLifecycleOwner(), progress -> {
        if (progress != null && progress)
            swipeRefreshLayout.setRefreshing(true);
        else
            swipeRefreshLayout.setRefreshing(false);
    });
    swipeRefreshLayout.setOnRefreshListener(() -> {
        viewModel.getFirstPage();
    });
    viewModel.getEmptyViewMutableLiveData().observe(getViewLifecycleOwner(), visibility -> {
        if (visibility != null)
            epmtyView.setVisibility(visibility);
    });
    viewModel.getGoToMorePage().observe(getViewLifecycleOwner(), data -> {
        if (getActivity() != null && data != null) {
            PopularMoreChannelFragment moreChannelFragment = new PopularMoreChannelFragment();
            Bundle bundle = new Bundle();
            bundle.putString("id", data.getId());
            bundle.putString("title", G.isAppRtl ? data.getTitle() : data.getTitleEn());
            moreChannelFragment.setArguments(bundle);
            new HelperFragment(getActivity().getSupportFragmentManager(), moreChannelFragment).setReplace(false).load(true);
        }
    });
    viewModel.getGoToRoom().observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            HelperUrl.checkUsernameAndGoToRoom(getActivity(), link, HelperUrl.ChatEntry.chat);
        }
    });
    viewModel.getGoToChannel().observe(getViewLifecycleOwner(), data -> {
        if (getActivity() != null && data != null) {
            if (data.isPrivate()) {
                HelperUrl.checkAndJoinToRoom(getActivity(), data.getSlug());
            } else {
                HelperUrl.checkUsernameAndGoToRoom(getActivity(), data.getSlug(), HelperUrl.ChatEntry.chat);
            }
        }
    });
    viewModel.getGoToWebViewPage().observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentWebView.newInstance(link, false, null)).setReplace(false).load();
        }
    });
    viewModel.getOpenBrowser().observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            SharedPreferences sharedPreferences = getActivity().getSharedPreferences(SHP_SETTING.FILE_NAME, Context.MODE_PRIVATE);
            int checkedInAppBrowser = sharedPreferences.getInt(SHP_SETTING.KEY_IN_APP_BROWSER, 1);
            if (checkedInAppBrowser == 1 && !HelperUrl.isNeedOpenWithoutBrowser(link)) {
                HelperUrl.openBrowser(link);
            } else {
                HelperUrl.openWithoutBrowser(link);
            }
        }
    });
    epmtyView.setOnClickListener(v -> viewModel.getFirstPage());
}
Also used : PopularChannelHomeAdapter(net.iGap.adapter.items.popularChannel.PopularChannelHomeAdapter) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) Bundle(android.os.Bundle) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) HelperToolbar(net.iGap.helper.HelperToolbar)

Example 4 with HelperFragment

use of net.iGap.helper.HelperFragment in project iGap-Android by KianIranian-STDG.

the class QRCodePaymentFragment method setObservers.

private void setObservers() {
    mViewModel.getConfirmButtonClick().observe(getViewLifecycleOwner(), new Observer<Boolean>() {

        @Override
        public void onChanged(Boolean aBoolean) {
            if (aBoolean) {
                if (!mMerchantPcqr && mBinding.desireAmount == null || !mMerchantPcqr && mBinding.desireAmount.getText().toString().replaceAll("\\D", "").length() == 0) {
                    Toast.makeText(getActivity(), R.string.you_have_not_specified_the_amount, Toast.LENGTH_SHORT).show();
                } else if (!mMerchantPcqr && mBinding.desireAmount.getText().toString().replaceAll("\\D", "").length() != 0 && Integer.parseInt(mBinding.desireAmount.getText().toString().replaceAll("\\D", "")) < 1000) {
                    Toast.makeText(getActivity(), R.string.the_amount_can_not_be_less_than_1000_rials, Toast.LENGTH_SHORT).show();
                } else if (!mMerchantPcqr && mBinding.desireAmount.getText().toString().replaceAll("\\D", "").length() != 0 && Integer.parseInt(mBinding.desireAmount.getText().toString().replaceAll("\\D", "")) > 500000000) {
                    Toast.makeText(getActivity(), R.string.the_amount_can_not_be_more_than_500_million_rials, Toast.LENGTH_SHORT).show();
                } else {
                    mBinding.progressBar.setVisibility(View.VISIBLE);
                    JsonObject jsonObject = new JsonObject();
                    jsonObject.addProperty("qr_code", mMerchantCode);
                    if (mMerchantPcqr) {
                        /**
                         *1000 is a default amount for pcqr true state. true pcqr means that The amount is filled automatically and do not need to get amount from customer
                         */
                        jsonObject.addProperty("amount", 1000);
                    } else {
                        jsonObject.addProperty("amount", Integer.parseInt(mBinding.desireAmount.getText().toString().replaceAll("\\D", "")));
                    }
                    Call<Token> call = new RetrofitFactory().getPecQrRetrofit().getPaymentToken(jsonObject);
                    call.enqueue(new Callback<Token>() {

                        @Override
                        public void onResponse(Call<Token> call, Response<Token> response) {
                            if (response.isSuccessful()) {
                                Token token = response.body();
                                new HelperFragment(getActivity().getSupportFragmentManager(), PaymentFragment.getInstance(getActivity().getResources().getString(R.string.payment), token.getToken(), new PaymentCallBack() {

                                    @Override
                                    public void onPaymentFinished(PaymentResult result) {
                                    }
                                })).setReplace(false).setAddToBackStack(true).load();
                                mBinding.progressBar.setVisibility(View.GONE);
                            } else {
                                try {
                                    String[] splittedErrorBody = response.errorBody().string().split("\"");
                                    Toast.makeText(getActivity(), splittedErrorBody[splittedErrorBody.length - 2], Toast.LENGTH_LONG).show();
                                    mBinding.progressBar.setVisibility(View.GONE);
                                    getActivity().getSupportFragmentManager().popBackStackImmediate();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                        @Override
                        public void onFailure(Call<Token> call, Throwable t) {
                        }
                    });
                }
            }
        }
    });
}
Also used : Call(retrofit2.Call) PaymentResult(net.iGap.model.payment.PaymentResult) JsonObject(com.google.gson.JsonObject) Token(net.iGap.model.qrCodePayment.Token) IOException(java.io.IOException) Response(retrofit2.Response) Callback(retrofit2.Callback) PaymentCallBack(net.iGap.observers.interfaces.PaymentCallBack) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) HelperFragment(net.iGap.helper.HelperFragment)

Example 5 with HelperFragment

use of net.iGap.helper.HelperFragment in project iGap-Android by KianIranian-STDG.

the class IGashtLocationDetailFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    binding.toolbar.addView(HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLogoShown(true).setLeftIcon(R.string.icon_back).setRightIcons(R.string.icon_time).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            if (getActivity() != null) {
                getActivity().onBackPressed();
            }
        }

        @Override
        public void onRightIconClickListener(View view) {
            if (getActivity() != null) {
                new HelperFragment(getActivity().getSupportFragmentManager(), new IGashtHistoryPlaceListFragment()).setReplace(false).load(true);
            }
        }
    }).getView());
    viewModel.getLoadBuyTicketView().observe(getViewLifecycleOwner(), loadBuyTicketView -> {
        if (loadBuyTicketView != null) {
            FragmentManager fragmentManager = getChildFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            Fragment fragment;
            binding.buyTicket.setTextColor(G.themeColor == Theme.DARK ? getResources().getColor(R.color.white) : (loadBuyTicketView ? getResources().getColor(R.color.white) : getResources().getColor(R.color.black)));
            binding.detail.setTextColor(G.themeColor == Theme.DARK ? getResources().getColor(R.color.white) : (loadBuyTicketView ? getResources().getColor(R.color.black) : getResources().getColor(R.color.white)));
            if (loadBuyTicketView) {
                fragment = fragmentManager.findFragmentByTag(IGashtBuyTicketFragment.class.getName());
                if (fragment == null) {
                    fragment = new IGashtBuyTicketFragment();
                    fragmentTransaction.addToBackStack(fragment.getClass().getName());
                }
            } else {
                fragment = fragmentManager.findFragmentByTag(IGashtLocationSubDetailFragment.class.getName());
                if (fragment == null) {
                    fragment = new IGashtLocationSubDetailFragment();
                    fragmentTransaction.addToBackStack(fragment.getClass().getName());
                }
            }
            fragmentTransaction.replace(R.id.detailFrame, fragment, fragment.getClass().getName()).commit();
        }
    });
    viewModel.getGoHistoryPage().observe(getViewLifecycleOwner(), voucherNumber -> {
        if (voucherNumber != null) {
            goToHistoryListPage();
        }
    });
    viewModel.getGoPayment().observe(getViewLifecycleOwner(), orderToken -> {
        if (getActivity() != null && orderToken != null) {
            new HelperFragment(getActivity().getSupportFragmentManager()).loadPayment(getString(R.string.igasht_title), orderToken, result -> {
                if (result.isSuccess()) {
                    goToHistoryListPage();
                }
            });
        }
    });
    viewModel.getPaymentError().observe(getViewLifecycleOwner(), isError -> {
        if (getContext() != null && isError != null && isError) {
            Toast.makeText(getContext(), R.string.error, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) HelperFragment(net.iGap.helper.HelperFragment) View(android.view.View) Fragment(androidx.fragment.app.Fragment) HelperFragment(net.iGap.helper.HelperFragment)

Aggregations

HelperFragment (net.iGap.helper.HelperFragment)93 Bundle (android.os.Bundle)32 View (android.view.View)31 Fragment (androidx.fragment.app.Fragment)25 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)15 RecyclerView (androidx.recyclerview.widget.RecyclerView)14 ToolbarListener (net.iGap.observers.interfaces.ToolbarListener)14 ViewGroup (android.view.ViewGroup)13 NonNull (androidx.annotation.NonNull)13 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)13 Theme (net.iGap.module.Theme)13 R (net.iGap.R)12 OnGetPermission (net.iGap.observers.interfaces.OnGetPermission)12 LayoutInflater (android.view.LayoutInflater)11 TextView (android.widget.TextView)11 Nullable (androidx.annotation.Nullable)11 HelperString (net.iGap.helper.HelperString)10 BackDrawable (net.iGap.messenger.ui.toolBar.BackDrawable)10