use of com.github.obsessive.simplifyreader.ui.adpter.VPFragmentAdapter in project SimplifyReader by chentao0707.
the class HomeActivity method initializeViews.
@Override
public void initializeViews(List<BaseLazyFragment> fragments, List<NavigationEntity> navigationList) {
mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
setTitle(getString(R.string.app_name));
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (null != mNavListAdapter) {
setTitle(mNavListAdapter.getItem(mCurrentMenuCheckedPos).getName());
}
}
};
mActionBarDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
if (null != fragments && !fragments.isEmpty()) {
mViewPager.setEnableScroll(false);
mViewPager.setOffscreenPageLimit(fragments.size());
mViewPager.setAdapter(new VPFragmentAdapter(getSupportFragmentManager(), fragments));
}
mNavListAdapter = new ListViewDataAdapter<NavigationEntity>(new ViewHolderCreator<NavigationEntity>() {
@Override
public ViewHolderBase<NavigationEntity> createViewHolder(int position) {
return new ViewHolderBase<NavigationEntity>() {
ImageView itemIcon;
TextView itemName;
@Override
public View createView(LayoutInflater layoutInflater) {
View convertView = layoutInflater.inflate(R.layout.list_item_navigation, null);
itemIcon = ButterKnife.findById(convertView, R.id.list_item_navigation_icon);
itemName = ButterKnife.findById(convertView, R.id.list_item_navigation_name);
return convertView;
}
@Override
public void showData(int i, NavigationEntity navigationEntity) {
itemIcon.setImageResource(navigationEntity.getIconResId());
itemName.setText(navigationEntity.getName());
if (mCurrentMenuCheckedPos == i) {
// checked
itemName.setTextColor(getResources().getColor(mCheckedListItemColorResIds[i]));
} else {
// unchecked
itemName.setTextColor(getResources().getColor(android.R.color.black));
}
}
};
}
});
mNavListView.setAdapter(mNavListAdapter);
mNavListAdapter.getDataList().addAll(navigationList);
mNavListAdapter.notifyDataSetChanged();
setTitle(mNavListAdapter.getItem(mCurrentMenuCheckedPos).getName());
mNavListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mCurrentMenuCheckedPos = position;
mNavListAdapter.notifyDataSetChanged();
mDrawerLayout.closeDrawer(Gravity.LEFT);
mViewPager.setCurrentItem(mCurrentMenuCheckedPos, false);
}
});
}
Aggregations