Skip to content

Commit

Permalink
Merge pull request #230 from cuappdev/kevin/quiz-mode
Browse files Browse the repository at this point in the history
Kevin/quiz mode
  • Loading branch information
Matthew Coufal committed Nov 15, 2018
2 parents 83e5946 + c471aeb commit 88506ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Clicker/Extensions/Utils.swift
Expand Up @@ -160,7 +160,7 @@ func buildMCResultModelType(from poll: Poll) -> PollOptionsModelType {
let percentSelected = totalNumResults > 0 ? Float(numSelected) / totalNumResults : 0
var isSelected = false
if let selected = poll.getSelected() as? String {
isSelected = option == selected
isSelected = mcOptionKey == selected || selected == option
}
let resultModel = MCResultModel(option: option, numSelected: Int(numSelected), percentSelected: percentSelected, isSelected: isSelected, choiceIndex: index)
mcResultModels.append(resultModel)
Expand Down
12 changes: 6 additions & 6 deletions Clicker/Models/Parsers/PollParser.swift
Expand Up @@ -28,11 +28,11 @@ class PollParser: Parser {
? .multipleChoice
: .freeResponse
let state: PollState = json[ParserKeys.sharedKey].boolValue ? .shared : .ended
var answer: String? = nil
let poll = Poll(id: id, text: text, questionType: questionType, options: options, results: results, state: state, correctAnswer: correctAnswer)
if let unwrappedAnswer = json[ParserKeys.answerKey].string, let answerDict = results[unwrappedAnswer], let answerText = answerDict[ParserKeys.textKey].string {
answer = answerText
poll.updateSelected(mcChoice: answerText)
}
return Poll(id: id, text: text, questionType: questionType, options: options, results: results, state: state, correctAnswer: correctAnswer)
return poll
}

static func parseItem(json: JSON, state: PollState) -> Poll {
Expand All @@ -49,10 +49,10 @@ class PollParser: Parser {
let questionType: QuestionType = json[ParserKeys.typeKey].stringValue == Identifiers.multipleChoiceIdentifier
? .multipleChoice
: .freeResponse
var answer: String?
let poll = Poll(id: id, text: text, questionType: questionType, options: options, results: results, state: state, correctAnswer: correctAnswer)
if let unwrappedAnswer = json[ParserKeys.answerKey].string, let answerDict = results[unwrappedAnswer], let answerText = answerDict[ParserKeys.textKey].string {
answer = answerText
poll.updateSelected(mcChoice: answerText)
}
return Poll(id: id, text: text, questionType: questionType, options: options, results: results, state: state, correctAnswer: correctAnswer)
return poll
}
}
13 changes: 5 additions & 8 deletions Clicker/Views/Cards/MCResultCell.swift
Expand Up @@ -24,8 +24,8 @@ class MCResultCell: UICollectionViewCell {
var correctAnswer: String?
var percentSelected: Float!
var highlightViewWidthConstraint: Constraint!
var didLayoutConstraints: Bool = false
var missedCorrectAnswer: Bool = false
var didLayoutConstraints = false
var showCorrectAnswer = false

// MARK: - Constants
let labelFontSize: CGFloat = 13
Expand Down Expand Up @@ -122,14 +122,14 @@ class MCResultCell: UICollectionViewCell {
optionLabel.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(optionLabelHorizontalPadding)
make.centerY.equalToSuperview()
if missedCorrectAnswer {
if showCorrectAnswer {
make.width.equalTo(optionLabelWidth >= maxWidth ? maxWidth : optionLabelWidth)
} else {
make.trailing.equalTo(numSelectedLabel).inset(optionLabelHorizontalPadding)
}
}

if missedCorrectAnswer {
if showCorrectAnswer {
checkImageView.snp.makeConstraints { make in
make.width.height.equalTo(checkImageViewLength)
make.leading.equalTo(optionLabel.snp.trailing).offset(optionLabelHorizontalPadding)
Expand Down Expand Up @@ -160,21 +160,18 @@ class MCResultCell: UICollectionViewCell {
if let correctAnswer = correctAnswer {
if correctAnswer != "" {
if answer == correctAnswer {
missedCorrectAnswer = !isSelected
showCorrectAnswer = true
highlightView.backgroundColor = isSelected ? .clickerGreen0 : .clickerGrey5
optionLabel.textColor = .black
} else {
highlightView.backgroundColor = isSelected ? .grapefruit : .clickerGrey5
optionLabel.textColor = isSelected ? .black : .clickerGrey2
missedCorrectAnswer = false
}
} else {
highlightView.backgroundColor = isSelected ? .clickerGreen0 : .clickerGreen1
missedCorrectAnswer = false
}
} else {
highlightView.backgroundColor = isSelected ? .clickerGreen0 : .clickerGreen1
missedCorrectAnswer = false
}
}
}
Expand Down

0 comments on commit 88506ba

Please sign in to comment.