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

Margaux/local game screen #53

Merged
merged 23 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions app/src/androidTest/java/ch/sdp/vibester/GameSetupScreenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GameSetupScreenTest {
@Test
fun checkIntentOnProceedDefault() { //FILLER TEST
onView(withId(R.id.nb_players_selected)).perform(click())
intended(hasComponent(WelcomeScreen::class.java.name))
intended(hasComponent(GamescreenActivity::class.java.name))
intended(hasExtra("Number of players", "One"))
}

Expand All @@ -82,7 +82,7 @@ class GameSetupScreenTest {
onView(withId(R.id.nb_player_spinner)).perform(click())
onData(Matchers.anything()).atPosition(0).perform(click())
onView(withId(R.id.nb_players_selected)).perform(click())
intended(hasComponent(WelcomeScreen::class.java.name))
intended(hasComponent(GamescreenActivity::class.java.name))
intended(hasExtra("Number of players", "One"))
}

Expand All @@ -91,7 +91,7 @@ class GameSetupScreenTest {
onView(withId(R.id.nb_player_spinner)).perform(click())
onData(Matchers.anything()).atPosition(1).perform(click())
onView(withId(R.id.nb_players_selected)).perform(click())
intended(hasComponent(WelcomeScreen::class.java.name))
intended(hasComponent(GamescreenActivity::class.java.name))
intended(hasExtra("Number of players", "Two"))
}

Expand All @@ -100,7 +100,7 @@ class GameSetupScreenTest {
onView(withId(R.id.nb_player_spinner)).perform(click())
onData(Matchers.anything()).atPosition(2).perform(click())
onView(withId(R.id.nb_players_selected)).perform(click())
intended(hasComponent(WelcomeScreen::class.java.name))
intended(hasComponent(GamescreenActivity::class.java.name))
intended(hasExtra("Number of players", "Three"))
}

Expand All @@ -109,7 +109,7 @@ class GameSetupScreenTest {
onView(withId(R.id.nb_player_spinner)).perform(click())
onData(Matchers.anything()).atPosition(3).perform(click())
onView(withId(R.id.nb_players_selected)).perform(click())
intended(hasComponent(WelcomeScreen::class.java.name))
intended(hasComponent(GamescreenActivity::class.java.name))
intended(hasExtra("Number of players", "Four"))
}
}
56 changes: 56 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/GamescreenActivityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ch.sdp.vibester

import android.app.AlertDialog
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.hamcrest.CoreMatchers.allOf
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)

class GamescreenActivityTest {

@get:Rule
val testRule = ActivityScenarioRule(
GamescreenActivity::class.java
)

@Before
fun setUp() {
Intents.init()
}

@After
fun clean() {
Intents.release()
}

@Test
fun buzzerLayoutIsDisplayed() {
onView(withId(R.id.buzzersLayout)).check(matches(isDisplayed()))
}

@Test
fun scoresLayoutIsDisplayed() {
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
/*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove empty test in comment maybe ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's why she leaves the FIXME here

@Test
fun clickingButtonLaunchesPopup() {


}
*/
}
85 changes: 44 additions & 41 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.sdp.vibester">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity
android:name=".profile.ProfileSetup"
android:exported="false" />
<activity
android:name=".MusicTemporary"
android:exported="false" />
<activity
android:name=".GameSetupScreen"
android:exported="false" />
<activity android:name=".scoreboard.ScoreBoardActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".WelcomeScreen"
android:exported="false" />
<activity
android:name=".GreetingActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.sdp.vibester">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity
android:name="ch.sdp.vibester.GamescreenActivity"
android:exported="false" />
<activity
android:name=".profile.ProfileSetup"
android:exported="false" />
<activity
android:name=".MusicTemporary"
android:exported="false" />
<activity
android:name=".GameSetupScreen"
android:exported="false" />
<activity android:name=".scoreboard.ScoreBoardActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".WelcomeScreen"
android:exported="false" />
<activity
android:name=".GreetingActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
2 changes: 1 addition & 1 deletion app/src/main/java/ch/sdp/vibester/GameSetupScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GameSetupScreen : AppCompatActivity(), AdapterView.OnItemSelectedListener
override fun onNothingSelected(parent: AdapterView<*>) {text = "One"}

fun proceedToGame(view: View) { //FILLER INTENT
val intent = Intent(this, WelcomeScreen::class.java)
val intent = Intent(this, GamescreenActivity::class.java)
intent.putExtra("Number of players", text)
startActivity(intent)
}
Expand Down
112 changes: 112 additions & 0 deletions app/src/main/java/ch/sdp/vibester/GamescreenActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package ch.sdp.vibester

import android.content.Intent
import android.os.Bundle
import android.view.Gravity
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AlertDialogLayout


class GamescreenActivity: AppCompatActivity() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add javadoc for whole class ?


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_gamescreen)

/* number of players for the game
currently hardcoded as a placeholder
will be retrieved from intent launched from the game setup screen
*/
val players = arrayOf("Kamila", "Jiabao", "Arda", "Laurynas")

val gamescreenIntent = Intent(this, GamescreenActivity::class.java)

// 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 ->
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not urgent now but should consider creating a method to send toast(...)

Toast.makeText(applicationContext,
"Congrats!", Toast.LENGTH_SHORT).show()
}

buildPopup.setNegativeButton("Wrong") { dialog, which ->
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

Toast.makeText(applicationContext,
"Too bad!", Toast.LENGTH_SHORT).show()
}

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

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

}

/*
Programmatically builds the table of scores according to the number of players
*/
private fun buildScores(players: Array<String>, allPoints: Array<Int>) {

val scores = findViewById<LinearLayout>(R.id.scoresTable)
val viewsOfPoints = arrayOfNulls<TableRow>(players.size)

var i = 0

for (pName in players) {

val score = TableRow(this)
score.gravity = Gravity.CENTER

val nameView = TextView(this)
nameView.text = pName
nameView.height = 75
nameView.width = 300
nameView.gravity = Gravity.LEFT

val points = TextView(this)
points.text = allPoints[i].toString()
points.height = 75
points.width = 150
points.gravity = Gravity.RIGHT

score.addView(nameView)
score.addView(points)
viewsOfPoints.set(i, score)
scores.addView(score)

i = i + 1
}
}

/*
Programmatically builds the buzzers according to the number and names of players.
*/
private fun buildBuzzers(players: Array<String>, popup: AlertDialog.Builder) {

val buzzers = findViewById<LinearLayout>(R.id.buzzersLayout)
val buttons = arrayOfNulls<Button>(players.size)

var i = 0

for (pName in players) {

val button = Button(this)
button.text = pName
button.width = 100
button.height = 150
buttons.set(i, button)
button.setOnClickListener {
popup.show()
}
buzzers.addView(button)

i = i + 1
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/ch/sdp/vibester/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.PopupMenu
import androidx.appcompat.app.AppCompatActivity
import ch.sdp.vibester.profile.ProfileDataProvider
import ch.sdp.vibester.scoreboard.ScoreBoardActivity
Expand Down Expand Up @@ -48,6 +49,7 @@ class MainActivity : AppCompatActivity() {
btnScoreboard.setOnClickListener {
startActivity(scoreboardIntent)
}

}

fun switchToWelcome(view: View) {
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/res/layout/activity_gamescreen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/buzzersLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="20dp"
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_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scoresTable" />

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



</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<string name="button_txt">Enter</string>
<string name="hint_input_txt">Enter</string>
<string name="scoreboard">S C O R E B O A R D</string>
<string name="the_song_was">The song was...</string>
<string name="wrong">Wrong</string>
<string name="correct">Correct</string>
<string name="best_score">Best Score</string>
<string name="total_games">Total Games</string>
<string name="correct_songs">Correct Songs</string>
Expand All @@ -19,7 +22,6 @@
<string name="welcome_scoreboard">SCOREBOARD</string>
<string name="listen_to_music">LISTEN TO MUSIC</string>
<string name="settings">SETTINGS</string>

<string-array name="nb_players">
<item>One</item>
<item>Two</item>
Expand Down