-
Notifications
You must be signed in to change notification settings - Fork 0
Rework Authentication #180
Changes from all commits
475483a
8460d2c
43a062e
6e2920a
41eb382
f2ba5d9
55e7377
d45b7df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
package ch.sdp.vibester.activity | ||
|
||
import android.graphics.Bitmap | ||
import android.os.Bundle | ||
import android.text.InputType | ||
import android.util.Log | ||
import android.view.Window | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.graphics.drawable.toBitmap | ||
import ch.sdp.vibester.R | ||
import ch.sdp.vibester.api.BitmapGetterApi | ||
import ch.sdp.vibester.model.UserSharedPref | ||
import ch.sdp.vibester.database.UsersRepo | ||
import ch.sdp.vibester.helper.IntentSwitcher | ||
import ch.sdp.vibester.profile.UserProfile | ||
import com.google.android.material.floatingactionbutton.FloatingActionButton | ||
import com.google.firebase.auth.FirebaseAuth | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.launch | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
|
@@ -35,11 +42,15 @@ class ProfileActivity : AppCompatActivity() { | |
|
||
setContentView(R.layout.activity_profile) | ||
|
||
setupProfile(UserSharedPref.getUser(this)) | ||
setupProfile(UserSharedPref.getUser(applicationContext)) | ||
|
||
val editUsername = findViewById<Button>(R.id.editUser) | ||
val editHandle = findViewById<Button>(R.id.editHandle) | ||
|
||
val logoutbutton = findViewById<Button>(R.id.logout) | ||
|
||
val retToMain = findViewById<FloatingActionButton>(R.id.profile_returnToMain) | ||
|
||
editUsername.setOnClickListener { | ||
showGeneralDialog(R.id.username, "username") | ||
} | ||
|
@@ -48,6 +59,15 @@ class ProfileActivity : AppCompatActivity() { | |
showGeneralDialog(R.id.handle, "handle") | ||
} | ||
|
||
retToMain.setOnClickListener{ | ||
IntentSwitcher.switchBackToWelcome(this) | ||
} | ||
|
||
logoutbutton.setOnClickListener{ | ||
FirebaseAuth.getInstance().signOut() | ||
IntentSwitcher.switchBackToWelcome(this) | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
@@ -105,24 +125,36 @@ class ProfileActivity : AppCompatActivity() { | |
|
||
|
||
private fun setupProfile(user: UserProfile){ | ||
findViewById<TextView>(R.id.handle).text = user.handle | ||
findViewById<TextView>(R.id.username).text = user.username | ||
findViewById<TextView>(R.id.totalGames).text = user.totalGames.toString() | ||
findViewById<TextView>(R.id.correctSongs).text = user.correctSongs.toString() | ||
findViewById<TextView>(R.id.bestScore).text = user.bestScore.toString() | ||
findViewById<TextView>(R.id.ranking).text = user.ranking.toString() | ||
|
||
// Currently assuming that empty username means no user ! | ||
if (user.username != ""){ | ||
findViewById<TextView>(R.id.username).text = user.username | ||
if (user.handle != ""){ | ||
findViewById<TextView>(R.id.handle).text = user.handle | ||
} | ||
findViewById<TextView>(R.id.totalGames).text = user.totalGames.toString() | ||
findViewById<TextView>(R.id.correctSongs).text = user.correctSongs.toString() | ||
findViewById<TextView>(R.id.bestScore).text = user.bestScore.toString() | ||
findViewById<TextView>(R.id.ranking).text = user.ranking.toString() | ||
} | ||
CoroutineScope(Dispatchers.Main).launch { | ||
val task = async(Dispatchers.IO) { | ||
try { | ||
val bit = BitmapGetterApi.download("https://" + user.image) | ||
bit.get() | ||
Log.e(getString(R.string.log_tag),user.image) | ||
val bit = BitmapGetterApi.download("https://raw.githubusercontent.com/Ashwinvalento/cartoon-avatar/master/lib/images/male/45.png") | ||
bit.get(10, TimeUnit.SECONDS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the user image will be displayed during 10 seconds? isnt it a lot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No the 10 sec is the timeout to get the image. Indeed it is a magic number for the moment, but I may set it a global var for all async timeout and should choose the value later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got you! |
||
}catch (e: Exception){ | ||
null | ||
} | ||
} | ||
val bm = task.await() | ||
findViewById<ImageView>(R.id.avatar).setImageBitmap(bm) | ||
|
||
if(bm != null){ | ||
val avatar = findViewById<ImageView>(R.id.avatar) | ||
avatar.setImageBitmap(Bitmap.createScaledBitmap(bm, 1000,1000, false)) | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,26 +8,36 @@ import android.view.Window.FEATURE_NO_TITLE | |
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import ch.sdp.vibester.R | ||
import ch.sdp.vibester.auth.FireBaseAuthenticator | ||
import com.google.firebase.database.ktx.database | ||
import com.google.firebase.ktx.Firebase | ||
import ch.sdp.vibester.model.UserSharedPref | ||
|
||
class WelcomeActivity : AppCompatActivity() { | ||
|
||
// For test purpose | ||
companion object{ | ||
var testLoggedIn: Boolean = false | ||
|
||
fun setLoggedIn(){ | ||
testLoggedIn = true | ||
} | ||
|
||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
requestWindowFeature(FEATURE_NO_TITLE) | ||
supportActionBar?.hide() | ||
setContentView(R.layout.activity_welcome_screen) | ||
|
||
val tv = findViewById<TextView>(R.id.user_status) | ||
val username = UserSharedPref.getUser(this).username | ||
if(username != "") | ||
val userStatusTextValue = findViewById<TextView>(R.id.user_status) | ||
if(FireBaseAuthenticator.isLoggedIn() || testLoggedIn) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are pushing to the main branch, I believe the code should be as clean as possible. So I am not sure whether the testing variables hsould be in main There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is testing var for cirrus, this is necessary (trick to allow unit test to test the below code, otherwise impossible) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohhh, i seee |
||
{ | ||
tv.text = "User: " + username | ||
userStatusTextValue.text = "User: " + FireBaseAuthenticator.getCurrentUserMail() | ||
} | ||
|
||
val currentEmail = UserSharedPref.getUser(this).email | ||
if (currentEmail != null){ | ||
UserSharedPref.userReset(this, currentEmail) | ||
} | ||
|
||
} | ||
|
||
private fun sendDirectIntent(arg: Class<*>?) { | ||
|
@@ -40,17 +50,17 @@ class WelcomeActivity : AppCompatActivity() { | |
} | ||
|
||
fun switchToProfile(view: View) { | ||
sendDirectIntent(ProfileActivity::class.java) | ||
if (FireBaseAuthenticator.isLoggedIn() || testLoggedIn){ | ||
sendDirectIntent(ProfileActivity::class.java) | ||
}else{ | ||
sendDirectIntent(AuthenticationActivity::class.java) | ||
} | ||
} | ||
|
||
fun switchToScoreboard(view: View) { | ||
sendDirectIntent(ScoreBoardActivity::class.java) | ||
} | ||
|
||
fun switchToSettings(view: View) { | ||
sendDirectIntent(AuthenticationActivity::class.java) | ||
} | ||
|
||
fun switchToDownload(view: View) { | ||
sendDirectIntent(DownloadActivity::class.java) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something to think about...
There are three options about profile images:
We use profile picture in scoreboard, user search and in a profile account. If we take scoreboard, there might be a lot of profiles without the image, maybe it would be better if each of the profile has a default image, so we dont do extra check and upload image your way. Or it would be better to have an image locally, since it is same and we dont upload your way every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we will see and try to solve this issue. Currently this is just a random image to test the display. I will rework it in part 2. There was issue with the database and account code that I will solve in part 2.