diff --git a/Mastodon/Diffiable/Section/PollSection.swift b/Mastodon/Diffiable/Section/PollSection.swift index d7a7b43f..45da63bd 100644 --- a/Mastodon/Diffiable/Section/PollSection.swift +++ b/Mastodon/Diffiable/Section/PollSection.swift @@ -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) } diff --git a/Mastodon/Diffiable/Section/StatusSection.swift b/Mastodon/Diffiable/Section/StatusSection.swift index 3c15996d..4863f475 100644 --- a/Mastodon/Diffiable/Section/StatusSection.swift +++ b/Mastodon/Diffiable/Section/StatusSection.swift @@ -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) diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift index e8500e05..64ffb167 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift @@ -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 ?? "") + } 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 ?? "") + } 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