Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into kamila/ui_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeZmt authored May 4, 2022
2 parents 373178e + bba638a commit cabad35
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class TypingGameActivityTest {
@get:Rule(order = 0)
var hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val activityRule = ActivityScenarioRule(TypingGameActivity::class.java)

@Before
fun setUp() {
hiltRule.inject()
Expand All @@ -64,10 +61,10 @@ class TypingGameActivityTest {
every { mockUsersRepo.updateFieldInt(any(), any(), any(), any()) } answers {}
every { mockUsersRepo.setFieldValue(any(), any(), any()) } answers {}
every { mockUsersRepo.updateSubFieldInt(any(), any(), any(), any(), any()) } answers {}

}

private val expectedSize = 200

private fun setGameManager(numSongs:Int = 1, valid: Boolean = true): TypingGameManager {
val epilogue = "{\"tracks\":{\"track\":["
val prologue =
Expand Down Expand Up @@ -103,8 +100,12 @@ class TypingGameActivityTest {
@Test
fun textGenTest() {
val txtInput = "hello"
val intent =
Intent(ApplicationProvider.getApplicationContext(), TypingGameActivity::class.java)
val scn: ActivityScenario<TypingGameActivity> = ActivityScenario.launch(intent)
val ctx = ApplicationProvider.getApplicationContext() as Context
val myText = GameActivity.generateText(txtInput, ctx)

assertEquals(txtInput, myText.text.toString())
assertEquals(expectedSize, myText.minHeight)
assertEquals(ContextCompat.getColor(ctx, R.color.black), myText.textColors.defaultColor)
Expand All @@ -122,6 +123,9 @@ class TypingGameActivityTest {
"""

val mySong = Song.singleSong(inputTxt)
val intent =
Intent(ApplicationProvider.getApplicationContext(), TypingGameActivity::class.java)
val scn: ActivityScenario<TypingGameActivity> = ActivityScenario.launch(intent)

val ctx = ApplicationProvider.getApplicationContext() as Context
val myTest = GameActivity.generateImage(mySong, ctx)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ch/sdp/vibester/activity/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ open class GameActivity : AppCompatActivity() {
/**
* Function called in the end of each round.
*/
open fun endRound(gameManager: GameManager) {
open fun endRound(gameManager: GameManager, callback: (()->Unit)?= null) {
checkRunnable()
if (isEndGame(gameManager)) {
callback?.invoke()
switchToEnding(gameManager)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class LyricsBelongGameActivity : GameActivity() {
barTimer(ctx, findViewById(R.id.progressBarLyrics))
}

override fun endRound(gameManager: GameManager) {
super.endRound(gameManager)
override fun endRound(gameManager: GameManager, callback: (() -> Unit)?) {
super.endRound(gameManager, null)
toggleBtnVisibility(R.id.nextSongButton, true)
}

Expand Down
26 changes: 13 additions & 13 deletions app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.widget.*
import androidx.core.content.ContextCompat.getColor
import androidx.core.widget.addTextChangedListener
import ch.sdp.vibester.R
import ch.sdp.vibester.TestMode
import ch.sdp.vibester.api.ItunesMusicApi
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
Expand Down Expand Up @@ -208,22 +207,12 @@ class TypingGameActivity : GameActivity() {
* Function called in the end of each round. Displays the button "Next" and
* sets the next songs to play.
*/
override fun endRound(gameManager: GameManager){
override fun endRound(gameManager: GameManager, callback: (() -> Unit)?) {
gameIsOn = false
findViewById<EditText>(R.id.yourGuessET).isEnabled = false
//checkRunnable()
super.endRound(gameManager)
super.endRound(gameManager,this::setScores)
//TODO: is it ok for the last round to go to the end game directly without waiting for the next btn?
toggleNextBtnVisibility(true)

// If currently not in test and has finished the game, update the scores
if (isEndGame(gameManager)) {
dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "totalGames", 1, method = "sum")
dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "correctSongs", gameManager.getCorrectSongs().size, method = "sum")
dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "bestScore", gameManager.getScore(), method = "best")
dataGetter.updateSubFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getScore(), "scores", gameManager.gameMode, method = "best")
}

}

/**
Expand All @@ -241,6 +230,17 @@ class TypingGameActivity : GameActivity() {
barTimer(findViewById(R.id.progressBarTyping), ctx, gameManager)
}

/**
* Function to set scores in the end of the game
*/
private fun setScores() {
if(::gameManager.isInitialized){
dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "totalGames", 1, method = "sum")
dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "correctSongs", gameManager.getCorrectSongs().size, method = "sum")
dataGetter.updateFieldInt(FireBaseAuthenticator.getCurrentUID(), "bestScore", gameManager.getScore(), method = "best")
dataGetter.updateSubFieldInt(FireBaseAuthenticator.getCurrentUID(), gameManager.getScore(), "scores", gameManager.gameMode, method = "best")
}
}
/**
* Functions for testing
*/
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/ch/sdp/vibester/database/DataGetter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ class DataGetter @Inject constructor() {
* @param uid id of the new user
*/
fun createUser(email: String, username: String, callback: (String) -> Unit, uid: String) {
val newUser = User()
newUser.email = email
newUser.username = username
newUser.uid = uid
val newUser = User(email = email, username = username, uid = uid)
dbUserRef.child(uid).setValue(newUser)
.addOnSuccessListener {
callback(email)
Expand Down

0 comments on commit cabad35

Please sign in to comment.