mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
fix percentage calculation for multiselect polls
for multiselect polls the total votes must be taken instead amount of voters (one voter can have more than 1 votes..) Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
9e8dbb70f3
commit
cedbcaefee
@ -33,7 +33,8 @@ data class Poll(
|
||||
val maxVotes: Int,
|
||||
val votedSelf: List<Int>?,
|
||||
val numVoters: Int,
|
||||
val details: List<PollDetails>?
|
||||
val details: List<PollDetails>?,
|
||||
val totalVotes: Int
|
||||
) {
|
||||
companion object {
|
||||
const val STATUS_OPEN: Int = 0
|
||||
|
@ -134,6 +134,7 @@ class PollRepositoryImpl(private val ncApi: NcApi, private val currentUserProvid
|
||||
pollResponse.votedSelf,
|
||||
pollResponse.numVoters,
|
||||
pollDetails,
|
||||
getTotalVotes(pollResponse.votes)
|
||||
)
|
||||
}
|
||||
|
||||
@ -153,5 +154,13 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class PollMainDialogFragment : DialogFragment() {
|
||||
}
|
||||
|
||||
private fun showResultsScreen(poll: Poll) {
|
||||
initVotersAmount(poll.numVoters)
|
||||
initVotesAmount(poll.totalVotes)
|
||||
|
||||
val contentFragment = PollResultsFragment.newInstance(
|
||||
user
|
||||
@ -126,11 +126,11 @@ class PollMainDialogFragment : DialogFragment() {
|
||||
transaction.commit()
|
||||
}
|
||||
|
||||
private fun initVotersAmount(numVoters: Int) {
|
||||
private fun initVotesAmount(totalVotes: Int) {
|
||||
binding.pollDetailsText.visibility = View.VISIBLE
|
||||
binding.pollDetailsText.text = String.format(
|
||||
resources.getString(R.string.polls_amount_voters),
|
||||
numVoters
|
||||
totalVotes
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -84,8 +84,7 @@ class PollResultsViewModel @Inject constructor() : ViewModel() {
|
||||
private fun initPollResults(poll: Poll) {
|
||||
_items.value = ArrayList()
|
||||
|
||||
val votersAmount = getVotersAmount(poll)
|
||||
val oneVoteInPercent = HUNDRED / votersAmount
|
||||
val oneVoteInPercent = HUNDRED / poll.totalVotes
|
||||
|
||||
poll.options?.forEachIndexed { index, option ->
|
||||
val votersAmountForThisOption = getVotersAmountForOption(poll, index)
|
||||
@ -115,16 +114,6 @@ class PollResultsViewModel @Inject constructor() : ViewModel() {
|
||||
_items.value = tempList
|
||||
}
|
||||
|
||||
private fun getVotersAmount(poll: Poll): Int {
|
||||
var votersAmount = 0
|
||||
if (poll.details != null) {
|
||||
votersAmount = poll.details.size
|
||||
} else if (poll.votes != null) {
|
||||
votersAmount = poll.numVoters
|
||||
}
|
||||
return votersAmount
|
||||
}
|
||||
|
||||
private fun getVotersAmountForOption(poll: Poll, index: Int): Int {
|
||||
var votersAmountForThisOption: Int? = 0
|
||||
if (poll.details != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user