-
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.
- Loading branch information
Showing
6 changed files
with
138 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,7 @@ | |
import android.widget.EditText; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import com.group3.spotifywrapped.summary.SummaryActivity; | ||
import com.group3.spotifywrapped.database.MyDatabase; | ||
|
@@ -38,8 +37,8 @@ public class LoginActivity extends AppCompatActivity { | |
|
||
public static User activeUser; | ||
|
||
private MyDatabaseDao userDao; | ||
private boolean tokenRecieved = false; | ||
private MyDatabaseDao myDatabaseDao; | ||
private AtomicBoolean tokenRecieved = new AtomicBoolean(false); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
|
@@ -53,19 +52,21 @@ protected void onCreate(Bundle savedInstanceState) { | |
Button loginButton = findViewById(R.id.loginButton); | ||
|
||
MyDatabase db = MyDatabase.getInstance(this); | ||
userDao = db.myDatabaseDao(); | ||
myDatabaseDao = db.myDatabaseDao(); | ||
|
||
//addTestUser(); | ||
|
||
loginButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Thread loginThread = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
List<User> usersFound = userDao.findByLoginInfo(username.getText().toString(), password.getText().toString()); | ||
List<User> usersFound = myDatabaseDao.findByLoginInfo(username.getText().toString(), password.getText().toString()); | ||
if (!usersFound.isEmpty()) { | ||
activeUser = usersFound.get(0); | ||
getToken(); | ||
while (!tokenRecieved); | ||
while (!tokenRecieved.get()); | ||
Log.d("LoginActivity", "Token recieved: " + activeUser.sToken); | ||
Intent i = new Intent(LoginActivity.this, SummaryActivity.class); | ||
startActivity(i); | ||
|
@@ -104,7 +105,24 @@ 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; | ||
tokenRecieved.set(true); | ||
} | ||
} | ||
|
||
private void addTestUser() { | ||
User trentUser = new User( | ||
0, | ||
"tdoiron0", | ||
"1234", | ||
"[email protected]", | ||
"Trent Doiron" | ||
); | ||
Thread insertUserThread = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
myDatabaseDao.insertUser(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
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
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