在综合界面加入一个功能相同的博客模块

This commit is contained in:
wei 2016-10-21 10:13:57 +08:00
parent 5ab21563fe
commit 3790320651
1 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,93 @@
package net.oschina.app.viewpagerfragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import net.oschina.app.R;
import net.oschina.app.adapter.ViewPageFragmentAdapter;
import net.oschina.app.base.BaseListFragment;
import net.oschina.app.base.BaseViewPagerFragment;
import net.oschina.app.bean.BlogList;
import net.oschina.app.bean.NewsList;
import net.oschina.app.improve.general.fragments.BlogFragment;
import net.oschina.app.improve.general.fragments.EventFragment;
import net.oschina.app.improve.base.fragments.BaseGeneralListFragment;
import net.oschina.app.improve.general.fragments.NewsFragment;
import net.oschina.app.improve.general.fragments.QuestionFragment;
import net.oschina.app.interf.OnTabReselectListener;
/**
* 综合Tab界面
*/
public class GeneralViewPagerFragment extends BaseViewPagerFragment implements
OnTabReselectListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
//综合界面的第一页显示内容
@Override
protected void onSetupTabAdapter(ViewPageFragmentAdapter adapter) {
String[] title = getResources().getStringArray(
R.array.general_viewpage_arrays);
adapter.addTab(title[0], "news", NewsFragment.class,
getBundle(NewsList.CATALOG_ALL));
adapter.addTab(title[1], "latest_blog", BlogFragment.class,
getBundle(NewsList.CATALOG_WEEK));
adapter.addTab(title[2], "question", QuestionFragment.class,
getBundle(BlogList.CATALOG_LATEST));
adapter.addTab(title[3], "activity", EventFragment.class,
getBundle(BlogList.CATALOG_RECOMMEND));
adapter.addTab(title[4],"latest_blog1", BlogFragment.class,
getBundle(NewsList.CATALOG_WEEK));
}
private Bundle getBundle(int newType) {
Bundle bundle = new Bundle();
bundle.putInt(BaseListFragment.BUNDLE_KEY_CATALOG, newType);
return bundle;
}
@Override
protected void setScreenPageLimit() {
mViewPager.setOffscreenPageLimit(4);
}
/**
* 基类会根据不同的catalog展示相应的数据
*
* @param catalog 要显示的数据类别
* @return
*/
private Bundle getBundle(String catalog) {
Bundle bundle = new Bundle();
bundle.putString(BlogFragment.BUNDLE_BLOG_TYPE, catalog);
return bundle;
}
@Override
public void onClick(View v) {
}
@Override
public void initView(View view) {
}
@Override
public void initData() {
}
@Override
public void onTabReselect() {
Fragment fragment = mTabsAdapter.getItem(mViewPager.getCurrentItem());
if (fragment != null && fragment instanceof BaseGeneralListFragment) {
((BaseGeneralListFragment) fragment).onTabReselect();
}
}
}