fix: poll option UI reuse issue
This commit is contained in:
parent
11cee6df35
commit
d79666679a
|
@ -73,9 +73,12 @@ extension PollSection {
|
|||
switch state {
|
||||
case .hidden:
|
||||
cell.optionPercentageLabel.isHidden = true
|
||||
cell.voteProgressStripView.isHidden = true
|
||||
cell.voteProgressStripView.setProgress(0.0, animated: false)
|
||||
case .reveal(let voted, let percentage, let animated):
|
||||
cell.optionPercentageLabel.isHidden = false
|
||||
cell.optionPercentageLabel.text = String(Int(100 * percentage)) + "%"
|
||||
cell.voteProgressStripView.isHidden = false
|
||||
cell.voteProgressStripView.tintColor = voted ? Asset.Colors.Background.Poll.highlight.color : Asset.Colors.Background.Poll.disabled.color
|
||||
cell.voteProgressStripView.setProgress(CGFloat(percentage), animated: animated)
|
||||
}
|
||||
|
|
|
@ -297,7 +297,7 @@ extension StatusSection {
|
|||
.map { option -> PollItem in
|
||||
let attribute: PollItem.Attribute = {
|
||||
let selectState: PollItem.Attribute.SelectState = {
|
||||
// make isPollVoted check later to make only local change possible
|
||||
// make isPollVoted check later to make the local change possible
|
||||
if !votedOptions.isEmpty {
|
||||
return votedOptions.contains(option) ? .on : .off
|
||||
} else if poll.expired {
|
||||
|
@ -309,7 +309,15 @@ extension StatusSection {
|
|||
}
|
||||
}()
|
||||
let voteState: PollItem.Attribute.VoteState = {
|
||||
guard isPollVoted else { return .hidden }
|
||||
var needsReveal: Bool
|
||||
if poll.expired {
|
||||
needsReveal = true
|
||||
} else if isPollVoted {
|
||||
needsReveal = true
|
||||
} else {
|
||||
needsReveal = false
|
||||
}
|
||||
guard needsReveal else { return .hidden }
|
||||
let percentage: Double = {
|
||||
guard poll.votesCount.intValue > 0 else { return 0.0 }
|
||||
return Double(option.votesCount?.intValue ?? 0) / Double(poll.votesCount.intValue)
|
||||
|
|
|
@ -103,12 +103,16 @@ extension StatusTableViewCell {
|
|||
extension StatusTableViewCell: UITableViewDelegate {
|
||||
func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
|
||||
if tableView === statusView.pollTableView, let diffableDataSource = statusView.pollTableViewDataSource {
|
||||
var pollID: String?
|
||||
defer {
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath: %s. PollID: %s", ((#file as NSString).lastPathComponent), #line, #function, indexPath.debugDescription, pollID ?? "<nil>")
|
||||
}
|
||||
guard let item = diffableDataSource.itemIdentifier(for: indexPath),
|
||||
case let .opion(objectID, _) = item,
|
||||
let option = delegate?.managedObjectContext.object(with: objectID) as? PollOption else {
|
||||
return false
|
||||
}
|
||||
|
||||
pollID = option.poll.id
|
||||
return !option.poll.expired
|
||||
} else {
|
||||
return true
|
||||
|
@ -117,7 +121,10 @@ extension StatusTableViewCell: UITableViewDelegate {
|
|||
|
||||
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
||||
if tableView === statusView.pollTableView, let diffableDataSource = statusView.pollTableViewDataSource {
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath", ((#file as NSString).lastPathComponent), #line, #function, indexPath.debugDescription)
|
||||
var pollID: String?
|
||||
defer {
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath: %s. PollID: %s", ((#file as NSString).lastPathComponent), #line, #function, indexPath.debugDescription, pollID ?? "<nil>")
|
||||
}
|
||||
|
||||
guard let context = delegate?.context else { return nil }
|
||||
guard let activeMastodonAuthenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else { return nil }
|
||||
|
@ -127,6 +134,7 @@ extension StatusTableViewCell: UITableViewDelegate {
|
|||
return nil
|
||||
}
|
||||
let poll = option.poll
|
||||
pollID = poll.id
|
||||
|
||||
// disallow select when: poll expired OR user voted remote OR user voted local
|
||||
let userID = activeMastodonAuthenticationBox.userID
|
||||
|
|
Loading…
Reference in New Issue