Search in sources :

Example 1 with NavigationEntity

use of com.github.obsessive.simplifyreader.bean.NavigationEntity 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);
        }
    });
}
Also used : ViewHolderBase(com.github.obsessive.library.adapter.ViewHolderBase) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) HomeView(com.github.obsessive.simplifyreader.view.HomeView) TextView(android.widget.TextView) ListView(android.widget.ListView) NavigationEntity(com.github.obsessive.simplifyreader.bean.NavigationEntity) VPFragmentAdapter(com.github.obsessive.simplifyreader.ui.adpter.VPFragmentAdapter) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) ViewHolderCreator(com.github.obsessive.library.adapter.ViewHolderCreator)

Example 2 with NavigationEntity

use of com.github.obsessive.simplifyreader.bean.NavigationEntity in project SimplifyReader by chentao0707.

the class HomeInteractorImpl method getNavigationListData.

@Override
public List<NavigationEntity> getNavigationListData(Context context) {
    List<NavigationEntity> navigationEntities = new ArrayList<>();
    String[] navigationArrays = context.getResources().getStringArray(R.array.navigation_list);
    navigationEntities.add(new NavigationEntity("", navigationArrays[0], R.drawable.ic_picture));
    navigationEntities.add(new NavigationEntity("", navigationArrays[1], R.drawable.ic_video));
    navigationEntities.add(new NavigationEntity("", navigationArrays[2], R.drawable.ic_music));
    return navigationEntities;
}
Also used : ArrayList(java.util.ArrayList) NavigationEntity(com.github.obsessive.simplifyreader.bean.NavigationEntity)

Aggregations

NavigationEntity (com.github.obsessive.simplifyreader.bean.NavigationEntity)2 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 ViewHolderBase (com.github.obsessive.library.adapter.ViewHolderBase)1 ViewHolderCreator (com.github.obsessive.library.adapter.ViewHolderCreator)1 VPFragmentAdapter (com.github.obsessive.simplifyreader.ui.adpter.VPFragmentAdapter)1 HomeView (com.github.obsessive.simplifyreader.view.HomeView)1 ArrayList (java.util.ArrayList)1