mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
calculate percent with voters instead votes
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
a8afb61745
commit
3b4be83ea7
@ -33,8 +33,7 @@ data class Poll(
|
|||||||
val maxVotes: Int,
|
val maxVotes: Int,
|
||||||
val votedSelf: List<Int>?,
|
val votedSelf: List<Int>?,
|
||||||
val numVoters: Int,
|
val numVoters: Int,
|
||||||
val details: List<PollDetails>?,
|
val details: List<PollDetails>?
|
||||||
val totalVotes: Int
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val STATUS_OPEN: Int = 0
|
const val STATUS_OPEN: Int = 0
|
||||||
|
@ -133,8 +133,7 @@ class PollRepositoryImpl(private val ncApi: NcApi, private val currentUserProvid
|
|||||||
pollResponse.maxVotes,
|
pollResponse.maxVotes,
|
||||||
pollResponse.votedSelf,
|
pollResponse.votedSelf,
|
||||||
pollResponse.numVoters,
|
pollResponse.numVoters,
|
||||||
pollDetails,
|
pollDetails
|
||||||
getTotalVotes(pollResponse.votes)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,13 +153,5 @@ class PollRepositoryImpl(private val ncApi: NcApi, private val currentUserProvid
|
|||||||
pollDetailsResponse.optionId,
|
pollDetailsResponse.optionId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTotalVotes(votes: Map<String, Int>?): Int {
|
|
||||||
var totalVotes = 0
|
|
||||||
votes?.forEach {
|
|
||||||
totalVotes += it.value
|
|
||||||
}
|
|
||||||
return totalVotes
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class PollResultsViewModel @Inject constructor() : ViewModel() {
|
|||||||
private fun initPollResults(poll: Poll) {
|
private fun initPollResults(poll: Poll) {
|
||||||
_items.value = ArrayList()
|
_items.value = ArrayList()
|
||||||
|
|
||||||
val oneVoteInPercent = HUNDRED / poll.totalVotes
|
val oneVoteInPercent = HUNDRED / poll.numVoters
|
||||||
|
|
||||||
poll.options?.forEachIndexed { index, option ->
|
poll.options?.forEachIndexed { index, option ->
|
||||||
val votersAmountForThisOption = getVotersAmountForOption(poll, index)
|
val votersAmountForThisOption = getVotersAmountForOption(poll, index)
|
||||||
|
Loading…
Reference in New Issue
Block a user