コード例 #1
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;
  }
コード例 #2
0
 @Override
 public void onClick(View v, NavigationAdapter.ItemRowHolder vh, int position) {
   if (vh.getSwitch() != null) {
     VPNManager manager = VPNManager.getLatestInstance();
     if (manager.isVPNInstalled()) {
       if (!manager.isConnected()) {
         manager.connect();
         vh.getSwitch().setChecked(true);
       } else {
         manager.disconnect();
         vh.getSwitch().setChecked(false);
       }
     } else {
       VPNInfoDialogFragment.show(getChildFragmentManager());
     }
   }
 }