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

Commit

Permalink
Merge pull request #123 from MaximeZmt/kamila/add_ending_screen
Browse files Browse the repository at this point in the history
Kamila/add ending screen
  • Loading branch information
kamilababayeva authored Mar 30, 2022
2 parents 235e2ee + ffac517 commit 477d19a
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 115 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GenreTemporaryTest {
onView(withId(R.id.imagDragonsButton)).check(matches(isDisplayed()))
onView(withId(R.id.billieEilishButton)).check(matches(isDisplayed()))
}

@Test
fun rockButtonClick() {
onView(withId(R.id.rockButton)).perform(click())
Expand All @@ -57,6 +57,7 @@ class GenreTemporaryTest {
fun topButtonClick() {
onView(withId(R.id.topTracksButton)).perform(click())
Thread.sleep(SLEEP_TIME)

intended(hasComponent(TypingGameActivity::class.java.getName()))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ package ch.sdp.vibester.activity

import android.content.Context
import android.content.Intent
import android.media.MediaPlayer
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getColor
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import ch.sdp.vibester.EndBasicGameTemporary
import ch.sdp.vibester.R
import ch.sdp.vibester.helper.GameManager
import ch.sdp.vibester.model.Song
Expand All @@ -25,7 +22,6 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.util.concurrent.CompletableFuture

class TypingGameActivityTest{
private val BY_TAG = "tag.gettoptracks"
Expand Down Expand Up @@ -191,5 +187,52 @@ class TypingGameActivityTest{
}
assertEquals(true, gameManager.getScore()==0)
}
/*
* Currently testing with the *static* values. Change to *dynamic* once the game is correctly
* implemented and all the data are being sent between activities.
*/
@Test
fun checkIntentOnEnding() {

val inputTxt = """
{
"resultCount":1,
"results": [
{"wrapperType":"track", "kind":"song", "artistId":358714030, "collectionId":1574210519, "trackId":1574210894, "artistName":"Test", "collectionName":"Mercury - Act 1", "trackName":"Test", "collectionCensoredName":"Mercury - Act 1", "trackCensoredName":"Monday", "artistViewUrl":"https://music.apple.com/us/artist/imagine-dragons/358714030?uo=4", "collectionViewUrl":"https://music.apple.com/us/album/monday/1574210519?i=1574210894&uo=4", "trackViewUrl":"https://music.apple.com/us/album/monday/1574210519?i=1574210894&uo=4",
"previewUrl":"https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview125/v4/bc/71/fc/bc71fca4-e0bb-609b-5b6e-92296df7b4b6/mzaf_8907306752631175088.plus.aac.p.m4a", "artworkUrl30":"https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/3e/04/c4/3e04c4e7-1863-34cb-e8f3-f168ae5b213e/source/30x30bb.jpg", "artworkUrl60":"https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/3e/04/c4/3e04c4e7-1863-34cb-e8f3-f168ae5b213e/source/60x60bb.jpg", "artworkUrl100":"https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/3e/04/c4/3e04c4e7-1863-34cb-e8f3-f168ae5b213e/source/100x100bb.jpg", "releaseDate":"2021-09-03T12:00:00Z", "collectionExplicitness":"notExplicit", "trackExplicitness":"notExplicit", "discCount":1, "discNumber":1, "trackCount":13, "trackNumber":4, "trackTimeMillis":187896, "country":"USA", "currency":"USD", "primaryGenreName":"Alternative", "isStreamable":true}]
}
"""

val songTest = Song.singleSong(inputTxt)
val gameManager = setGameManager()
gameManager.setNextSong()
gameManager.gameSize = 1
lateinit var temp: Unit

val intent = Intent(ApplicationProvider.getApplicationContext(), TypingGameActivity::class.java)
val scn: ActivityScenario<TypingGameActivity> = ActivityScenario.launch(intent)
val ctx = ApplicationProvider.getApplicationContext() as Context
scn.onActivity {
activity -> temp = activity.checkAnswer(ctx, songTest, gameManager)
}
val incArray: ArrayList<String> =ArrayList(gameManager.getWrongSongs().map{it.getTrackName() +" - "+ it.getArtistName()})

val statNames: ArrayList<String> = arrayListOf()
val statName = "Total Score"
statNames.addAll(arrayOf(statName,statName,statName,statName,statName))

val statVal: ArrayList<String> = arrayListOf()
val score = gameManager.getScore().toString()
statVal.addAll(arrayOf(score, score, score, score, score))

Intents.intended(IntentMatchers.hasComponent(GameEndingActivity::class.java.name))

// Intents.intended(IntentMatchers.hasExtra("playerName", "Default"))
Intents.intended(IntentMatchers.hasExtra("nbIncorrectSong", 1))

Intents.intended(IntentMatchers.hasExtra("str_arr_inc", incArray))
Intents.intended(IntentMatchers.hasExtra("str_arr_name", statNames))
Intents.intended(IntentMatchers.hasExtra("str_arr_val", statVal))
}

}
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
android:usesCleartextTraffic="true">
<activity
android:name=".EndBasicGameTemporary"
android:exported="false" />
<activity
android:name=".activity.IncorrectSongsActivity"
android:exported="false" />
Expand Down
24 changes: 0 additions & 24 deletions app/src/main/java/ch/sdp/vibester/EndBasicGameTemporary.kt

This file was deleted.

28 changes: 24 additions & 4 deletions app/src/main/java/ch/sdp/vibester/activity/TypingGameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat.getColor
import androidx.core.widget.addTextChangedListener
import ch.sdp.vibester.EndBasicGameTemporary
import ch.sdp.vibester.R
import ch.sdp.vibester.api.BitmapGetterApi
import ch.sdp.vibester.api.ItunesMusicApi
Expand Down Expand Up @@ -164,6 +163,7 @@ class TypingGameActivity : AppCompatActivity() {
hasWon(ctx, gameManager.getScore(),true,playedSong)
}else{
hasWon(ctx, gameManager.getScore(),false, playedSong)
gameManager.addWrongSong()
}
playRound(ctx, gameManager)
}
Expand Down Expand Up @@ -235,6 +235,7 @@ class TypingGameActivity : AppCompatActivity() {
* Function to set a new round. It includes reinitializing activity elements,
* and setting new song for the round.
*/

fun playRound(ctx: Context, gameManager: GameManager){
if(gameManager.checkGameStatus() && gameManager.setNextSong()){
findViewById<LinearLayout>(R.id.displayGuess).removeAllViews()
Expand All @@ -246,9 +247,28 @@ class TypingGameActivity : AppCompatActivity() {
else{
if(runnable !=null ){
h.removeCallbacks(runnable!!);}
val i = Intent(this, EndBasicGameTemporary::class.java)
i.putExtra("score", gameManager.getScore().toString())
startActivity(i)
switchToEnding(gameManager)
}
}

private fun switchToEnding(gameManager:GameManager) {
val intent = Intent(this, GameEndingActivity::class.java)
val incArray: ArrayList<String> = ArrayList(gameManager.getWrongSongs().map{it.getTrackName() +" - "+ it.getArtistName()})

val statNames: ArrayList<String> = arrayListOf()
val statName = "Total Score"
statNames.addAll(arrayOf(statName,statName,statName,statName,statName))

val statVal: ArrayList<String> = arrayListOf()
val score = gameManager.getScore().toString()
statVal.addAll(arrayOf(score, score, score, score, score))

intent.putExtra("nbIncorrectSong", gameManager.gameSize - gameManager.getScore())

intent.putStringArrayListExtra("str_arr_inc", incArray)
intent.putStringArrayListExtra("str_arr_name", statNames)
intent.putStringArrayListExtra("str_arr_val", statVal)

startActivity(intent)
}
}
9 changes: 8 additions & 1 deletion app/src/main/java/ch/sdp/vibester/api/ServiceBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ package ch.sdp.vibester.api
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
* Retrofit service that make API calls with chosen API interface.
*/
object ServiceBuilder {
private fun buildRetrofit(baseUrl:String) =
Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build()

fun <T> buildService(baseUrl: String, service: Class<T>): T {
/**
* Connect API interface to a retrofit service to make an API call.
* @return retrofit service with a connected API interface
*/
fun <T> buildService(baseUrl: String, service: Class<T>): T {
return buildRetrofit(baseUrl).create(service)
}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/ch/sdp/vibester/helper/GameManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.concurrent.CompletableFuture
class GameManager: Serializable{
private var score = 0;
private var nextSongInd = 0
private val gameSize = 10
var gameSize = 5
private var numPlayedSongs = 0
private lateinit var currentSong: Song
private var gameSongList: MutableList<Pair<String, String>> = mutableListOf()
Expand Down Expand Up @@ -161,5 +161,4 @@ class GameManager: Serializable{
mediaPlayer.get().stop()
}


}
1 change: 0 additions & 1 deletion app/src/main/java/ch/sdp/vibester/model/SongList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class SongList(jsonMeta: String, method: String) {
val artistDetails = songObj.getJSONObject("artist")
val artistName = artistDetails.getString("name").lowercase()
songList.add(Pair("$songName", "$artistName"))

++i
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/table_shape.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/purple_200"/>
<solid android:color="@color/maximum_yellow_red"/>
<corners android:radius="70px"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
</shape>
17 changes: 0 additions & 17 deletions app/src/main/res/layout/activity_end_basic_game_temporary.xml

This file was deleted.

5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_game_ending_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF00E0"
android:background="@color/floral_white"
tools:context=".activity.GameEndingActivity">

<TextView
Expand Down Expand Up @@ -153,9 +153,10 @@
android:id="@+id/end_go_to_inc"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginTop="44dp"
android:onClick="goToIncorrectlyGuessedSongs"
android:text="@string/game_end__view_incorrect_songs"
android:backgroundTint="@color/cg_blue"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_incorrect_songs_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff00e0"
android:background="@color/floral_white"
tools:context=".activity.IncorrectSongsActivity">

<ScrollView
Expand All @@ -22,7 +22,7 @@
android:id="@+id/incorrect_songs_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
android:orientation="vertical" />
</ScrollView>

<TextView
Expand All @@ -43,6 +43,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:onClick="switchBackToWelcome"
android:backgroundTint="@color/cg_blue"
android:text="@string/game_end__go_back"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down

0 comments on commit 477d19a

Please sign in to comment.