calculate percent with voters instead votes

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-07-14 15:32:25 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent a8afb61745
commit 3b4be83ea7
3 changed files with 3 additions and 13 deletions

View File

@ -33,8 +33,7 @@ data class Poll(
val maxVotes: Int,
val votedSelf: List<Int>?,
val numVoters: Int,
val details: List<PollDetails>?,
val totalVotes: Int
val details: List<PollDetails>?
) {
companion object {
const val STATUS_OPEN: Int = 0

View File

@ -133,8 +133,7 @@ class PollRepositoryImpl(private val ncApi: NcApi, private val currentUserProvid
pollResponse.maxVotes,
pollResponse.votedSelf,
pollResponse.numVoters,
pollDetails,
getTotalVotes(pollResponse.votes)
pollDetails
)
}
@ -154,13 +153,5 @@ class PollRepositoryImpl(private val ncApi: NcApi, private val currentUserProvid
pollDetailsResponse.optionId,
)
}
private fun getTotalVotes(votes: Map<String, Int>?): Int {
var totalVotes = 0
votes?.forEach {
totalVotes += it.value
}
return totalVotes
}
}
}

View File

@ -84,7 +84,7 @@ class PollResultsViewModel @Inject constructor() : ViewModel() {
private fun initPollResults(poll: Poll) {
_items.value = ArrayList()
val oneVoteInPercent = HUNDRED / poll.totalVotes
val oneVoteInPercent = HUNDRED / poll.numVoters
poll.options?.forEachIndexed { index, option ->
val votersAmountForThisOption = getVotersAmountForOption(poll, index)