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/genres_api
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilababayeva authored Mar 17, 2022
2 parents 5ffc2f6 + 4267f6f commit dcb4e45
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 30 deletions.
28 changes: 24 additions & 4 deletions app/src/androidTest/java/ch/sdp/vibester/GamescreenActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,34 @@ class GamescreenActivityTest {
onView(withId(R.id.scoresTable)).check(matches(isDisplayed()))
}

// FIXME: Find a way to test the popup showing despite not being a component / make robolectric work
/*
@Test
fun clickingButtonLaunchesPopup() {
fun answerIsPresentButInvisibleOnStartup() {
onView(withId(R.id.answer)).check(matches(withEffectiveVisibility(Visibility.INVISIBLE)))
}

@Test
fun clickingBuzzerMakesAnswerVisible() {
var i = 0
while (i < 4) {
onView(withId(R.id.answer)).check(matches(withEffectiveVisibility(Visibility.INVISIBLE)))
onView(withId(i)).perform(click())
onView(withId(R.id.answer)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
i = i + 1
onView(withId(R.id.buttonCorrect)).perform(click())
}
}

@Test
fun clickingAnswerButtonsMakesAnswerInvisible() {
val buttonIdArray = arrayOf(R.id.buttonCorrect, R.id.buttonWrong)
for (butId in buttonIdArray) {
onView(withId(0)).perform(click()) // make answer visible first
onView(withId(butId)).perform(click())
onView(withId(R.id.answer)).check(matches(withEffectiveVisibility(Visibility.INVISIBLE)))
}
}
*/



/*
* Currently testing with the *static* values. Change to *dynamic* once the game is correctly
Expand Down
38 changes: 19 additions & 19 deletions app/src/main/java/ch/sdp/vibester/GamescreenActivity.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package ch.sdp.vibester

import android.content.Intent
import android.opengl.Visibility
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AlertDialogLayout
import androidx.core.view.get


class GamescreenActivity: AppCompatActivity() {
Expand All @@ -22,31 +24,21 @@ class GamescreenActivity: AppCompatActivity() {
*/
val players = arrayOf("Kamila", "Jiabao", "Arda", "Laurynas")

val gamescreenIntent = Intent(this, GamescreenActivity::class.java)
val answer = findViewById<LinearLayout>(R.id.answer)
val answerText = findViewById<TextView>(R.id.answerText)

// hardcoded test values
val song = "Demo"
val artist = "The Placeholders"

val buildPopup = AlertDialog.Builder(this)
buildPopup.setTitle("Solution")
buildPopup.setMessage("The song was " + song + " by " + artist)

buildPopup.setPositiveButton("Correct") { dialog, which ->
Toast.makeText(applicationContext,
"Congrats!", Toast.LENGTH_SHORT).show()
}

buildPopup.setNegativeButton("Wrong") { dialog, which ->
Toast.makeText(applicationContext,
"Too bad!", Toast.LENGTH_SHORT).show()
}
answerText.text= "The song was $song by $artist"

val allPoints = arrayOf(1, 2, 3, 4)

buildScores(players, allPoints)
buildBuzzers(players, buildPopup)

buildBuzzers(players, answer)
setAnswerButton(answer, findViewById(R.id.buttonCorrect))
setAnswerButton(answer, findViewById(R.id.buttonWrong))
}

/*
Expand Down Expand Up @@ -88,7 +80,7 @@ class GamescreenActivity: AppCompatActivity() {
/*
Programmatically builds the buzzers according to the number and names of players.
*/
private fun buildBuzzers(players: Array<String>, popup: AlertDialog.Builder) {
private fun buildBuzzers(players: Array<String>, answer: LinearLayout) {

val buzzers = findViewById<LinearLayout>(R.id.buzzersLayout)
val buttons = arrayOfNulls<Button>(players.size)
Expand All @@ -98,19 +90,26 @@ class GamescreenActivity: AppCompatActivity() {
for (pName in players) {

val button = Button(this)
button.id = i
button.text = pName
button.width = 100
button.height = 150
button.height = 0
buttons.set(i, button)
button.setOnClickListener {
popup.show()
answer.visibility = android.view.View.VISIBLE
}
buzzers.addView(button)

i = i + 1
}
}

private fun setAnswerButton(answer: LinearLayout, button: Button) {
button.setOnClickListener {
answer.visibility = android.view.View.INVISIBLE
}
}

fun switchToEnding(view: View) {
val intent = Intent(this, GameEndingScreen::class.java)
//MOCK VALUES FOR INCORRECT SONGS, ADAPT FROM GAME DATA IN THE FUTURE
Expand Down Expand Up @@ -143,4 +142,5 @@ class GamescreenActivity: AppCompatActivity() {
intent.putExtra("stat_res_1", "General Kenobi")
startActivity(intent)
}

}
57 changes: 50 additions & 7 deletions app/src/main/res/layout/activity_gamescreen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,73 @@

<LinearLayout
android:id="@+id/buzzersLayout"
android:layout_width="385dp"
android:layout_height="433dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="16dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/go_to_end"
app:layout_constraintVertical_bias="0.0">
app:layout_constraintTop_toBottomOf="@+id/scoresTable">


</LinearLayout>

<LinearLayout
android:id="@+id/answer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="116dp"
android:orientation="vertical"
android:visibility="invisible"
android:gravity="center"
android:background="#AAAAAA"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scoresTable">

<TextView
android:id="@+id/answerText"
android:layout_width="275dp"
android:layout_height="wrap_content"
android:gravity="center" />

<Button
android:id="@+id/buttonCorrect"
android:layout_width="125dp"
android:layout_height="40dp"
android:gravity="center"
android:text="@string/correct" />

<Button
android:id="@+id/buttonWrong"
android:layout_width="125dp"
android:layout_height="40dp"
android:gravity="center"
android:text="@string/wrong" />

</LinearLayout>

<TableLayout
android:id="@+id/scoresTable"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_height="0dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="114dp"
android:gravity="center"
app:layout_constraintBottom_toTopOf="@+id/answer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></TableLayout>
app:layout_constraintTop_toTopOf="parent">

</TableLayout>

<Button
android:id="@+id/go_to_end"
Expand Down

0 comments on commit dcb4e45

Please sign in to comment.