Search in sources :

Example 1 with BaseFragmentPagerAdapter

use of com.itculturalfestival.smartcampus.adapter.BaseFragmentPagerAdapter in project SmartCampus by Vegen.

the class HomeFragment method setupUI.

@Override
protected void setupUI() {
    showContentView();
    ImmersionBar.setTitleBar(getActivity(), toolbar);
    float marginHeight = SystemUtils.getStatusBarHeight(getContext()) + SystemUtils.getActionBarHeight(getContext());
    viewTop.getLayoutParams().height = (int) marginHeight;
    banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
    banner.setIndicatorGravity(BannerConfig.CENTER);
    banner.setImageLoader(new GlideImageLoader());
    banner.setOnBannerListener(position -> {
        if (bannerList.isEmpty())
            return;
        TopFunArticleDetailActivity.start(getContext(), bannerList.get(position).getTitle(), bannerList.get(position).getNextUrl());
    });
    List<Fragment> fragments = new ArrayList<>();
    flashFragment = NewsFragment.getInstance(Constant.NEWS_TYPE_FLASH);
    focusFragment = NewsFragment.getInstance(Constant.NEWS_TYPE_FOCUS);
    comprehensiveFragment = NewsFragment.getInstance(Constant.NEWS_TYPE_COMPREHENSIVE);
    otherFragment = NewsFragment.getInstance(Constant.NEWS_TYPE_OTHER);
    fragments.add(flashFragment);
    fragments.add(focusFragment);
    fragments.add(comprehensiveFragment);
    fragments.add(otherFragment);
    List<String> strings = new ArrayList<>();
    strings.add("快讯");
    strings.add("要闻");
    strings.add("综合");
    strings.add("其他");
    fragmentPagerAdapter = new BaseFragmentPagerAdapter(getChildFragmentManager(), fragments, strings);
    viewPager.setAdapter(fragmentPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    viewPager.setOffscreenPageLimit(fragments.size());
}
Also used : ArrayList(java.util.ArrayList) BaseFragmentPagerAdapter(com.itculturalfestival.smartcampus.adapter.BaseFragmentPagerAdapter) GlideImageLoader(com.itculturalfestival.smartcampus.utils.GlideImageLoader) AppBaseFragment(com.itculturalfestival.smartcampus.AppBaseFragment) Fragment(android.support.v4.app.Fragment)

Example 2 with BaseFragmentPagerAdapter

use of com.itculturalfestival.smartcampus.adapter.BaseFragmentPagerAdapter in project SmartCampus by Vegen.

the class MainActivity method setupViewPager.

private void setupViewPager() {
    List<Fragment> fragments = new ArrayList<>();
    fragments.add(HomeFragment.getInstance());
    fragments.add(TeamFragment.getInstance());
    fragments.add(CircleFragment.getInstance());
    fragments.add(MessageFragment.getInstance());
    fragments.add(UserFragment.getInstance());
    pageAdapter = new BaseFragmentPagerAdapter(getSupportFragmentManager(), fragments);
    viewPager.setAdapter(pageAdapter);
    viewPager.setOffscreenPageLimit(fragments.size());
    viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
        // changeToolbar(position);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            super.onPageScrolled(position, positionOffset, positionOffsetPixels);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) BaseFragmentPagerAdapter(com.itculturalfestival.smartcampus.adapter.BaseFragmentPagerAdapter) HomeFragment(com.itculturalfestival.smartcampus.ui.main.home.HomeFragment) Fragment(android.support.v4.app.Fragment) NoScrollViewPager(com.itculturalfestival.smartcampus.ui.custom.NoScrollViewPager) ViewPager(android.support.v4.view.ViewPager)

Aggregations

Fragment (android.support.v4.app.Fragment)2 BaseFragmentPagerAdapter (com.itculturalfestival.smartcampus.adapter.BaseFragmentPagerAdapter)2 ArrayList (java.util.ArrayList)2 ViewPager (android.support.v4.view.ViewPager)1 AppBaseFragment (com.itculturalfestival.smartcampus.AppBaseFragment)1 NoScrollViewPager (com.itculturalfestival.smartcampus.ui.custom.NoScrollViewPager)1 HomeFragment (com.itculturalfestival.smartcampus.ui.main.home.HomeFragment)1 GlideImageLoader (com.itculturalfestival.smartcampus.utils.GlideImageLoader)1