-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from batshalregmi/trent-firebase
Trent firebase
- Loading branch information
Showing
34 changed files
with
980 additions
and
582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "808515235747", | ||
"project_id": "cs2340-spotify-wrapped-2e02f", | ||
"storage_bucket": "cs2340-spotify-wrapped-2e02f.appspot.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:808515235747:android:d86d46bd9d94ae4f277416", | ||
"android_client_info": { | ||
"package_name": "com.group3.spotifywrapped" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyBKBzlAz70yBwn_mqm4_1R7R0rmgaPfdWU" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.group3.spotifywrapped; | ||
package com.group3.spotifywrapped.CoreAppViews; | ||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.room.Room; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
|
@@ -10,19 +10,32 @@ | |
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import java.util.List; | ||
|
||
import com.group3.spotifywrapped.CoreAppViews.MainPageActivity; | ||
import com.group3.spotifywrapped.database.AppDatabase; | ||
import android.widget.Toast; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import com.google.android.gms.tasks.OnCompleteListener; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.firebase.auth.AuthResult; | ||
import com.google.firebase.auth.FirebaseAuth; | ||
import com.google.firebase.database.DatabaseReference; | ||
import com.google.firebase.database.FirebaseDatabase; | ||
import com.group3.spotifywrapped.Foo; | ||
import com.group3.spotifywrapped.R; | ||
import com.group3.spotifywrapped.database.FirebaseHelper; | ||
import com.group3.spotifywrapped.database.User; | ||
import com.group3.spotifywrapped.database.UserDao; | ||
|
||
import com.group3.spotifywrapped.summary.SummarySelectorActivity; | ||
import com.spotify.sdk.android.auth.AuthorizationClient; | ||
import com.spotify.sdk.android.auth.AuthorizationRequest; | ||
import com.spotify.sdk.android.auth.AuthorizationResponse; | ||
|
||
public class LoginActivity extends AppCompatActivity { | ||
private static final String TAG = "LoginActivity"; | ||
|
||
public static final String CLIENT_ID = "9e3e12a5d1424f068a20c6db49de005c"; | ||
public static final String REDIRECT_URI = "spotifywrapped://auth"; | ||
public static final String[] SCOPES = new String[] { | ||
|
@@ -35,10 +48,10 @@ public class LoginActivity extends AppCompatActivity { | |
public static final int AUTH_TOKEN_REQUEST_CODE = 0; | ||
public static final int AUTH_CODE_REQUEST_CODE = 1; | ||
|
||
public static User activeUser; | ||
public static AtomicReference<DatabaseReference> activeUser = new AtomicReference<>(null); | ||
public static String token; | ||
|
||
private UserDao userDao; | ||
private boolean tokenRecieved = false; | ||
private AtomicBoolean tokenRecieved = new AtomicBoolean(false); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
|
@@ -47,42 +60,40 @@ protected void onCreate(Bundle savedInstanceState) { | |
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); | ||
StrictMode.setThreadPolicy(policy); | ||
|
||
EditText username = findViewById(R.id.username); | ||
EditText password = findViewById(R.id.password); | ||
EditText usernameTextField = findViewById(R.id.username); | ||
EditText passwordTextField = findViewById(R.id.password); | ||
Button loginButton = findViewById(R.id.loginButton); | ||
Button signUpButton = findViewById(R.id.signUpButton); | ||
|
||
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "local-database") | ||
.fallbackToDestructiveMigration() | ||
.build(); | ||
userDao = db.userDao(); | ||
|
||
//addTestUser(); | ||
|
||
loginButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Thread loginThread = new Thread(new Runnable() { | ||
if (passwordTextField.getText().toString().length() < 6) { | ||
Toast.makeText(LoginActivity.this, "Password must be 6 characters long", Toast.LENGTH_SHORT).show(); | ||
return; | ||
} | ||
FirebaseAuth mAuth = FirebaseAuth.getInstance(); | ||
mAuth.signInWithEmailAndPassword(usernameTextField.getText().toString(), passwordTextField.getText().toString()).addOnCompleteListener(new OnCompleteListener<AuthResult>() { | ||
@Override | ||
public void run() { | ||
List<User> usersFound = userDao.findByLoginInfo(username.getText().toString(), password.getText().toString()); | ||
if (!usersFound.isEmpty()) { | ||
activeUser = usersFound.get(0); | ||
getToken(); | ||
while (!tokenRecieved); | ||
Log.d("LoginActivity", "Token recieved: " + activeUser.sToken); | ||
//switch to settings screen | ||
Intent i = new Intent(view.getContext(), MainPageActivity.class); | ||
startActivity(i); | ||
} else { | ||
Log.e("LoginActivity", "Login credentials invalid"); | ||
public void onComplete(@NonNull Task<AuthResult> task) { | ||
if (task.isSuccessful()) { | ||
Thread thread = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
activeUser = FirebaseHelper.getUserByFirebaseUser(); | ||
getToken(); | ||
while(!tokenRecieved.get()); | ||
Intent i = new Intent(LoginActivity.this, SummarySelectorActivity.class); | ||
startActivity(i); | ||
} | ||
}); | ||
thread.start(); | ||
} | ||
} | ||
}); | ||
loginThread.start(); | ||
} | ||
}); | ||
|
||
Button signUpButton = findViewById(R.id.signUpButton); | ||
signUpButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
|
@@ -116,24 +127,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
|
||
if (AUTH_TOKEN_REQUEST_CODE == requestCode) { | ||
//Log.d("LoginActivity", "Response: " + response.getAccessToken()); | ||
activeUser.sToken = response.getAccessToken(); | ||
tokenRecieved = true; | ||
token = response.getAccessToken(); | ||
tokenRecieved.set(true); | ||
} | ||
} | ||
|
||
private void addTestUser() { | ||
User trentUser = new User( | ||
"tdoiron0", | ||
"1234", | ||
"[email protected]", | ||
"Trent Doiron" | ||
); | ||
Thread insertUserThread = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
userDao.insert(trentUser); | ||
} | ||
}); | ||
insertUserThread.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/group3/spotifywrapped/CoreAppViews/SignUpActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.group3.spotifywrapped.CoreAppViews; | ||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import com.google.android.gms.tasks.OnCompleteListener; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.firebase.auth.AuthResult; | ||
import com.google.firebase.auth.FirebaseAuth; | ||
import com.group3.spotifywrapped.R; | ||
import com.group3.spotifywrapped.database.FirebaseHelper; | ||
import com.group3.spotifywrapped.database.User; | ||
import com.group3.spotifywrapped.summary.SummarySelectorActivity; | ||
|
||
|
||
public class SignUpActivity extends AppCompatActivity { | ||
public static final String TAG = "SignUpActivity"; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_sign_up); | ||
|
||
EditText username = findViewById(R.id.username); | ||
EditText password = findViewById(R.id.password); | ||
EditText confirmPassword = findViewById(R.id.confirmPassword); | ||
EditText email = findViewById(R.id.email); | ||
EditText name = findViewById(R.id.name); | ||
Button createAccountButton = findViewById(R.id.createAccount); | ||
|
||
createAccountButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
FirebaseAuth.getInstance().createUserWithEmailAndPassword(email.getText().toString(), password.getText().toString()).addOnCompleteListener(new OnCompleteListener<AuthResult>() { | ||
@Override | ||
public void onComplete(@NonNull Task<AuthResult> task) { | ||
if (task.isSuccessful()) { | ||
User newUser = new User(); | ||
newUser.userUid = FirebaseAuth.getInstance().getUid(); | ||
newUser.username = username.getText().toString(); | ||
newUser.name = name.getText().toString(); | ||
LoginActivity.activeUser.set(FirebaseHelper.addUser(newUser)); | ||
Intent i = new Intent(SignUpActivity.this, SummarySelectorActivity.class); | ||
startActivity(i); | ||
} else { | ||
Toast.makeText(SignUpActivity.this, "Failed to sign up", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
app/src/main/java/com/group3/spotifywrapped/DevStartActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.group3.spotifywrapped; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Foo { | ||
public int num; | ||
public String str = "abcd"; | ||
|
||
public Foo(int num, String str) { | ||
this.num = num; | ||
this.str = str; | ||
} | ||
} |
Oops, something went wrong.