Skip to content

Commit

Permalink
Achievements and LeaderBoard improvements
Browse files Browse the repository at this point in the history
- Fixed all Achievements scoring
- Updated LeaderBoard submissions
  • Loading branch information
jiangshen committed Apr 24, 2018
1 parent e40e42c commit c77935e
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 208 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ freeline.py
freeline/
freeline_project_description.json
.DS_Store
app/src/main/*.xml
app/src/main/res/values/*.xml
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Android drawing application for annotating the backbone of worms.
- App takes up to 70% less space on devices

### 1.02 (2017-12-08)
- Added Firebase Crashlytics and Performance Monitoring
- Added FireBase Crashlytics and Performance Monitoring
- Added feedback and rate app dialog
- Removed brush color functionality
- Images expanded to fill the screen
Expand Down
2 changes: 2 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
/src/main/*.xml
/src/main/res/values/*.xml
Binary file modified app/.idea/caches/build_file_checksums.ser
Binary file not shown.
434 changes: 255 additions & 179 deletions app/.idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.08"
versionName "1.09"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
android:screenOrientation="portrait"
android:label="@string/title_activity_settings"
android:parentActivityName=".DrawingActivity"
android:theme="@style/AppTheme.Settings">
android:theme="@style/AppTheme.Settings"
android:configChanges="locale">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.caden.drawingtest.DrawingActivity" />
Expand Down
Binary file removed app/src/main/ic_launcher-web.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.transition.TransitionManager;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -36,8 +35,6 @@
import com.google.android.gms.games.AchievementsClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.games.LeaderboardsClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
Expand Down Expand Up @@ -74,6 +71,7 @@ public class DrawingActivity extends AppCompatActivity
private static final int RC_ACHIEVEMENT_UI = 9003;
private static final int RC_LEADERBOARD_UI = 9004;
private static final int RC_SETTING_UI = 9005;
private static final int RC_LEADERBOARD_SCORE = 1337;

/* Variables */
String currBatchName;
Expand Down Expand Up @@ -159,6 +157,7 @@ protected void onCreate(Bundle savedInstanceState) {
/* Get Wurm image from FireBase */
fireBaseRetrieveImage();
fireBaseRetrieveUserScore();
updateLeaderBoard();

tvUserScore = findViewById(R.id.tv_user_score);
tvUserScore.setText(String.valueOf(userScore));
Expand Down Expand Up @@ -311,6 +310,8 @@ private void feedbackScreen() {
// say he presses home button and then comes back to app, onResume() is called.
protected void onResume() {
drawView.onResume();
updateLeaderBoard();

if (GoogleSignIn.getLastSignedInAccount(this) == null) {
FirebaseAuth.getInstance().signOut();
Intent i = new Intent(this, LoginActivity.class);
Expand All @@ -333,6 +334,12 @@ protected void onPause() {
super.onPause();
}

@Override
protected void onStop() {
updateLeaderBoard();
super.onStop();
}

@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
Expand Down Expand Up @@ -484,10 +491,7 @@ public void sendImage(View v) {

/* Update User Score internally, with FireBase and with Google Play Games */
userScore++;
if (mAchClient != null) {
mAchClient.increment(getString(R.string.achievement_newbie_id), 1);

}
updateWurmsAchievements();

tvUserScore.setText(String.valueOf(userScore));
mDatabase.child("user_scores").child(mUser.getUid()).setValue(userScore);
Expand Down Expand Up @@ -540,13 +544,44 @@ public void markAsBad(View v) {
}
mDatabase.child("bad_images").child(currBatchName).child(String.valueOf(currImgNo))
.child(userUID).setValue(textToSend);
updateReporterAchievements();
nextImage(v);
dialog.dismiss();
})
.setNegativeButton("Cancel", (dialog, id) -> dialog.cancel())
.show();
}

private void updateWurmsAchievements() {
if (isGoogleSignIn) {
mAchClient.increment(getString(R.string.achievement_newbie_1_id), 1);
mAchClient.increment(getString(R.string.achievement_newbie_2_id), 1);
mAchClient.increment(getString(R.string.achievement_growing_1_id), 1);
mAchClient.increment(getString(R.string.achievement_growing_2_id), 1);
mAchClient.increment(getString(R.string.achievement_silver_id), 1);
mAchClient.increment(getString(R.string.achievement_gold_id), 1);
mAchClient.increment(getString(R.string.achievement_diamond_id), 1);
mAchClient.increment(getString(R.string.achievement_platinum_id), 1);
mAchClient.increment(getString(R.string.achievement_master_of_all_id), 1);
}
}

private void updateReporterAchievements() {
if (isGoogleSignIn) {
mAchClient.increment(getString(R.string.achievement_reporter_1_id), 1);
mAchClient.increment(getString(R.string.achievement_reporter_2_id), 1);
mAchClient.increment(getString(R.string.achievement_exp_reporter_id), 1);
mAchClient.increment(getString(R.string.achievement_pro_reporter_id), 1);
}
}

private void updateLeaderBoard() {
if (isGoogleSignIn && userScore > 0) {
mLeadClient.submitScore(getString(R.string.leaderboard_wurm_scores_id), RC_LEADERBOARD_SCORE);
}

}

private void fireBaseRetrieveImage() {
mDatabase.child("master_upload").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
Expand All @@ -12,6 +13,7 @@
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MenuItem;

Expand All @@ -22,12 +24,14 @@
import com.google.firebase.auth.UserProfileChangeRequest;

import java.util.List;
import java.util.Locale;
import java.util.Objects;

public class SettingsActivity extends AppCompatPreferenceActivity {

private static FirebaseUser user;
private static String userName;
private static SharedPreferences sharedPrefs;

/**
* A preference value change listener that updates the preference's summary
Expand Down Expand Up @@ -99,10 +103,11 @@ protected void onCreate(Bundle savedInstanceState) {
new WurmPrefFragment()).commit();
setupActionBar();

SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString("user_name", user.getDisplayName());
editor.putString("user_email", user.getEmail());

editor.apply();
}

Expand Down Expand Up @@ -141,22 +146,19 @@ protected boolean isValidFragment(String fragmentName) {


public static class WurmPrefFragment extends PreferenceFragment {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_wurm);
setHasOptionsMenu(true);

for (UserInfo u : user.getProviderData()) {
if (u.getProviderId().equals("google.com")) {
findPreference("user_email").setEnabled(false);
}
}

bindPreferenceSummaryToValue(findPreference("user_name"));
bindPreferenceSummaryToValue(findPreference("user_email"));

// bindPreferenceSummaryToValue(findPreference("example_list"));
}

@Override
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
<string name="default_user_name">虫涂涂 用户</string>
<string name="title_activity_settings">虫涂涂 设置</string>
<string name="title_activity_about">关于 虫涂涂</string>
<string name="pref_change_language_title">更改语言</string>
</resources>
33 changes: 21 additions & 12 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,32 @@
<string name="reset_psw_text">Reset Password</string>
<string name="reenter_email_text">Re-enter your email</string>
<string name="reset_text">Reset</string>

<!-- Google Play Achievements and LeaderBoard -->
<string name="app_id" translatable="false">52423362671</string>
<string name="achievement_newbie_id" translatable="false">CgkI75C0pcMBEAIQAQ</string>

<string name="achievement_newbie_1_id" translatable="false">CgkI75C0pcMBEAIQAQ</string>
<string name="achievement_newbie_2_id" translatable="false">CgkI75C0pcMBEAIQBA</string>
<string name="achievement_growing_1_id" translatable="false">CgkI75C0pcMBEAIQBQ</string>
<string name="achievement_growing_2_id" translatable="false">CgkI75C0pcMBEAIQBg</string>
<string name="achievement_silver_id" translatable="false">CgkI75C0pcMBEAIQBw</string>
<string name="achievement_gold_id" translatable="false">CgkI75C0pcMBEAIQCA</string>
<string name="achievement_diamond_id" translatable="false">CgkI75C0pcMBEAIQCQ</string>
<string name="achievement_platinum_id" translatable="false">CgkI75C0pcMBEAIQCg</string>
<string name="achievement_master_of_all_id" translatable="false">CgkI75C0pcMBEAIQCw</string>

<string name="achievement_reporter_1_id" translatable="false">CgkI75C0pcMBEAIQAg</string>
<string name="achievement_reporter_2_id" translatable="false">CgkI75C0pcMBEAIQDA</string>
<string name="achievement_exp_reporter_id" translatable="false">CgkI75C0pcMBEAIQDQ</string>
<string name="achievement_pro_reporter_id" translatable="false">CgkI75C0pcMBEAIQDg</string>

<string name="leaderboard_wurm_scores_id" translatable="false">CgkI75C0pcMBEAIQAw</string>


<string name="default_user_name">Wurm Painter</string>

<!-- Settings -->
<string name="title_activity_settings">Wurm Settings</string>
<string-array name="pref_example_list_titles">
<item>Always</item>
<item>When possible</item>
<item>Never</item>
</string-array>
<string-array name="pref_example_list_values">
<item>1</item>
<item>0</item>
<item>-1</item>
</string-array>

<string name="pref_title_system_sync_settings">System sync settings</string>
<string name="pref_title_add_friends_to_messages">Add friends to messages</string>
Expand Down Expand Up @@ -95,7 +104,7 @@
</span>
<h3>1.02 (2017-12-08)</h3>
<span>
- Added Firebase Crashlytics and Performance Monitoring <br />
- Added FireBase Crashlytics and Performance Monitoring <br />
- Added feedback and rate app dialog <br />
- Removed brush color functionality <br />
- Images expanded to fill the screen <br />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/pref_wurm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</PreferenceCategory>

<PreferenceCategory
android:title="Game Settings"
android:title="Application Settings"
android:key="game_category">

<SwitchPreference
Expand Down

0 comments on commit c77935e

Please sign in to comment.