mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +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 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
|
||||||
|
@ -134,6 +134,7 @@ class PollRepositoryImpl(private val ncApi: NcApi, private val currentUserProvid
|
|||||||
pollResponse.votedSelf,
|
pollResponse.votedSelf,
|
||||||
pollResponse.numVoters,
|
pollResponse.numVoters,
|
||||||
pollDetails,
|
pollDetails,
|
||||||
|
getTotalVotes(pollResponse.votes)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,5 +154,13 @@ 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ class PollMainDialogFragment : DialogFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showResultsScreen(poll: Poll) {
|
private fun showResultsScreen(poll: Poll) {
|
||||||
initVotersAmount(poll.numVoters)
|
initVotesAmount(poll.totalVotes)
|
||||||
|
|
||||||
val contentFragment = PollResultsFragment.newInstance(
|
val contentFragment = PollResultsFragment.newInstance(
|
||||||
user
|
user
|
||||||
@ -126,11 +126,11 @@ class PollMainDialogFragment : DialogFragment() {
|
|||||||
transaction.commit()
|
transaction.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initVotersAmount(numVoters: Int) {
|
private fun initVotesAmount(totalVotes: Int) {
|
||||||
binding.pollDetailsText.visibility = View.VISIBLE
|
binding.pollDetailsText.visibility = View.VISIBLE
|
||||||
binding.pollDetailsText.text = String.format(
|
binding.pollDetailsText.text = String.format(
|
||||||
resources.getString(R.string.polls_amount_voters),
|
resources.getString(R.string.polls_amount_voters),
|
||||||
numVoters
|
totalVotes
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +84,7 @@ class PollResultsViewModel @Inject constructor() : ViewModel() {
|
|||||||
private fun initPollResults(poll: Poll) {
|
private fun initPollResults(poll: Poll) {
|
||||||
_items.value = ArrayList()
|
_items.value = ArrayList()
|
||||||
|
|
||||||
val votersAmount = getVotersAmount(poll)
|
val oneVoteInPercent = HUNDRED / poll.totalVotes
|
||||||
val oneVoteInPercent = HUNDRED / votersAmount
|
|
||||||
|
|
||||||
poll.options?.forEachIndexed { index, option ->
|
poll.options?.forEachIndexed { index, option ->
|
||||||
val votersAmountForThisOption = getVotersAmountForOption(poll, index)
|
val votersAmountForThisOption = getVotersAmountForOption(poll, index)
|
||||||
@ -115,16 +114,6 @@ class PollResultsViewModel @Inject constructor() : ViewModel() {
|
|||||||
_items.value = tempList
|
_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 {
|
private fun getVotersAmountForOption(poll: Poll, index: Int): Int {
|
||||||
var votersAmountForThisOption: Int? = 0
|
var votersAmountForThisOption: Int? = 0
|
||||||
if (poll.details != null) {
|
if (poll.details != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user