コード例 #1
0
  /**
   * Called when a list item is selected.
   *
   * <p>Updates the state of the list, closes the drawer, and fowards the event to the parent
   * activity to handle.
   *
   * @param position position of the item in the list
   */
  public void selectItem(int position) {
    mCurrentSelectedPosition = position;

    if (mDrawerLayout != null) {
      mDrawerLayout.closeDrawer(mNavigationDrawerContainer);
    }

    if (mCallbacks != null) {
      NavDrawerItem navDrawerItem = mAdapter.getItem(position + 1);
      mCallbacks.onNavigationDrawerItemSelected(
          navDrawerItem, null != navDrawerItem ? navDrawerItem.getTitle() : null);
    }

    mAdapter.notifyDataSetChanged();
  }
コード例 #2
0
        @Override
        public void onItemClick(
            View v, NavigationAdapter.ItemRowHolder vh, NavDrawerItem item, int position) {
          if (null != item.getOnClickListener()) {
            item.onClick(v, vh, position);
            return;
          }

          selectItem(mAdapter.getCorrectPosition(position));
        }
コード例 #3
0
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mAdapter = new NavigationAdapter(getActivity(), this, initItems());
    mAdapter.setOnItemClickListener(mOnItemClickListener);

    mRecyclerView.addItemDecoration(new OneShotDividerDecorator(getActivity(), 3));
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.requestFocus();
  }
コード例 #4
0
  public List<NavDrawerItem> initItems() {
    // todo: make list items dynamic
    List<NavDrawerItem> navItems = new ArrayList<>();
    navItems.add(new NavDrawerItem(true));
    navItems.add(
        new NavDrawerItem(
            getString(R.string.title_movies), R.drawable.ic_nav_movies, new YTSProvider()));
    navItems.add(
        new NavDrawerItem(
            getString(R.string.title_shows), R.drawable.ic_nav_tv, new EZTVProvider()));
    navItems.add(
        new NavDrawerItem(
            getString(R.string.title_anime), R.drawable.ic_nav_anime, new HaruProvider()));
    if (PrefUtils.get(getActivity(), Prefs.SHOW_VPN, true)
        && VPNHTChecker.isDownloadAvailable(getActivity())) {
      navItems.add(
          mVPNItem =
              new NavDrawerItem(
                  getString(R.string.vpn),
                  R.drawable.ic_nav_vpn,
                  mOnVPNClickListener,
                  VPNManager.getLatestInstance().isConnected()));
    }
    navItems.add(
        new NavDrawerItem(
            getString(R.string.preferences), R.drawable.ic_nav_settings, mOnSettingsClickListener));

    if (mAdapter != null) mAdapter.setItems(navItems);

    VPNManager.State state = VPNManager.getCurrentState();
    NavigationDrawerFragment.NavDrawerItem vpnItem = getVPNItem();
    if (vpnItem != null) {
      if (state.equals(VPNManager.State.DISCONNECTED)) {
        vpnItem.setSwitchValue(false);
        vpnItem.showProgress(false);
      } else if (state.equals(VPNManager.State.CONNECTING)) {
        vpnItem.showProgress(true);
      } else if (state.equals(VPNManager.State.CONNECTED)) {
        vpnItem.setSwitchValue(true);
        vpnItem.showProgress(false);
      }
    }

    return navItems;
  }
コード例 #5
0
 public NavDrawerItem getCurrentItem() {
   return mAdapter.getItem(getSelectedPosition() + 1);
 }