public Fragment root() {
    Configuration configuration = lock.getConfiguration();
    if (lock.getConfiguration() == null) {
      return login();
    }

    if (signUpMode) {
      return SocialSignUpFragment.newFragment(activeSocialStrategies());
    }

    final boolean hasEnterprise = !configuration.getEnterpriseStrategies().isEmpty();
    final boolean hasSocial = !configuration.getSocialStrategies().isEmpty();
    final boolean hasDB = configuration.getDefaultDatabaseConnection() != null;
    final boolean hasAD = configuration.getActiveDirectoryStrategy() != null;

    if (!hasDB && hasSocial && !hasEnterprise) {
      return social();
    }

    if (!hasDB && hasSocial && hasAD) {
      return enterpriseLoginWithSocial(configuration.getDefaultActiveDirectoryConnection());
    }

    if ((hasDB || hasEnterprise) && hasSocial) {
      return loginWithSocial();
    }

    if (!hasDB && hasAD) {
      return enterpriseLoginWithConnection(
          configuration.getDefaultActiveDirectoryConnection(), true);
    }

    return login();
  }
 public Fragment login() {
   final DatabaseLoginFragment fragment = new DatabaseLoginFragment();
   Bundle arguments = new Bundle();
   arguments.putSerializable(
       BaseTitledFragment.AUTHENTICATION_PARAMETER_ARGUMENT,
       new HashMap<>(lock.getAuthenticationParameters()));
   arguments.putBoolean(
       BaseTitledFragment.AUTHENTICATION_USES_EMAIL_ARGUMENT, lock.shouldUseEmail());
   fragment.setArguments(arguments);
   return fragment;
 }
 public Fragment social() {
   final SocialFragment fragment = new SocialFragment();
   if (lock.getConfiguration() != null) {
     Bundle bundle = new Bundle();
     bundle.putStringArrayList(
         SocialFragment.SOCIAL_FRAGMENT_STRATEGIES_ARGUMENT, activeSocialStrategies());
     bundle.putSerializable(
         BaseTitledFragment.AUTHENTICATION_PARAMETER_ARGUMENT,
         new HashMap<>(lock.getAuthenticationParameters()));
     fragment.setArguments(bundle);
   }
   return fragment;
 }
 private Fragment enterpriseLoginWithConnection(Connection connection, boolean isRoot) {
   final DatabaseLoginFragment fragment = new DatabaseLoginFragment();
   Bundle arguments = new Bundle();
   arguments.putSerializable(
       BaseTitledFragment.AUTHENTICATION_PARAMETER_ARGUMENT,
       new HashMap<>(lock.getAuthenticationParameters()));
   arguments.putBoolean(
       BaseTitledFragment.AUTHENTICATION_USES_EMAIL_ARGUMENT, lock.shouldUseEmail());
   if (connection != null) {
     arguments.putParcelable(DatabaseLoginFragment.AD_ENTERPRISE_CONNECTION_ARGUMENT, connection);
   }
   arguments.putBoolean(DatabaseLoginFragment.IS_MAIN_LOGIN_ARGUMENT, isRoot);
   fragment.setArguments(arguments);
   return fragment;
 }
 private ArrayList<String> activeSocialStrategies() {
   Configuration configuration = lock.getConfiguration();
   ArrayList<String> strategies = new ArrayList<>(configuration.getSocialStrategies().size());
   for (Strategy strategy : configuration.getSocialStrategies()) {
     strategies.add(strategy.getName());
   }
   return strategies;
 }