Skip to content

Commit

Permalink
🔨 Score fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbatovK committed Apr 16, 2022
1 parent 001a85d commit c45abdb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 30 deletions.
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ data class ClientInfo(
@Expose
var started: Boolean = false,

@SerializedName("score")
@Expose
var score: Int = 0,

@SerializedName("questionMap")
@Expose
var questionMap: HashMap<Int, QuestionInfo> = HashMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ class ResultAdapter(private val clients: MutableList<ClientInfo>) :
with(binding) {

binding.root.playFadeInAnimation(R.anim.fade_in_animation)
name.text = it.name

val scr = it.questionMap.values.filter { item -> item.right }.sumOf {
1200 - it.time * 10
}

score.text = scr.toString()
name.text = it.name
score.text = it.score.toString()

place.text = root.context.getString(R.string.place, clients.map {
item -> item.questionMap.values.sumOf { q -> if (q.right) 1200 - q.time * 10 else 0 }
}.indexOf(scr) + 1)
place.text = root.context.getString(R.string.place, clients.map(ClientInfo::score).indexOf(it.score) + 1)

val from = if (it.questionMap.size == 0) 0 else it.questionMap.size - 1
val to = if (it.questionMap.size > 2) it.questionMap.size - 3 else 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class ResultViewModel(

private val _usersInfo = MutableLiveData<List<ClientInfo>>().apply {
viewModelScope.launch(Dispatchers.Main) {
value = api.getClientsInfo(repo.sessionId).sortedByDescending {
it.questionMap.count { item -> item.value.right }
}
value = api.getClientsInfo(repo.sessionId).sortedByDescending(ClientInfo::score)
}
}

Expand Down

0 comments on commit c45abdb

Please sign in to comment.