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

Kamila/scoreboard fragment #311

Merged
merged 19 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f973c7c
add scoreboard logo
kamilababayeva May 19, 2022
40f8eb1
scoreboard_scoreboard: rename to fragment_screoboard
kamilababayeva May 19, 2022
5f49374
bottom_menu: ad scoreboard button
kamilababayeva May 19, 2022
5e466f7
bottom_navigation: add scoreboard button
kamilababayeva May 19, 2022
ccd9414
genre_for_scoreboard: remove onClick methid
kamilababayeva May 19, 2022
5a5dbf9
fragment_layout_screen: remove onlick
kamilababayeva May 19, 2022
ecf11f3
WelcomScreenFragment: remove scorebaord button functionality
kamilababayeva May 19, 2022
46ebfe1
ScoreboardActivity: move to Scoreboard Fragment
kamilababayeva May 19, 2022
3464dca
AndroidManifest:remove ScoreboardActivity
kamilababayeva May 19, 2022
44392a4
WelcomeScreenFragmentTest: remove scoreboard test
kamilababayeva May 19, 2022
e52feb1
move screoboard activity test to screoboard fragment test
kamilababayeva May 19, 2022
9381bc7
Merge branch 'main' into kamila/scoreboard-fragment
MaximeZmt May 20, 2022
1776477
ScoreBoardFragment: fix the review comments
kamilababayeva May 20, 2022
f3130a9
Merge branch 'main' into kamila/scoreboard-fragment
kamilababayeva May 20, 2022
da0e8d3
ScoreBoadFragment: set recycle view in onViewCreated
kamilababayeva May 20, 2022
233b144
ScoreboardFragment: remove unnecessary test
kamilababayeva May 20, 2022
a479ad5
set view and context properly
kamilababayeva May 20, 2022
eac0181
ScoreBoardFragment: set view fromthe beginning
kamilababayeva May 20, 2022
147126b
Scoreboard fragment: fix the layout
kamilababayeva May 20, 2022
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch.sdp.vibester.activity
package ch.sdp.vibester.fragment

import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
Expand All @@ -9,9 +9,9 @@ import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.launchFragmentInHiltContainer
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.CoreMatchers.not
Expand All @@ -23,18 +23,19 @@ import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class ScoreBoardActivityTest {
class ScoreBoardFragmentTest {

@get:Rule(order=0)
var hiltRule = HiltAndroidRule(this)

@get:Rule(order=1)
val activityRule = ActivityScenarioRule(ScoreBoardActivity::class.java)

@Before
fun setUp() {
hiltRule.inject()
Intents.init()
launchFragmentInHiltContainer<ScoreBoardFragment>(
themeResId = R.style.AppTheme
)
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,6 @@ class WelcomeScreenFragmentTest {
onView(withId(R.id.welcome_profile)).perform(click())
intended(hasComponent(MyProfileActivity::class.java.name))
}

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

onView(withId(R.id.welcome_scoreboard)).perform(click())
intended(hasComponent(ScoreBoardActivity::class.java.name))
}

@Test
fun checkIntentOnDownload() {
val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java)
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@
android:name=".activity.profile.PublicProfileActivity"
android:windowSoftInputMode="adjustPan"
android:exported="false" />
<activity
android:name=".activity.ScoreBoardActivity"
android:exported="false"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.AuthenticationActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package ch.sdp.vibester.activity
package ch.sdp.vibester.fragment

import android.content.ContentValues
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.widget.NestedScrollView
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ch.sdp.vibester.R
Expand All @@ -26,42 +28,46 @@ import com.google.firebase.database.ValueEventListener
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ScoreBoardActivity : AppCompatActivity(), OnItemClickListener {
class ScoreBoardFragment : Fragment(), OnItemClickListener, View.OnClickListener{
private val dbRef: DatabaseReference = Database.get().getReference("users")
private var players: MutableList<User>? = null
private var userScoreboardAdapter: UserScoreboardAdapter? = null
private var genre: String = ""

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.scoreboard_scoreboard)
setSupportActionBar(findViewById(R.id.toolbar))
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_scoreboard, container, false)
view.findViewById<Button>(R.id.kpopButton).setOnClickListener(this)
view.findViewById<Button>(R.id.rockButton).setOnClickListener(this)
view.findViewById<Button>(R.id.btsButton).setOnClickListener(this)
view.findViewById<Button>(R.id.topTracksButton).setOnClickListener(this)
view.findViewById<Button>(R.id.imagDragonsButton).setOnClickListener(this)
view.findViewById<Button>(R.id.billieEilishButton).setOnClickListener(this)
return view
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupRecycleView()
players = ArrayList()
}

fun selectScoreboard(view: View) {
var sortedBy = "scores/"
// can't use R.string for genre (getOrDefault in setScore in UserScoreboardAdapter)
when (view.id) {
R.id.btsButton -> {sortedBy += R.string.bts; genre = "BTS"}
R.id.kpopButton -> {sortedBy += R.string.kpop; genre = "kpop"}
R.id.imagDragonsButton -> {sortedBy += R.string.imagine_dragons; genre = "Imagine Dragons"}
R.id.billieEilishButton -> {sortedBy += R.string.billie_eilish; genre = "Billie Eilish"}
R.id.rockButton -> {sortedBy += R.string.rock; genre = "rock"}
R.id.topTracksButton -> {sortedBy += R.string.top_tracks; genre = "top tracks"}
}
fun selectScoreboard() {
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved
println("here")
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved
val sortedBy = "scores/" + genre
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved

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

loadPlayersSortedBy(sortedBy)
}

private fun setupRecycleView() {
findViewById<RecyclerView>(R.id.recycler_view).apply {
requireView().findViewById<RecyclerView>(R.id.recycler_view).apply {
layoutManager = LinearLayoutManager(context)
adapter = players?.let { UserScoreboardAdapter(it, genre, this@ScoreBoardActivity) }
adapter = players?.let { UserScoreboardAdapter(it, genre, this@ScoreBoardFragment) }
setHasFixedSize(true)
}
}
Expand Down Expand Up @@ -98,17 +104,41 @@ class ScoreBoardActivity : AppCompatActivity(), OnItemClickListener {

private fun showPlayersPosition(players: MutableList<User>?) {
userScoreboardAdapter = UserScoreboardAdapter(players!!, genre, this)
findViewById<RecyclerView>(R.id.recycler_view)!!.adapter = userScoreboardAdapter
requireView().findViewById<RecyclerView>(R.id.recycler_view)!!.adapter = userScoreboardAdapter
}

/**
* @param position index of the item on click
* go to the profile of the player at index position
*/
override fun onItemClick(position: Int) {
val intent = Intent(this, PublicProfileActivity::class.java)
val intent = Intent(requireActivity(), PublicProfileActivity::class.java)
intent.putExtra("UserId", players?.get(position)?.uid)
intent.putExtra("ScoresOrFollowing", R.string.profile_scores.toString() )
startActivity(intent)
}

override fun onClick(v: View?) {
when(v!!.getId()) {
R.id.btsButton -> {
genre = "BTS"
}
R.id.kpopButton -> {
genre = "kpop"
}
R.id.imagDragonsButton -> {
genre = "Imagine Dragons"
}
R.id.billieEilishButton -> {
genre = "Billie Eilish"
}
R.id.rockButton -> {
genre = "rock"
}
R.id.topTracksButton -> {
genre = "top tracks"
}
}
selectScoreboard()
}
kamilababayeva marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class WelcomeScreenFragment : Fragment(),View.OnClickListener {

view.findViewById<Button>(R.id.welcome_profile).setOnClickListener(this)
view.findViewById<Button>(R.id.welcome_download).setOnClickListener(this)
view.findViewById<Button>(R.id.welcome_scoreboard).setOnClickListener(this)
view.findViewById<Button>(R.id.welcome_search).setOnClickListener(this)

return view
Expand Down Expand Up @@ -71,9 +70,6 @@ class WelcomeScreenFragment : Fragment(),View.OnClickListener {
}
}

private fun switchToScoreboard() {
sendDirectIntent(ScoreBoardActivity::class.java)
}

private fun switchToDownload() {
sendDirectIntent(DownloadActivity::class.java)
Expand All @@ -88,7 +84,6 @@ class WelcomeScreenFragment : Fragment(),View.OnClickListener {
R.id.welcome_search -> switchToSearch()
R.id.welcome_download -> switchToDownload()
R.id.welcome_profile -> switchToProfile()
R.id.welcome_scoreboard -> switchToScoreboard()
}
}
}
Binary file added app/src/main/res/drawable/scoreboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 0 additions & 13 deletions app/src/main/res/layout/fragment_welcome_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@
android:gravity="center"
android:orientation="vertical">


<Button
android:id="@+id/welcome_scoreboard"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_marginTop="10dp"
android:backgroundTint="@color/cg_blue"
android:elevation="10dp"
android:stateListAnimator="@null"
android:text="@string/welcomeScreen_scoreboard"
android:translationZ="10dp"
app:icon="@android:drawable/ic_menu_share" />

<Button
android:id="@+id/welcome_profile"
android:layout_width="200dp"
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/genre_for_scoreboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
android:layout_height="130dp"
android:layout_weight="1"
android:background="@drawable/rounded_button"
android:onClick="selectScoreboard"
android:text="@string/imagine_dragons"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -51,7 +50,6 @@
android:layout_height="130dp"
android:layout_weight="1"
android:background="@drawable/rounded_button"
android:onClick="selectScoreboard"
android:text="@string/billie_eilish"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -76,7 +74,6 @@
android:layout_height="130sp"
android:layout_weight="1"
android:background="@drawable/rounded_button"
android:onClick="selectScoreboard"
android:text="@string/r_o_c_k"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -96,7 +93,6 @@
android:layout_height="130dp"
android:layout_weight="1"
android:background="@drawable/rounded_button"
android:onClick="selectScoreboard"
android:text="@string/bts"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -121,7 +117,6 @@
android:layout_height="130dp"
android:layout_weight="1"
android:background="@drawable/rounded_button"
android:onClick="selectScoreboard"
android:text="@string/t_o_p_t_r_a_c_k_s"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -141,7 +136,6 @@
android:layout_height="130dp"
android:layout_weight="1"
android:background="@drawable/rounded_button"
android:onClick="selectScoreboard"
android:text="@string/k_p_o_p"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/menu/bottom_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
/>


<item
android:id="@+id/scoreboardBtn"
android:title="Scoreboard"
android:icon="@drawable/scoreboard"
/>


</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/navigation/bottom_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
android:label="fragment_home" tools:layout="@layout/fragment_welcome_screen"/>
<fragment android:id="@+id/gameSetupBtn" android:name="ch.sdp.vibester.fragment.GameSetupFragment"
android:label="fragment_settings" tools:layout="@layout/fragment_game_setup"/>
<fragment android:id="@+id/scoreboardBtn" android:name="ch.sdp.vibester.fragment.ScoreBoardFragment"
android:label="fragment_scoreboard" tools:layout="@layout/fragment_scoreboard"/>
</navigation>