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 #300 from MaximeZmt/maximezmt/playbyartist
Browse files Browse the repository at this point in the history
Maximezmt/playbyartist
  • Loading branch information
MaximeZmt authored May 18, 2022
2 parents cd6927e + 28318d6 commit c6eab9d
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package ch.sdp.vibester.fragment

import android.view.View
import androidx.test.espresso.Espresso.onData
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
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.hasExtra
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
Expand All @@ -21,9 +18,7 @@ import ch.sdp.vibester.activity.TypingGameActivity
import ch.sdp.vibester.launchFragmentInHiltContainer
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.Matcher
import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -67,23 +62,23 @@ class GameSetupFragmentTest {
fun returnFromGenreToGame(){
onView(withId(R.id.local_buzzer_game_button)).perform(scrollTo(), click())
onView(withId(R.id.chooseGame)).check(matches(withEffectiveVisibility(Visibility.GONE)))
onView(withId(R.id.chooseGenre)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)));
onView(withId(R.id.genrePerScoreboard)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)));

onView(withId(R.id.gameSetup_returnToMain)).perform(click())
onView(withId(R.id.chooseGenre)).check(matches(withEffectiveVisibility(Visibility.GONE)))
onView(withId(R.id.genrePerScoreboard)).check(matches(withEffectiveVisibility(Visibility.GONE)))
onView(withId(R.id.chooseGame)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

@Test
fun returnFromSettingToGenre(){
onView(withId(R.id.local_buzzer_game_button)).perform(scrollTo(), click())
onView(withId(R.id.btsButton)).perform(click())
onView(withId(R.id.chooseGenre)).check(matches(withEffectiveVisibility(Visibility.GONE)))
onView(withId(R.id.genrePerScoreboard)).check(matches(withEffectiveVisibility(Visibility.GONE)))
onView(withId(R.id.chooseSetting)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)));

onView(withId(R.id.gameSetup_returnToMain)).perform(click())
onView(withId(R.id.chooseSetting)).check(matches(withEffectiveVisibility(Visibility.GONE)))
onView(withId(R.id.chooseGenre)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
onView(withId(R.id.genrePerScoreboard)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

@Test
Expand Down Expand Up @@ -295,5 +290,12 @@ class GameSetupFragmentTest {
onView(withId(R.id.btsButton)).perform(click())
}

@Test
fun customButtonClick() {
onView(withId(R.id.local_buzzer_game_button)).perform(scrollTo(), click())
onView(withId(R.id.searchArtist)).perform(typeText("muse"), closeSoftKeyboard())
onView(withId(R.id.validateSearch)).perform(scrollTo(), click())
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.util.Log
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.widget.NestedScrollView
Expand Down Expand Up @@ -50,7 +51,7 @@ class ScoreBoardActivity : AppCompatActivity(), OnItemClickListener {
R.id.topTracksButton -> {sortedBy += R.string.top_tracks; genre = "top tracks"}
}

findViewById<ConstraintLayout>(R.id.genrePerScoreboard).visibility = GONE
findViewById<LinearLayout>(R.id.genrePerScoreboard).visibility = GONE
findViewById<NestedScrollView>(R.id.scoreboard_content_scrolling).visibility = VISIBLE

loadPlayersSortedBy(sortedBy)
Expand Down
39 changes: 24 additions & 15 deletions app/src/main/java/ch/sdp/vibester/fragment/GameSetupFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ch.sdp.vibester.fragment
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.text.Editable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -36,6 +36,7 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe
var difficulty = R.string.easy.toString()
var game = "local_buzzer"
var gameSize = R.string.one.toString()
var searchArtistEditable: Editable? = null
lateinit var gameManager: GameManager
/* TODO: OFFLINE
private var hasInternet: Boolean = true
Expand All @@ -60,6 +61,9 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe
view.findViewById<Button>(R.id.billieEilishButton).setOnClickListener(this)
view.findViewById<Button>(R.id.difficulty_proceed).setOnClickListener(this)

searchArtistEditable = view.findViewById<EditText>(R.id.searchArtist).text
view.findViewById<Button>(R.id.validateSearch).setOnClickListener(this)

setReturnBtnListener(view)
setSpinnerListener(view, ctx, R.id.difficulty_spinner, R.array.difficulties_name)
setSpinnerListener(view, ctx, R.id.size_spinner, R.array.game_size_options)
Expand All @@ -69,12 +73,12 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe

private fun setReturnBtnListener(view:View) {
view.findViewById<FloatingActionButton>(R.id.gameSetup_returnToMain).setOnClickListener {
if (view.findViewById<ConstraintLayout>(R.id.chooseGenre).visibility == View.VISIBLE) {
toggleViewsVisibility(goneView = view.findViewById<ConstraintLayout>(R.id.chooseGenre),
if (view.findViewById<LinearLayout>(R.id.genrePerScoreboard).visibility == View.VISIBLE) {
toggleViewsVisibility(goneView = view.findViewById<LinearLayout>(R.id.genrePerScoreboard),
visibleView = view.findViewById<LinearLayout>(R.id.chooseGame))
} else if (view.findViewById<RelativeLayout>(R.id.chooseSetting).visibility == View.VISIBLE) {
toggleViewsVisibility(goneView = view.findViewById<RelativeLayout>(R.id.chooseSetting),
visibleView = view.findViewById<ConstraintLayout>(R.id.chooseGenre))
visibleView = view.findViewById<LinearLayout>(R.id.genrePerScoreboard))
}
}
}
Expand Down Expand Up @@ -181,7 +185,7 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe
this.gameManager = gameManager

toggleViewsVisibility(goneView = requireView().findViewById<LinearLayout>(R.id.chooseGame),
visibleView = requireView().findViewById<ConstraintLayout>(R.id.chooseGenre))
visibleView = requireView().findViewById<ConstraintLayout>(R.id.genrePerScoreboard))
}

/**
Expand All @@ -192,19 +196,22 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe
* @param mode: official game mode name
*/
private fun chooseGenre(method: String = "", artist: String = "", tag: String = "", mode: Int = 0) {
val uri = LastfmUri()

uri.method = method
uri.artist = artist
uri.tag = tag
if (artist != "") {
val uri = LastfmUri()

toggleViewsVisibility(goneView = requireView().findViewById<ConstraintLayout>(R.id.chooseGenre),
visibleView = requireView().findViewById<ConstraintLayout>(R.id.chooseSetting))
uri.method = method
uri.artist = artist
uri.tag = tag

gameManager.gameMode = getString(mode)
AppPreferences.setStr(getString(R.string.preferences_game_genre), getString(mode))
toggleViewsVisibility(
goneView = requireView().findViewById<LinearLayout>(R.id.genrePerScoreboard),
visibleView = requireView().findViewById<ConstraintLayout>(R.id.chooseSetting)
)

setGameSongList(uri)
gameManager.gameMode = getString(mode)
AppPreferences.setStr(getString(R.string.preferences_game_genre), getString(mode))
setGameSongList(uri)
}
}

override fun onClick(v: View?) {
Expand All @@ -221,6 +228,8 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe
R.id.topTracksButton -> chooseGenre(method = LastfmMethod.BY_CHART.method, mode = R.string.top_tracks)
R.id.billieEilishButton -> chooseGenre(method = LastfmMethod.BY_ARTIST.method, artist = "Billie Eilish", mode = R.string.billie_eilish)

R.id.validateSearch -> chooseGenre(method = LastfmMethod.BY_ARTIST.method, artist = searchArtistEditable.toString(), mode = R.string.byArtistSearch)

R.id.difficulty_proceed -> proceedGame()
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_search_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_alignParentTop="true"
android:layout_marginStart="34dp"
android:layout_marginTop="42dp"
android:autofillHints="Enter username to search"
android:hint="Enter username to search"
android:background="@drawable/rounded_edittext"
android:padding="10dp"></EditText>

Expand Down
Loading

0 comments on commit c6eab9d

Please sign in to comment.