From c45abdb14322a15d6c1b5dbc14a6d19079b087b9 Mon Sep 17 00:00:00 2001 From: AlbatovK Date: Sat, 16 Apr 2022 14:48:56 +0600 Subject: [PATCH] :hammer: Score fix --- .idea/deploymentTargetDropDown.xml | 17 ----------------- .idea/misc.xml | 2 +- .../kquiz/model/data/info/ClientInfo.kt | 4 ++++ .../kquiz/ui/adapter/client/ResultAdapter.kt | 12 +++--------- .../ui/fragments/result/ResultViewModel.kt | 4 +--- 5 files changed, 9 insertions(+), 30 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index ea11fc6..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 013d7e6..ba2afcd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -16,7 +16,7 @@ - + diff --git a/app/src/main/java/com/albatros/kquiz/model/data/info/ClientInfo.kt b/app/src/main/java/com/albatros/kquiz/model/data/info/ClientInfo.kt index 57f9382..b7ec8db 100644 --- a/app/src/main/java/com/albatros/kquiz/model/data/info/ClientInfo.kt +++ b/app/src/main/java/com/albatros/kquiz/model/data/info/ClientInfo.kt @@ -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 = HashMap() diff --git a/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ResultAdapter.kt b/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ResultAdapter.kt index 32f6bb3..070eb2c 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ResultAdapter.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/adapter/client/ResultAdapter.kt @@ -38,17 +38,11 @@ class ResultAdapter(private val clients: MutableList) : 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 diff --git a/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultViewModel.kt b/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultViewModel.kt index 3428b1c..e123840 100644 --- a/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultViewModel.kt +++ b/app/src/main/java/com/albatros/kquiz/ui/fragments/result/ResultViewModel.kt @@ -34,9 +34,7 @@ class ResultViewModel( private val _usersInfo = MutableLiveData>().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) } }