Ejemplo n.º 1
0
  /**
   * Called when the user wants to view his/her score relative to other players
   *
   * @param view the button clicked
   */
  public void relativeUserScore() {
    // set up the Parse database and have the user log in if not already
    currentUser = ParseUser.getCurrentUser();
    if (currentUser == null) {
      Log.i("Leaderboard", "user begins logging in");
      buildPopup(false);
    } else {
      Log.i("Leaderboard", "user is logged in");

      // make a new MultiLeaderBoardModel with the given username
      try {
        mlb.setPlayer(currentUser.getString("username"));
      } catch (InternetConnectionException e) {
        e.fillInStackTrace();
        Log.i("Leaderboard", "triggering internet connection error screen");
        Intent intent = new Intent(this, ErrorScreen.class);
        intent.putExtra("error", R.layout.activity_connection_error_lb);
        startActivity(intent);
        return;
      }
      int userRank = mlb.getRank();
      // inform the user that he/she has no scores yet

      if (userRank <= 0) {
        InterfaceUtils.buildAlertDialog(this, R.string.no_scores_title, R.string.no_scores_msg);
        return;
      }
      int highestRank = mlb.getHighestRelScoreRank();
      // get the relative position of the user with the passed in NUM_RELATIVE
      ScoreEntry[] relativeEntrys = mlb.getRelativeScores();

      // add the relativeScore tab
      Fragment currentFragment =
          RelativeUserScoreTab.newInstance(relativeEntrys, userRank, highestRank);
      FragmentTransaction fst = getSupportFragmentManager().beginTransaction();
      fst.replace(R.id.leaderboard_layout, currentFragment);
      fst.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
      fst.commit();
    }
  }