From 634b57c67caf0425a914e8c3c7a556e5265da137 Mon Sep 17 00:00:00 2001 From: Christopher Luc Date: Fri, 6 Mar 2015 00:06:47 -0800 Subject: [PATCH] Push scores even if it's lower than best score, because best score of the day. Use apply on sharedprefs, optimization. --- .../google/example/games/basegameutils/GameHelper.java | 4 ++-- app/build.gradle | 4 ++-- .../onesearch/base/BaseGooglePlayServicesActivity.java | 6 +++--- .../main/java/chrisjluc/onesearch/ui/MenuActivity.java | 2 +- .../main/java/chrisjluc/onesearch/ui/ResultsActivity.java | 8 ++++---- app/src/main/res/values/strings.xml | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/BaseGameUtils/src/main/java/com/google/example/games/basegameutils/GameHelper.java b/BaseGameUtils/src/main/java/com/google/example/games/basegameutils/GameHelper.java index c666cfd..53e24f0 100755 --- a/BaseGameUtils/src/main/java/com/google/example/games/basegameutils/GameHelper.java +++ b/BaseGameUtils/src/main/java/com/google/example/games/basegameutils/GameHelper.java @@ -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; } @@ -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. */ diff --git a/app/build.gradle b/app/build.gradle index 1641c53..dab2713 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/java/chrisjluc/onesearch/base/BaseGooglePlayServicesActivity.java b/app/src/main/java/chrisjluc/onesearch/base/BaseGooglePlayServicesActivity.java index dccb438..cfe00d3 100644 --- a/app/src/main/java/chrisjluc/onesearch/base/BaseGooglePlayServicesActivity.java +++ b/app/src/main/java/chrisjluc/onesearch/base/BaseGooglePlayServicesActivity.java @@ -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)); } } @@ -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); @@ -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(); } } } diff --git a/app/src/main/java/chrisjluc/onesearch/ui/MenuActivity.java b/app/src/main/java/chrisjluc/onesearch/ui/MenuActivity.java index 3b19477..447f9aa 100644 --- a/app/src/main/java/chrisjluc/onesearch/ui/MenuActivity.java +++ b/app/src/main/java/chrisjluc/onesearch/ui/MenuActivity.java @@ -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); diff --git a/app/src/main/java/chrisjluc/onesearch/ui/ResultsActivity.java b/app/src/main/java/chrisjluc/onesearch/ui/ResultsActivity.java index aaac35d..60bc8ff 100644 --- a/app/src/main/java/chrisjluc/onesearch/ui/ResultsActivity.java +++ b/app/src/main/java/chrisjluc/onesearch/ui/ResultsActivity.java @@ -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(); @@ -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); @@ -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); } } @@ -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(); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3a6786c..72fbc57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ - Failed to sign in + There was an issue with sign in, please try again later. Onesearch Results menu