-
Notifications
You must be signed in to change notification settings - Fork 0
Jwen/scoreboard real data per genre #264
Changes from all commits
aecf5e9
ed32d1d
58d1bc6
d1749fd
6ebac72
5a17535
c6fc843
034d8b1
d50f08b
1c2f01a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ class UserScoreboardAdapterTest { | |
val players: MutableList<User> = arrayListOf() | ||
players.addAll(listOf(user1, user2)) | ||
val userScoreboardViewHolder: RecyclerView.Adapter<UserScoreboardAdapter.PlayerViewHolder> = | ||
UserScoreboardAdapter(players) | ||
UserScoreboardAdapter(players, "rock") | ||
assertThat(userScoreboardViewHolder.itemCount, equalTo(2)) | ||
} | ||
|
||
|
@@ -29,7 +29,7 @@ class UserScoreboardAdapterTest { | |
val players: MutableList<User> = arrayListOf() | ||
players.addAll(listOf(user1, user2)) | ||
val userScoreboardViewHolder: RecyclerView.Adapter<UserScoreboardAdapter.PlayerViewHolder> = | ||
UserScoreboardAdapter(players) | ||
UserScoreboardAdapter(players, "BTS") | ||
val defaultType = 0 | ||
assertThat(userScoreboardViewHolder.getItemViewType(0), equalTo(defaultType)) | ||
} | ||
|
@@ -43,7 +43,7 @@ class UserScoreboardAdapterTest { | |
val recyclerView = RecyclerView(ApplicationProvider.getApplicationContext()) | ||
recyclerView.layoutManager = | ||
LinearLayoutManager(ApplicationProvider.getApplicationContext()) | ||
val playerAdapter = UserScoreboardAdapter(players) | ||
val playerAdapter = UserScoreboardAdapter(players, "Imagine Dragons") | ||
recyclerView.adapter = playerAdapter | ||
val newPlayers: MutableList<User> = arrayListOf() | ||
newPlayers.add(User("test3","https://images.app.goo.gl/YkBi16zwyjB7ejj96", "[email protected]")) | ||
|
@@ -60,7 +60,7 @@ class UserScoreboardAdapterTest { | |
val recyclerView = RecyclerView(ApplicationProvider.getApplicationContext()) | ||
recyclerView.layoutManager = | ||
LinearLayoutManager(ApplicationProvider.getApplicationContext()) | ||
val playerAdapter = UserScoreboardAdapter(players) | ||
val playerAdapter = UserScoreboardAdapter(players, "Billie Eilish") | ||
val player3 = User("test3","https://images.app.goo.gl/YkBi16zwyjB7ejj96", "[email protected]") | ||
val updatedList = arrayListOf(player3) | ||
playerAdapter.addPlayers(updatedList) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,12 +163,12 @@ class GameSetupActivity : AppCompatActivity(), AdapterView.OnItemSelectedListene | |
var mode = "" | ||
val uri = LastfmUri() | ||
when (view.id) { | ||
R.id.btsButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "BTS"; mode = "BTS" } | ||
R.id.kpopButton -> {method = LastfmMethod.BY_TAG.method; tag = "kpop"; mode = "kpop" } | ||
R.id.imagDragonsButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "Imagine Dragons"; mode = "Imagine Dragons"} | ||
R.id.rockButton-> {method = LastfmMethod.BY_TAG.method; tag = "rock"; mode = "rock" } | ||
R.id.topTracksButton -> {method = LastfmMethod.BY_CHART.method; mode = "top tracks"} | ||
R.id.billieEilishButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "Billie Eilish"; mode = "billie eilish"} | ||
R.id.btsButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "BTS"; mode = R.string.bts.toString() } | ||
R.id.kpopButton -> {method = LastfmMethod.BY_TAG.method; tag = "kpop"; mode = R.string.kpop.toString() } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 5 locations. Consider refactoring. |
||
R.id.imagDragonsButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "Imagine Dragons"; mode = R.string.imagine_dragons.toString()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 5 locations. Consider refactoring. |
||
R.id.rockButton-> {method = LastfmMethod.BY_TAG.method; tag = "rock"; mode = R.string.rock.toString() } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 5 locations. Consider refactoring. |
||
R.id.topTracksButton -> {method = LastfmMethod.BY_CHART.method; mode = R.string.top_tracks.toString()} | ||
R.id.billieEilishButton -> {method = LastfmMethod.BY_ARTIST.method; artist = "Billie Eilish"; mode = R.string.billie_eilish.toString()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 5 locations. Consider refactoring. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to refactor these lines in, for example, a function that takes the "method" and the "mode" as parameters and the artist/tag as an optional String parameter? It's not urgent but it could solve the detected duplication. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will keep this in mind when we do the general refactoring. |
||
} | ||
uri.method = method | ||
uri.artist = artist | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,9 @@ import com.google.firebase.database.ValueEventListener | |
|
||
class ScoreBoardActivity : AppCompatActivity() { | ||
private val dbRef: DatabaseReference = Database.get().getReference("users") | ||
private var players: List<User>? = null | ||
private var players: MutableList<User>? = null | ||
private var userScoreboardAdapter: UserScoreboardAdapter? = null | ||
private var genre: String = "" | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
@@ -33,19 +34,16 @@ class ScoreBoardActivity : AppCompatActivity() { | |
players = ArrayList() | ||
} | ||
|
||
/** | ||
* TODO: replace "ranking" by appropriate label | ||
*/ | ||
fun selectScoreboard(view: View) { | ||
var sortedBy = "" | ||
val ranking = "ranking" | ||
var sortedBy = "scores/" | ||
// can't use R.string for genre (getOrDefault in setScore in UserScoreboardAdapter) | ||
when (view.id) { | ||
R.id.btsButton -> sortedBy = ranking | ||
R.id.kpopButton -> sortedBy = ranking | ||
R.id.imagDragonsButton -> sortedBy = ranking | ||
R.id.billieEilishButton -> sortedBy = ranking | ||
R.id.rockButton -> sortedBy = ranking | ||
R.id.topTracksButton -> sortedBy = ranking | ||
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"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we put genre into the strings as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried but that doesn't work, I explained in the comment in line 39. |
||
} | ||
|
||
findViewById<ConstraintLayout>(R.id.genrePerScoreboard).visibility = GONE | ||
|
@@ -57,13 +55,13 @@ class ScoreBoardActivity : AppCompatActivity() { | |
private fun setupRecycleView() { | ||
findViewById<RecyclerView>(R.id.recycler_view).apply { | ||
layoutManager = LinearLayoutManager(context) | ||
adapter = players?.let { UserScoreboardAdapter(it) } | ||
adapter = players?.let { UserScoreboardAdapter(it, genre) } | ||
setHasFixedSize(true) | ||
} | ||
} | ||
|
||
private fun loadPlayersSortedBy(order: String) { | ||
dbRef.orderByChild(order) | ||
private fun loadPlayersSortedBy(genre: String) { | ||
dbRef.orderByChild(genre) | ||
.addValueEventListener(object : ValueEventListener { | ||
override fun onDataChange(snapshots: DataSnapshot) { | ||
for (snapshot in snapshots.children) { | ||
|
@@ -72,6 +70,8 @@ class ScoreBoardActivity : AppCompatActivity() { | |
(players as? ArrayList<User>)?.add(player) | ||
} | ||
} | ||
players = players?.let { replaceRankingByScore(it) } | ||
players = players?.sortedByDescending { it.ranking } as MutableList<User>? | ||
showPlayersPosition(players) | ||
} | ||
|
||
|
@@ -80,8 +80,18 @@ class ScoreBoardActivity : AppCompatActivity() { | |
}) | ||
} | ||
|
||
private fun showPlayersPosition(players: List<User>?) { | ||
userScoreboardAdapter = UserScoreboardAdapter(players!!) | ||
private fun replaceRankingByScore(list: MutableList<User>): MutableList<User> { | ||
val iterator = list.listIterator() | ||
while(iterator.hasNext()) { | ||
val player = iterator.next() | ||
player.ranking = player.scores.getOrDefault(genre, 0) | ||
iterator.set(player) | ||
} | ||
return list | ||
} | ||
|
||
private fun showPlayersPosition(players: MutableList<User>?) { | ||
userScoreboardAdapter = UserScoreboardAdapter(players!!, genre) | ||
findViewById<RecyclerView>(R.id.recycler_view)!!.adapter = userScoreboardAdapter | ||
} | ||
} |
There was a problem hiding this comment.
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 5 locations. Consider refactoring.