@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mUserLearnedDrawer = PrefUtils.get(getActivity(), Prefs.DRAWER_LEARNED, false);

    if (savedInstanceState != null) {
      mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
      mFromSavedInstanceState = true;
    }
  }
  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;
  }
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  @Override
  public View onCreateView(
      LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    mRoot = inflater.inflate(R.layout.fragment_moviedetail, container, false);
    if (VersionUtils.isJellyBean() && container != null) {
      mRoot.setMinimumHeight(container.getMinimumHeight());
    }
    ButterKnife.inject(this, mRoot);

    if (!VersionUtils.isJellyBean()) {
      mPlayButton.setBackgroundDrawable(
          PixelUtils.changeDrawableColor(
              mPlayButton.getContext(), R.drawable.play_button_circle, sMovie.color));
    } else {
      mPlayButton.setBackground(
          PixelUtils.changeDrawableColor(
              mPlayButton.getContext(), R.drawable.play_button_circle, sMovie.color));
    }

    mTitle.setText(sMovie.title);
    if (!sMovie.rating.equals("-1")) {
      Double rating = Double.parseDouble(sMovie.rating);
      mRating.setProgress(rating.intValue());
      mRating.setVisibility(View.VISIBLE);
    } else {
      mRating.setVisibility(View.GONE);
    }

    String metaDataStr = sMovie.year;
    if (!TextUtils.isEmpty(sMovie.runtime)) {
      metaDataStr += " • ";
      metaDataStr += sMovie.runtime + " " + getString(R.string.minutes);
    }

    if (!TextUtils.isEmpty(sMovie.genre)) {
      metaDataStr += " • ";
      metaDataStr += sMovie.genre;
    }

    mMeta.setText(metaDataStr);

    if (!TextUtils.isEmpty(sMovie.synopsis)) {
      mSynopsis.setText(sMovie.synopsis);
      mSynopsis.post(
          new Runnable() {
            @Override
            public void run() {
              boolean ellipsized = false;
              Layout layout = mSynopsis.getLayout();
              if (layout == null) return;
              int lines = layout.getLineCount();
              if (lines > 0) {
                int ellipsisCount = layout.getEllipsisCount(lines - 1);
                if (ellipsisCount > 0) {
                  ellipsized = true;
                }
              }
              mReadMore.setVisibility(ellipsized ? View.VISIBLE : View.GONE);
            }
          });
    } else {
      mSynopsis.setClickable(false);
      mReadMore.setVisibility(View.GONE);
    }

    mWatchTrailer.setVisibility(
        sMovie.trailer == null || sMovie.trailer.isEmpty() ? View.GONE : View.VISIBLE);

    mSubtitles.setFragmentManager(getFragmentManager());
    mQuality.setFragmentManager(getFragmentManager());
    mSubtitles.setTitle(R.string.subtitles);
    mQuality.setTitle(R.string.quality);

    mSubtitles.setText(R.string.loading_subs);
    mSubtitles.setClickable(false);

    if (sMovie.getSubsProvider() != null) {
      sMovie
          .getSubsProvider()
          .getList(
              sMovie,
              new SubsProvider.Callback() {
                @Override
                public void onSuccess(Map<String, String> subtitles) {
                  if (!mAttached) return;

                  if (subtitles == null) {
                    ThreadUtils.runOnUiThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            mSubtitles.setText(R.string.no_subs_available);
                          }
                        });
                    return;
                  }

                  sMovie.subtitles = subtitles;

                  String[] languages = subtitles.keySet().toArray(new String[subtitles.size()]);
                  Arrays.sort(languages);
                  final String[] adapterLanguages = new String[languages.length + 1];
                  adapterLanguages[0] = "no-subs";
                  System.arraycopy(languages, 0, adapterLanguages, 1, languages.length);

                  String[] readableNames = new String[adapterLanguages.length];
                  for (int i = 0; i < readableNames.length; i++) {
                    String language = adapterLanguages[i];
                    if (language.equals("no-subs")) {
                      readableNames[i] = getString(R.string.no_subs);
                    } else {
                      Locale locale = LocaleUtils.toLocale(language);
                      readableNames[i] = locale.getDisplayName(locale);
                    }
                  }

                  mSubtitles.setListener(
                      new OptionSelector.SelectorListener() {
                        @Override
                        public void onSelectionChanged(int position, String value) {
                          onSubtitleLanguageSelected(adapterLanguages[position]);
                        }
                      });
                  mSubtitles.setData(readableNames);
                  ThreadUtils.runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          mSubtitles.setClickable(true);
                        }
                      });

                  String defaultSubtitle =
                      PrefUtils.get(mSubtitles.getContext(), Prefs.SUBTITLE_DEFAULT, null);
                  if (subtitles.containsKey(defaultSubtitle)) {
                    onSubtitleLanguageSelected(defaultSubtitle);
                    mSubtitles.setDefault(Arrays.asList(adapterLanguages).indexOf(defaultSubtitle));
                  } else {
                    onSubtitleLanguageSelected("no-subs");
                    mSubtitles.setDefault(Arrays.asList(adapterLanguages).indexOf("no-subs"));
                  }
                }

                @Override
                public void onFailure(Exception e) {
                  mSubtitles.setData(new String[0]);
                  mSubtitles.setClickable(true);
                }
              });
    } else {
      mSubtitles.setClickable(false);
      mSubtitles.setText(R.string.no_subs_available);
    }

    if (sMovie.torrents.size() > 0) {
      final String[] qualities =
          sMovie.torrents.keySet().toArray(new String[sMovie.torrents.size()]);
      SortUtils.sortQualities(qualities);
      mQuality.setData(qualities);
      mQuality.setListener(
          new OptionSelector.SelectorListener() {
            @Override
            public void onSelectionChanged(int position, String value) {
              mSelectedQuality = value;
              renderHealth();
              updateMagnet();
            }
          });
      String defaultQuality = PrefUtils.get(mQuality.getContext(), Prefs.QUALITY_DEFAULT, "720p");
      int qualityIndex =
          Arrays.asList(qualities).contains(defaultQuality)
              ? Arrays.asList(qualities).indexOf(defaultQuality)
              : qualities.length - 1;
      mSelectedQuality = qualities[qualityIndex];
      mQuality.setText(mSelectedQuality);
      mQuality.setDefault(qualityIndex);
      renderHealth();
      updateMagnet();
    }

    if (mCoverImage != null) {
      Picasso.with(mCoverImage.getContext()).load(sMovie.image).into(mCoverImage);
    }

    return mRoot;
  }