Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe to weekly steps in Home; Check if user has created account … #74

Merged
merged 1 commit into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
// The Task returned from this call is always completed, no need to attach a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);

//If sign in was successful then launchActivity
if ( gSignInAndOut.handleSignInResult(task) == true )
{
// No longer need to launch activity, taken care of by finish button
// If the user logs in, already has an account, and tries to create a new account
// redirects them to their home page/the main activity
if (SharedPrefData.userSharedPrefExists(this)) {
launchActivity();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ protected void onPostExecute(String result) {

@Override
protected void onPreExecute() {
gFit.subscribeForWeeklySteps();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
if ( gSignInAndOut.handleSignInResult(task) == true )
{
launchHomeScreenActivity();
// Checks if users sign-in on their first use without creating an account first,
// redirects them to collect info such as their name and height
if (SharedPrefData.userSharedPrefExists(this.getApplicationContext())) {
launchHomeScreenActivity();
} else {
launchGetToKnowYouActivity();
}

}
}
}
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/android/personalbest/SharedPrefData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;

import java.io.File;
import java.util.Calendar;
import java.util.Map;

Expand Down Expand Up @@ -155,4 +156,27 @@ public static void setHeightIn(Context context, int heightIn) {
editor.putInt("heightin", heightIn);
editor.apply();
}


// Check if a logged in user has a SharedPreference file to indicate whether or not they
// created a Personal Best account; controls the login/create-account flow
public static boolean userSharedPrefExists(Context context) {
String accountId = getLoggedInUserId(context);
String SHARED_PREF_FILE_PATH = "/data/data/" + context.getPackageName() + "/shared_prefs/" + accountId + ".xml";

File f = new File(SHARED_PREF_FILE_PATH);
return f.exists() ? true : false;
}


// Helper method to print out all the key-values of a SharedPref file
public static void logAllKeyValues(Context context) {
String accountId = getLoggedInUserId(context);
SharedPreferences sharedPreferences = context.getSharedPreferences(accountId, Context.MODE_PRIVATE);

Map<String, ?> allEntries = sharedPreferences.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
Log.d(TAG + " Content", entry.getKey() + ": " + entry.getValue().toString());
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
<string name="title_activity_main">MainActivity</string>
<string name="title_activity_main">Personal Best</string>
<string name="title_home">Home</string>

<string name="title_history">History</string>
Expand Down