Merge branch 'develop' into flescio/1040-poll_detail

# Conflicts:
#	Riot/Assets/en.lproj/Vector.strings
#	Riot/Generated/Strings.swift
This commit is contained in:
Flavio Alescio
2023-01-25 15:49:40 +01:00
95 changed files with 714 additions and 957 deletions
@@ -139,17 +139,21 @@ extension TimelinePollDetails {
closed: poll.isClosed,
startDate: poll.startDate,
totalAnswerCount: poll.totalAnswerCount,
type: Self.pollKindToTimelinePollType(poll.kind),
type: poll.kind.timelinePollType,
eventType: eventType,
maxAllowedSelections: poll.maxAllowedSelections,
hasBeenEdited: poll.hasBeenEdited,
hasDecryptionError: poll.hasDecryptionError)
}
private static func pollKindToTimelinePollType(_ kind: PollKind) -> TimelinePollType {
let mapping = [PollKind.disclosed: TimelinePollType.disclosed,
PollKind.undisclosed: TimelinePollType.undisclosed]
return mapping[kind] ?? .disclosed
}
private extension PollKind {
var timelinePollType: TimelinePollType {
switch self {
case .disclosed:
return .disclosed
case .undisclosed:
return .undisclosed
}
}
}
@@ -71,33 +71,9 @@ struct TimelinePollDetails {
var type: TimelinePollType
var eventType: TimelinePollEventType
var maxAllowedSelections: UInt
var hasBeenEdited = true
var hasBeenEdited: Bool
var hasDecryptionError: Bool
init(id: String,
question: String,
answerOptions: [TimelinePollAnswerOption],
closed: Bool,
startDate: Date,
totalAnswerCount: UInt,
type: TimelinePollType,
eventType: TimelinePollEventType,
maxAllowedSelections: UInt,
hasBeenEdited: Bool,
hasDecryptionError: Bool) {
self.id = id
self.question = question
self.answerOptions = answerOptions
self.closed = closed
self.startDate = startDate
self.totalAnswerCount = totalAnswerCount
self.type = type
self.eventType = eventType
self.maxAllowedSelections = maxAllowedSelections
self.hasBeenEdited = hasBeenEdited
self.hasDecryptionError = hasDecryptionError
}
var hasCurrentUserVoted: Bool {
answerOptions.contains(where: \.selected)
}
@@ -25,23 +25,26 @@ struct TimelinePollAnswerOptionButton: View {
let poll: TimelinePollDetails
let answerOption: TimelinePollAnswerOption
let action: () -> Void
let action: (() -> Void)?
// MARK: Public
var body: some View {
Button(action: action) {
Button {
action?()
} label: {
let rect = RoundedRectangle(cornerRadius: 4.0)
answerOptionLabel
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 8.0)
.padding(.top, 12.0)
.padding(.bottom, 12.0)
.padding(.bottom, 8.0)
.clipShape(rect)
.overlay(rect.stroke(borderAccentColor, lineWidth: 1.0))
.accentColor(progressViewAccentColor)
}
.accessibilityIdentifier("PollAnswerOption\(optionIndex)")
.disabled(action == nil)
}
var answerOptionLabel: some View {
@@ -60,23 +63,20 @@ struct TimelinePollAnswerOptionButton: View {
Spacer()
Image(uiImage: Asset.Images.pollWinnerIcon.image)
}
if poll.shouldDiscloseResults {
Text(answerOption.count == 1 ? VectorL10n.pollTimelineOneVote : VectorL10n.pollTimelineVotesCount(Int(answerOption.count)))
.font(theme.fonts.footnote)
.foregroundColor(poll.closed && answerOption.winner ? theme.colors.accent : theme.colors.secondaryContent)
.accessibilityIdentifier("PollAnswerOption\(optionIndex)Count")
}
}
if poll.type == .disclosed || poll.closed {
HStack {
ProgressView(value: Double(poll.shouldDiscloseResults ? answerOption.count : 0),
total: Double(poll.totalAnswerCount))
.progressViewStyle(LinearProgressViewStyle())
.scaleEffect(x: 1.0, y: 1.2, anchor: .center)
.accessibilityIdentifier("PollAnswerOption\(optionIndex)Progress")
if poll.shouldDiscloseResults {
Text(answerOption.count == 1 ? VectorL10n.pollTimelineOneVote : VectorL10n.pollTimelineVotesCount(Int(answerOption.count)))
.font(theme.fonts.footnote)
.foregroundColor(poll.closed && answerOption.winner ? theme.colors.accent : theme.colors.secondaryContent)
.accessibilityIdentifier("PollAnswerOption\(optionIndex)Count")
}
}
ProgressView(value: Double(poll.shouldDiscloseResults ? answerOption.count : 0), total: Double(poll.totalAnswerCount))
.progressViewStyle(LinearProgressViewStyle.linear)
.scaleEffect(x: 1.0, y: 1.2, anchor: .center)
.accessibilityIdentifier("PollAnswerOption\(optionIndex)Progress")
}
}
}
@@ -143,6 +143,7 @@ struct TimelinePollAnswerOptionButton_Previews: PreviewProvider {
}
}
}
.padding()
}
static func buildPoll(closed: Bool, type: TimelinePollType) -> TimelinePollDetails {