Browse Source

calculate percent with voters instead votes

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 3 years ago
parent
commit
3b4be83ea7

+ 1 - 2
app/src/main/java/com/nextcloud/talk/polls/model/Poll.kt

@@ -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

+ 1 - 10
app/src/main/java/com/nextcloud/talk/polls/repositories/PollRepositoryImpl.kt

@@ -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
-        }
     }
 }

+ 1 - 1
app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollResultsViewModel.kt

@@ -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)