Search in sources :

Example 1 with ToolbarListener

use of net.iGap.observers.interfaces.ToolbarListener 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 ToolbarListener

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

the class NewsPublisherListFrag method onViewCreated.

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

        @Override
        public void onLeftIconClickListener(View view) {
            popBackStackFragment();
        }
    }).setLogoShown(true);
    binding.toolbar.addView(mHelperToolbar.getView());
    binding.pullToRefresh.setOnRefreshListener(() -> {
        viewModel.getData();
        binding.noItemInListError.setVisibility(View.GONE);
    });
    binding.rcGroup.setHasFixedSize(true);
    GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 3);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    binding.rcGroup.setLayoutManager(layoutManager);
    viewModel.getData();
    onErrorObserver();
    onDataChanged();
    onProgress();
}
Also used : ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) HelperToolbar(net.iGap.helper.HelperToolbar) View(android.view.View)

Example 3 with ToolbarListener

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

the class PollFragment method init.

private void init(View view) {
    emptyRecycle = view.findViewById(R.id.emptyRecycle);
    rcDiscovery = view.findViewById(R.id.rcDiscovery);
    pollAdapter = new PollAdapter(getActivity(), new ArrayList<>());
    swipeRefreshLayout = view.findViewById(R.id.pullToRefresh);
    swipeRefreshLayout.setOnRefreshListener(() -> {
        setRefreshing(true);
        boolean isSend = updateOrFetchRecycleViewData();
        if (!isSend) {
            setRefreshing(false);
            HelperError.showSnackMessage(getString(R.string.wallet_error_server), false);
        }
    });
    emptyRecycle.setOnClickListener(v -> {
        boolean isSend = updateOrFetchRecycleViewData();
        if (!isSend) {
            HelperError.showSnackMessage(getString(R.string.wallet_error_server), false);
        }
    });
    rcDiscovery.setLayoutManager(new LinearLayoutManager(getContext()));
    rcDiscovery.setAdapter(pollAdapter);
    mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setLogoShown(true).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            popBackStackFragment();
        }
    });
    ViewGroup viewGroup = view.findViewById(R.id.fd_layout_toolbar);
    viewGroup.addView(mHelperToolbar.getView());
    tryToUpdateOrFetchRecycleViewData(0);
}
Also used : PollAdapter(net.iGap.adapter.items.poll.PollAdapter) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 4 with ToolbarListener

use of net.iGap.observers.interfaces.ToolbarListener 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)

Example 5 with ToolbarListener

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

the class IGashtLocationListFragment 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()).setLeftIcon(R.string.icon_back).setRightIcons(R.string.icon_time).setLogoShown(true).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());
    binding.locationListView.addItemDecoration(new DividerItemDecoration(binding.locationListView.getContext(), DividerItemDecoration.VERTICAL));
    binding.locationListView.setAdapter(new IGashtLocationListAdapter(viewModel.getSelectedProvinceName(), new IGashtLocationListAdapter.onLocationItemClickListener() {

        @Override
        public void buyTicket(int position) {
            viewModel.buyTicket(position);
        }

        @Override
        public void onItem(int position) {
            viewModel.buyTicket(position);
        }
    }));
    viewModel.getLocationList().observe(getViewLifecycleOwner(), data -> {
        if (binding.locationListView.getAdapter() instanceof IGashtLocationListAdapter && data != null) {
            ((IGashtLocationListAdapter) binding.locationListView.getAdapter()).setItems(data);
        }
    });
    viewModel.getGoToLocationDetail().observe(getViewLifecycleOwner(), isGo -> {
        if (getActivity() != null && isGo != null) {
            if (isGo) {
                new HelperFragment(getActivity().getSupportFragmentManager()).setFragment(new IGashtLocationDetailFragment()).setReplace(false).load(true);
            } else {
                Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) HelperFragment(net.iGap.helper.HelperFragment) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) View(android.view.View) IGashtLocationListAdapter(net.iGap.adapter.igahst.IGashtLocationListAdapter)

Aggregations

View (android.view.View)35 ToolbarListener (net.iGap.observers.interfaces.ToolbarListener)35 HelperToolbar (net.iGap.helper.HelperToolbar)18 HelperFragment (net.iGap.helper.HelperFragment)13 LinearLayout (android.widget.LinearLayout)9 TextView (android.widget.TextView)9 Bundle (android.os.Bundle)8 ViewGroup (android.view.ViewGroup)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 Fragment (androidx.fragment.app.Fragment)5 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)5 LayoutInflater (android.view.LayoutInflater)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 DataBindingUtil (androidx.databinding.DataBindingUtil)4 ViewModelProviders (androidx.lifecycle.ViewModelProviders)4 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 R (net.iGap.R)4 ActivityMain (net.iGap.activities.ActivityMain)4 AdapterView (android.widget.AdapterView)3