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

Commit

Permalink
fixed reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeZmt committed May 11, 2022
1 parent 683a427 commit 4459d32
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ch.sdp.vibester.helper

import android.content.Intent
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.GameSetupActivity
import ch.sdp.vibester.activity.WelcomeActivity
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.io.Serializable


@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
class IntentSwitcherTest {
@get:Rule
var hiltRule = HiltAndroidRule(this)


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

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

@Test
fun checkIntentOnPlay() {
val intent = Intent(ApplicationProvider.getApplicationContext(), WelcomeActivity::class.java)
val scn: ActivityScenario<WelcomeActivity> = ActivityScenario.launch(intent)

val testMap: HashMap<String, Serializable> = HashMap()
testMap.put("test", true)

IntentSwitcher.switch(ApplicationProvider.getApplicationContext(), GameSetupActivity::class.java, testMap)
Intents.intended(IntentMatchers.hasComponent(GameSetupActivity::class.java.name))
Intents.intended(IntentMatchers.hasExtra("test", true))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class AuthenticationActivity : AppCompatActivity() {
* Listener bound to the red return button in the Authentication activity.
*/
fun returnToMainListener(view: View) {
IntentSwitcher.switch(this, WelcomeActivity::class.java, null)
IntentSwitcher.switch(this, WelcomeActivity::class.java)
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DeleteSongsActivity : AppCompatActivity() {
setContentView(R.layout.activity_delete_songs)

findViewById<FloatingActionButton>(R.id.delete_returnToMain).setOnClickListener {
IntentSwitcher.switch(this, WelcomeActivity::class.java, null)
IntentSwitcher.switch(this, WelcomeActivity::class.java)
}

val layout: LinearLayout = findViewById(R.id.delete_songs_linear)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DownloadActivity : AppCompatActivity() {
}

findViewById<FloatingActionButton>(R.id.download_returnToMain).setOnClickListener {
IntentSwitcher.switch(this, WelcomeActivity::class.java, null)
IntentSwitcher.switch(this, WelcomeActivity::class.java)
}

var broadcast = object:BroadcastReceiver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GameSetupActivity : AppCompatActivity(), AdapterView.OnItemSelectedListene
private fun setReturnBtnListener() {
findViewById<FloatingActionButton>(R.id.gameSetup_returnToMain).setOnClickListener {
if (findViewById<LinearLayout>(R.id.chooseGame).visibility == VISIBLE) {
IntentSwitcher.switch(this, WelcomeActivity::class.java, null)
IntentSwitcher.switch(this, WelcomeActivity::class.java)
finish()
} else if (findViewById<ConstraintLayout>(R.id.chooseGenre).visibility == VISIBLE) {
findViewById<LinearLayout>(R.id.chooseGame).visibility = VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class IncorrectSongsActivity : AppCompatActivity() {

findViewById<Button>(R.id.incorrect_songs_back_to_welcome)
.setOnClickListener {
IntentSwitcher.switch(this, WelcomeActivity::class.java, null)
IntentSwitcher.switch(this, WelcomeActivity::class.java)
}

if (intent.hasExtra("str_arr_inc")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ class LyricsBelongGameActivity : GameActivity() {
getAndCheckLyrics(ctx, song, speechInput, gameManager)
}

fun getSong(): Song {
return song
}

fun testProgressBar(progressTime:Int = 0) {
superTestProgressBar(findViewById(R.id.progressBarLyrics), progressTime)
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ch/sdp/vibester/activity/ProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ProfileActivity : AppCompatActivity() {
private fun setLogOutBtnListener() {
findViewById<Button>(R.id.logout).setOnClickListener {
FirebaseAuth.getInstance().signOut()
IntentSwitcher.switch(this, WelcomeActivity::class.java, null)
IntentSwitcher.switch(this, WelcomeActivity::class.java)
finish()
}
}
Expand All @@ -96,7 +96,7 @@ class ProfileActivity : AppCompatActivity() {
*/
private fun setRetToMainBtnListener() {
findViewById<FloatingActionButton>(R.id.profile_returnToMain).setOnClickListener {
IntentSwitcher.switch(this, WelcomeActivity::class.java, null)
IntentSwitcher.switch(this, WelcomeActivity::class.java)
finish()
}
}
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/ch/sdp/vibester/activity/WelcomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ class WelcomeActivity : AppCompatActivity() {
}

fun switchToPlay(view: View) {
IntentSwitcher.switch(this, GameSetupActivity::class.java, null)
IntentSwitcher.switch(this, GameSetupActivity::class.java)
}

fun switchToProfile(view: View) {
if (authenticator.isLoggedIn()){
IntentSwitcher.switch(this, ProfileActivity::class.java, null)
IntentSwitcher.switch(this, ProfileActivity::class.java)
}else{
IntentSwitcher.switch(this, AuthenticationActivity::class.java, null)
IntentSwitcher.switch(this, AuthenticationActivity::class.java)
}
}

fun switchToScoreboard(view: View) {
IntentSwitcher.switch(this, ScoreBoardActivity::class.java, null)
IntentSwitcher.switch(this, ScoreBoardActivity::class.java)
}

fun switchToDownload(view: View) {
IntentSwitcher.switch(this, DownloadActivity::class.java, null)
IntentSwitcher.switch(this, DownloadActivity::class.java)
}

fun switchToSearch(view: View) {
IntentSwitcher.switch(this, SearchUserActivity::class.java, null)
IntentSwitcher.switch(this, SearchUserActivity::class.java)
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/ch/sdp/vibester/helper/IntentSwitcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package ch.sdp.vibester.helper

import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import java.io.Serializable

class IntentSwitcher private constructor() {
companion object {
fun switch(ctx: Context, arg: Class<*>?, extrasMap: Map<String, Serializable>?) {
fun switch(ctx: Context, arg: Class<*>?, extrasMap: Map<String, Serializable>? = null) {
val intent = Intent(ctx, arg)
intent.setFlags(FLAG_ACTIVITY_NEW_TASK)
if (extrasMap != null) {
extrasMap.forEach{
entry -> intent.putExtra(entry.key, entry.value)
Expand Down

0 comments on commit 4459d32

Please sign in to comment.