forked from shadowfacts/Tusker
Show percentage of voters for multi-choice polls
This commit is contained in:
parent
aaa031f212
commit
073a1afbde
|
@ -101,6 +101,10 @@ struct InstanceFeatures {
|
|||
hasMastodonVersion(3, 5, 0)
|
||||
}
|
||||
|
||||
var pollVotersCount: Bool {
|
||||
instanceType.isMastodon
|
||||
}
|
||||
|
||||
mutating func update(instance: Instance, nodeInfo: NodeInfo?) {
|
||||
let ver = instance.version.lowercased()
|
||||
if ver.contains("glitch") {
|
||||
|
|
|
@ -15,7 +15,7 @@ class PollOptionView: UIView {
|
|||
|
||||
let checkbox: PollOptionCheckboxView
|
||||
|
||||
init(poll: Poll, option: Poll.Option) {
|
||||
init(poll: Poll, option: Poll.Option, mastodonController: MastodonController) {
|
||||
checkbox = PollOptionCheckboxView(multiple: poll.multiple)
|
||||
|
||||
super.init(frame: .zero)
|
||||
|
@ -48,7 +48,14 @@ class PollOptionView: UIView {
|
|||
|
||||
if (poll.voted ?? false) || poll.effectiveExpired,
|
||||
let optionVotes = option.votesCount {
|
||||
let frac = poll.votesCount == 0 ? 0 : CGFloat(optionVotes) / CGFloat(poll.votesCount)
|
||||
let frac: CGFloat
|
||||
if poll.multiple,
|
||||
let votersCount = poll.votersCount,
|
||||
mastodonController.instanceFeatures.pollVotersCount {
|
||||
frac = votersCount == 0 ? 0 : CGFloat(optionVotes) / CGFloat(votersCount)
|
||||
} else {
|
||||
frac = poll.votesCount == 0 ? 0 : CGFloat(optionVotes) / CGFloat(poll.votesCount)
|
||||
}
|
||||
let percent = String(format: "%.0f%%", frac * 100)
|
||||
|
||||
percentLabel.isHidden = false
|
||||
|
|
|
@ -11,6 +11,8 @@ import Pachyderm
|
|||
|
||||
class PollOptionsView: UIControl {
|
||||
|
||||
var mastodonController: MastodonController!
|
||||
|
||||
var checkedOptionIndices: [Int] {
|
||||
options.enumerated().filter { $0.element.checkbox.isChecked }.map(\.offset)
|
||||
}
|
||||
|
@ -62,7 +64,7 @@ class PollOptionsView: UIControl {
|
|||
options.forEach { $0.removeFromSuperview() }
|
||||
|
||||
options = poll.options.enumerated().map { (index, opt) in
|
||||
let optionView = PollOptionView(poll: poll, option: opt)
|
||||
let optionView = PollOptionView(poll: poll, option: opt, mastodonController: mastodonController)
|
||||
optionView.checkbox.readOnly = !isEnabled
|
||||
optionView.checkbox.isChecked = poll.ownVotes?.contains(index) ?? false
|
||||
optionView.checkbox.voted = poll.voted ?? false
|
||||
|
|
|
@ -101,6 +101,7 @@ class StatusPollView: UIView {
|
|||
canVote = true
|
||||
}
|
||||
|
||||
optionsView.mastodonController = mastodonController
|
||||
optionsView.isEnabled = canVote
|
||||
optionsView.updateUI(poll: poll)
|
||||
|
||||
|
|
Loading…
Reference in New Issue