Skip to content

Commit

Permalink
Release Version 1.08
Browse files Browse the repository at this point in the history
- Added about screen
- Redesigned navigation drawer layout
- Added user preferences
- Update navigation drawer based on whether user is signed in via Google or otherwise
- App automatically signs out if Google Account is signed out.
- Added more Google Play Achievements
  • Loading branch information
jiangshen committed Apr 24, 2018
1 parent f895e09 commit e40e42c
Show file tree
Hide file tree
Showing 17 changed files with 572 additions and 473 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ freeline.py
freeline/
freeline_project_description.json
.DS_Store
app/src/main/AndroidManifest.xml
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Android drawing application for annotating the backbone of worms.

## Releases

### 1.08 (2018-04-23)
- Added about screen
- Redesigned navigation drawer layout
- Added user preferences
- Update navigation drawer based on whether user is signed in via Google or otherwise
- App automatically signs out if Google Account is signed out.
- Added more Google Play Achievements

### 1.07 (2018-04-14)
- Added user scores in FireBase
- More robust image loading from FireBase
Expand Down
4 changes: 2 additions & 2 deletions app/.idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified app/.idea/caches/build_file_checksums.ser
Binary file not shown.
670 changes: 310 additions & 360 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.07"
versionName "1.08"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down Expand Up @@ -84,6 +83,7 @@
</activity>
<activity
android:name=".AboutActivity"
android:label="@string/title_activity_about"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.Settings"/>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ protected void onCreate(Bundle savedInstanceState) {
}

TextView tvChangeLog = findViewById(R.id.tv_change_log);
tvChangeLog.setText(Html.fromHtml(getString(R.string.about_screen_text)));
tvChangeLog.setText(Html.fromHtml(getString(R.string.change_log_text)));
tvChangeLog.setMovementMethod(LinkMovementMethod.getInstance());

TextView tvAboutApp = findViewById(R.id.tv_about_app);
tvAboutApp.setText(Html.fromHtml(getString(R.string.about_app_text)));
tvAboutApp.setMovementMethod(LinkMovementMethod.getInstance());

TextView tvPrivacyPolicy = findViewById(R.id.tv_privacy_policy);
tvPrivacyPolicy.setText(Html.fromHtml(getString(R.string.privacy_policy_text)));
tvPrivacyPolicy.setMovementMethod(LinkMovementMethod.getInstance());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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 @@ -35,9 +36,13 @@
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;
import com.google.firebase.auth.UserInfo;
import com.google.firebase.auth.UserProfileChangeRequest;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
Expand Down Expand Up @@ -68,6 +73,7 @@ public class DrawingActivity extends AppCompatActivity
private static final int PIXEL_HEIGHT = 280;
private static final int RC_ACHIEVEMENT_UI = 9003;
private static final int RC_LEADERBOARD_UI = 9004;
private static final int RC_SETTING_UI = 9005;

/* Variables */
String currBatchName;
Expand Down Expand Up @@ -101,6 +107,7 @@ public class DrawingActivity extends AppCompatActivity
ProgressBar barSend;
FloatingActionButton fabSend;
TextView navUserEmail;
TextView navUserName;
TextView tvImageName;
TextView tvUserScore;

Expand All @@ -114,6 +121,8 @@ public class DrawingActivity extends AppCompatActivity
NavigationView navView;
View navHeaderLayout;

boolean isGoogleSignIn = false;


@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -138,6 +147,12 @@ protected void onCreate(Bundle savedInstanceState) {
userUID = mUser.getUid();
userEmail = mUser.getEmail();

for (UserInfo u : mUser.getProviderData()) {
if (u.getProviderId().equals("google.com")) {
isGoogleSignIn = true;
}
}

// get drawing view from XML (where the finger writes the number)
drawView = findViewById(R.id.draw);

Expand All @@ -160,10 +175,23 @@ protected void onCreate(Bundle savedInstanceState) {
navUserEmail.setText(userEmail);
tvImageName = findViewById(R.id.tv_img_name);

TextView navUserName = navHeaderLayout.findViewById(R.id.nav_drawer_name);
navUserName = navHeaderLayout.findViewById(R.id.nav_drawer_name);
String userName = mUser.getDisplayName();
if (!(userName == null || userName.equals(""))) {
navUserName.setText(userName);
if (userName == null || userName.equals("")) {
/* New users gets the default name */
userName = getString(R.string.default_user_name);
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(userName)
.build();
mUser.updateProfile(profileUpdates);
}
navUserName.setText(userName);

if (!isGoogleSignIn) {
Menu menu = navView.getMenu();
menu.findItem(R.id.nav_achievements).setEnabled(false);
menu.findItem(R.id.nav_leaderboard).setEnabled(false);
menu.findItem(R.id.nav_gplay_setting).setEnabled(false);
}

// FIXME get user profile photo
Expand Down Expand Up @@ -203,7 +231,9 @@ protected void onCreate(Bundle savedInstanceState) {
/* Google Play Game */
gAcct = GoogleSignIn.getLastSignedInAccount(this);
if (gAcct != null) {
// Games.getGamesClient(this, gAcct).setViewForPopups(clDrawMain);
Games.getGamesClient(this, gAcct).setViewForPopups(clDrawMain);
}
if (isGoogleSignIn) {
mAchClient = Games.getAchievementsClient(this, gAcct);
mLeadClient = Games.getLeaderboardsClient(this, gAcct);
}
Expand All @@ -212,10 +242,12 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_achievements) {
if (id == R.id.nav_achievements && isGoogleSignIn) {
showAchievements();
} else if (id == R.id.nav_leaderboard) {
} else if (id == R.id.nav_leaderboard && isGoogleSignIn) {
showLeaderBoard();
} else if (id == R.id.nav_gplay_setting && isGoogleSignIn) {
showGPlaySettings();
} else if (id == R.id.nav_logout) {
logOut();
} else if (id == R.id.nav_settings) {
Expand All @@ -229,18 +261,20 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return true;
}


private void showAchievements() {
if (gAcct != null) {
mAchClient.getAchievementsIntent()
.addOnSuccessListener((intent -> startActivityForResult(intent, RC_ACHIEVEMENT_UI)));
}
mAchClient.getAchievementsIntent()
.addOnSuccessListener((intent -> startActivityForResult(intent, RC_ACHIEVEMENT_UI)));
}

private void showLeaderBoard() {
if (gAcct != null) {
mLeadClient.getLeaderboardIntent(getString(R.string.leaderboard_wurm_scores_id))
.addOnSuccessListener((intent -> startActivityForResult(intent, RC_LEADERBOARD_UI)));
}
mLeadClient.getLeaderboardIntent(getString(R.string.leaderboard_wurm_scores_id))
.addOnSuccessListener((intent -> startActivityForResult(intent, RC_LEADERBOARD_UI)));
}

private void showGPlaySettings() {
Games.getGamesClient(this, gAcct).getSettingsIntent()
.addOnSuccessListener((intent -> startActivityForResult(intent, RC_SETTING_UI)));
}

private void showSettings() {
Expand Down Expand Up @@ -277,6 +311,17 @@ private void feedbackScreen() {
// say he presses home button and then comes back to app, onResume() is called.
protected void onResume() {
drawView.onResume();
if (GoogleSignIn.getLastSignedInAccount(this) == null) {
FirebaseAuth.getInstance().signOut();
Intent i = new Intent(this, LoginActivity.class);
startActivity(i);
}
mUser.reload().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
navUserName.setText(mUser.getDisplayName());
navUserEmail.setText(mUser.getEmail());
}
});
super.onResume();
}

Expand Down
21 changes: 15 additions & 6 deletions app/src/main/java/com/example/caden/drawingtest/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser != null) {
updateUI();
updateUI(false);
}
}

Expand Down Expand Up @@ -105,9 +105,18 @@ public void register(View v){
startActivity(i);
}

public void updateUI() {
Intent i = new Intent(this, DrawingActivity.class);
startActivity(i);
public void updateUI(boolean delay) {
if (delay) {
/* Slight delay to allow for Google Play Games popup to show */
new android.os.Handler().postDelayed(() -> {
Intent i = new Intent(this, DrawingActivity.class);
startActivity(i);
},
300);
} else {
Intent i = new Intent(this, DrawingActivity.class);
startActivity(i);
}
}

@Override
Expand Down Expand Up @@ -142,7 +151,7 @@ private void fireBaseAuthWithGoogle(GoogleSignInAccount acct) {
.addOnCompleteListener(this, task -> {
progressbar.setVisibility(View.INVISIBLE);
if (task.isSuccessful()) {
updateUI();
updateUI(true);
} else {
String msg = task.getException() == null ?
"Something went wrong, please try again!" :
Expand Down Expand Up @@ -190,7 +199,7 @@ public void login(View v) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
if (user.isEmailVerified()) {
updateUI();
updateUI(false);
} else {
new AlertDialog.Builder(this)
.setMessage("User is not verified, do you want to verify now?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.util.Log;
import android.view.MenuItem;

/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
* settings are split by category, with category headers shown to the left of
* the list of settings.
* <p>
* See <a href="http://developer.android.com/design/patterns/settings.html">
* Android Design: Settings</a> for design guidelines and the <a
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
* API Guide</a> for more information on developing a Settings UI.
*/
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.UserInfo;
import com.google.firebase.auth.UserProfileChangeRequest;

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

public class SettingsActivity extends AppCompatPreferenceActivity {

private static FirebaseUser user;
private static String userName;

/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
Expand All @@ -39,6 +42,15 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
int index = listPreference.findIndexOfValue(strVal);
// Set the summary to reflect the new value.
pref.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
} else if (pref instanceof EditTextPreference) {
if (pref.getKey().equals("user_name")) {
userName = strVal;
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(userName)
.build();
user.updateProfile(profileUpdates);
}
pref.setSummary(strVal);
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
Expand All @@ -47,6 +59,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
return true;
};


/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
Expand Down Expand Up @@ -80,9 +93,17 @@ private static void bindPreferenceSummaryToValue(Preference preference) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

user = FirebaseAuth.getInstance().getCurrentUser();
getFragmentManager().beginTransaction().replace(android.R.id.content,
new WurmPrefFragment()).commit();
setupActionBar();

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

editor.apply();
}

private void setupActionBar() {
Expand Down Expand Up @@ -126,14 +147,16 @@ public void onCreate(Bundle savedInstanceState) {
addPreferencesFromResource(R.xml.pref_wurm);
setHasOptionsMenu(true);

// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
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"));
// bindPreferenceSummaryToValue(findPreference("example_list"));
}

@Override
Expand Down
Loading

0 comments on commit e40e42c

Please sign in to comment.