Skip to content

Commit

Permalink
Push scores even if it's lower than best score, because best score of…
Browse files Browse the repository at this point in the history
… the day. Use apply on sharedprefs, optimization.
  • Loading branch information
chrisjluc committed Mar 6, 2015
1 parent 9a77f24 commit 634b57c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ int incrementSignInCancellations() {
SharedPreferences.Editor editor = mAppContext.getSharedPreferences(
GAMEHELPER_SHARED_PREFS, Context.MODE_PRIVATE).edit();
editor.putInt(KEY_SIGN_IN_CANCELLATIONS, cancellations + 1);
editor.commit();
editor.apply();
return cancellations + 1;
}

Expand All @@ -783,7 +783,7 @@ void resetSignInCancellations() {
SharedPreferences.Editor editor = mAppContext.getSharedPreferences(
GAMEHELPER_SHARED_PREFS, Context.MODE_PRIVATE).edit();
editor.putInt(KEY_SIGN_IN_CANCELLATIONS, 0);
editor.commit();
editor.apply();
}

/** Handles a connection failure. */
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "chrisjluc.onesearch"
minSdkVersion 14
targetSdkVersion 21
versionCode 7
versionName "1.0.2.1"
versionCode 8
versionName "1.0.3"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onConnectionFailed(ConnectionResult connectionResult) {

mResolvingConnectionFailure = BaseGameUtils.resolveConnectionFailure(this,
mGoogleApiClient, connectionResult,
RC_SIGN_IN, "Failed to sign in");
RC_SIGN_IN, getString(R.string.sign_in_failed));
}
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public void onConnected(Bundle bundle) {
if (isFirstTime) {
SharedPreferences.Editor editor = getSharedPreferences(BGP_PREF_MAME, MODE_PRIVATE).edit();
editor.putBoolean(FIRST_CONNECT, false);
editor.commit();
editor.apply();

// Push high scores
prefs = getSharedPreferences(ResultsActivity.PREF_NAME, MODE_PRIVATE);
Expand Down Expand Up @@ -130,7 +130,7 @@ public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult) {
if (score > currentScore) {
SharedPreferences.Editor editor = getSharedPreferences(ResultsActivity.PREF_NAME, MODE_PRIVATE).edit();
editor.putInt(ResultsActivity.SCORE_PREFIX + gameDifficulty, score);
editor.commit();
editor.apply();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/chrisjluc/onesearch/ui/MenuActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (isFirstTime) {
SharedPreferences.Editor editor = getSharedPreferences(MENU_PREF_NAME, MODE_PRIVATE).edit();
editor.putBoolean(FIRST_TIME, false);
editor.commit();
editor.apply();

Intent i = new Intent(getApplicationContext(), SplashActivity.class);
startActivity(i);
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/chrisjluc/onesearch/ui/ResultsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected void onCreate(Bundle savedInstanceState) {
int numRounds = prefs.getInt(COMPLETED_ROUND_PREFIX + mGameMode.getDifficulty(), 0);
SharedPreferences.Editor editor = getSharedPreferences(PREF_NAME, MODE_PRIVATE).edit();
editor.putInt(COMPLETED_ROUND_PREFIX + mGameMode.getDifficulty(), ++numRounds);
editor.commit();
editor.apply();
}

updateSavedScoreAndRenderViews();
Expand All @@ -91,7 +91,7 @@ private void updateSavedScoreAndRenderViews() {
if (mScore > bestScore) {
SharedPreferences.Editor editor = getSharedPreferences(PREF_NAME, MODE_PRIVATE).edit();
editor.putInt(SCORE_PREFIX + mGameMode.getDifficulty(), mScore);
editor.commit();
editor.apply();

findViewById(R.id.tvBestScoreResultNotify).setVisibility(View.VISIBLE);
Animation anim = new AlphaAnimation(1.0f, 0.0f);
Expand All @@ -108,7 +108,7 @@ private void updateSavedScoreAndRenderViews() {
}

private void updateLeaderboard() {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected() && mScore > mPreviousBestScore) {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
Games.Leaderboards.submitScore(mGoogleApiClient, mLeaderboardId, mScore);
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ private void updateAchievements() {
if (score > highestScore) {
SharedPreferences.Editor editor = getSharedPreferences(PREF_NAME, MODE_PRIVATE).edit();
editor.putInt(HIGHEST_SCORE_FOR_ACHIEVEMENT_PREFIX + mGameMode.getDifficulty(), score);
editor.commit();
editor.apply();
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="sign_in_failed">Failed to sign in</string>
<string name="sign_in_failed">There was an issue with sign in, please try again later.</string>
<string name="app_name">Onesearch</string>
<string name="title_activity_results">Results</string>
<string name="title_activity_menu">menu</string>
Expand Down

0 comments on commit 634b57c

Please sign in to comment.