package org.phphub.app.ui.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.Bundler;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import org.phphub.app.R;
import org.phphub.app.common.base.BaseSupportFragment;
import org.phphub.app.common.qualified.TopicType;

import butterknife.Bind;
import static org.phphub.app.common.qualified.TopicType.*;

public class TopicsFragment extends BaseSupportFragment {
    @Bind(R.id.viewpagertab)
    SmartTabLayout viewpagerTabView;

    @Bind(R.id.viewpager)
    ViewPager viewPagerView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.topic_viewpager_list, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        FragmentPagerItems pages = FragmentPagerItems.with(getActivity())
                .add(R.string.recent, TopicFragment.class, getTopicTypeBundle(TOPIC_TYPE_RECENT))
                .add(R.string.vote, TopicFragment.class, getTopicTypeBundle(TOPIC_TYPE_VOTE))
                .add(R.string.nobody, TopicFragment.class, getTopicTypeBundle(TOPIC_TYPE_NOBODY))
                .create();
        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getChildFragmentManager(),
                pages);

        viewPagerView.setOffscreenPageLimit(pages.size());
        viewPagerView.setAdapter(adapter);
        viewpagerTabView.setViewPager(viewPagerView);
    }

    private Bundle getTopicTypeBundle(@TopicType String topicType) {
        return new Bundler().putString(TopicFragment.TOPIC_TYPE_KEY, topicType).get();
    }

}
@@ -542,27 +542,20 @@
 on.base.
-BaseSupport
+Lazy
 Fragment
@@ -732,29 +732,96 @@
 nds 
-BaseSupportFragment %7B
+LazyFragment %7B%0A%0A    private boolean isPrepared;%0A%0A    private boolean adapterHasCreated;%0A
 %0A   
@@ -1299,16 +1299,188 @@
 eState);
+%0A        isPrepared = true;%0A    %7D%0A%0A    @Override%0A    protected void lazyLoad() %7B%0A        if (!isPrepared %7C%7C !isVisible %7C%7C adapterHasCreated) %7B%0A            return;%0A        %7D
 %0A%0A      
@@ -2107,16 +2107,16 @@
 apter);%0A
-
         
@@ -2160,16 +2160,51 @@
 erView);
+%0A%0A        adapterHasCreated = true;
 %0A    %7D%0A%0A

修改 TopicsFragment 展示方式为懒加载